Author: dgolovin
Date: 2011-12-01 15:09:36 -0500 (Thu, 01 Dec 2011)
New Revision: 36847
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.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
Log:
reverted patch with full document rebuild optimization, because it has problem with
loosing events
applied previous patch which seems to have right behavior without optimization
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java 2011-12-01
19:48:11 UTC (rev 36846)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java 2011-12-01
20:09:36 UTC (rev 36847)
@@ -1,40 +0,0 @@
-package org.jboss.tools.vpe.editor;
-
-public class ActiveEditorSwitcher {
- public static final int ACTIVE_EDITOR_CANNOT = 0;
- public static final int ACTIVE_EDITOR_NONE = 1;
- public static final int ACTIVE_EDITOR_SOURCE = 2;
- public static final int ACTIVE_EDITOR_VISUAL = 3;
-
- private int type = ACTIVE_EDITOR_CANNOT;
- private VpeController vpeController;
- private VpeEditorPart editPart;
-
- public ActiveEditorSwitcher(VpeController vpeController, VpeEditorPart editPart) {
- this.vpeController = vpeController;
- this.editPart = editPart;
- }
-
- public void initActiveEditor() {
- type = ACTIVE_EDITOR_NONE;
- }
-
- public void destroyActiveEditor() {
- type = ACTIVE_EDITOR_CANNOT;
- }
-
- public boolean startActiveEditor(int newType) {
- if (type != ACTIVE_EDITOR_NONE || type == ACTIVE_EDITOR_NONE && newType ==
ACTIVE_EDITOR_SOURCE
- && editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
- return false;
- } else {
- type = newType;
- return true;
- }
- }
-
- public void stopActiveEditor() {
- vpeController.onRefresh();
- type = ACTIVE_EDITOR_NONE;
- }
-}
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java 2011-12-01
20:09:36 UTC (rev 36847)
@@ -0,0 +1,40 @@
+package org.jboss.tools.vpe.editor;
+
+public class ActiveEditorSwitcher {
+ public static final int ACTIVE_EDITOR_CANNOT = 0;
+ public static final int ACTIVE_EDITOR_NONE = 1;
+ public static final int ACTIVE_EDITOR_SOURCE = 2;
+ public static final int ACTIVE_EDITOR_VISUAL = 3;
+
+ private int type = ACTIVE_EDITOR_CANNOT;
+ private VpeController vpeController;
+ private VpeEditorPart editPart;
+
+ public ActiveEditorSwitcher(VpeController vpeController, VpeEditorPart editPart) {
+ this.vpeController = vpeController;
+ this.editPart = editPart;
+ }
+
+ public void initActiveEditor() {
+ type = ACTIVE_EDITOR_NONE;
+ }
+
+ public void destroyActiveEditor() {
+ type = ACTIVE_EDITOR_CANNOT;
+ }
+
+ public boolean startActiveEditor(int newType) {
+ if (type != ACTIVE_EDITOR_NONE || type == ACTIVE_EDITOR_NONE && newType ==
ACTIVE_EDITOR_SOURCE
+ && editPart.getVisualMode() == VpeEditorPart.SOURCE_MODE) {
+ return false;
+ } else {
+ type = newType;
+ return true;
+ }
+ }
+
+ public void stopActiveEditor() {
+ vpeController.onRefresh();
+ type = ACTIVE_EDITOR_NONE;
+ }
+}
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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 2011-12-01
19:48:11 UTC (rev 36846)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2011-12-01
20:09:36 UTC (rev 36847)
@@ -42,6 +42,8 @@
import org.eclipse.swt.custom.LineStyleListener;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.SelectionEvent;
@@ -562,7 +564,6 @@
return;
}
// visualBuilder.rebuildFlag = false;
- boolean rebuildWholeDocumentFlag = false;
switch (eventType) {
case INodeNotifier.CHANGE:
sourceChangeFlag = true;
@@ -575,13 +576,12 @@
boolean update = visualBuilder.setText((Node) notifier);
visualEditor.showResizer();
// Added by Max Areshkau JBIDE-1554
- if (!update) {
- rebuildWholeDocumentFlag = visualBuilder.updateNode((Node) notifier);
- }
+ if (!update)
+ visualBuilder.updateNode((Node) notifier);
} else if (type == Node.COMMENT_NODE) {
if ("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$
visualBuilder.clearSelectionRectangle();
- rebuildWholeDocumentFlag = visualBuilder.updateNode((Node) notifier);
+ visualBuilder.updateNode((Node) notifier);
}
} else if (feature != null
&& ((Node) feature).getNodeType() == Node.ATTRIBUTE_NODE) {
@@ -590,7 +590,7 @@
if ((Attr) feature == lastRemovedAttr
&& !attrName.equals(lastRemovedAttrName)) {
lastRemovedAttr = null;
- rebuildWholeDocumentFlag = visualBuilder.removeAttribute((Element) notifier,
+ visualBuilder.removeAttribute((Element) notifier,
lastRemovedAttrName);
}
visualBuilder.setAttribute((Element) notifier,
@@ -598,7 +598,7 @@
} else {
lastRemovedAttr = (Attr) feature;
lastRemovedAttrName = ((Attr) feature).getName();
- rebuildWholeDocumentFlag = visualBuilder.removeAttribute((Element) notifier,
+ visualBuilder.removeAttribute((Element) notifier,
lastRemovedAttrName);
}
}
@@ -630,7 +630,7 @@
*/
if (Node.COMMENT_NODE == ((Node) feature).getNodeType()) {
commentRemoveCount++;
- rebuildWholeDocumentFlag = visualBuilder.updateNode((Node) feature);
+ visualBuilder.updateNode((Node) feature);
commentNodeChanged = true;
} else {
commentRemoveCount--;
@@ -652,7 +652,7 @@
if (!commentNodeChanged ||(commentNodeChanged && (commentAddCount != 1 ||
commentRemoveCount != 1))) {
visualEditor.hideResizer();
visualBuilder.clearSelectionRectangle();
- rebuildWholeDocumentFlag = visualBuilder.updateNode((Node) notifier);
+ visualBuilder.updateNode((Node) notifier);
} else {
commentNodeChanged = false;
}
@@ -678,10 +678,6 @@
}
break;
}
- if (rebuildWholeDocumentFlag) {
- // whole document rebuild occur -> so cleanup change events queue
- getChangeEvents().clear();
- }
} finally {
// fix for jbide-675, swithcer is null when vpecontroller is
// disposed
@@ -1954,7 +1950,6 @@
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
- getChangeEvents().clear();
reinitImpl();
return Status.OK_STATUS;
}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java 2011-12-01
19:48:11 UTC (rev 36846)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java 2011-12-01
20:09:36 UTC (rev 36847)
@@ -1,113 +0,0 @@
-package org.jboss.tools.vpe.editor;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.ui.progress.UIJob;
-import org.jboss.tools.vpe.VpePlugin;
-import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
-import org.jboss.tools.vpe.messages.VpeUIMessages;
-
-public class VpeUpdateJob extends UIJob {
-
- protected boolean execState = false;
-
- protected VpeController vpeController;
- protected ActiveEditorSwitcher switcher;
-
- public VpeUpdateJob(VpeController vpeController, ActiveEditorSwitcher switcher) {
- super(VpeUIMessages.VPE_UPDATE_JOB_TITLE);
- this.vpeController = vpeController;
- this.switcher = switcher;
- }
-
- protected synchronized void setExecState(boolean execState) {
- this.execState = execState;
- }
-
- protected synchronized boolean isExecState() {
- return execState;
- }
-
- public void interrupt() {
- setExecState(false);
- }
-
- public void execute() {
- setExecState(true);
- schedule();
- }
-
- @Override
- public IStatus runInUIThread(IProgressMonitor monitor) {
- IStatus res = Status.OK_STATUS;
- final int totalWork = 10000;
- final int maxQueue4WholeRefresh = 30;
- monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE, totalWork);
- final List<VpeEventBean> changeEvents = vpeController.getChangeEvents();
- while (changeEvents.size() > 0) {
- if (!isExecState()) {
- break;
- }
- if (changeEvents.size() > maxQueue4WholeRefresh) {
- changeEvents.clear();
- monitor.worked((int) (totalWork / 2));
- vpeController.reinitImpl();
- monitor.worked(totalWork);
- break;
- }
- monitor.worked((int) (totalWork / changeEvents.size()));
- VpeEventBean eventBean = changeEvents.remove(0);
- if (monitor.isCanceled()) {
- // Yahor Radtsevich: the following line is commented as fix of JBIDE-3758: VPE
autorefresh is broken in
- // some cases. Now if the change events queue should be cleared, the user have to do
it explicitly.
- // getChangeEvents().clear();
- res = Status.CANCEL_STATUS;
- break;
- }
- try {
- vpeController.notifyChangedInUiThread(eventBean);
- } catch (VpeDisposeException ex) {
- // JBIDE-675 we will get this exception if user
- // close editor,
- // when update visual editor job is running, we
- // shoud ignore this
- // exception
- break;
- } catch (NullPointerException ex) {
- if (switcher != null) {
- throw ex;
- } else {
- // class was disposed and exception result
- // of that we can't stop
- // refresh job in time, so we just ignore
- // this exception
- }
- } catch (RuntimeException ex) {
- VpePlugin.getPluginLog().logError(ex);
- }
- }
- if (isExecState() && res == Status.OK_STATUS) {
- // cause is to lock calls others events
- if (switcher != null &&
switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
- try {
- vpeController.sourceSelectionChanged();
- //
https://jira.jboss.org/jira/browse/JBIDE-3619 VpeViewUpdateJob takes place after
toolbar selection
- // have been updated. New nodes haven't been put into dom mapping thus toolbar
becomes desabled.
- // Updating toolbar state here takes into account updated vpe nodes.
- final FormatControllerManager tfcm =
vpeController.getToolbarFormatControllerManager();
- if (tfcm != null) {
- tfcm.selectionChanged();
- }
- } finally {
- switcher.stopActiveEditor();
- }
- }
- }
- monitor.done();
- return res;
- }
-
-}
\ No newline at end of file
Added:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java
(rev 0)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java 2011-12-01
20:09:36 UTC (rev 36847)
@@ -0,0 +1,113 @@
+package org.jboss.tools.vpe.editor;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.progress.UIJob;
+import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.toolbar.format.FormatControllerManager;
+import org.jboss.tools.vpe.messages.VpeUIMessages;
+
+public class VpeUpdateJob extends UIJob {
+
+ protected boolean execState = false;
+
+ protected VpeController vpeController;
+ protected ActiveEditorSwitcher switcher;
+
+ public VpeUpdateJob(VpeController vpeController, ActiveEditorSwitcher switcher) {
+ super(VpeUIMessages.VPE_UPDATE_JOB_TITLE);
+ this.vpeController = vpeController;
+ this.switcher = switcher;
+ }
+
+ protected synchronized void setExecState(boolean execState) {
+ this.execState = execState;
+ }
+
+ protected synchronized boolean isExecState() {
+ return execState;
+ }
+
+ public void interrupt() {
+ setExecState(false);
+ }
+
+ public void execute() {
+ setExecState(true);
+ schedule();
+ }
+
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ IStatus res = Status.OK_STATUS;
+ final int totalWork = 10000;
+ final int maxQueue4WholeRefresh = 30;
+ monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE, totalWork);
+ final List<VpeEventBean> changeEvents = vpeController.getChangeEvents();
+ while (changeEvents.size() > 0) {
+ if (!isExecState()) {
+ break;
+ }
+ if (changeEvents.size() > maxQueue4WholeRefresh) {
+ changeEvents.clear();
+ monitor.worked((int) (totalWork / 2));
+ vpeController.reinitImpl();
+ monitor.worked(totalWork);
+ break;
+ }
+ monitor.worked((int) (totalWork / changeEvents.size()));
+ VpeEventBean eventBean = changeEvents.remove(0);
+ if (monitor.isCanceled()) {
+ // Yahor Radtsevich: the following line is commented as fix of JBIDE-3758: VPE
autorefresh is broken in
+ // some cases. Now if the change events queue should be cleared, the user have to do
it explicitly.
+ // getChangeEvents().clear();
+ res = Status.CANCEL_STATUS;
+ break;
+ }
+ try {
+ vpeController.notifyChangedInUiThread(eventBean);
+ } catch (VpeDisposeException ex) {
+ // JBIDE-675 we will get this exception if user
+ // close editor,
+ // when update visual editor job is running, we
+ // shoud ignore this
+ // exception
+ break;
+ } catch (NullPointerException ex) {
+ if (switcher != null) {
+ throw ex;
+ } else {
+ // class was disposed and exception result
+ // of that we can't stop
+ // refresh job in time, so we just ignore
+ // this exception
+ }
+ } catch (RuntimeException ex) {
+ VpePlugin.getPluginLog().logError(ex);
+ }
+ }
+ if (isExecState() && res == Status.OK_STATUS) {
+ // cause is to lock calls others events
+ if (switcher != null &&
switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
+ try {
+ vpeController.sourceSelectionChanged();
+ //
https://jira.jboss.org/jira/browse/JBIDE-3619 VpeViewUpdateJob takes place after
toolbar selection
+ // have been updated. New nodes haven't been put into dom mapping thus toolbar
becomes desabled.
+ // Updating toolbar state here takes into account updated vpe nodes.
+ final FormatControllerManager tfcm =
vpeController.getToolbarFormatControllerManager();
+ if (tfcm != null) {
+ tfcm.selectionChanged();
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ }
+ }
+ monitor.done();
+ return res;
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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 2011-12-01
19:48:11 UTC (rev 36846)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2011-12-01
20:09:36 UTC (rev 36847)
@@ -79,7 +79,6 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-@SuppressWarnings("restriction")
public class VpeVisualDomBuilder extends VpeDomBuilder {
public static final String VPE_USER_TOGGLE_ID = "vpe-user-toggle-id";
//$NON-NLS-1$
public static final String VPE_USER_TOGGLE_LOOKUP_PARENT =
"vpe-user-toggle-lookup-parent"; //$NON-NLS-1$
@@ -766,26 +765,21 @@
// ==========================================================
- // return true in case if rebuild whole document occur
- public boolean updateNode(Node sourceNode) {
- boolean res = false;
+ public void updateNode(Node sourceNode) {
if (sourceNode == null) {
- return res;
+ return;
}
switch (sourceNode.getNodeType()) {
case Node.DOCUMENT_NODE:
rebuildDom((Document) sourceNode);
- res = true;
break;
default:
- res = updateElement(sourceNode);
+ updateElement(sourceNode);
}
- return res;
}
- // return true in case if rebuild whole document occur
- private boolean updateElement(Node sourceNode) {
+ private void updateElement(Node sourceNode) {
VpeElementMapping elementMapping = null;
VpeNodeMapping nodeMapping = domMapping.getNodeMapping(sourceNode);
if (nodeMapping instanceof VpeElementMapping) {
@@ -799,7 +793,7 @@
*/
if (HTML.TAG_STYLE.equalsIgnoreCase(sourceNode.getNodeName())) {
VpeStyleUtil.refreshStyleElement(this, elementMapping);
- return false;
+ return;
}
Node updateNode = elementMapping.getTemplate()
.getNodeForUpdate(pageContext,
@@ -807,11 +801,11 @@
elementMapping.getVisualNode(),
elementMapping.getData());
if ((updateNode != null) && (updateNode != sourceNode)) {
- return updateNode(updateNode);
+ updateNode(updateNode);
+ return;
}
}
}
- boolean res = false;
/*
* 1) Remove source node from mappings and lists.
*/
@@ -838,12 +832,11 @@
// node?
// looks like we haven't need do it.
if (sourceNode.getNodeType() == Node.TEXT_NODE) {
- res = updateNode(sourceNode.getParentNode());
- } else if(HTML.TAG_LINK.equalsIgnoreCase(sourceNode.getNodeName())) {
+ updateNode(sourceNode.getParentNode());
+ }else if(HTML.TAG_LINK.equalsIgnoreCase(sourceNode.getNodeName())) {
addNode(sourceNode, null, getHeadNode());
}
}
- return res;
}
public void removeNode(Node sourceNode) {
@@ -898,19 +891,16 @@
return false;
}
- // return true in case if rebuild whole document occur
- public boolean setAttribute(Element sourceElement, String name, String value) {
+ public void setAttribute(Element sourceElement, String name, String value) {
VpeElementMapping elementMapping = (VpeElementMapping) domMapping
.getNodeMapping(sourceElement);
/*
*
https://jira.jboss.org/jira/browse/JBIDE-4110
* Update any template automatically on attribute adding.
*/
- boolean res = false;
if (elementMapping != null) {
- res = updateElement(sourceElement);
+ updateElement(sourceElement);
}
- return res;
}
public void stopToggle(Node sourceNode) {
@@ -1033,19 +1023,16 @@
return null;
}
- // return true in case if rebuild whole document occur
- public boolean removeAttribute(Element sourceElement, String name) {
+ public void removeAttribute(Element sourceElement, String name) {
VpeElementMapping elementMapping = (VpeElementMapping) domMapping
.getNodeMapping(sourceElement);
/*
*
https://jira.jboss.org/jira/browse/JBIDE-4110
* Update any template automatically on attribute deleting.
*/
- boolean res = false;
if (elementMapping != null) {
- res = updateElement(sourceElement);
+ updateElement(sourceElement);
}
- return res;
}
public void refreshBundleValues(Element sourceElement) {