Author: dgolovin
Date: 2011-12-01 20:44:25 -0500 (Thu, 01 Dec 2011)
New Revision: 36861
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
Log:
https://issues.jboss.org/browse/JBIDE-10016 NullPointerException in VPE when an attribute
is intensively changed
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-02
01:42:26 UTC (rev 36860)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/ActiveEditorSwitcher.java 2011-12-02
01:44:25 UTC (rev 36861)
@@ -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;
- }
-}
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-02
01:42:26 UTC (rev 36860)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2011-12-02
01:44:25 UTC (rev 36861)
@@ -14,7 +14,6 @@
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -85,6 +84,7 @@
import org.jboss.tools.common.model.event.XModelTreeEvent;
import org.jboss.tools.common.model.event.XModelTreeListener;
import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.ui.dnd.ModelTransfer;
import org.jboss.tools.common.model.ui.util.ModelUtilities;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.XModelTreeListenerSWTSync;
@@ -104,6 +104,7 @@
import org.jboss.tools.vpe.dnd.VpeDnD;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
import org.jboss.tools.vpe.editor.menu.VpeMenuCreator;
import org.jboss.tools.vpe.editor.mozilla.MozillaEditor;
@@ -131,6 +132,16 @@
import org.jboss.tools.vpe.editor.util.DocTypeUtil;
import org.jboss.tools.vpe.editor.util.SelectionUtil;
import org.jboss.tools.vpe.editor.util.VisualDomUtil;
+import org.jboss.tools.vpe.editor.util.VpeDebugUtil;
+import org.jboss.tools.vpe.editor.util.VpeNodesManagingUtil;
+import org.jboss.tools.vpe.handlers.PageDesignOptionsHandler;
+import org.jboss.tools.vpe.handlers.PreferencesHandler;
+import org.jboss.tools.vpe.handlers.RefreshHandler;
+import org.jboss.tools.vpe.handlers.RotateEditorsHandler;
+import org.jboss.tools.vpe.handlers.ShowBorderHandler;
+import org.jboss.tools.vpe.handlers.ShowBundleAsELHandler;
+import org.jboss.tools.vpe.handlers.ShowNonVisualTagsHandler;
+import org.jboss.tools.vpe.handlers.ShowTextFormattingHandler;
import org.jboss.tools.vpe.handlers.VisualPartAbstractHandler;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.resref.core.AbsoluteFolderReferenceList;
@@ -153,7 +164,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-@SuppressWarnings({ "restriction", "deprecation" })
public class VpeController implements INodeAdapter,
IModelLifecycleListener, INodeSelectionListener,
ITextSelectionListener, SelectionListener,
@@ -164,6 +174,7 @@
MozillaContextMenuListener, MozillaResizeListener,
MozillaAfterPaintListener, MozillaScrollListener {
+ public static final int DEFAULT_UPDATE_DELAY_TIME = 400;
private boolean visualEditorVisible = true;
private boolean synced = true;
StructuredTextEditor sourceEditor;
@@ -178,7 +189,7 @@
private VpeVisualDomBuilder visualBuilder;
private VpeDnD vpeDnD;
// private VpeVisualKeyHandler visualKeyHandler;
- private ActiveEditorSwitcher switcher;
+ private ActiveEditorSwitcher switcher = new ActiveEditorSwitcher();
private Attr lastRemovedAttr;
private String lastRemovedAttrName;
private boolean mouseUpSelectionReasonFlag;
@@ -201,7 +212,7 @@
private XModelTreeListenerSWTSync optionsListener;
// Added by Max Areshkau Fix for JBIDE-1479
private UIJob job = null;
- private VpeUpdateJob uiJob;
+ private UIJob uiJob;
// JBIDE-675, visual refresh job
private UIJob visualRefreshJob;
private UIJob reinitJob;
@@ -213,7 +224,7 @@
* Added by Max Areshkau JBIDE-675, stores information about modification
* events
*/
- private List<VpeEventBean> changeEvents;
+ private LinkedList<VpeEventBean> changeEvents;
Shell tip;
@@ -227,10 +238,12 @@
*/
private IKeyEventHandler keyEventHandler;
+ // contains vpe update delau time in miliseconds
+ private int vpeUpdateDelayTime;
+
public VpeController(VpeEditorPart editPart) {
this.editPart = editPart;
- this.switcher = new ActiveEditorSwitcher(this, editPart);
dropWindow = new VpeDropWindow(editPart.getSite().getShell());
}
@@ -354,6 +367,9 @@
elReferenceListListener = ELReferenceList.getInstance();
elReferenceListListener.addChangeListener(this);
+ // initialization of vpe update delay time
+ vpeUpdateDelayTime = DEFAULT_UPDATE_DELAY_TIME;
+
// pageContext.fireTaglibsChanged();
// yradtsevich: we have to refresh VPE selection on init (fix of
@@ -511,13 +527,23 @@
display = PlatformUI.getWorkbench().getDisplay();
if (display != null && (Thread.currentThread() == display.getThread())) {
- getChangeEvents().add(new VpeEventBean(notifier, eventType, feature, oldValue,
newValue, pos));
+ getChangeEvents().addLast(
+ new VpeEventBean(notifier, eventType, feature, oldValue,
+ newValue, pos));
if (uiJob == null) {
- uiJob = new VpeUpdateJob(this, switcher);
+ uiJob = new VPEUpdateJob(VpeUIMessages.VPE_UPDATE_JOB_TITLE);
+ }
+
+ if (uiJob.getState() != Job.RUNNING) {
uiJob.setPriority(Job.LONG);
+ // Fix of JBIDE-1900
+ uiJob.schedule(getVpeUpdateDelayTime());
+ } else {
+ uiJob.cancel();
+ uiJob.schedule(getVpeUpdateDelayTime());
+ setVpeUpdateDelayTime(400);
}
- uiJob.interrupt();
- uiJob.execute();
+
return;
}
// start job when we modify file in non ui thread
@@ -542,11 +568,6 @@
job.schedule(1000L);
}
- public void notifyChangedInUiThread(VpeEventBean eventBean) {
- notifyChangedInUiThread(eventBean.getNotifier(), eventBean.getEventType(),
eventBean.getFeature(),
- eventBean.getOldValue(), eventBean.getNewValue(), eventBean.getPos());
- }
-
public void notifyChangedInUiThread(INodeNotifier notifier, int eventType,
Object feature, Object oldValue, Object newValue, int pos) {
if (switcher == null
@@ -1180,11 +1201,11 @@
public void keyPress(nsIDOMKeyEvent keyEvent) {
if (VpeDebug.PRINT_VISUAL_KEY_EVENT) {
System.out.println("<<< keyPress type: " + keyEvent.getType() +
//$NON-NLS-1$
- " Ctrl: " //$NON-NLS-1$
+ " Ctrl: "
+ keyEvent.getCtrlKey()
- + " Shift: " + keyEvent.getShiftKey() + //$NON-NLS-1$
- " CharCode: " + keyEvent.getCharCode() //$NON-NLS-1$
- + " KeyCode: " + keyEvent.getKeyCode()); //$NON-NLS-1$
+ + " Shift: " + keyEvent.getShiftKey() + //$NON-NLS-1$ //$NON-NLS-2$
+ " CharCode: " + keyEvent.getCharCode()
+ + " KeyCode: " + keyEvent.getKeyCode()); //$NON-NLS-1$ //$NON-NLS-2$
}
if (!switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_VISUAL)) {
@@ -1196,6 +1217,7 @@
} finally {
switcher.stopActiveEditor();
}
+ setVpeUpdateDelayTime(0);
/*
* adding calls of core event handlers, for example' CTR+H' or
'CTRL+M'
* event handler dialog
@@ -1493,6 +1515,127 @@
System.out.println();
}
+ private class VPEUpdateJob extends UIJob {
+ private boolean cancelled = false;
+
+ final static int MAX_EVENTS_TILL_REFRESH = 30;
+
+ private VPEUpdateJob(String name) {
+ super(name);
+ }
+
+ @Override
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ cancelled=false;
+ monitor.beginTask(VpeUIMessages.VPE_UPDATE_JOB_TITLE,
+ 100);
+ while (getChangeEvents().size() > 0) {
+ if (monitor.isCanceled() || cancelled) {
+ return Status.CANCEL_STATUS;
+ }
+
+ if (changeEvents.size() > MAX_EVENTS_TILL_REFRESH) {
+ monitor.worked((int) (10000 / 2));
+ System.out.println("full refresh is started");
+ reinitImpl();
+ System.out.println("full refresh is finished");
+ monitor.worked(10000);
+ changeEvents.clear();
+ return Status.OK_STATUS;
+ }
+
+ monitor.worked((int) (100 / getChangeEvents().size()));
+ VpeEventBean eventBean = getChangeEvents().getFirst();
+ try {
+ notifyChangedInUiThread(
+ eventBean.getNotifier(), eventBean
+ .getEventType(), eventBean
+ .getFeature(), eventBean
+ .getOldValue(), eventBean
+ .getNewValue(), eventBean
+ .getPos());
+ } 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);
+ } finally {
+ getChangeEvents().remove(eventBean);
+ }
+ }
+ // cause is to lock calls others events
+ if (switcher != null &&
switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE))
+ try {
+ 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.
+ */
+ if (toolbarFormatControllerManager != null) {
+ toolbarFormatControllerManager.selectionChanged();
+ }
+ } finally {
+ switcher.stopActiveEditor();
+ }
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+
+ protected void canceling() {
+ this.cancelled = true;
+ }
+ }
+
+ 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 void initActiveEditor() {
+ type = ACTIVE_EDITOR_NONE;
+ }
+
+ private 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() {
+ onRefresh();
+ type = ACTIVE_EDITOR_NONE;
+ }
+ }
+
void refreshTemplates() {
if (includeList.includesRefresh()) {
visualRefresh();
@@ -1931,9 +2074,11 @@
/**
* @return the changeEvents
*/
- public List<VpeEventBean> getChangeEvents() {
+ public LinkedList<VpeEventBean> getChangeEvents() {
+
if (changeEvents == null) {
- changeEvents = Collections.synchronizedList(new LinkedList<VpeEventBean>());
+
+ changeEvents = new LinkedList<VpeEventBean>();
}
return changeEvents;
}
@@ -1956,19 +2101,19 @@
reinitJob.schedule();
}
- void reinitImpl() {
+ private void reinitImpl() {
try {
if (switcher == null
|| !switcher
.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) {
return;
}
-
+
// this method must be invoked before any visual
// node is created, see JBIDE-5105
visualEditor.reinitDesignMode();
-
visualBuilder.clearSelectionRectangle();
+ //selectionManager = null;
IDOMModel sourceModel = (IDOMModel) getModel();
if (sourceModel != null) {
IDOMDocument sourceDocument = sourceModel.getDocument();
@@ -2064,6 +2209,21 @@
}
/**
+ * @return the vpeUpdateDelayTime
+ */
+ private int getVpeUpdateDelayTime() {
+ return vpeUpdateDelayTime;
+ }
+
+ /**
+ * @param vpeUpdateDelayTime
+ * the vpeUpdateDelayTime to set
+ */
+ private void setVpeUpdateDelayTime(int vpeUpdateDelayTime) {
+ this.vpeUpdateDelayTime = vpeUpdateDelayTime;
+ }
+
+ /**
* @return the selectionManager
*/
public ISelectionManager getSelectionManager() {
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-02
01:42:26 UTC (rev 36860)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeUpdateJob.java 2011-12-02
01:44:25 UTC (rev 36861)
@@ -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