Author: mareshkau
Date: 2008-05-29 09:56:18 -0400 (Thu, 29 May 2008)
New Revision: 8435
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/UpdateJobGroup.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
Log:
http://jira.jboss.org/jira/browse/JBIDE-675
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/UpdateJobGroup.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/UpdateJobGroup.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/UpdateJobGroup.java 2008-05-29
13:56:18 UTC (rev 8435)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+* Copyright (c) 2007 Red Hat, Inc.
+* Distributed under license by Red Hat, Inc. All rights reserved.
+* This program is made available under the terms of the
+* Eclipse Public License v1.0 which accompanies this distribution,
+* and is available at
http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* Red Hat, Inc. - initial API and implementation
+******************************************************************************/
+package org.jboss.tools.vpe.editor;
+
+
+import org.eclipse.ui.progress.UIJob;
+
+/**
+ * @author mareshkau
+ *
+ * Creates a group of jobs for updating vpe content
+ */
+
+public abstract class UpdateJobGroup extends UIJob {
+
+ /**
+ * Current job identification
+ */
+ private String jobName;
+ /**
+ * Contains indetification for job group
+ */
+ public static final String UPDATE_JOB="UPDATE_JOB"; //$NON-NLS-1$
+
+ /**
+ * Update Job
+ * @param name
+ * @param jobName
+ */
+ public UpdateJobGroup(String name, String jobName) {
+ super(name);
+ setJobName(jobName);
+ }
+
+ public boolean belongsTo(Object family) {
+
+ return UPDATE_JOB.equals(getJobName());
+ }
+ /**
+ * @return the jobName
+ */
+ private String getJobName() {
+ return jobName;
+ }
+ /**
+ * @param jobName the jobName to set
+ */
+ private void setJobName(String jobName) {
+ this.jobName = jobName;
+ }
+
+}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-05-29
12:59:17 UTC (rev 8434)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2008-05-29
13:56:18 UTC (rev 8435)
@@ -11,6 +11,7 @@
package org.jboss.tools.vpe.editor;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
@@ -209,6 +210,10 @@
private XModelTreeListenerSWTSync optionsListener;
// Added by Max Areshkau Fix for JBIDE-1479
private UIJob job = null;
+ private LinkedList<Job> jobQueue;
+ private IProgressMonitor progressMonitor;
+ private Object mutex = new Object();
+
Shell tip;
public final static String MODEL_FLAVOR = ModelTransfer.MODEL; //$NON-NLS-1$
@@ -394,50 +399,94 @@
public boolean isAdapterForType(Object type) {
return type == this;
}
-
// FIX Fox JBIDE-1479 added by Max Areshkau
public void notifyChanged(final INodeNotifier notifier,
- final int eventType, final Object feature, final Object oldValue,
- final Object newValue, final int pos) {
+ final int eventType, final Object feature, final Object oldValue,
+ final Object newValue, final int pos) {
- if (!isVisualEditorVisible()) {
- synced = false;
- return;
- }
+ if (!visualEditorVisible) {
+ synced = false;
+ return;
+ }
- // start job when we modify file in ui thread, without this code
- // changes will be applied with 1 second delay
- Display display = null;
- if (PlatformUI.isWorkbenchRunning())
- display = PlatformUI.getWorkbench().getDisplay();
+ // start job when we modify file in ui thread, without this code
+ // changes will be applied with 1 second delay
+ Display display = null;
+ if (PlatformUI.isWorkbenchRunning())
+ display = PlatformUI.getWorkbench().getDisplay();
- if (display != null && (Thread.currentThread() == display.getThread())) {
- notifyChangedInUiThread(notifier, eventType, feature, oldValue,
- newValue, pos);
- return;
- }
- // start job when we modify file in non ui thread
- if (job != null) {
- job.cancel();
- }
+ if (display != null && (Thread.currentThread() == display.getThread())) {
+// notifyChangedInUiThread(notifier, eventType, feature, oldValue,
+// newValue, pos);
+// return;
+// notifyChangedInUiThread(notifier, eventType, feature, oldValue,
+// newValue, pos);
+// return;
+ UIJob nonUIJob = new
UpdateJobGroup(VpeUIMessages.VPE_UPDATE_JOB_TITLE,UpdateJobGroup.UPDATE_JOB){
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
- job = new UIJob("NotifyChangedJob") {
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- // we checks is job was canceled and if is it true we cancel job
- if (monitor.isCanceled()) {
- return Status.CANCEL_STATUS;
- } else {
- notifyChangedInUiThread(notifier, eventType, feature,
- oldValue, newValue, pos);
- }
- return Status.OK_STATUS;
- }
- };
- job.setPriority(Job.LONG);
- job.schedule(1000L);
- }
+ synchronized (mutex) {
+
+ if (monitor.isCanceled()) {
+ getJobQueue().clear();
+ return Status.CANCEL_STATUS;
+ }
+ monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE, getJobQueue().size());
+ monitor.worked(1);
+ notifyChangedInUiThread(notifier, eventType, feature, oldValue, newValue, pos);
+ if (monitor.isCanceled()) {
+ getJobQueue().clear();
+ return Status.CANCEL_STATUS;
+ }
+
+ getJobQueue().remove(this);
+
+ if(getJobQueue().size()>0) {
+ Job job =getJobQueue().getFirst();
+ job.schedule();
+ }
+ }
+ return Status.OK_STATUS;
+ }};
+ nonUIJob.setPriority(Job.LONG);
+ getJobQueue().addLast(nonUIJob);
+ if(getJobQueue().size()==1) {
+ setProgressMonitor(null);
+ nonUIJob.setProgressGroup(getProgressMonitor(), 100);
+ Job job = getJobQueue().getFirst();
+ job.schedule();
+ } else {
+
+ nonUIJob.setProgressGroup(getProgressMonitor(), 100);
+ }
+
+ return;
+ }
+ // start job when we modify file in non ui thread
+ if (job != null) {
+ job.cancel();
+ }
+
+ job = new UIJob("NotifyChangedJob") {
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ // we checks is job was canceled and if is it true we cancel job
+ if (monitor.isCanceled()) {
+ return Status.CANCEL_STATUS;
+ } else {
+ notifyChangedInUiThread(notifier, eventType, feature,
+ oldValue, newValue, pos);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setPriority(Job.LONG);
+ job.schedule(1000L);
+ }
+
+
public void notifyChangedInUiThread(INodeNotifier notifier, int eventType,
Object feature, Object oldValue, Object newValue, int pos) {
if (switcher == null || !switcher
@@ -591,6 +640,14 @@
}
public void sourceSelectionChanged(boolean showCaret) {
+
+ //we should processed if we have correct view in visual editor,
+ //otherwise we shouldn't process this event
+ if(getJobQueue().size()>0) {
+
+ return;
+ }
+
Point range = sourceEditor.getTextViewer().getSelectedRange();
int anchorPosition = range.x;
int focusPosition = range.x + range.y;
@@ -2817,5 +2874,37 @@
}
synced = true;
}
+ /**
+ * @return the jobQueue
+ */
+ private LinkedList<Job> getJobQueue() {
+
+ if(jobQueue==null) {
+
+ jobQueue = new LinkedList<Job>();
+ }
+ return jobQueue;
+ }
+ /**
+ * @return the progressMonitor
+ */
+ private IProgressMonitor getProgressMonitor() {
+
+ if(progressMonitor==null) {
+
+ progressMonitor = Job.getJobManager().createProgressGroup();
+ }
+
+ return progressMonitor;
+ }
+
+ /**
+ * @param progressMonitor the progressMonitor to set
+ */
+ private void setProgressMonitor(IProgressMonitor progressMonitor) {
+
+ this.progressMonitor = progressMonitor;
+ }
+
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-05-29
12:59:17 UTC (rev 8434)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-05-29
13:56:18 UTC (rev 8435)
@@ -444,6 +444,10 @@
protected nsIDOMNode createNode(Node sourceNode,
nsIDOMNode visualOldContainer) {
boolean registerFlag = isCurrentMainDocument();
+
+ //reads and dispatch events
+ getPageContext().processDisplayEvents();
+
switch (sourceNode.getNodeType()) {
case Node.ELEMENT_NODE:
// Map<?, ?> xmlnsMap = createXmlns((Element) sourceNode);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2008-05-29
12:59:17 UTC (rev 8434)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/context/VpePageContext.java 2008-05-29
13:56:18 UTC (rev 8435)
@@ -20,6 +20,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
@@ -407,5 +408,20 @@
}
return vpeCash;
}
+
+ /**
+ * Processes display events to prevent eclipse froze
+ */
+ public void processDisplayEvents() {
+
+ Display display=null;
+ display = Display.getCurrent();
+ if(display==null) {
+ display=Display.getDefault();
+ }
+ if(display!=null) {
+ while(display.readAndDispatch()){}
+ }
+ }
}
\ No newline at end of file
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2008-05-29
12:59:17 UTC (rev 8434)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/VpeUIMessages.java 2008-05-29
13:56:18 UTC (rev 8435)
@@ -92,6 +92,6 @@
public static String CONFIRM_SELECTION_BAR_DIALOG_TITLE;
public static String CONFIRM_SELECTION_BAR_DIALOG_MESSAGE;
public static String CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE;
+ public static String VPE_UPDATE_JOB_TITLE;
-
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2008-05-29
12:59:17 UTC (rev 8434)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/messages/messages.properties 2008-05-29
13:56:18 UTC (rev 8435)
@@ -52,3 +52,4 @@
CONFIRM_SELECTION_BAR_DIALOG_TITLE=Confirm hide selection bar
CONFIRM_SELECTION_BAR_DIALOG_MESSAGE=Hide selection bar ?
CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE=Always hide selection bar without prompt
+VPE_UPDATE_JOB_TITLE=Visual Editor View Update