Index: E:/workspace-3.3.1.1-jboss/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java =================================================================== --- E:/workspace-3.3.1.1-jboss/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java (revision 5571) +++ E:/workspace-3.3.1.1-jboss/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java (working copy) @@ -16,6 +16,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.ILock; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IContributionItem; import org.eclipse.jface.action.IMenuListener; @@ -51,8 +54,11 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.progress.UIJob; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; +import org.eclipse.wst.sse.core.internal.ILockable; import org.eclipse.wst.sse.core.internal.model.ModelLifecycleEvent; import org.eclipse.wst.sse.core.internal.provisional.IModelLifecycleListener; import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter; @@ -185,6 +191,7 @@ private FormatControllerManager toolbarFormatControllerManager = null; private SelectionBar selectionBar = null; Shell tip; + private UIJob refreshJob; public final static String MODEL_FLAVOR = ModelTransfer.MODEL; //$NON-NLS-1$ @@ -322,88 +329,133 @@ public boolean isAdapterForType(Object type) { return type == this; } + + public void notifyChanged(final INodeNotifier notifier, final int eventType, final Object feature, final Object oldValue, final Object newValue, final int pos) { + final Runnable runnable = new Runnable() { + public void run() { + if (!switcher + .startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) { + return; + } + if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) { + printSourceEvent(notifier, eventType, feature, oldValue, + newValue, pos); + } + if (visualBuilder == null) { + return; + } + visualBuilder.rebuildFlag = false; + switch (eventType) { + case INodeNotifier.CHANGE: + sourceChangeFlag = true; + int type = ((Node) notifier).getNodeType(); + visualEditor.hideResizer(); + visualBuilder.setSelectionRectangle(null); + if (type == Node.TEXT_NODE) { + visualBuilder + .setText((Node) notifier); + visualEditor.showResizer(); + //Added by Max Areshkau JBIDE-1554 + visualBuilder.updateNode((Node) notifier); + } else if (type == Node.COMMENT_NODE) { + if ("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$ + visualBuilder.setSelectionRectangle(null); + visualBuilder.updateNode((Node) notifier); + } + } else if (feature != null + && ((Node) feature).getNodeType() == Node.ATTRIBUTE_NODE) { + if (newValue != null) { + String attrName = ((Attr) feature).getName(); + if ((Attr) feature == lastRemovedAttr + && !attrName.equals(lastRemovedAttrName)) { + lastRemovedAttr = null; + visualBuilder + .removeAttribute((Element) notifier, + lastRemovedAttrName); + } + visualBuilder.setAttribute((Element) notifier, + ((Attr) feature).getName(), + (String) newValue); + } else { + lastRemovedAttr = (Attr) feature; + lastRemovedAttrName = ((Attr) feature).getName(); + visualBuilder.removeAttribute((Element) notifier, + lastRemovedAttrName); + } + } + visualEditor.showResizer(); + break; + + case INodeNotifier.ADD: + break; - public void notifyChanged(INodeNotifier notifier, int eventType, Object feature, Object oldValue, Object newValue, int pos) { - if (!switcher.startActiveEditor(ActiveEditorSwitcher.ACTIVE_EDITOR_SOURCE)) { - return; - } - if (VpeDebug.PRINT_SOURCE_MUTATION_EVENT) { - printSourceEvent(notifier, eventType, feature, oldValue, newValue, pos); - } - if(visualBuilder==null) { - return; - } - visualBuilder.rebuildFlag = false; - - switch (eventType) { - case INodeNotifier.CHANGE: - sourceChangeFlag = true; - int type = ((Node)notifier).getNodeType(); - visualEditor.hideResizer(); - visualBuilder.setSelectionRectangle(null); - if (type == Node.TEXT_NODE) { - visualBuilder.setText((Node)notifier); - visualEditor.showResizer(); - //Added by Max Areshkau JBIDE-1554 - visualBuilder.updateNode((Node)notifier); - } else if (type == Node.COMMENT_NODE) { - if("yes".equals(VpePreference.SHOW_COMMENTS.getValue())) { //$NON-NLS-1$ + case INodeNotifier.REMOVE: + visualBuilder.stopToggle((Node) feature); + visualBuilder.removeNode((Node) feature); + break; + + case INodeNotifier.STRUCTURE_CHANGED: + visualEditor.hideResizer(); visualBuilder.setSelectionRectangle(null); - visualBuilder.updateNode((Node)notifier); - } - } else if (feature != null && ((Node)feature).getNodeType() == Node.ATTRIBUTE_NODE) { - if (newValue != null) { - String attrName = ((Attr)feature).getName(); - if ((Attr)feature == lastRemovedAttr && !attrName.equals(lastRemovedAttrName)) { - lastRemovedAttr = null; - visualBuilder.removeAttribute((Element)notifier, lastRemovedAttrName); + visualBuilder.updateNode((Node) notifier); + break; + + case INodeNotifier.CONTENT_CHANGED: + if (!sourceChangeFlag) { + if (feature != null + && ((Node) feature).getNodeType() == Node.TEXT_NODE) { + //if (((Node)notifier).getNodeName().equalsIgnoreCase("style")) { + visualEditor.hideResizer(); + visualBuilder.setSelectionRectangle(null); + visualBuilder.setText((Node) feature); + visualEditor.showResizer(); + //} + } + } else { + sourceChangeFlag = false; } - visualBuilder.setAttribute((Element)notifier, ((Attr)feature).getName(), (String)newValue); - } else { - lastRemovedAttr = (Attr)feature; - lastRemovedAttrName = ((Attr)feature).getName(); - visualBuilder.removeAttribute((Element)notifier, lastRemovedAttrName); + break; + } + if (visualBuilder.rebuildFlag) { + pageContext.fireTaglibsChanged(); + } else if (pageContext.isTaglibChanged()) { + visualRefreshImpl(); + pageContext.fireTaglibsChanged(); } + switcher.stopActiveEditor(); + } + }; + if (getDisplay() == null || (Thread.currentThread() == getDisplay().getThread())) { + runnable.run(); + } else { + if (refreshJob != null) { + refreshJob.cancel(); } - visualEditor.showResizer(); - break; + refreshJob = new UIJob("Refreshing the Visual Page Editor") { - case INodeNotifier.ADD: - break; - - case INodeNotifier.REMOVE: - visualBuilder.stopToggle((Node)feature); - visualBuilder.removeNode((Node)feature); - break; - - case INodeNotifier.STRUCTURE_CHANGED: - visualEditor.hideResizer(); - visualBuilder.setSelectionRectangle(null); - visualBuilder.updateNode((Node)notifier); - break; + public IStatus runInUIThread(IProgressMonitor monitor) { + if (monitor.isCanceled()) { + return Status.CANCEL_STATUS; + } + runnable.run(); + return Status.OK_STATUS; + } - case INodeNotifier.CONTENT_CHANGED: - if (!sourceChangeFlag) { - if (feature != null && ((Node)feature).getNodeType() == Node.TEXT_NODE) { - //if (((Node)notifier).getNodeName().equalsIgnoreCase("style")) { - visualEditor.hideResizer(); - visualBuilder.setSelectionRectangle(null); - visualBuilder.setText((Node)feature); - visualEditor.showResizer(); - //} - } - } else { - sourceChangeFlag = false; - } - break; + }; + refreshJob.schedule(1000); } - if (visualBuilder.rebuildFlag) { - pageContext.fireTaglibsChanged(); - } else if (pageContext.isTaglibChanged()) { - visualRefreshImpl(); - pageContext.fireTaglibsChanged(); - } - switcher.stopActiveEditor(); + /*if (getDisplay() == null || (Thread.currentThread() == getDisplay().getThread())) { + runnable.run(); + } else { + getDisplay().asyncExec(runnable); + }*/ + } + + private Display getDisplay() { + if (PlatformUI.isWorkbenchRunning()) + return PlatformUI.getWorkbench().getDisplay(); + else + return null; } // INodeSelectionListener implementation