[109441] Use base selection notification instead of ViewerSelectionManager
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/CSSContentOutlineConfiguration.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/CSSContentOutlineConfiguration.java
index cd274ee..e056cab 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/CSSContentOutlineConfiguration.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/CSSContentOutlineConfiguration.java
@@ -8,28 +8,25 @@
****************************************************************************/
package org.eclipse.wst.css.ui.internal.views.contentoutline;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSValue;
import org.eclipse.wst.css.ui.internal.CSSUIPlugin;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateActionContributionItem;
import org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.StructuredContentOutlineConfiguration;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
public class CSSContentOutlineConfiguration extends StructuredContentOutlineConfiguration {
- private final String OUTLINE_SORT_PREF = "outline-sort"; //$NON-NLS-1$
private IContentProvider fContentProvider = null;
private ILabelProvider fLabelProvider = null;
+ private final String OUTLINE_SORT_PREF = "outline-sort"; //$NON-NLS-1$
public CSSContentOutlineConfiguration() {
super();
@@ -44,7 +41,8 @@
if (items == null) {
items = new IContributionItem[1];
items[0] = sortItem;
- } else {
+ }
+ else {
IContributionItem[] combinedItems = new IContributionItem[items.length + 1];
combinedItems[0] = sortItem;
System.arraycopy(items, 0, combinedItems, 1, items.length);
@@ -54,61 +52,67 @@
}
public IContentProvider getContentProvider(TreeViewer viewer) {
- if (fContentProvider == null && getFactory() != null)
- fContentProvider = new JFaceNodeContentProviderCSS((INodeAdapterFactory) getFactory());
+ if (fContentProvider == null)
+ fContentProvider = new JFaceNodeContentProviderCSS();
return fContentProvider;
}
+ private Object getFilteredNode(Object o) {
+ ICSSNode node = null;
+ if (o instanceof ICSSNode) {
+ node = (ICSSNode) o;
+ short nodeType = node.getNodeType();
+ if (node instanceof ICSSValue) {
+ while (node != null && !(node instanceof ICSSStyleDeclItem)) {
+ node = node.getParentNode();
+ }
+ }
+ else if (nodeType == ICSSNode.STYLEDECLARATION_NODE) {
+ node = node.getParentNode();
+ }
+ else if (nodeType == ICSSNode.MEDIALIST_NODE) {
+ node = node.getParentNode();
+ }
+ }
+ return node;
+ }
+
+ private Object[] getFilteredNodes(Object[] objects) {
+ Object[] filtered = new Object[objects.length];
+ for (int i = 0; i < filtered.length; i++) {
+ filtered[i] = getFilteredNode(objects[i]);
+ }
+ return filtered;
+ }
+
public ILabelProvider getLabelProvider(TreeViewer viewer) {
- if (fLabelProvider == null && getFactory() != null)
- fLabelProvider = new JFaceNodeLabelProviderCSS((INodeAdapterFactory) getFactory());
+ if (fLabelProvider == null)
+ fLabelProvider = new JFaceNodeLabelProviderCSS();
return fLabelProvider;
}
- public List getNodes(List nodes) {
- List filteredNodes = new ArrayList(nodes);
-
- List targetNodes = new ArrayList();
- Iterator i = filteredNodes.iterator();
- while (i.hasNext()) {
- Object obj = i.next();
- if (obj instanceof ICSSNode) {
- ICSSNode node = (ICSSNode) obj;
- short nodeType = node.getNodeType();
- if (node instanceof ICSSValue) {
- while (node != null && !(node instanceof ICSSStyleDeclItem)) {
- node = node.getParentNode();
- }
- } else if (nodeType == ICSSNode.STYLEDECLARATION_NODE) {
- node = node.getParentNode();
- } else if (nodeType == ICSSNode.MEDIALIST_NODE) {
- node = node.getParentNode();
- }
- if (node != null) {
- obj = node;
- }
- }
- targetNodes.add(obj);
- }
-
- return targetNodes;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.wst.sse.ui.views.contentoutline.StructuredContentOutlineConfiguration#getPreferenceStore()
+ */
+ protected IPreferenceStore getPreferenceStore() {
+ return CSSUIPlugin.getDefault().getPreferenceStore();
}
- public List getSelectedNodes(NodeSelectionChangedEvent event) {
- return getNodes(event.getSelectedNodes());
+ public ISelection getSelection(TreeViewer viewer, ISelection selection) {
+ ISelection filteredSelection = selection;
+ if (selection instanceof IStructuredSelection) {
+ Object[] filteredNodes = getFilteredNodes(((IStructuredSelection) selection).toArray());
+ filteredSelection = new StructuredSelection(filteredNodes);
+ }
+ return filteredSelection;
}
/**
* @deprecated use key directly (no need for generator)
*/
public String getSortPreferenceKey() {
-// return PreferenceKeyGenerator.generateKey(OUTLINE_SORT_PREF, getDeclaringID());
return OUTLINE_SORT_PREF;
}
- /* (non-Javadoc)
- * @see org.eclipse.wst.sse.ui.views.contentoutline.StructuredContentOutlineConfiguration#getPreferenceStore()
- */
- protected IPreferenceStore getPreferenceStore() {
- return CSSUIPlugin.getDefault().getPreferenceStore();
- }
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeContentProviderCSS.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeContentProviderCSS.java
index a8e5ab5..314f60a 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeContentProviderCSS.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeContentProviderCSS.java
@@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSModel;
@@ -22,56 +23,18 @@
import org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeContentProvider;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.stylesheets.MediaList;
/**
* A Content provider for a JFace viewer used to display DOM nodes. This
- * content provider takes an adapter factory to create JFace adapters for the
- * nodes in the tree.
+ * content provider does not use adapters.
*/
-class JFaceNodeContentProviderCSS extends JFaceNodeContentProvider {
- protected INodeAdapterFactory adapterFactory;
+class JFaceNodeContentProviderCSS implements ITreeContentProvider {
- //protected DomainNotifier domainNotifier;
- /**
- */
- public JFaceNodeContentProviderCSS(INodeAdapterFactory adapterFactory) {
- super(adapterFactory);
- this.adapterFactory = adapterFactory;
- }
-
- /**
- */
- protected void adaptElements(Object element) {
-
- ICSSNode node;
-
- if (element instanceof ICSSModel) {
- ICSSDocument doc = ((ICSSModel) element).getDocument();
- adapterFactory.adapt((INodeNotifier) doc);
- node = doc.getFirstChild();
- } else if (element instanceof ICSSNode) {
- node = ((ICSSNode) element).getFirstChild();
- } else {
- return;
- }
-
- while (node != null) {
- // if (node instanceof CSSRule) {
- adapterFactory.adapt((INodeNotifier) node);
- adaptElements(node);
- // }
- // else{
- // adapterFactory.adapt((INodeNotifier) node);
- // }
-
- node = node.getNextSibling();
- }
+ public JFaceNodeContentProviderCSS() {
+ super();
}
/**
@@ -83,8 +46,6 @@
if (element instanceof ICSSModel) {
ICSSModel model = (ICSSModel) element;
ICSSDocument doc = model.getDocument();
- // addAdapter((INodeNotifier) doc);
- adapterFactory.adapt((INodeNotifier) doc);
node = doc.getFirstChild();
} else if (element instanceof ICSSNode) {
node = ((ICSSNode) element).getFirstChild();
@@ -152,7 +113,6 @@
ArrayList v = new ArrayList();
// internalGetElements(object, v);
addElements(object, v);
- adaptElements(object);
return v.toArray();
}
return new Object[0];
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeLabelProviderCSS.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeLabelProviderCSS.java
index f102975..fdfe893 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeLabelProviderCSS.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/views/contentoutline/JFaceNodeLabelProviderCSS.java
@@ -10,11 +10,7 @@
*******************************************************************************/
package org.eclipse.wst.css.ui.internal.views.contentoutline;
-
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule;
import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
@@ -24,53 +20,17 @@
import org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule;
import org.eclipse.wst.css.ui.internal.image.CSSImageHelper;
import org.eclipse.wst.css.ui.internal.image.CSSImageType;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
-import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter;
import org.w3c.dom.css.CSSImportRule;
import org.w3c.dom.css.CSSRule;
import org.w3c.dom.stylesheets.MediaList;
-
-/**
- * A class that uses a JFaceNodeAdapterFactory to provide adapters to provide
- * the labels and images for DOM nodes.
- */
-class JFaceNodeLabelProviderCSS implements ILabelProvider {
- protected INodeAdapterFactory fAdapterFactory;
+class JFaceNodeLabelProviderCSS extends LabelProvider {
/**
* JFaceNodeLabelProvider constructor comment.
*/
- public JFaceNodeLabelProviderCSS(INodeAdapterFactory adapterFactory) {
+ public JFaceNodeLabelProviderCSS() {
super();
- this.fAdapterFactory = adapterFactory;
- }
-
- /**
- * Adds a listener to the label provider. A label provider should inform
- * its listener about state changes that enforces rendering of the visual
- * part that uses this label provider.
- */
- public void addListener(ILabelProviderListener listener) {
- // The label provider state never changes so we do not have
- // to implement this method.
- }
-
- /**
- * The visual part that is using this label provider is about to be
- * disposed. Deallocate all allocated SWT resources.
- */
- public void dispose() {
- // Nothing to dispose
- }
-
- /**
- * Returns the JFace adapter for the specified object.
- *
- */
- protected IJFaceNodeAdapter getAdapter(Object adaptable) {
- return (IJFaceNodeAdapter) fAdapterFactory.adapt((INodeNotifier) adaptable);
}
/**
@@ -85,27 +45,19 @@
* to the viewer.
*/
public Image getImage(Object element) {
- // return getAdapter(element).getLabelImage((Node) element);
if (element instanceof ICSSNode) {
CSSImageHelper helper = CSSImageHelper.getInstance();
return helper.getImage(CSSImageType.getImageType((ICSSNode) element));
- // Image image = getCSSNodeImage(element);
- // return image;
- // return getAdapter(element).getLabelImage((ICSSNode) element);
+ // Image image = getCSSNodeImage(element);
+ // return image;
+ // return getAdapter(element).getLabelImage((ICSSNode) element);
}
return null;
}
/**
- * Insert the method's description here.
- */
- public String getLabelText(Viewer viewer, Object element) {
- return ""; //$NON-NLS-1$
- }
-
- /**
* Returns the text for the label of the given element, for use in the
* given viewer.
*
@@ -168,10 +120,10 @@
}
}
- // if (element instanceof ICSSNode) {
- // ICSSNode node = ((ICSSNode)element);
- // result = getAdapter(element).getLabelText((ICSSNode) element);
- // }
+ // if (element instanceof ICSSNode) {
+ // ICSSNode node = ((ICSSNode)element);
+ // result = getAdapter(element).getLabelText((ICSSNode) element);
+ // }
return result;
}
@@ -192,8 +144,8 @@
* Checks whether this label provider is affected by the given domain
* event.
*/
- public boolean isAffected(Object dummy) {//DomainEvent event) {
- //return event.isModifier(DomainEvent.NON_STRUCTURE_CHANGE);
+ public boolean isAffected(Object dummy) {// DomainEvent event) {
+ // return event.isModifier(DomainEvent.NON_STRUCTURE_CHANGE);
return true;
}
@@ -214,12 +166,4 @@
public boolean isLabelProperty(Object element, String property) {
return false;
}
-
- /**
- * Removes a listener from the label provider.
- */
- public void removeListener(ILabelProviderListener listener) {
- // The label provider state never changes so we do not have
- // to implement this method.
- }
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContentOutlineConfiguration.java b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContentOutlineConfiguration.java
index c1ba7fe..996b3dc 100644
--- a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContentOutlineConfiguration.java
+++ b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContentOutlineConfiguration.java
@@ -31,7 +31,6 @@
import org.eclipse.wst.common.ui.internal.dnd.ViewerDropAdapter;
import org.eclipse.wst.dtd.ui.internal.DTDUIPlugin;
import org.eclipse.wst.dtd.ui.internal.dnd.DTDDragAndDropManager;
-import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateActionContributionItem;
import org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.StructuredContentOutlineConfiguration;
import org.eclipse.wst.sse.ui.internal.util.Assert;
@@ -96,7 +95,7 @@
if (fContentProvider == null) {
fContentProvider = new DTDTreeContentProvider();
}
- //return super.getContentProvider(viewer);
+ // return super.getContentProvider(viewer);
return fContentProvider;
}
@@ -109,7 +108,7 @@
if (fLabelProvider == null) {
fLabelProvider = new DTDLabelProvider();
}
- //return super.getLabelProvider(viewer);
+ // return super.getLabelProvider(viewer);
return fLabelProvider;
}
@@ -119,8 +118,13 @@
* @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getMenuListener(org.eclipse.jface.viewers.TreeViewer)
*/
public IMenuListener getMenuListener(TreeViewer viewer) {
- fMenuHelper.createMenuListenersFor(viewer);
- return fMenuHelper.getMenuListener();
+ if (fMenuHelper == null) {
+// fMenuHelper = new DTDContextMenuHelper(getEditor());
+ System.out.println("DTDContextMenuHelper not implemented");
+ }
+// fMenuHelper.createMenuListenersFor(viewer);
+// return fMenuHelper.getMenuListener();
+ return null;
}
/*
@@ -212,23 +216,13 @@
/*
* (non-Javadoc)
*
- * @see org.eclipse.wst.sse.ui.views.contentoutline.StructuredContentOutlineConfiguration#setEditor(org.eclipse.wst.sse.ui.StructuredTextEditor)
- */
- public void setEditor(StructuredTextEditor editor) {
- super.setEditor(editor);
- fMenuHelper = new DTDContextMenuHelper(editor);
- }
-
- /*
- * (non-Javadoc)
- *
* @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#unconfigure(org.eclipse.jface.viewers.TreeViewer)
*/
public void unconfigure(TreeViewer viewer) {
super.unconfigure(viewer);
fViewerContributions.remove(viewer);
if (fMenuHelper != null) {
- fMenuHelper.removeMenuListenersFor(viewer);
+// fMenuHelper.removeMenuListenersFor(viewer);
}
}
}
diff --git a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContextMenuHelper.java b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContextMenuHelper.java
index 1daaa71..d498075 100644
--- a/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContextMenuHelper.java
+++ b/bundles/org.eclipse.wst.dtd.ui/src/org/eclipse/wst/dtd/ui/internal/views/contentoutline/DTDContextMenuHelper.java
@@ -14,6 +14,7 @@
package org.eclipse.wst.dtd.ui.internal.views.contentoutline;
+/*
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
@@ -23,6 +24,7 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.wst.dtd.core.internal.AttributeList;
@@ -48,21 +50,16 @@
import org.eclipse.wst.dtd.ui.internal.views.contentoutline.actions.AddNotationAction;
import org.eclipse.wst.dtd.ui.internal.views.contentoutline.actions.AddParameterEntityReferenceAction;
import org.eclipse.wst.dtd.ui.internal.views.contentoutline.actions.DeleteAction;
-import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
-
+*/
/**
* Menu helper for Content Outline page. This should not be used elsewhere.
*/
public class DTDContextMenuHelper // extends FocusAdapter
{
+/*
class DTDMenuListener implements IMenuListener {
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.action.IMenuListener#menuAboutToShow(org.eclipse.jface.action.IMenuManager)
- */
public void menuAboutToShow(IMenuManager manager) {
updateActions();
Object node = null;
@@ -92,7 +89,7 @@
private DeleteAction deleteAction;
// default access, for inner class
- StructuredTextEditor fEditor;
+ IEditorPart fEditor;
private IMenuListener fMenuListener;
private IAction redoAction;
@@ -104,7 +101,7 @@
// private List viewerList = new Vector();
- public DTDContextMenuHelper(StructuredTextEditor editor) {
+ public DTDContextMenuHelper(IEditorPart editor) {
this.fEditor = editor;
fMenuListener = new DTDMenuListener();
addNotationAction = new AddNotationAction(editor, DTDUIMessages._UI_ACTION_ADD_DTD_NOTATION); //$NON-NLS-1$
@@ -278,9 +275,6 @@
return deleteAction;
}
- /**
- * @return Returns the menuListener.
- */
public IMenuListener getMenuListener() {
return fMenuListener;
}
@@ -324,4 +318,5 @@
// redoAction);
// }
}
+*/
}
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentoutline/JFaceNodeAdapterForHTML.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentoutline/JFaceNodeAdapterForHTML.java
index 916f079..3a18a7d 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentoutline/JFaceNodeAdapterForHTML.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/contentoutline/JFaceNodeAdapterForHTML.java
@@ -16,8 +16,8 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImageHelper;
import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImages;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeAdapter;
+import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeAdapterFactory;
import org.w3c.dom.Node;
/**
@@ -37,7 +37,7 @@
*
* @param adapterFactory
*/
- public JFaceNodeAdapterForHTML(INodeAdapterFactory adapterFactory) {
+ public JFaceNodeAdapterForHTML(JFaceNodeAdapterFactory adapterFactory) {
super(adapterFactory);
}
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/views/contentoutline/HTMLContentOutlineConfiguration.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/views/contentoutline/HTMLContentOutlineConfiguration.java
index 11891a2..0567171 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/views/contentoutline/HTMLContentOutlineConfiguration.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/views/contentoutline/HTMLContentOutlineConfiguration.java
@@ -14,6 +14,7 @@
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.wst.html.ui.internal.HTMLUIPlugin;
import org.eclipse.wst.html.ui.internal.contentoutline.HTMLNodeActionManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager;
import org.eclipse.wst.xml.ui.internal.views.contentoutline.XMLContentOutlineConfiguration;
@@ -27,8 +28,9 @@
}
protected XMLNodeActionManager createNodeActionManager(TreeViewer treeViewer) {
- return new HTMLNodeActionManager(getEditor().getModel(), treeViewer);
+ return new HTMLNodeActionManager((IStructuredModel) treeViewer.getInput(), treeViewer);
}
+
protected IPreferenceStore getPreferenceStore() {
return HTMLUIPlugin.getDefault().getPreferenceStore();
}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextEditor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextEditor.java
index 134c709..481cfda 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextEditor.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextEditor.java
@@ -16,6 +16,8 @@
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
@@ -32,6 +34,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.emf.common.command.Command;
@@ -51,11 +54,14 @@
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ISelectionValidator;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextOperationTarget;
+import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerExtension;
import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.IVerticalRuler;
@@ -63,7 +69,17 @@
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
+import org.eclipse.jface.util.ListenerList;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
@@ -106,7 +122,7 @@
import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.IDocumentProviderExtension;
-import org.eclipse.ui.texteditor.IElementStateListener;
+import org.eclipse.ui.texteditor.IDocumentProviderExtension4;
import org.eclipse.ui.texteditor.IStatusField;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
@@ -121,14 +137,16 @@
import org.eclipse.wst.sse.core.internal.encoding.EncodingMemento;
import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
import org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable;
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;
import org.eclipse.wst.sse.core.internal.util.StringUtils;
import org.eclipse.wst.sse.ui.internal.actions.ActionDefinitionIds;
import org.eclipse.wst.sse.ui.internal.actions.StructuredTextEditorActionConstants;
-import org.eclipse.wst.sse.ui.internal.contentoutline.StructuredTextEditorContentOutlinePage;
+import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
import org.eclipse.wst.sse.ui.internal.debug.BreakpointRulerAction;
import org.eclipse.wst.sse.ui.internal.debug.EditBreakpointAction;
import org.eclipse.wst.sse.ui.internal.debug.ManageBreakpointAction;
@@ -161,7 +179,6 @@
import org.eclipse.wst.sse.ui.internal.util.Assert;
public class StructuredTextEditor extends TextEditor {
-
class InternalDocumentListener implements IDocumentListener {
// This is for the IDocumentListener interface
public void documentAboutToBeChanged(DocumentEvent event) {
@@ -221,30 +238,7 @@
}
}
- class InternalElementStateListener implements IElementStateListener {
-
- public void elementContentAboutToBeReplaced(Object element) {
- // nothing to do
- }
-
- public void elementContentReplaced(Object element) {
- // nothing to do
- }
-
- public void elementDeleted(Object element) {
- // nothing to do
- }
-
- public void elementDirtyStateChanged(Object element, boolean isDirty) {
- // nothing to do
- }
-
- public void elementMoved(Object originalElement, Object movedElement) {
- // nothing to do
- }
- }
-
- class InternalModelStateListener implements IModelStateListener {
+ private class InternalModelStateListener implements IModelStateListener {
public void modelAboutToBeChanged(IStructuredModel model) {
if (getTextViewer() != null) {
// getTextViewer().setRedraw(false);
@@ -394,7 +388,97 @@
}
}
- class ShowInTargetListAdapter implements IShowInTargetList {
+ /**
+ * Listens to double-click and selection from the outline page
+ */
+ private class OutlinePageListener implements IDoubleClickListener, ISelectionChangedListener {
+ public void doubleClick(DoubleClickEvent event) {
+ if (event.getSelection().isEmpty())
+ return;
+
+ int start = -1;
+ int length = 0;
+ if (event.getSelection() instanceof IStructuredSelection) {
+ ISelection currentSelection = getSelectionProvider().getSelection();
+ if (currentSelection instanceof IStructuredSelection) {
+ Object current = ((IStructuredSelection) currentSelection).toArray();
+ Object newSelection = ((IStructuredSelection) event.getSelection()).toArray();
+ if (!current.equals(newSelection)) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ Object o = selection.getFirstElement();
+ Object o2 = null;
+ if (selection.size() > 1) {
+ o2 = selection.toArray()[selection.size() - 1];
+ }
+ else {
+ o2 = o;
+ }
+ if (o instanceof IndexedRegion) {
+ start = ((IndexedRegion) o).getStartOffset();
+ length = ((IndexedRegion) o2).getEndOffset() - start;
+ }
+ else if (o instanceof ITextRegion) {
+ start = ((ITextRegion) o).getStart();
+ length = ((ITextRegion) o2).getEnd() - start;
+ }
+ }
+ }
+ }
+ else if (event.getSelection() instanceof ITextSelection) {
+ start = ((ITextSelection) event.getSelection()).getOffset();
+ length = ((ITextSelection) event.getSelection()).getLength();
+ }
+ if (start > -1) {
+ getSourceViewer().setRangeIndication(start, length, false);
+ selectAndReveal(start, length);
+ }
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ /*
+ * Do not allow selection from other parts to affect selection in
+ * the text widget if it has focus, or if we're still firing a
+ * change of selection. Selection events "bouncing" off of other
+ * parts are all that we can receive if we have focus (since we
+ * forwarded our selection to the service just a moment ago), and
+ * only the user should affect selection if we have focus.
+ */
+
+ /* The isFiringSelection check only works if a selection listener */
+ if (event.getSelection().isEmpty() || fStructuredSelectionProvider.isFiringSelection())
+ return;
+
+ if (getSourceViewer() != null && getSourceViewer().getTextWidget() != null && !getSourceViewer().getTextWidget().isDisposed() && !getSourceViewer().getTextWidget().isFocusControl()) {
+ int start = -1;
+ if (event.getSelection() instanceof IStructuredSelection) {
+ ISelection current = getSelectionProvider().getSelection();
+ if (current instanceof IStructuredSelection) {
+ Object[] currentSelection = ((IStructuredSelection) current).toArray();
+ Object[] newSelection = ((IStructuredSelection) event.getSelection()).toArray();
+ if (!Arrays.equals(currentSelection, newSelection)) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ Object o = selection.getFirstElement();
+ if (o instanceof IndexedRegion) {
+ start = ((IndexedRegion) o).getStartOffset();
+ }
+ else if (o instanceof ITextRegion) {
+ start = ((ITextRegion) o).getStart();
+ }
+ }
+ }
+ }
+ else if (event.getSelection() instanceof ITextSelection) {
+ start = ((ITextSelection) event.getSelection()).getOffset();
+ }
+ if (start > -1) {
+ updateRangeIndication(event.getSelection());
+ selectAndReveal(start, 0);
+ }
+ }
+ }
+ }
+
+ private class ShowInTargetListAdapter implements IShowInTargetList {
/**
* Array of ID Strings that define the default show in targets for
* this editor.
@@ -408,8 +492,222 @@
}
}
- class TimeOutExpired extends TimerTask {
+ /**
+ * A post selection provider that wraps the provider implemented in
+ * AbstractTextEditor to provide a StructuredTextSelection to post
+ * selection listeners. Listens to selection changes from the source
+ * viewer.
+ */
+ private class StructuredSelectionProvider implements IPostSelectionProvider, ISelectionValidator {
+ /**
+ * A "hybrid" text and structured selection class. Converts the source
+ * viewer text selection to a generic "getIndexedRegion"-derived
+ * structured selection, allowing selection changed listeners to
+ * possibly not need to reference the model directly.
+ */
+ private class StructuredTextSelection extends TextSelection implements IStructuredSelection {
+ private Object[] selectedStructures = null;
+ public StructuredTextSelection(ITextSelection selection) {
+ super(getSourceViewer().getDocument(), selection.getOffset(), selection.getLength());
+ selectedStructures = getSelectedObjects(selection);
+ }
+
+ public StructuredTextSelection(ITextSelection selection, Object[] selectedObjects) {
+ super(getSourceViewer().getDocument(), selection.getOffset(), selection.getLength());
+ selectedStructures = selectedObjects;
+ }
+
+ public Object getFirstElement() {
+ return selectedStructures.length > 0 ? selectedStructures[0] : null;
+ }
+
+ private Object[] getSelectedObjects(ITextSelection selection) {
+ IStructuredModel model = getInternalModel();
+ if (model != null) {
+ IndexedRegion region = model.getIndexedRegion(selection.getOffset());
+ int end = selection.getOffset() + selection.getLength();
+ if (region != null && end <= region.getEndOffset()) {
+ // single selection
+ selectedStructures = new Object[1];
+ selectedStructures[0] = region;
+ }
+ else {
+ // multiple selection
+ int maxLength = getSourceViewer().getDocument().getLength();
+ List structures = new ArrayList(2);
+ while (region != null && region.getEndOffset() <= end && region.getEndOffset() < maxLength) {
+ structures.add(region);
+ region = model.getIndexedRegion(region.getEndOffset() + 1);
+ }
+ selectedStructures = structures.toArray();
+ }
+ }
+ else {
+ selectedStructures = new Object[0];
+ }
+ return selectedStructures;
+ }
+
+ public boolean isEmpty() {
+ return super.isEmpty() && selectedStructures.length > 0;
+ }
+
+ public Iterator iterator() {
+ return toList().iterator();
+ }
+
+ public int size() {
+ return selectedStructures.length;
+ }
+
+ public Object[] toArray() {
+ return selectedStructures;
+ }
+
+ public List toList() {
+ return Arrays.asList(selectedStructures);
+ }
+
+ public String toString() {
+ return getOffset() + ":" + getLength() + "@" + selectedStructures;
+ }
+ }
+
+ ISelectionProvider fParentProvider = null;
+ private boolean isFiringSelection = false;
+ private ListenerList listeners = new ListenerList();
+ private ListenerList postListeners = new ListenerList();
+
+ StructuredSelectionProvider(ISelectionProvider parentProvider) {
+ fParentProvider = parentProvider;
+ fParentProvider.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ handleSelectionChanged(event);
+ }
+ });
+ if (fParentProvider instanceof IPostSelectionProvider) {
+ ((IPostSelectionProvider) fParentProvider).addPostSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ handlePostSelectionChanged(event);
+ }
+ });
+ }
+ }
+
+ public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
+ postListeners.add(listener);
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ listeners.add(listener);
+ }
+
+ private void fireSelectionChanged(final SelectionChangedEvent event, ListenerList listenerList) {
+ Object[] listeners = listenerList.getListeners();
+ isFiringSelection = true;
+ for (int i = 0; i < listeners.length; ++i) {
+ final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
+ Platform.run(new SafeRunnable() {
+ public void run() {
+ l.selectionChanged(event);
+ }
+ });
+ }
+ isFiringSelection = false;
+ }
+
+ private ISelectionProvider getParentProvider() {
+ return fParentProvider;
+ }
+
+ public ISelection getSelection() {
+ /*
+ * When a client explicitly asks for selection, provide the hybrid
+ * result.
+ */
+ ISelection selection = getParentProvider().getSelection();
+ if (!(selection instanceof IStructuredSelection) && selection instanceof ITextSelection) {
+ selection = new StructuredTextSelection((ITextSelection) selection);
+ }
+ return selection;
+ }
+
+ void handlePostSelectionChanged(SelectionChangedEvent event) {
+ SelectionChangedEvent structuredEvent = updateEvent(event);
+ // only update the range indicator on post selection
+ updateRangeIndication(structuredEvent.getSelection());
+ fireSelectionChanged(structuredEvent, postListeners);
+ }
+
+ void handleSelectionChanged(SelectionChangedEvent event) {
+ SelectionChangedEvent structuredEvent = updateEvent(event);
+ fireSelectionChanged(structuredEvent, listeners);
+ }
+
+ boolean isFiringSelection() {
+ return isFiringSelection;
+ }
+
+ public boolean isValid(ISelection selection) {
+ if (getParentProvider() instanceof ISelectionValidator) {
+ return ((ISelectionValidator) getParentProvider()).isValid(selection);
+ }
+ return true;
+ }
+
+ public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
+ postListeners.remove(listener);
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void setSelection(ISelection selection) {
+ if (isFiringSelection()) {
+ return;
+ }
+ ISelection textSelection = updateSelection(selection);
+ getParentProvider().setSelection(textSelection);
+ updateRangeIndication(textSelection);
+ }
+
+ /**
+ * Create a corresponding event that contains a
+ * StructuredTextselection
+ *
+ * @param event
+ * @return
+ */
+ private SelectionChangedEvent updateEvent(SelectionChangedEvent event) {
+ ISelection selection = event.getSelection();
+ if (selection instanceof ITextSelection && !(selection instanceof IStructuredSelection)) {
+ selection = new StructuredTextSelection((ITextSelection) event.getSelection());
+ }
+ SelectionChangedEvent newEvent = new SelectionChangedEvent(event.getSelectionProvider(), selection);
+ return newEvent;
+ }
+
+ /**
+ * Create a corresponding StructuredTextselection
+ *
+ * @param selection
+ * @return
+ */
+ private ISelection updateSelection(ISelection selection) {
+ ISelection updated = selection;
+ if (selection instanceof IStructuredSelection && !(selection instanceof ITextSelection) && !selection.isEmpty()) {
+ Object[] selectedObjects = ((IStructuredSelection) selection).toArray();
+ int start = ((IndexedRegion) selectedObjects[0]).getStartOffset();
+
+ updated = new StructuredTextSelection(new TextSelection(getSourceViewer().getDocument(), start, 0), selectedObjects);
+ }
+ return updated;
+ };
+ }
+
+ class TimeOutExpired extends TimerTask {
public void run() {
getDisplay().syncExec(new Runnable() {
public void run() {
@@ -418,6 +716,7 @@
}
});
}
+
}
private class ConfigurationAndTarget {
@@ -439,22 +738,23 @@
}
protected final static char[] BRACKETS = {'{', '}', '(', ')', '[', ']'};
+
private static final long BUSY_STATE_DELAY = 1000;
protected static final String DOT = "."; //$NON-NLS-1$
private static final String EDITOR_CONTEXT_MENU_ID = "org.eclipse.wst.sse.ui.StructuredTextEditor.EditorContext"; //$NON-NLS-1$
private static final String EDITOR_CONTEXT_MENU_POSTFIX = ".source.EditorContext"; //$NON-NLS-1$
- private static final String RULER_CONTEXT_MENU_ID = "org.eclipse.wst.sse.ui.StructuredTextEditor.RulerContext"; //$NON-NLS-1$
- private static final String RULER_CONTEXT_MENU_POSTFIX = ".source.RulerContext"; //$NON-NLS-1$
/** Non-NLS strings */
private static final String EDITOR_KEYBINDING_SCOPE_ID = "org.eclipse.wst.sse.ui.structuredTextEditorScope"; //$NON-NLS-1$
-
public static final String GROUP_NAME_ADDITIONS = "additions"; //$NON-NLS-1$
public static final String GROUP_NAME_FORMAT = "Format"; //$NON-NLS-1$
public static final String GROUP_NAME_FORMAT_EXT = "Format.ext"; //$NON-NLS-1$
+
private static final String REDO_ACTION_DESC = SSEUIMessages.Redo___0___UI_; //$NON-NLS-1$ = "Redo: {0}."
private static final String REDO_ACTION_DESC_DEFAULT = SSEUIMessages.Redo_Text_Change__UI_; //$NON-NLS-1$ = "Redo Text Change."
private static final String REDO_ACTION_TEXT = SSEUIMessages._Redo__0___Ctrl_Y_UI_; //$NON-NLS-1$ = "&Redo {0} @Ctrl+Y"
private static final String REDO_ACTION_TEXT_DEFAULT = SSEUIMessages._Redo_Text_Change__Ctrl_Y_UI_; //$NON-NLS-1$ = "&Redo Text Change @Ctrl+Y"
+ private static final String RULER_CONTEXT_MENU_ID = "org.eclipse.wst.sse.ui.StructuredTextEditor.RulerContext"; //$NON-NLS-1$
+ private static final String RULER_CONTEXT_MENU_POSTFIX = ".source.RulerContext"; //$NON-NLS-1$
protected static final String SSE_MODEL_ID = "org.eclipse.wst.sse.core"; //$NON-NLS-1$
/**
* Constant for representing an error status. This is considered a value
@@ -467,15 +767,15 @@
*/
static final protected IStatus STATUS_OK = new Status(IStatus.OK, SSEUIPlugin.ID, IStatus.OK, "OK", null); //$NON-NLS-1$
private final static String UNDERSCORE = "_"; //$NON-NLS-1$
-
/** Translatable strings */
private static final String UNDO_ACTION_DESC = SSEUIMessages.Undo___0___UI_; //$NON-NLS-1$ = "Undo: {0}."
+
private static final String UNDO_ACTION_DESC_DEFAULT = SSEUIMessages.Undo_Text_Change__UI_; //$NON-NLS-1$ = "Undo Text Change."
private static final String UNDO_ACTION_TEXT = SSEUIMessages._Undo__0___Ctrl_Z_UI_; //$NON-NLS-1$ = "&Undo {0} @Ctrl+Z"
private static final String UNDO_ACTION_TEXT_DEFAULT = SSEUIMessages._Undo_Text_Change__Ctrl_Z_UI_; //$NON-NLS-1$ = "&Undo Text Change @Ctrl+Z"
-
// development time/debug variables only
private int adapterRequests;
+
private long adapterTime;
private boolean fBackgroundJobEnded;
private boolean fBusyState;
@@ -488,38 +788,43 @@
private IEditorPart fEditorPart;
private IDocumentListener fInternalDocumentListener;
private InternalModelStateListener fInternalModelStateListener;
-
private MouseTracker fMouseTracker;
protected IContentOutlinePage fOutlinePage;
+
+ private OutlinePageListener fOutlinePageListener = null;
/** This editor's projection model updater */
private IStructuredTextFoldingProvider fProjectionModelUpdater;
/** This editor's projection support */
private ProjectionSupport fProjectionSupport;
protected IPropertySheetPage fPropertySheetPage;
private String fRememberTitle;
- String[] fShowInTargetIds = new String[]{IPageLayout.ID_RES_NAV};
- private IAction fShowPropertiesAction = null;
- private IStructuredModel fStructuredModel;
- /** The text context menu to be disposed. */
- private Menu fTextContextMenu;
- /** The text context menu manager to be disposed. */
- private MenuManager fTextContextMenuManager;
/** The ruler context menu to be disposed. */
private Menu fRulerContextMenu;
/** The ruler context menu manager to be disposed. */
private MenuManager fRulerContextMenuManager;
+
+ String[] fShowInTargetIds = new String[]{IPageLayout.ID_RES_NAV};
+
+ private IAction fShowPropertiesAction = null;
+ private IStructuredModel fStructuredModel;
+ StructuredSelectionProvider fStructuredSelectionProvider = null;
+ /** The text context menu to be disposed. */
+ private Menu fTextContextMenu;
+ /** The text context menu manager to be disposed. */
+ private MenuManager fTextContextMenuManager;
private String fViewerConfigurationTargetId;
private boolean fUpdateMenuTextPending;
int hoverX = -1;
int hoverY = -1;
- private InternalElementStateListener internalElementStateListener = new InternalElementStateListener();
+
private boolean shouldClose = false;
private long startPerfTime;
private boolean fisReleased;
- public StructuredTextEditor() {
+ private ViewerSelectionManager fViewerSelectionManager;
+ public StructuredTextEditor() {
super();
initializeDocumentProvider(null);
}
@@ -597,12 +902,12 @@
}
}
-
-
protected void addExtendedRulerContextMenuActions(IMenuManager menu) {
// none at this level
}
+
+
/**
*
*/
@@ -616,17 +921,6 @@
}
}
- // private void addFindOccurrencesAction(String matchType, String
- // matchText, IMenuManager menu) {
- //
- // AbstractFindOccurrencesAction action = new
- // AbstractFindOccurrencesAction(getFileInEditor(), new
- // SearchUIConfiguration(), (IStructuredDocument) getDocument(),
- // matchType, matchText, getProgressMonitor());
- // action.setText("Occurrences of \"" + matchText + "\" in File");
- // menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, action);
- // }
-
/**
*
*/
@@ -643,6 +937,17 @@
showBusy(true);
}
+ // private void addFindOccurrencesAction(String matchType, String
+ // matchText, IMenuManager menu) {
+ //
+ // AbstractFindOccurrencesAction action = new
+ // AbstractFindOccurrencesAction(getFileInEditor(), new
+ // SearchUIConfiguration(), (IStructuredDocument) getDocument(),
+ // matchType, matchText, getProgressMonitor());
+ // action.setText("Occurrences of \"" + matchText + "\" in File");
+ // menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, action);
+ // }
+
/**
* Instead of us closing directly, we have to close with our containing
* (multipage) editor, if it exists.
@@ -717,13 +1022,12 @@
* Compute and set double-click action for the source editor, depending on
* the input.
*/
- private void computeAndSetDoubleClickAction(IStructuredModel model) {
- if (model == null)
- return;
+ private void computeAndSetDoubleClickAction() {
// If we're editing a breakpoint-supported input, make double-clicking
// on the ruler toggle a breakpoint instead of toggling a bookmark.
- String ext = BreakpointRulerAction.getFileExtension(getEditorInput());
- if (BreakpointProviderBuilder.getInstance().isAvailable(model.getContentTypeIdentifier(), ext)) {
+ String contentTypeIdentifier = getInputContentIdentifier(getEditorInput());
+ String filenameExtension = BreakpointRulerAction.getFileExtension(getEditorInput());
+ if (BreakpointProviderBuilder.getInstance().isAvailable(contentTypeIdentifier, filenameExtension)) {
setAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK, getAction(ActionDefinitionIds.TOGGLE_BREAKPOINTS));
}
else {
@@ -1116,11 +1420,6 @@
fRulerContextMenuManager.dispose();
}
- // added this 2/19/2004 to match the 'add' in
- // intializeDocumentProvider.
- if (getDocumentProvider() != null)
- getDocumentProvider().removeElementStateListener(internalElementStateListener);
-
// added this 2/20/2004 based on probe results --
// seems should be handled by setModel(null), but
// that's a more radical change.
@@ -1142,6 +1441,17 @@
}
}
+ // some things in the configuration need to clean
+ // up after themselves
+ if (fOutlinePage != null) {
+ if (fOutlinePage instanceof ConfigurableContentOutlinePage && fOutlinePageListener != null) {
+ ((ConfigurableContentOutlinePage) fOutlinePage).removeDoubleClickListener(fOutlinePageListener);
+ }
+ if (fOutlinePageListener != null) {
+ fOutlinePage.removeSelectionChangedListener(fOutlinePageListener);
+ }
+ }
+
fEditorDisposed = true;
disposeModelDependentFields();
@@ -1376,15 +1686,19 @@
ContentOutlineConfiguration cfg = createContentOutlineConfiguration();
if (cfg != null) {
if (cfg instanceof StructuredContentOutlineConfiguration) {
- ((StructuredContentOutlineConfiguration) cfg).setEditor(this);
+ ((StructuredContentOutlineConfiguration) cfg).setEditor(getEditorPart());
}
- StructuredTextEditorContentOutlinePage outlinePage = new StructuredTextEditorContentOutlinePage();
+ ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage();
outlinePage.setConfiguration(cfg);
- outlinePage.setViewerSelectionManager(getViewerSelectionManager());
- // note: model might be null at this point, but
- // if so, once model is set in editor,
- // update will be called and set it
- outlinePage.setModel(getInternalModel());
+ outlinePage.setInput(getInternalModel());
+
+ if (fOutlinePageListener == null) {
+ fOutlinePageListener = new OutlinePageListener();
+ }
+
+ outlinePage.addSelectionChangedListener(fOutlinePageListener);
+ outlinePage.addDoubleClickListener(fOutlinePageListener);
+
fOutlinePage = outlinePage;
}
}
@@ -1396,23 +1710,15 @@
PropertySheetConfiguration cfg = createPropertySheetConfiguration();
if (cfg != null) {
if (cfg instanceof StructuredPropertySheetConfiguration) {
- ((StructuredPropertySheetConfiguration) cfg).setEditor(this);
+ ((StructuredPropertySheetConfiguration) cfg).setEditor(getEditorPart());
}
ConfigurablePropertySheetPage propertySheetPage = new ConfigurablePropertySheetPage();
propertySheetPage.setConfiguration(cfg);
- propertySheetPage.setViewerSelectionManager(getViewerSelectionManager());
- // note: model might be null at this point, but
- // if so, once model is set in editor,
- // update will be called and set it
- propertySheetPage.setModel(getInternalModel());
fPropertySheetPage = propertySheetPage;
}
}
result = fPropertySheetPage;
}
- else if (ViewerSelectionManager.class.equals(required)) {
- result = getViewerSelectionManager();
- }
else if (IDocument.class.equals(required)) {
result = getDocumentProvider().getDocument(getEditorInput());
}
@@ -1426,17 +1732,8 @@
return new ShowInTargetListAdapter();
}
else {
- // Document document = getDOMDocument();
- // if (document != null && document instanceof INodeNotifier) {
- // result = ((INodeNotifier) document).getAdapterFor(required);
- // }
- if (result == null) {
- if (getInternalModel() != null) {
- result = getInternalModel().getAdapter(required);
- }
- else {
- result = super.getAdapter(required);
- }
+ if (result == null && getInternalModel() != null) {
+ result = getInternalModel().getAdapter(required);
}
// others
if (result == null)
@@ -1455,11 +1752,11 @@
return result;
}
-
private String[] getConfigurationPoints() {
String contentTypeIdentifierID = null;
- if (getInternalModel() != null)
+ if (getInternalModel() != null) {
contentTypeIdentifierID = getInternalModel().getContentTypeIdentifier();
+ }
return ConfigurationPointCalculator.getConfigurationPoints(this, contentTypeIdentifierID, ConfigurationPointCalculator.SOURCE, StructuredTextEditor.class);
}
@@ -1483,6 +1780,7 @@
return result;
}
+
Display getDisplay() {
return PlatformUI.getWorkbench().getDisplay();
}
@@ -1507,6 +1805,25 @@
return result;
}
+ private String getInputContentIdentifier(Object element) {
+ String id = null;
+ if (getInternalModel() != null) {
+ id = getInternalModel().getContentTypeIdentifier();
+ }
+ else if (getDocumentProvider() != null && getDocumentProvider() instanceof IDocumentProviderExtension4) {
+ IContentType type;
+ try {
+ type = ((IDocumentProviderExtension4) getDocumentProvider()).getContentType(element);
+ if (type != null) {
+ id = type.getId();
+ }
+ }
+ catch (CoreException e) {
+ }
+ }
+ return id;
+ }
+
private IDocumentListener getInternalDocumentListener() {
if (fInternalDocumentListener == null) {
fInternalDocumentListener = new InternalDocumentListener();
@@ -1588,6 +1905,19 @@
return SWT.LEFT_TO_RIGHT;
}
+ public ISelectionProvider getSelectionProvider() {
+ if (fStructuredSelectionProvider == null) {
+ ISelectionProvider parentProvider = super.getSelectionProvider();
+ if (parentProvider != null) {
+ fStructuredSelectionProvider = new StructuredSelectionProvider(parentProvider);
+ }
+ }
+ if (fStructuredSelectionProvider == null) {
+ return super.getSelectionProvider();
+ }
+ return fStructuredSelectionProvider;
+ }
+
private IStatusLineManager getStatusLineManager() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null)
@@ -1616,16 +1946,15 @@
}
/**
- * @deprecated
- *
- * will be made protected or removed in M4
+ * @deprecated - use normal selection with our ISelectionProvider
*
* @return
*/
public ViewerSelectionManager getViewerSelectionManager() {
- if (getTextViewer() != null)
- return getTextViewer().getViewerSelectionManager();
- return null;
+ if (fViewerSelectionManager == null) {
+ fViewerSelectionManager = new ViewerSelectionManagerImpl(getSourceViewer());
+ }
+ return fViewerSelectionManager;
}
protected void handleCursorPositionChanged() {
@@ -1683,13 +2012,9 @@
}
public void initializeDocumentProvider(IDocumentProvider documentProvider) {
- if (getDocumentProvider() != null)
- getDocumentProvider().removeElementStateListener(internalElementStateListener);
if (documentProvider != null) {
setDocumentProvider(documentProvider);
}
- if (documentProvider != null)
- documentProvider.addElementStateListener(internalElementStateListener);
}
protected void initializeDrop(ITextViewer textViewer) {
@@ -1738,138 +2063,6 @@
}
}
- /**
- * Updates the editor context menu by creating a new context menu with the
- * given menu id
- *
- * @param contextMenuId
- * Cannot be null
- */
- private void updateEditorContextMenuId(String contextMenuId) {
- // update editor context menu id if updating to a new id or if context
- // menu is not already set up
- if (!contextMenuId.equals(getEditorContextMenuId()) || (fTextContextMenu == null)) {
- setEditorContextMenuId(contextMenuId);
-
- if (getSourceViewer() != null) {
- StyledText styledText = getSourceViewer().getTextWidget();
- if (styledText != null) {
- // dispose of previous context menu
- if (fTextContextMenu != null) {
- fTextContextMenu.dispose();
- }
- if (fTextContextMenuManager != null) {
- fTextContextMenuManager.removeMenuListener(getContextMenuListener());
- fTextContextMenuManager.removeAll();
- fTextContextMenuManager.dispose();
- }
-
- fTextContextMenuManager = new MenuManager(getEditorContextMenuId(), getEditorContextMenuId());
- fTextContextMenuManager.setRemoveAllWhenShown(true);
- fTextContextMenuManager.addMenuListener(getContextMenuListener());
-
- fTextContextMenu = fTextContextMenuManager.createContextMenu(styledText);
- styledText.setMenu(fTextContextMenu);
-
- getSite().registerContextMenu(getEditorContextMenuId(), fTextContextMenuManager, getSelectionProvider());
-
- // also register this menu for source page part and
- // structured text editor ids
- String partId = getSite().getId();
- if (partId != null) {
- getSite().registerContextMenu(partId + EDITOR_CONTEXT_MENU_POSTFIX, fTextContextMenuManager, getSelectionProvider());
- }
- getSite().registerContextMenu(EDITOR_CONTEXT_MENU_ID, fTextContextMenuManager, getSelectionProvider());
- }
- }
- }
- }
-
- /**
- * Updates editor context menu, vertical ruler menu, help context id for
- * new content type
- *
- * @param contentType
- */
- private void updateEditorControlsForContentType(String contentType) {
- if (contentType == null) {
- updateEditorContextMenuId(EDITOR_CONTEXT_MENU_ID);
- updateRulerContextMenuId(RULER_CONTEXT_MENU_ID);
- updateHelpContextId(ITextEditorHelpContextIds.TEXT_EDITOR);
- }
- else {
- updateEditorContextMenuId(contentType + EDITOR_CONTEXT_MENU_POSTFIX);
- updateRulerContextMenuId(contentType + RULER_CONTEXT_MENU_POSTFIX);
- updateHelpContextId(contentType + "_source_HelpId"); //$NON-NLS-1$
- }
- }
-
- /**
- * Updates the help context of the editor with the given help context id
- *
- * @param helpContextId
- * Cannot be null
- */
- private void updateHelpContextId(String helpContextId) {
- if (!helpContextId.equals(getHelpContextId())) {
- setHelpContextId(helpContextId);
-
- if (getSourceViewer() != null) {
- StyledText styledText = getSourceViewer().getTextWidget();
- if (styledText != null) {
- IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
- helpSystem.setHelp(styledText, getHelpContextId());
- }
- }
- }
- }
-
- /**
- * Updates the editor vertical ruler menu by creating a new vertical ruler
- * context menu with the given menu id
- *
- * @param rulerMenuId
- * Cannot be null
- */
- private void updateRulerContextMenuId(String rulerMenuId) {
- // update ruler context menu id if updating to a new id or if context
- // menu is not already set up
- if (!rulerMenuId.equals(getRulerContextMenuId()) || (fRulerContextMenu == null)) {
- setRulerContextMenuId(rulerMenuId);
-
- if (getVerticalRuler() != null) {
- // dispose of previous ruler context menu
- if (fRulerContextMenu != null) {
- fRulerContextMenu.dispose();
- }
- if (fRulerContextMenuManager != null) {
- fRulerContextMenuManager.removeMenuListener(getContextMenuListener());
- fRulerContextMenuManager.removeAll();
- fRulerContextMenuManager.dispose();
- }
-
- fRulerContextMenuManager = new MenuManager(getRulerContextMenuId(), getRulerContextMenuId());
- fRulerContextMenuManager.setRemoveAllWhenShown(true);
- fRulerContextMenuManager.addMenuListener(getContextMenuListener());
-
- Control rulerControl = getVerticalRuler().getControl();
- fRulerContextMenu = fRulerContextMenuManager.createContextMenu(rulerControl);
- rulerControl.setMenu(fRulerContextMenu);
- rulerControl.addMouseListener(getRulerMouseListener());
-
- getSite().registerContextMenu(getRulerContextMenuId(), fRulerContextMenuManager, getSelectionProvider());
-
- // also register this menu for source page part and structured
- // text editor ids
- String partId = getSite().getId();
- if (partId != null) {
- getSite().registerContextMenu(partId + RULER_CONTEXT_MENU_POSTFIX, fRulerContextMenuManager, getSelectionProvider());
- }
- getSite().registerContextMenu(RULER_CONTEXT_MENU_ID, fRulerContextMenuManager, getSelectionProvider());
- }
- }
- }
-
/*
* (non-Javadoc)
*
@@ -1884,10 +2077,7 @@
* viewer-dependent.
*/
private void initializeSourceViewer() {
- if (getViewerSelectionManager() != null)
- getViewerSelectionManager().setModel(getInternalModel());
-
- computeAndSetDoubleClickAction(getInternalModel());
+ computeAndSetDoubleClickAction();
IAction contentAssistAction = getAction(StructuredTextEditorActionConstants.ACTION_NAME_CONTENTASSIST_PROPOSALS);
if (contentAssistAction instanceof IUpdate) {
@@ -1951,7 +2141,6 @@
projectionViewer.doOperation(ProjectionViewer.TOGGLE);
}
-
/**
* Return whether document folding should be enabled according to the
* preference store settings.
@@ -2036,6 +2225,7 @@
super.rememberSelection();
}
+
/**
* both starts and resets the busy state timer
*/
@@ -2091,17 +2281,6 @@
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.texteditor.AbstractTextEditor#selectAndReveal(int,
- * int, int, int)
- */
- protected void selectAndReveal(int selectionStart, int selectionLength, int revealStart, int revealLength) {
- super.selectAndReveal(selectionStart, selectionLength, revealStart, revealLength);
- getTextViewer().notifyViewerSelectionManager(selectionStart, selectionLength);
- }
-
/**
* Ensure that the correct IDocumentProvider is used. For direct models, a
* special provider is used. For StorageEditorInputs, use a custom
@@ -2128,15 +2307,6 @@
}
/**
- * @deprecated - use setInput as if we were a text editor - may be REMOVED
- * AT ANY TIME
- *
- */
- public void setModel(IFileEditorInput input) {
- setInput(input);
- }
-
- /**
* Sets the model field within this editor.
*
* @deprecated - can eventually be eliminated
@@ -2194,13 +2364,12 @@
}
private void startBusyTimer() {
- // TODO: we need a resetable timer, so not so
- // many created
+ // TODO: we need a resettable timer, so not so
+ // many are created
fBusyTimer = new Timer(true);
fBusyTimer.schedule(new TimeOutExpired(), BUSY_STATE_DELAY);
}
-
private void statusError(IStatus status) {
statusError(status.getMessage());
ErrorDialog.openError(getSite().getShell(), null, null, status);
@@ -2219,14 +2388,13 @@
* swapped)
*/
public void update() {
- if (fOutlinePage != null && fOutlinePage instanceof StructuredTextEditorContentOutlinePage) {
+ if (fOutlinePage != null && fOutlinePage instanceof ConfigurableContentOutlinePage) {
ContentOutlineConfiguration cfg = createContentOutlineConfiguration();
if (cfg instanceof StructuredContentOutlineConfiguration) {
((StructuredContentOutlineConfiguration) cfg).setEditor(this);
}
- ((StructuredTextEditorContentOutlinePage) fOutlinePage).setConfiguration(cfg);
- ((StructuredTextEditorContentOutlinePage) fOutlinePage).setModel(getInternalModel());
- ((StructuredTextEditorContentOutlinePage) fOutlinePage).setViewerSelectionManager(getViewerSelectionManager());
+ ((ConfigurableContentOutlinePage) fOutlinePage).setConfiguration(cfg);
+ ((ConfigurableContentOutlinePage) fOutlinePage).setInput(getInternalModel());
}
if (fPropertySheetPage != null && fPropertySheetPage instanceof ConfigurablePropertySheetPage) {
PropertySheetConfiguration cfg = createPropertySheetConfiguration();
@@ -2234,20 +2402,15 @@
((StructuredPropertySheetConfiguration) cfg).setEditor(this);
}
((ConfigurablePropertySheetPage) fPropertySheetPage).setConfiguration(cfg);
- ((ConfigurablePropertySheetPage) fPropertySheetPage).setModel(getInternalModel());
- ((ConfigurablePropertySheetPage) fPropertySheetPage).setViewerSelectionManager(getViewerSelectionManager());
}
- if (getViewerSelectionManager() != null)
- getViewerSelectionManager().setModel(getInternalModel());
disposeModelDependentFields();
fShowInTargetIds = createShowInTargetIds();
-
updateSourceViewerConfiguration();
createModelDependentFields();
- computeAndSetDoubleClickAction(getInternalModel());
+ computeAndSetDoubleClickAction();
}
/**
@@ -2267,6 +2430,73 @@
updateMenuText();
}
+
+ /**
+ * Updates the editor context menu by creating a new context menu with the
+ * given menu id
+ *
+ * @param contextMenuId
+ * Cannot be null
+ */
+ private void updateEditorContextMenuId(String contextMenuId) {
+ // update editor context menu id if updating to a new id or if context
+ // menu is not already set up
+ if (!contextMenuId.equals(getEditorContextMenuId()) || (fTextContextMenu == null)) {
+ setEditorContextMenuId(contextMenuId);
+
+ if (getSourceViewer() != null) {
+ StyledText styledText = getSourceViewer().getTextWidget();
+ if (styledText != null) {
+ // dispose of previous context menu
+ if (fTextContextMenu != null) {
+ fTextContextMenu.dispose();
+ }
+ if (fTextContextMenuManager != null) {
+ fTextContextMenuManager.removeMenuListener(getContextMenuListener());
+ fTextContextMenuManager.removeAll();
+ fTextContextMenuManager.dispose();
+ }
+
+ fTextContextMenuManager = new MenuManager(getEditorContextMenuId(), getEditorContextMenuId());
+ fTextContextMenuManager.setRemoveAllWhenShown(true);
+ fTextContextMenuManager.addMenuListener(getContextMenuListener());
+
+ fTextContextMenu = fTextContextMenuManager.createContextMenu(styledText);
+ styledText.setMenu(fTextContextMenu);
+
+ getSite().registerContextMenu(getEditorContextMenuId(), fTextContextMenuManager, getSelectionProvider());
+
+ // also register this menu for source page part and
+ // structured text editor ids
+ String partId = getSite().getId();
+ if (partId != null) {
+ getSite().registerContextMenu(partId + EDITOR_CONTEXT_MENU_POSTFIX, fTextContextMenuManager, getSelectionProvider());
+ }
+ getSite().registerContextMenu(EDITOR_CONTEXT_MENU_ID, fTextContextMenuManager, getSelectionProvider());
+ }
+ }
+ }
+ }
+
+ /**
+ * Updates editor context menu, vertical ruler menu, help context id for
+ * new content type
+ *
+ * @param contentType
+ */
+ private void updateEditorControlsForContentType(String contentType) {
+ if (contentType == null) {
+ updateEditorContextMenuId(EDITOR_CONTEXT_MENU_ID);
+ updateRulerContextMenuId(RULER_CONTEXT_MENU_ID);
+ updateHelpContextId(ITextEditorHelpContextIds.TEXT_EDITOR);
+ }
+ else {
+ updateEditorContextMenuId(contentType + EDITOR_CONTEXT_MENU_POSTFIX);
+ updateRulerContextMenuId(contentType + RULER_CONTEXT_MENU_POSTFIX);
+ updateHelpContextId(contentType + "_source_HelpId"); //$NON-NLS-1$
+ }
+ }
+
private void updateEncodingMemento() {
boolean failed = false;
IStructuredModel internalModel = getInternalModel();
@@ -2294,6 +2524,26 @@
}
}
+ /**
+ * Updates the help context of the editor with the given help context id
+ *
+ * @param helpContextId
+ * Cannot be null
+ */
+ private void updateHelpContextId(String helpContextId) {
+ if (!helpContextId.equals(getHelpContextId())) {
+ setHelpContextId(helpContextId);
+
+ if (getSourceViewer() != null) {
+ StyledText styledText = getSourceViewer().getTextWidget();
+ if (styledText != null) {
+ IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem();
+ helpSystem.setHelp(styledText, getHelpContextId());
+ }
+ }
+ }
+ }
+
/*
* Update the hovering behavior depending on the preferences.
*/
@@ -2329,7 +2579,6 @@
}
}
-
protected void updateMenuText() {
if (fStructuredModel != null && !fStructuredModel.isModelStateChanging() && getTextViewer().getTextWidget() != null) {
// performance: don't force an update of the action bars unless
@@ -2406,6 +2655,65 @@
}
}
+ void updateRangeIndication(ISelection selection) {
+ if (selection instanceof IStructuredSelection && !((IStructuredSelection) selection).isEmpty()) {
+ Object[] objects = ((IStructuredSelection) selection).toArray();
+ int start = ((IndexedRegion) objects[0]).getStartOffset();
+ int end = ((IndexedRegion) objects[objects.length - 1]).getEndOffset();
+ getSourceViewer().setRangeIndication(start, end - start, false);
+ }
+ else {
+ getSourceViewer().removeRangeIndication();
+ }
+ }
+
+
+ /**
+ * Updates the editor vertical ruler menu by creating a new vertical ruler
+ * context menu with the given menu id
+ *
+ * @param rulerMenuId
+ * Cannot be null
+ */
+ private void updateRulerContextMenuId(String rulerMenuId) {
+ // update ruler context menu id if updating to a new id or if context
+ // menu is not already set up
+ if (!rulerMenuId.equals(getRulerContextMenuId()) || (fRulerContextMenu == null)) {
+ setRulerContextMenuId(rulerMenuId);
+
+ if (getVerticalRuler() != null) {
+ // dispose of previous ruler context menu
+ if (fRulerContextMenu != null) {
+ fRulerContextMenu.dispose();
+ }
+ if (fRulerContextMenuManager != null) {
+ fRulerContextMenuManager.removeMenuListener(getContextMenuListener());
+ fRulerContextMenuManager.removeAll();
+ fRulerContextMenuManager.dispose();
+ }
+
+ fRulerContextMenuManager = new MenuManager(getRulerContextMenuId(), getRulerContextMenuId());
+ fRulerContextMenuManager.setRemoveAllWhenShown(true);
+ fRulerContextMenuManager.addMenuListener(getContextMenuListener());
+
+ Control rulerControl = getVerticalRuler().getControl();
+ fRulerContextMenu = fRulerContextMenuManager.createContextMenu(rulerControl);
+ rulerControl.setMenu(fRulerContextMenu);
+ rulerControl.addMouseListener(getRulerMouseListener());
+
+ getSite().registerContextMenu(getRulerContextMenuId(), fRulerContextMenuManager, getSelectionProvider());
+
+ // also register this menu for source page part and structured
+ // text editor ids
+ String partId = getSite().getId();
+ if (partId != null) {
+ getSite().registerContextMenu(partId + RULER_CONTEXT_MENU_POSTFIX, fRulerContextMenuManager, getSelectionProvider());
+ }
+ getSite().registerContextMenu(RULER_CONTEXT_MENU_ID, fRulerContextMenuManager, getSelectionProvider());
+ }
+ }
+ }
+
private void updateSourceViewerConfiguration() {
SourceViewerConfiguration configuration = getSourceViewerConfiguration();
// no need to update source viewer configuration if one does not exist
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
index 73a75e9..13f4d47 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
@@ -15,7 +15,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.Vector;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.text.BadLocationException;
@@ -40,25 +39,17 @@
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
-import org.eclipse.jface.viewers.ContentViewer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.texteditor.IEditorStatusLine;
-import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.wst.sse.core.internal.cleanup.StructuredContentCleanupHandler;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.undo.IDocumentSelectionMediator;
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;
@@ -68,10 +59,6 @@
import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider;
import org.eclipse.wst.sse.ui.internal.reconcile.StructuredRegionProcessor;
import org.eclipse.wst.sse.ui.internal.util.PlatformStatusLineUtil;
-import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Node;
public class StructuredTextViewer extends ProjectionViewer implements IDocumentSelectionMediator {
@@ -108,50 +95,30 @@
}
}
- /**
- * A private delegate class to move INodeSelectionListener and
- * IDoubleClickListener off of the viewer's APIs
- */
- private class InternalSelectionListener implements INodeSelectionListener, IDoubleClickListener {
- public void doubleClick(DoubleClickEvent event) {
- handleDoubleClick(event);
- }
-
- public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
- handleNodeSelectionChanged(event);
- }
- }
-
/** Text operation codes */
private static final int BASE = ProjectionViewer.EXPAND_ALL; // see
// ProjectionViewer.EXPAND_ALL
- public static final int CLEANUP_DOCUMENT = BASE + 1;
- public static final int FORMAT_ACTIVE_ELEMENTS = BASE + 3;
+ private static final int CLEANUP_DOCUMENT = BASE + 1;
+ protected static final int FORMAT_ACTIVE_ELEMENTS = BASE + 3;
private static final String FORMAT_ACTIVE_ELEMENTS_TEXT = SSEUIMessages.Format_Active_Elements_UI_; //$NON-NLS-1$
public static final int FORMAT_DOCUMENT = BASE + 2;
private static final String FORMAT_DOCUMENT_TEXT = SSEUIMessages.Format_Document_UI_; //$NON-NLS-1$
- public static final int QUICK_FIX = BASE + 4;
+ protected static final int QUICK_FIX = BASE + 4;
private static final String TEXT_CUT = SSEUIMessages.Text_Cut_UI_; //$NON-NLS-1$
private static final String TEXT_PASTE = SSEUIMessages.Text_Paste_UI_; //$NON-NLS-1$
private static final String TEXT_SHIFT_LEFT = SSEUIMessages.Text_Shift_Left_UI_; //$NON-NLS-1$ = "Text Shift Left"
private static final String TEXT_SHIFT_RIGHT = SSEUIMessages.Text_Shift_Right_UI_; //$NON-NLS-1$ = "Text Shift Right"
+
private boolean fBackgroundupdateInProgress;
- protected StructuredContentCleanupHandler fContentCleanupHandler = null;
- protected IContentAssistant fCorrectionAssistant;
- protected boolean fCorrectionAssistantInstalled;
+ private StructuredContentCleanupHandler fContentCleanupHandler = null;
+ private IContentAssistant fCorrectionAssistant;
+ private boolean fCorrectionAssistantInstalled;
private IDocumentAdapter fDocAdapter;
- private InternalSelectionListener fSelectionListener = null;
-
- /**
- * TODO Temporary workaround for BUG44665
- */
/** The most recent widget modification as document command */
private StructuredDocumentCommand fDocumentCommand = new StructuredDocumentCommand();
private Highlighter fHighlighter;
- // TODO: never read locally
- boolean fRememberedStateContentAssistInstalled;
/**
* TODO Temporary workaround for BUG44665
@@ -159,7 +126,7 @@
/** Verify listener */
private TextVerifyListener fVerifyListener = new TextVerifyListener();
- private ViewerSelectionManager fViewerSelectionManager;
+ // private ViewerSelectionManager fViewerSelectionManager;
private SourceViewerConfiguration fConfiguration;
/**
@@ -168,7 +135,6 @@
*/
public StructuredTextViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles) {
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles);
- fSelectionListener = new InternalSelectionListener();
}
/**
@@ -265,7 +231,8 @@
if (fContentAssistant != null) {
fContentAssistant.install(this);
fContentAssistantInstalled = true;
- } else {
+ }
+ else {
// 248036
// disable the content assist operation if no content assistant
enableOperation(CONTENTASSIST_PROPOSALS, false);
@@ -279,7 +246,8 @@
if (fCorrectionAssistant != null) {
fCorrectionAssistant.install(this);
fCorrectionAssistantInstalled = true;
- } else {
+ }
+ else {
// disable the correction assist operation if no correction
// assistant
enableOperation(QUICK_FIX, false);
@@ -303,16 +271,16 @@
fUndoManager.disconnect();
}
setUndoManager(configuration.getUndoManager(this));
-
+
// release old annotation hover before setting new one
if (fAnnotationHover instanceof StructuredTextAnnotationHover) {
- ((StructuredTextAnnotationHover)fAnnotationHover).release();
+ ((StructuredTextAnnotationHover) fAnnotationHover).release();
}
setAnnotationHover(configuration.getAnnotationHover(this));
-
+
// release old annotation hover before setting new one
if (fOverviewRulerAnnotationHover instanceof StructuredTextAnnotationHover) {
- ((StructuredTextAnnotationHover)fOverviewRulerAnnotationHover).release();
+ ((StructuredTextAnnotationHover) fOverviewRulerAnnotationHover).release();
}
setOverviewRulerAnnotationHover(configuration.getAnnotationHover(this));
@@ -344,7 +312,8 @@
int stateMask = stateMasks[j];
setTextHover(configuration.getTextHover(this, t, stateMask), t, stateMask);
}
- } else {
+ }
+ else {
setTextHover(configuration.getTextHover(this, t), t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
}
@@ -396,7 +365,8 @@
IStructuredDocument structuredDocument = null;
if (document instanceof IStructuredDocument) {
structuredDocument = (IStructuredDocument) document;
- } else {
+ }
+ else {
if (document instanceof ProjectionDocument) {
IDocument doc = ((ProjectionDocument) document).getMasterDocument();
if (doc instanceof IStructuredDocument) {
@@ -409,7 +379,8 @@
}
if (structuredDocument == null) {
return false;
- } else {
+ }
+ else {
int length = end - start;
return structuredDocument.containsReadOnly(start, length);
}
@@ -472,7 +443,8 @@
IStatus status = editor.validateEdit(getControl().getShell());
if (status != null && status.isOK())
undo();
- } else
+ }
+ else
undo();
break;
}
@@ -482,7 +454,8 @@
IStatus status = editor.validateEdit(getControl().getShell());
if (status != null && status.isOK())
redo();
- } else
+ }
+ else
redo();
break;
}
@@ -517,7 +490,8 @@
PlatformStatusLineUtil.displayErrorMessage(err);
}
PlatformStatusLineUtil.addOneTimeClearListener();
- } else
+ }
+ else
beep();
}
break;
@@ -568,10 +542,12 @@
context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
extension.format(getDocument(), context);
- } else {
+ }
+ else {
fContentFormatter.format(getDocument(), region);
}
- } finally {
+ }
+ finally {
// end recording
selection = getTextWidget().getSelection();
cursorPosition = selection.x;
@@ -588,7 +564,8 @@
Point s = getSelectedRange();
IRegion region = new Region(s.x, s.y);
fContentFormatter.format(getDocument(), region);
- } finally {
+ }
+ finally {
// end recording
selection = getTextWidget().getSelection();
cursorPosition = selection.x;
@@ -607,7 +584,8 @@
IStructuredDocument structuredDocument = (IStructuredDocument) doc;
IStructuredTextUndoManager undoManager = structuredDocument.getUndoManager();
undoManager.endRecording(this, cursorPosition, selectionLength);
- } else {
+ }
+ else {
// TODO: how to handle other document types?
}
}
@@ -618,7 +596,8 @@
IStructuredDocument structuredDocument = (IStructuredDocument) doc;
IStructuredTextUndoManager undoManager = structuredDocument.getUndoManager();
undoManager.beginRecording(this, label, description, cursorPosition, selectionLength);
- } else {
+ }
+ else {
// TODO: how to handle other document types?
}
}
@@ -628,25 +607,7 @@
enabledRedrawing();
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.TextViewer#findAndSelect(int,
- * java.lang.String, boolean, boolean, boolean, boolean)
- */
- protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
- int result = super.findAndSelect(startPosition, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
-
- // findAndSelect calls fTextWidget.setSelectionRange(widgetPos,
- // length) to set selection,
- // which does not fire text widget selection event.
- // Need to notify ViewerSelectionManager here.
- notifyViewerSelectionManager(getSelectedRange().x, getSelectedRange().y);
-
- return result;
- }
-
- protected IExtendedSimpleEditor getActiveExtendedSimpleEditor() {
+ private IExtendedSimpleEditor getActiveExtendedSimpleEditor() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
@@ -660,25 +621,6 @@
return null;
}
-
- protected ViewerSelectionManager getDefaultViewerSelectionManager() {
- return new ViewerSelectionManagerImpl(this);
- }
-
- /**
- * @deprecated
- * @return the current ViewerSelectionManager
- */
- public ViewerSelectionManager getViewerSelectionManager() {
- if (fViewerSelectionManager == null) {
- ViewerSelectionManager viewerSelectionManager = getDefaultViewerSelectionManager();
- // use setter instead of field directly, so it get initialized
- // properly
- setViewerSelectionManager(viewerSelectionManager);
- }
- return fViewerSelectionManager;
- }
-
protected void handleDispose() {
Logger.trace("Source Editor", "StructuredTextViewer::handleDispose entry"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -690,12 +632,6 @@
// leaks very hard.
setSelection(TextSelection.emptySelection());
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.removeNodeDoubleClickListener(fSelectionListener);
- fViewerSelectionManager.removeNodeSelectionListener(fSelectionListener);
- fViewerSelectionManager.release();
- }
-
if (fHighlighter != null) {
fHighlighter.uninstall();
}
@@ -704,99 +640,6 @@
Logger.trace("Source Editor", "StructuredTextViewer::handleDispose exit"); //$NON-NLS-1$ //$NON-NLS-2$
}
- void handleDoubleClick(DoubleClickEvent event) {
- IStructuredSelection selection = (IStructuredSelection) event.getSelection();
- int selectionSize = selection.size();
- List selectedNodes = selection.toList();
- IndexedRegion doubleClickedNode = null;
- int selectionStart = 0;
- int selectionEnd = 0;
- if (selectionSize > 0) {
- // something selected
- // only one node can be double-clicked at a time
- // so, we get the first one
- Object o = selectedNodes.get(0);
- if (o instanceof IndexedRegion) {
- doubleClickedNode = (IndexedRegion) o;
- selectionStart = doubleClickedNode.getStartOffset();
- selectionEnd = doubleClickedNode.getEndOffset();
- // set new selection
- setSelectedRange(selectionStart, selectionEnd - selectionStart);
- }
- }
- }
-
- void handleNodeSelectionChanged(NodeSelectionChangedEvent event) {
-
- // Skip NodeSelectionChanged processing if this is the source of the
- // event.
- if (event.getSource().equals(this))
- return;
- List selectedNodes = new Vector(event.getSelectedNodes());
- boolean attrOrTextNodeSelected = false;
- int attrOrTextNodeStartOffset = 0;
- for (int i = 0; i < selectedNodes.size(); i++) {
- Object eachNode = selectedNodes.get(i);
- // replace attribute node with its parent
- if (eachNode instanceof Attr) {
- attrOrTextNodeSelected = true;
- attrOrTextNodeStartOffset = ((IndexedRegion) eachNode).getStartOffset();
- selectedNodes.set(i, ((Attr) eachNode).getOwnerElement());
- }
- // replace TextNode with its parent
- if ((eachNode instanceof Node) && (((Node) eachNode).getNodeType() == Node.TEXT_NODE)) {
- attrOrTextNodeSelected = true;
- attrOrTextNodeStartOffset = ((IndexedRegion) eachNode).getStartOffset();
- selectedNodes.set(i, ((Node) eachNode).getParentNode());
- }
- }
- if (nothingToSelect(selectedNodes)) {
- removeRangeIndication();
- } else {
- IndexedRegion startNode = (IndexedRegion) selectedNodes.get(0);
- IndexedRegion endNode = (IndexedRegion) selectedNodes.get(selectedNodes.size() - 1);
- int startOffset = startNode.getStartOffset();
- int endOffset = endNode.getEndOffset();
- // if end node is a child node of start node
- if (startNode.getEndOffset() > endNode.getEndOffset()) {
- endOffset = startNode.getEndOffset();
- }
- int length = endOffset - startOffset;
- // Move cursor only if the original source really came from
- // a ContentViewer (for example, the SourceEditorTreeViewer or the
- // XMLTableTreeViewer)
- // or a ContentOutlinePage (for example, the XSDTreeViewer).
- // Do not move the cursor if the source is a textWidget (which
- // means the selection came from the text viewer) or
- // if the source is the ViewerSelectionManager (which means the
- // selection was set programmatically).
- boolean moveCursor = (event.getSource() instanceof ContentViewer) || (event.getSource() instanceof IContentOutlinePage);
- // 20031012 (pa)
- // Changed moveCursor to "false" because it was causing the cursor
- // to jump to the beginning of the parent node in the case that a
- // child of the parent is deleted.
- // We really only want to set the range indicator on the left to
- // the range of the parent, but not move the cursor
- // setRangeIndication(startOffset, length, false);
- // 20040714 (nsd) Chnaged back to tru given that selection
- // problems
- // caused by the Outline view appear fixed.
- setRangeIndication(startOffset, length, moveCursor);
- if ((moveCursor) && (attrOrTextNodeSelected)) {
- setSelectedRange(attrOrTextNodeStartOffset, 0);
- revealRange(attrOrTextNodeStartOffset, 0);
- }
- // if(moveCursor) {
- // System.out.print("moving");
- // }
- // else {
- // System.out.print("not moving");
- // }
- // System.out.println(" on NodeSelectionEvent: " +
- // event.getSource());
- }
- }
-
/**
* TODO Temporary workaround for BUG44665
*/
@@ -845,10 +688,12 @@
try {
getSlaveDocumentManager().setAutoExpandMode(visible, true);
fDocumentCommand.executeStructuredDocumentCommand(getDocument());
- } finally {
+ }
+ finally {
getSlaveDocumentManager().setAutoExpandMode(visible, false);
}
- } else {
+ }
+ else {
fDocumentCommand.executeStructuredDocumentCommand(getDocument());
}
@@ -870,12 +715,14 @@
}
}
- } catch (BadLocationException x) {
+ }
+ catch (BadLocationException x) {
if (TRACE_ERRORS)
System.out.println("TextViewer.error.bad_location.verifyText"); //$NON-NLS-1$
- } finally {
+ }
+ finally {
if (compoundChange && fUndoManager != null)
fUndoManager.endCompoundChange();
@@ -910,7 +757,8 @@
if ((modelLineRegion.getOffset() < region.getOffset()) || (modelEnd > regionEnd))
return -1;
}
- } catch (BadLocationException e) {
+ }
+ catch (BadLocationException e) {
// returns -1 if modelLine is invalid
return -1;
}
@@ -963,46 +811,6 @@
* e.start, e.end)) { e.doit = false; beep(); } }
*/
- /**
- * @param selectedNodes
- * @return whether the IndexedNodes within the list should form a
- * selectionrange
- */
- private boolean nothingToSelect(List selectedNodes) {
- if (selectedNodes == null || selectedNodes.isEmpty() || selectedNodes.get(0) == null) // empty
- // selections
- return true;
- if (getDocument() == null) // viewer shutdown
- return true;
- // if the range would be the entire document's length, there's nothing
- // to show
- Object o = selectedNodes.get(0);
- if (o instanceof IndexedRegion) {
- IndexedRegion firstIndexedNode = (IndexedRegion) o;
- return firstIndexedNode.getEndOffset() - firstIndexedNode.getStartOffset() >= getDocument().getLength();
- }
- return true;
- }
-
- /**
- * Notify the ViewerSelectionManager when text is selected
- * programmatically, for example, by double-click processing or an editor
- * action like Edit->SelectAll
- */
- protected void notifyViewerSelectionManager(int offset, int length) {
- if (fViewerSelectionManager != null) {
- Event event = new Event();
- event.widget = getTextWidget();
- // sometimes null while closing
- if (event.widget != null) {
- SelectionEvent selectionEvent = new SelectionEvent(event);
- selectionEvent.x = offset;
- selectionEvent.y = offset + length;
- fViewerSelectionManager.widgetSelected(selectionEvent);
- }
- }
- }
-
private void redo() {
ignoreAutoEditStrategies(true);
fUndoManager.redo();
@@ -1045,7 +853,8 @@
}
// CaretEvent is not sent to ViewerSelectionManager after Save As.
// Need to notify ViewerSelectionManager here.
- notifyViewerSelectionManager(getSelectedRange().x, getSelectedRange().y);
+ // notifyViewerSelectionManager(getSelectedRange().x,
+ // getSelectedRange().y);
}
}
@@ -1069,28 +878,6 @@
}
}
- public void setViewerSelectionManager(ViewerSelectionManager viewerSelectionManager) {
- // disconnect from old one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.removeNodeDoubleClickListener(fSelectionListener);
- fViewerSelectionManager.removeNodeSelectionListener(fSelectionListener);
- fViewerSelectionManager.release();
- // No need to removeSelectionChangedListener here. Done when
- // editor
- // calls "new ViewerSelectionManagerImpl(ITextViewer)".
- // removeSelectionChangedListener(fViewerSelectionManager);
- }
- fViewerSelectionManager = viewerSelectionManager;
- // connect to new one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.addNodeDoubleClickListener(fSelectionListener);
- fViewerSelectionManager.addNodeSelectionListener(fSelectionListener);
- // No need to addSelectionChangedListener here. Done when editor
- // calls "new ViewerSelectionManagerImpl(ITextViewer)".
- // addSelectionChangedListener(fViewerSelectionManager);
- }
- }
-
/**
* Uninstalls anything that was installed by configure
*/
@@ -1102,13 +889,13 @@
if (fCorrectionAssistant != null) {
fCorrectionAssistant.uninstall();
}
-
+
if (fAnnotationHover instanceof StructuredTextAnnotationHover) {
- ((StructuredTextAnnotationHover)fAnnotationHover).release();
+ ((StructuredTextAnnotationHover) fAnnotationHover).release();
}
if (fOverviewRulerAnnotationHover instanceof StructuredTextAnnotationHover) {
- ((StructuredTextAnnotationHover)fOverviewRulerAnnotationHover).release();
+ ((StructuredTextAnnotationHover) fOverviewRulerAnnotationHover).release();
}
// doesn't seem to be handled elsewhere, so we'll be sure error
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/ConfigurableContentOutlinePage.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/ConfigurableContentOutlinePage.java
new file mode 100644
index 0000000..eedd2dc
--- /dev/null
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/ConfigurableContentOutlinePage.java
@@ -0,0 +1,584 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - initial API and implementation
+ * Jens Lukowski/Innoopract - initial renaming/restructuring
+ *
+ *******************************************************************************/
+package org.eclipse.wst.sse.ui.internal.contentoutline;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.util.DelegatingDragAdapter;
+import org.eclipse.jface.util.DelegatingDropAdapter;
+import org.eclipse.jface.util.ListenerList;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.util.TransferDragSourceListener;
+import org.eclipse.jface.util.TransferDropTargetListener;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DragSource;
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.IShowInTarget;
+import org.eclipse.ui.part.ShowInContext;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+import org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.ContentOutlineConfiguration;
+
+
+public class ConfigurableContentOutlinePage extends ContentOutlinePage implements IAdaptable {
+ /*
+ * Menu listener to create the additions group; required since the context
+ * menu is cleared every time it is shown
+ */
+ class AdditionGroupAdder implements IMenuListener {
+ public void menuAboutToShow(IMenuManager manager) {
+ IContributionItem[] items = manager.getItems();
+ if (items.length > 0 && items[items.length - 1].getId() != null) {
+ manager.insertAfter(items[items.length - 1].getId(), new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+ else {
+ manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ }
+ }
+ }
+
+ private class DoubleClickProvider implements IDoubleClickListener {
+ private IDoubleClickListener[] listeners = null;
+
+ void addDoubleClickListener(IDoubleClickListener newListener) {
+ if (listeners == null) {
+ listeners = new IDoubleClickListener[]{newListener};
+ }
+ else {
+ IDoubleClickListener[] newListeners = new IDoubleClickListener[listeners.length + 1];
+ System.arraycopy(listeners, 0, newListeners, 0, listeners.length);
+ newListeners[listeners.length] = newListener;
+ listeners = newListeners;
+ }
+ }
+
+ public void doubleClick(DoubleClickEvent event) {
+ fireDoubleClickEvent(event);
+ }
+
+ private void fireDoubleClickEvent(final DoubleClickEvent event) {
+ IDoubleClickListener[] firingListeners = listeners;
+ for (int i = 0; i < firingListeners.length; ++i) {
+ final IDoubleClickListener l = firingListeners[i];
+ Platform.run(new SafeRunnable() {
+ public void run() {
+ l.doubleClick(event);
+ }
+ });
+ }
+ }
+
+ void removeDoubleClickListener(IDoubleClickListener oldListener) {
+ if (listeners != null) {
+ if (listeners.length == 1 && listeners[0].equals(oldListener)) {
+ listeners = null;
+ }
+ else {
+ List newListeners = new ArrayList(Arrays.asList(listeners));
+ newListeners.remove(oldListener);
+ listeners = (IDoubleClickListener[]) newListeners.toArray(new IDoubleClickListener[listeners.length - 1]);
+ }
+ }
+ }
+ }
+
+ /**
+ * Forwards post-selection from the tree viewer to the listeners while
+ * acting as this page's selection provider.
+ */
+ private class PostOnlySelectionProvider implements IPostSelectionProvider, ISelectionChangedListener {
+ private ListenerList listeners = new ListenerList();
+ private ListenerList postListeners = new ListenerList();
+
+ public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
+ listeners.add(listener);
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ listeners.add(listener);
+ }
+
+ public void fireSelectionChanged(final SelectionChangedEvent event, ListenerList listenerList) {
+ Object[] listeners = listenerList.getListeners();
+ for (int i = 0; i < listeners.length; ++i) {
+ final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
+ Platform.run(new SafeRunnable() {
+ public void run() {
+ l.selectionChanged(event);
+ }
+ });
+ }
+ }
+
+ public ISelection getSelection() {
+ return getTreeViewer().getSelection();
+ }
+
+ public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ listeners.remove(listener);
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ fireSelectionChanged(event, listeners);
+ fireSelectionChanged(event, postListeners);
+ }
+
+ public void setSelection(ISelection selection) {
+ getTreeViewer().setSelection(selection);
+ };
+ }
+
+ /**
+ * Listens to post selection from the selection service, applying it to
+ * the tree viewer.
+ */
+ private class PostSelectionListener implements ISelectionListener {
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ // from selection service
+ _DEBUG_TIME = System.currentTimeMillis();
+ if (getControl() != null && !getControl().isDisposed() && !getControl().isFocusControl()) {
+ /*
+ * Do not allow selection from other parts to affect selection
+ * in the tree widget if it has focus. Selection events
+ * "bouncing" off of other parts are all that we can receive
+ * if we have focus (since we forward selection to the
+ * service), and only the user should affect selection if we
+ * have focus.
+ */
+ ISelection validContentSelection = getConfiguration().getSelection(getTreeViewer(), selection);
+ getTreeViewer().refresh(true);
+ boolean isLinked = getConfiguration().isLinkedWithEditor(getTreeViewer());
+ if (isLinked) {
+ getTreeViewer().setSelection(validContentSelection, true);
+ }
+ }
+ if (_DEBUG_SELECTION) {
+ System.out.println("(O:" + (System.currentTimeMillis() - _DEBUG_TIME) + "ms) " + part + " : " + selection);
+ }
+ }
+ }
+
+ private class ShowInTarget implements IShowInTarget {
+ /*
+ * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
+ */
+ public boolean show(ShowInContext context) {
+ setSelection(context.getSelection());
+ return getTreeViewer().getSelection().equals(context.getSelection());
+ }
+ }
+
+ protected static ContentOutlineConfiguration NULL_CONFIGURATION = new ContentOutlineConfiguration();
+
+ private static final String OUTLINE_CONTEXT_MENU_ID = "org.eclipse.wst.sse.ui.StructuredTextEditor.OutlineContext"; //$NON-NLS-1$
+ private static final String OUTLINE_CONTEXT_MENU_POSTFIX = ".source.OutlineContext"; //$NON-NLS-1$
+
+ private final boolean _DEBUG_SELECTION = false;
+ private long _DEBUG_TIME = 0;
+ private TransferDragSourceListener[] fActiveDragListeners;
+ private TransferDropTargetListener[] fActiveDropListeners;
+
+ private ContentOutlineConfiguration fConfiguration;
+ private Menu fContextMenu;
+
+ private String fContextMenuId;
+ private MenuManager fContextMenuManager;
+
+ private DoubleClickProvider fDoubleClickProvider = null;
+ private DelegatingDragAdapter fDragAdapter;
+ private DragSource fDragSource;
+ private DelegatingDropAdapter fDropAdapter;
+ private DropTarget fDropTarget;
+ private IMenuListener fGroupAdder = null;
+ private Object fInput = null;
+
+ private IEditorPart fOwnerEditor;
+ private ISelectionListener fSelectionListener = null;
+
+ public ConfigurableContentOutlinePage() {
+ super();
+ fGroupAdder = new AdditionGroupAdder();
+ }
+
+ public void addDoubleClickListener(IDoubleClickListener newListener) {
+ if (fDoubleClickProvider == null) {
+ fDoubleClickProvider = new DoubleClickProvider();
+ }
+ fDoubleClickProvider.addDoubleClickListener(newListener);
+ }
+
+ /**
+ * @see ContentOutlinePage#createControl
+ */
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+
+ IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage();
+ if (page != null) {
+ fOwnerEditor = page.getActiveEditor();
+ }
+
+ // create the context menu
+ fContextMenuManager = new MenuManager("#popup"); //$NON-NLS-1$
+ fContextMenuManager.setRemoveAllWhenShown(true);
+ Menu menu = fContextMenuManager.createContextMenu(getControl());
+ getControl().setMenu(menu);
+
+ fDragAdapter = new DelegatingDragAdapter();
+ fDragSource = new DragSource(getTreeViewer().getControl(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK);
+ fDropAdapter = new DelegatingDropAdapter();
+ fDropTarget = new DropTarget(getTreeViewer().getControl(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK);
+
+ setConfiguration(getConfiguration());
+
+ /*
+ * ContentOutlinePage only implements ISelectionProvider while the
+ * tree viewer implements both ISelectionProvider and
+ * IPostSelectionProvider. Use an ISelectionProvider that listens to
+ * post selection from the tree viewer and forward only post selection
+ * to the selection service.
+ */
+ PostOnlySelectionProvider provider = new PostOnlySelectionProvider();
+ getTreeViewer().addPostSelectionChangedListener(provider);
+ if (fDoubleClickProvider == null) {
+ fDoubleClickProvider = new DoubleClickProvider();
+ }
+ getTreeViewer().addDoubleClickListener(fDoubleClickProvider);
+ getSite().setSelectionProvider(provider);
+ }
+
+ public void dispose() {
+ super.dispose();
+ getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(getSelectionListener());
+ if (fDoubleClickProvider != null) {
+ getTreeViewer().removeDoubleClickListener(fDoubleClickProvider);
+ }
+
+ // dispose menu controls
+ if (fContextMenu != null) {
+ fContextMenu.dispose();
+ }
+ if (fContextMenuManager != null) {
+ IMenuListener listener = getConfiguration().getMenuListener(getTreeViewer());
+ if (listener != null)
+ fContextMenuManager.removeMenuListener(listener);
+ fContextMenuManager.removeMenuListener(fGroupAdder);
+ fContextMenuManager.removeAll();
+ fContextMenuManager.dispose();
+ }
+ setConfiguration(NULL_CONFIGURATION);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class key) {
+ Object adapter = getConfiguration().getAdapter(key);
+ if (adapter == null) {
+ if (key.equals(IShowInTarget.class)) {
+ adapter = new ShowInTarget();
+ }
+ }
+ return adapter;
+ }
+
+ /**
+ * @return
+ */
+ public ContentOutlineConfiguration getConfiguration() {
+ if (fConfiguration == null)
+ return NULL_CONFIGURATION;
+ return fConfiguration;
+ }
+
+ public ISelection getSelection() {
+ if (getTreeViewer() == null)
+ return StructuredSelection.EMPTY;
+ return getTreeViewer().getSelection();
+ }
+
+ private ISelectionListener getSelectionListener() {
+ if (fSelectionListener == null) {
+ fSelectionListener = new PostSelectionListener();
+ }
+ return fSelectionListener;
+ }
+
+ public void init(IPageSite pageSite) {
+ super.init(pageSite);
+ getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(getSelectionListener());
+ }
+
+
+ public void removeDoubleClickListener(IDoubleClickListener oldListener) {
+ if (fDoubleClickProvider != null) {
+ fDoubleClickProvider.removeDoubleClickListener(oldListener);
+ }
+ }
+
+ /**
+ * @param configuration
+ */
+ public void setConfiguration(ContentOutlineConfiguration configuration) {
+ // intentionally do not check to see if the new configuration != old
+ // configuration
+ if (getTreeViewer() != null) {
+ // remove the key listeners
+ if (getTreeViewer().getControl() != null && !getTreeViewer().getControl().isDisposed()) {
+ KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
+ for (int i = 0; i < listeners.length; i++) {
+ getTreeViewer().getControl().removeKeyListener(listeners[i]);
+ }
+ }
+ // remove any menu listeners
+ if (fContextMenuManager != null) {
+ IMenuListener listener = getConfiguration().getMenuListener(getTreeViewer());
+ if (listener != null)
+ fContextMenuManager.removeMenuListener(listener);
+ fContextMenuManager.removeMenuListener(fGroupAdder);
+ }
+ // clear the selection changed and double click listeners from the
+ // configuration
+ if (getConfiguration().getSelectionChangedListener(getTreeViewer()) != null)
+ removeSelectionChangedListener(getConfiguration().getSelectionChangedListener(getTreeViewer()));
+ if (getConfiguration().getPostSelectionChangedListener(getTreeViewer()) != null)
+ getTreeViewer().removePostSelectionChangedListener(getConfiguration().getPostSelectionChangedListener(getTreeViewer()));
+ IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
+ if (toolbarItems.length > 0 && getSite() != null && getSite().getActionBars() != null && getSite().getActionBars().getToolBarManager() != null) {
+ IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
+ for (int i = 0; i < toolbarItems.length; i++) {
+ toolbar.remove(toolbarItems[i]);
+ }
+ toolbar.update(false);
+ }
+ IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
+ if (menuItems.length > 0 && getSite().getActionBars().getMenuManager() != null) {
+ IContributionManager menubar = getSite().getActionBars().getMenuManager();
+ for (int i = 0; i < menuItems.length; i++) {
+ menubar.remove(menuItems[i]);
+ }
+ menubar.remove(IWorkbenchActionConstants.MB_ADDITIONS);
+ menubar.update(false);
+ }
+ // clear the DnD listeners and transfer types
+ if (fDragAdapter != null && !fDragAdapter.isEmpty() && !fDragSource.isDisposed() && fDragSource.getTransfer().length > 0) {
+ if (fActiveDragListeners != null) {
+ for (int i = 0; i < fActiveDragListeners.length; i++) {
+ fDragAdapter.removeDragSourceListener(fActiveDragListeners[i]);
+ }
+ }
+ fActiveDragListeners = null;
+ fDragSource.removeDragListener(fDragAdapter);
+ fDragSource.setTransfer(new Transfer[0]);
+ }
+ if (fDropAdapter != null && !fDropAdapter.isEmpty() && !fDropTarget.isDisposed() && fDropTarget.getTransfer().length > 0) {
+ if (fActiveDropListeners != null) {
+ for (int i = 0; i < fActiveDropListeners.length; i++) {
+ fDropAdapter.removeDropTargetListener(fActiveDropListeners[i]);
+ }
+ }
+ fActiveDropListeners = null;
+ fDropTarget.removeDropListener(fDropAdapter);
+ fDropTarget.setTransfer(new Transfer[0]);
+ }
+ // release any ties to this tree viewer
+ getConfiguration().unconfigure(getTreeViewer());
+ }
+
+ fConfiguration = configuration;
+ if (fConfiguration == null) {
+ fConfiguration = NULL_CONFIGURATION;
+ }
+
+ if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
+ // add a menu listener if one is provided
+ if (fContextMenuManager != null) {
+ IMenuListener listener = getConfiguration().getMenuListener(getTreeViewer());
+ if (listener != null)
+ fContextMenuManager.addMenuListener(listener);
+ fContextMenuManager.addMenuListener(fGroupAdder);
+ }
+ // (re)set the providers
+ getTreeViewer().setLabelProvider(getConfiguration().getLabelProvider(getTreeViewer()));
+ getTreeViewer().setContentProvider(getConfiguration().getContentProvider(getTreeViewer()));
+ if (getConfiguration().getSelectionChangedListener(getTreeViewer()) != null)
+ addSelectionChangedListener(getConfiguration().getSelectionChangedListener(getTreeViewer()));
+ if (getConfiguration().getPostSelectionChangedListener(getTreeViewer()) != null)
+ getTreeViewer().addPostSelectionChangedListener(getConfiguration().getPostSelectionChangedListener(getTreeViewer()));
+
+ // view toolbar
+ IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
+ if (toolbarItems.length > 0 && getSite() != null && getSite().getActionBars() != null && getSite().getActionBars().getToolBarManager() != null) {
+ IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
+ for (int i = 0; i < toolbarItems.length; i++) {
+ toolbar.add(toolbarItems[i]);
+ }
+ toolbar.update(true);
+ }
+ // view menu
+ IContributionManager menu = getSite().getActionBars().getMenuManager();
+ if (menu != null) {
+ IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
+ if (menuItems.length > 0) {
+ for (int i = 0; i < menuItems.length; i++) {
+ menuItems[i].setVisible(true);
+ menu.add(menuItems[i]);
+ menuItems[i].update();
+ }
+ menu.update(true);
+ }
+ }
+ // add the allowed DnD listeners and types
+ TransferDragSourceListener[] dragListeners = fConfiguration.getTransferDragSourceListeners(getTreeViewer());
+ if (fDragAdapter != null && dragListeners.length > 0) {
+ for (int i = 0; i < dragListeners.length; i++) {
+ fDragAdapter.addDragSourceListener(dragListeners[i]);
+ }
+ fActiveDragListeners = dragListeners;
+ fDragSource.addDragListener(fDragAdapter);
+ fDragSource.setTransfer(fDragAdapter.getTransfers());
+ }
+ TransferDropTargetListener[] dropListeners = fConfiguration.getTransferDropTargetListeners(getTreeViewer());
+ if (fDropAdapter != null && dropListeners.length > 0) {
+ for (int i = 0; i < dropListeners.length; i++) {
+ fDropAdapter.addDropTargetListener(dropListeners[i]);
+ }
+ fActiveDropListeners = dropListeners;
+ fDropTarget.addDropListener(fDropAdapter);
+ fDropTarget.setTransfer(fDropAdapter.getTransfers());
+ }
+ // add the key listeners
+ KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
+ for (int i = 0; i < listeners.length; i++) {
+ getTreeViewer().getControl().addKeyListener(listeners[i]);
+ }
+ }
+
+ if (fInput != null) {
+ setInput(fInput);
+ }
+ }
+
+ public void setInput(Object newInput) {
+ fInput = newInput;
+ /*
+ * Intentionally not optimized for checking new input vs. old input so
+ * that any existing content providers can be updated
+ */
+ if (getControl() != null && !getControl().isDisposed()) {
+ getTreeViewer().setInput(fInput);
+ updateContextMenuId();
+ }
+ }
+
+ /**
+ * Updates the outline page's context menu for the current input
+ */
+ private void updateContextMenuId() {
+ String contextMenuId = null;
+ // update outline view's context menu control and ID
+
+ if (fOwnerEditor == null) {
+ IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage();
+ if (page != null) {
+ fOwnerEditor = page.getActiveEditor();
+ }
+ }
+
+ contextMenuId = getConfiguration().getContentTypeID(getTreeViewer());
+
+ if (contextMenuId == null) {
+ contextMenuId = OUTLINE_CONTEXT_MENU_ID;
+ }
+
+ /*
+ * Update outline context menu id if updating to a new id or if
+ * context menu is not already set up
+ */
+ if (!contextMenuId.equals(fContextMenuId) || (fContextMenu == null)) {
+ fContextMenuId = contextMenuId;
+
+ if (getControl() != null && !getControl().isDisposed()) {
+ // dispose of previous context menu
+ if (fContextMenu != null) {
+ fContextMenu.dispose();
+ }
+ if (fContextMenuManager != null) {
+ IMenuListener listener = getConfiguration().getMenuListener(getTreeViewer());
+ if (listener != null)
+ fContextMenuManager.removeMenuListener(listener);
+ fContextMenuManager.removeMenuListener(fGroupAdder);
+ fContextMenuManager.removeAll();
+ fContextMenuManager.dispose();
+ }
+
+ fContextMenuManager = new MenuManager(fContextMenuId, fContextMenuId);
+ fContextMenuManager.setRemoveAllWhenShown(true);
+ IMenuListener listener = getConfiguration().getMenuListener(getTreeViewer());
+ if (listener != null)
+ fContextMenuManager.addMenuListener(listener);
+ fContextMenuManager.addMenuListener(fGroupAdder);
+
+ fContextMenu = fContextMenuManager.createContextMenu(getTreeViewer().getControl());
+ getTreeViewer().getControl().setMenu(fContextMenu);
+
+ getSite().registerContextMenu(fContextMenuId, fContextMenuManager, this);
+
+ /*
+ * also register this menu for source page part and structured
+ * text outline view ids
+ */
+ if (fOwnerEditor != null) {
+ String partId = fOwnerEditor.getSite().getId();
+ if (partId != null) {
+ getSite().registerContextMenu(partId + OUTLINE_CONTEXT_MENU_POSTFIX, fContextMenuManager, this);
+ }
+ }
+ getSite().registerContextMenu(OUTLINE_CONTEXT_MENU_ID, fContextMenuManager, this);
+ }
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/SourceEditorTreeViewer.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/SourceEditorTreeViewer.java
index 68fb4df..e9cf4f1 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/SourceEditorTreeViewer.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/SourceEditorTreeViewer.java
@@ -30,6 +30,9 @@
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.ui.internal.StructuredTextSelectionChangedEvent;
+/**
+ * @deprecated
+ */
public class SourceEditorTreeViewer extends TreeViewer {
private int fCaretPosition;
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/StructuredTextEditorContentOutlinePage.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/StructuredTextEditorContentOutlinePage.java
deleted file mode 100644
index f4e1baa..0000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentoutline/StructuredTextEditorContentOutlinePage.java
+++ /dev/null
@@ -1,654 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are 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:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.contentoutline;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.jface.action.GroupMarker;
-import org.eclipse.jface.action.IContributionItem;
-import org.eclipse.jface.action.IContributionManager;
-import org.eclipse.jface.action.IMenuListener;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.action.MenuManager;
-import org.eclipse.jface.util.DelegatingDragAdapter;
-import org.eclipse.jface.util.DelegatingDropAdapter;
-import org.eclipse.jface.util.TransferDragSourceListener;
-import org.eclipse.jface.util.TransferDropTargetListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.DragSource;
-import org.eclipse.swt.dnd.DropTarget;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.IWorkbenchActionConstants;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.part.IShowInTarget;
-import org.eclipse.ui.part.ShowInContext;
-import org.eclipse.ui.texteditor.IUpdate;
-import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
-import org.eclipse.wst.sse.core.internal.model.FactoryRegistry;
-import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.ui.internal.ViewerSelectionManager;
-import org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.ContentOutlineConfiguration;
-import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.ITextSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
-import org.eclipse.wst.sse.ui.internal.view.events.TextSelectionChangedEvent;
-
-
-public class StructuredTextEditorContentOutlinePage extends ContentOutlinePage implements INodeSelectionListener, ITextSelectionListener, IUpdate, IAdaptable {
- /**
- * @deprecated
- */
- // Disables Tree redraw during large model changes
- protected class ControlRedrawEnabler implements IModelStateListener {
- public void modelAboutToBeChanged(IStructuredModel model) {
- setControlRedraw(false);
- }
-
- public void modelChanged(IStructuredModel model) {
- setControlRedraw(true);
- }
-
- public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
- }
-
- public void modelResourceDeleted(IStructuredModel model) {
- }
-
- public void modelResourceMoved(IStructuredModel originalmodel, IStructuredModel movedmodel) {
- }
-
- private void setControlRedraw(boolean doRedraw) {
- // check if we're on a Display Thread
- if (Display.getCurrent() != null) {
- setRedraw(doRedraw);
- }
- else {
- final boolean redrawOrNot = doRedraw;
- Runnable modifyRedraw = new Runnable() {
- public void run() {
- setRedraw(redrawOrNot);
- }
- };
- /*
- * This may not result in the enablement change happening
- * "soon enough", but better to do it later than to cause a
- * deadlock
- */
- Display.getDefault().asyncExec(modifyRedraw);
- }
- }
-
- public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
- }
-
- public void modelReinitialized(IStructuredModel structuredModel) {
- }
- }
-
- class ShowInTarget implements IShowInTarget {
- /*
- * @see org.eclipse.ui.part.IShowInTarget#show(org.eclipse.ui.part.ShowInContext)
- */
- public boolean show(ShowInContext context) {
- if (getViewerSelectionManager() == null) {
- return false;
- }
- boolean shown = false;
- List selectedNodes = getViewerSelectionManager().getSelectedNodes();
- if (selectedNodes == null) {
- selectedNodes = new ArrayList(0);
- }
- ISelection selection = new StructuredSelection(getConfiguration().getNodes(selectedNodes));
- if (!selection.isEmpty()) {
- setSelection(selection, true);
- shown = selection.equals(fSelection);
- }
- return shown;
- }
- }
-
- /*
- * Menu listener to create the additions group; required since the context
- * menu is cleared every time it is shown
- */
- class AdditionGroupAdder implements IMenuListener {
- public void menuAboutToShow(IMenuManager manager) {
- IContributionItem[] items = manager.getItems();
- if (items.length > 0 && items[items.length - 1].getId() != null) {
- manager.insertAfter(items[items.length - 1].getId(), new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
- }
- else {
- manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
- }
- }
- }
-
- private static final String OUTLINE_CONTEXT_MENU_ID = "org.eclipse.wst.sse.ui.StructuredTextEditor.OutlineContext"; //$NON-NLS-1$
- private static final String OUTLINE_CONTEXT_MENU_POSTFIX = ".source.OutlineContext"; //$NON-NLS-1$
-
- protected static ContentOutlineConfiguration NULL_CONFIGURATION = new ContentOutlineConfiguration();
- private TransferDragSourceListener[] fActiveDragListeners;
- private TransferDropTargetListener[] fActiveDropListeners;
- private ContentOutlineConfiguration fConfiguration;
-
- private String fContextMenuId;
- private MenuManager fContextMenuManager;
- private Menu fContextMenu;
- private DelegatingDragAdapter fDragAdapter;
- private DragSource fDragSource;
- private DelegatingDropAdapter fDropAdapter;
- private DropTarget fDropTarget;
- protected IStructuredModel fModel;
- // Current selection, maintained so selection doesn't bounce back from the
- // Tree
- ISelection fSelection;
- protected SourceEditorTreeViewer fTreeViewer;
- protected ViewerSelectionManager fViewerSelectionManager;
- private IMenuListener fGroupAdder = null;
-
- public StructuredTextEditorContentOutlinePage() {
- super();
- fSelection = StructuredSelection.EMPTY;
- fGroupAdder = new AdditionGroupAdder();
- }
-
- /**
- * @see ContentOutlinePage#createControl
- */
- public void createControl(Composite parent) {
- fTreeViewer = new SourceEditorTreeViewer(new Tree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL));
- fDragAdapter = new DelegatingDragAdapter();
- fDragSource = new DragSource(fTreeViewer.getControl(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK);
- fDropAdapter = new DelegatingDropAdapter();
- fDropTarget = new DropTarget(fTreeViewer.getControl(), DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK);
- setConfiguration(getConfiguration());
- fTreeViewer.setInput(getModel());
- IJFaceNodeAdapterFactory adapterFactory = getViewerRefreshFactory();
- if (adapterFactory != null) {
- adapterFactory.addListener(fTreeViewer);
- }
-
- // set initial selection
- if (getViewerSelectionManager() != null) {
- List selectedNodes = getViewerSelectionManager().getSelectedNodes();
- if (selectedNodes == null) {
- selectedNodes = new ArrayList(0);
- }
- ISelection selection = new StructuredSelection(getConfiguration().getNodes(selectedNodes));
- if (!selection.isEmpty()) {
- setSelection(selection, true);
- }
- }
-
- // update local selection on invalid selection to prevent bounces
- fTreeViewer.addInvalidSelectionListener(new ISelectionListener() {
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- fSelection = selection;
- }
- });
- fTreeViewer.addPostSelectionChangedListener(this);
-
- // update outline view's context menu control
- if (fModel != null) {
- updateContextMenuId(fModel.getContentTypeIdentifier());
- } else {
- updateContextMenuId(OUTLINE_CONTEXT_MENU_ID);
- }
- }
-
- public void dispose() {
- super.dispose();
- // disconnect from the ViewerSelectionManager
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.removeNodeSelectionListener(this);
- }
- IJFaceNodeAdapterFactory adapterFactory = getViewerRefreshFactory();
- if (adapterFactory != null) {
- adapterFactory.removeListener(fTreeViewer);
- }
- // dispose menu controls
- if (fContextMenu != null) {
- fContextMenu.dispose();
- }
- if (fContextMenuManager != null) {
- IMenuListener listener = getConfiguration().getMenuListener(fTreeViewer);
- if (listener != null)
- fContextMenuManager.removeMenuListener(listener);
- fContextMenuManager.removeMenuListener(fGroupAdder);
- fContextMenuManager.removeAll();
- fContextMenuManager.dispose();
- }
- setConfiguration(NULL_CONFIGURATION);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- public Object getAdapter(Class key) {
- Object adapter = getConfiguration().getAdapter(key);
- if (adapter == null) {
- if (key.equals(IShowInTarget.class)) {
- adapter = new ShowInTarget();
- }
- }
- return adapter;
- }
-
- /**
- * @return
- */
- public ContentOutlineConfiguration getConfiguration() {
- if (fConfiguration == null)
- return NULL_CONFIGURATION;
- return fConfiguration;
- }
-
- public Control getControl() {
- if (getTreeViewer() == null)
- return null;
- return getTreeViewer().getControl();
- }
-
-
- protected IStructuredModel getModel() {
- return fModel;
- }
-
- protected List getSelectedNodes(NodeSelectionChangedEvent event) {
- return getConfiguration().getSelectedNodes(event);
- }
-
- public ISelection getSelection() {
- if (getTreeViewer() == null)
- return StructuredSelection.EMPTY;
- return getTreeViewer().getSelection();
- }
-
- /**
- * Returns this page's tree viewer.
- *
- * @return this page's tree viewer, or <code>null</code> if
- * <code>createControl</code> has not been called yet
- */
- protected TreeViewer getTreeViewer() {
- return fTreeViewer;
- }
-
- protected IJFaceNodeAdapterFactory getViewerRefreshFactory() {
- if (getModel() == null)
- return null;
- FactoryRegistry factoryRegistry = getModel().getFactoryRegistry();
- IJFaceNodeAdapterFactory adapterFactory = (IJFaceNodeAdapterFactory) factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class);
- return adapterFactory;
- }
-
- /**
- * Returns this page's viewer selection manager.
- *
- * @return this page's viewer selection manager, or <code>null</code> if
- * <code>setViewerSelectionManager</code> has not been called
- * yet
- */
- public ViewerSelectionManager getViewerSelectionManager() {
- return fViewerSelectionManager;
- }
-
- public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
- if (getTreeViewer() != null && getConfiguration().isLinkedWithEditor(getTreeViewer())) {
- List selectedNodes = getSelectedNodes(event);
- if (selectedNodes != null) {
- StructuredSelection selection = new StructuredSelection(selectedNodes);
- setSelection(selection);
- int caretPosition = event.getCaretPosition();
- ((SourceEditorTreeViewer) getTreeViewer()).setCaretPosition(caretPosition);
- }
- }
- }
-
- /**
- * Updates the outline page's context menu by creating a new context menu with the
- * given menu id
- *
- * @param contextMenuId
- * Cannot be null
- */
- private void updateContextMenuId(String contextMenuId) {
- // update outline context menu id if updating to a new id or if context
- // menu is not already set up
- if (!contextMenuId.equals(fContextMenuId) || (fContextMenu == null)) {
- fContextMenuId = contextMenuId;
-
- if (getTreeViewer() != null && getTreeViewer().getControl() != null) {
- // dispose of previous context menu
- if (fContextMenu != null) {
- fContextMenu.dispose();
- }
- if (fContextMenuManager != null) {
- IMenuListener listener = getConfiguration().getMenuListener(fTreeViewer);
- if (listener != null)
- fContextMenuManager.removeMenuListener(listener);
- fContextMenuManager.removeMenuListener(fGroupAdder);
- fContextMenuManager.removeAll();
- fContextMenuManager.dispose();
- }
-
- fContextMenuManager = new MenuManager(fContextMenuId, fContextMenuId);
- fContextMenuManager.setRemoveAllWhenShown(true);
- IMenuListener listener = getConfiguration().getMenuListener(fTreeViewer);
- if (listener != null)
- fContextMenuManager.addMenuListener(listener);
- fContextMenuManager.addMenuListener(fGroupAdder);
-
- fContextMenu = fContextMenuManager.createContextMenu(getTreeViewer().getControl());
- getTreeViewer().getControl().setMenu(fContextMenu);
-
- getSite().registerContextMenu(fContextMenuId, fContextMenuManager, this);
-
- // also register this menu for source page part and structured text outline view ids
- String partId = null;
- // get editor this page belongs to
- IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage();
- if (page != null) {
- IEditorPart ownerEditor = page.getActiveEditor();
- if (ownerEditor != null)
- partId = ownerEditor.getSite().getId();
- }
- if (partId != null) {
- getSite().registerContextMenu(partId+OUTLINE_CONTEXT_MENU_POSTFIX, fContextMenuManager, this);
- }
- getSite().registerContextMenu(OUTLINE_CONTEXT_MENU_ID, fContextMenuManager, this);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.views.contentoutline.ContentOutlinePage#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
- */
- public void selectionChanged(SelectionChangedEvent event) {
- if (!fSelection.equals(event.getSelection())) {
- super.selectionChanged(event);
- }
- }
-
- /**
- * @param configuration
- */
- public void setConfiguration(ContentOutlineConfiguration configuration) {
- // intentionally do not check to see if the new configuration != old
- // configuration
- if (fTreeViewer != null) {
- // remove the key listeners
- if (fTreeViewer.getControl() != null && !fTreeViewer.getControl().isDisposed()) {
- KeyListener[] listeners = getConfiguration().getKeyListeners(fTreeViewer);
- for (int i = 0; i < listeners.length; i++) {
- fTreeViewer.getControl().removeKeyListener(listeners[i]);
- }
- }
- // remove any menu listeners
- if (fContextMenuManager != null) {
- IMenuListener listener = getConfiguration().getMenuListener(fTreeViewer);
- if (listener != null)
- fContextMenuManager.removeMenuListener(listener);
- fContextMenuManager.removeMenuListener(fGroupAdder);
- }
- // clear the selection changed and double click listeners from the
- // configuration
- if (getConfiguration().getSelectionChangedListener(fTreeViewer) != null)
- removeSelectionChangedListener(getConfiguration().getSelectionChangedListener(fTreeViewer));
- if (getConfiguration().getDoubleClickListener(fTreeViewer) != null)
- fTreeViewer.removeDoubleClickListener(getConfiguration().getDoubleClickListener(fTreeViewer));
- IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(fTreeViewer);
- if (toolbarItems.length > 0 && getSite() != null && getSite().getActionBars() != null && getSite().getActionBars().getToolBarManager() != null) {
- IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
- for (int i = 0; i < toolbarItems.length; i++) {
- toolbar.remove(toolbarItems[i]);
- }
- toolbar.update(false);
- }
- IContributionItem[] menuItems = getConfiguration().getMenuContributions(fTreeViewer);
- if (menuItems.length > 0 && getSite().getActionBars().getMenuManager() != null) {
- IContributionManager menubar = getSite().getActionBars().getMenuManager();
- for (int i = 0; i < menuItems.length; i++) {
- menubar.remove(menuItems[i]);
- }
- menubar.remove(IWorkbenchActionConstants.MB_ADDITIONS);
- menubar.update(false);
- }
- // clear the DnD listeners and transfer types
- if (fDragAdapter != null && !fDragAdapter.isEmpty() && !fDragSource.isDisposed() && fDragSource.getTransfer().length > 0) {
- if (fActiveDragListeners != null) {
- for (int i = 0; i < fActiveDragListeners.length; i++) {
- fDragAdapter.removeDragSourceListener(fActiveDragListeners[i]);
- }
- }
- fActiveDragListeners = null;
- fDragSource.removeDragListener(fDragAdapter);
- fDragSource.setTransfer(new Transfer[0]);
- }
- if (fDropAdapter != null && !fDropAdapter.isEmpty() && !fDropTarget.isDisposed() && fDropTarget.getTransfer().length > 0) {
- if (fActiveDropListeners != null) {
- for (int i = 0; i < fActiveDropListeners.length; i++) {
- fDropAdapter.removeDropTargetListener(fActiveDropListeners[i]);
- }
- }
- fActiveDropListeners = null;
- fDropTarget.removeDropListener(fDropAdapter);
- fDropTarget.setTransfer(new Transfer[0]);
- }
- // release any ties to this tree viewer
- getConfiguration().unconfigure(fTreeViewer);
- }
-
- fConfiguration = configuration;
- if (fConfiguration == null)
- fConfiguration = NULL_CONFIGURATION;
- fSelection = StructuredSelection.EMPTY;
-
- if (fTreeViewer != null && fTreeViewer.getControl() != null && !fTreeViewer.getControl().isDisposed()) {
- // add a menu listener if one is provided
- if (fContextMenuManager != null) {
- IMenuListener listener = getConfiguration().getMenuListener(fTreeViewer);
- if (listener != null)
- fContextMenuManager.addMenuListener(listener);
- fContextMenuManager.addMenuListener(fGroupAdder);
- }
- // (re)set the providers
- fTreeViewer.setLabelProvider(getConfiguration().getLabelProvider(fTreeViewer));
- fTreeViewer.setContentProvider(getConfiguration().getContentProvider(fTreeViewer));
- if (getConfiguration().getSelectionChangedListener(fTreeViewer) != null)
- addSelectionChangedListener(getConfiguration().getSelectionChangedListener(fTreeViewer));
- if (getConfiguration().getDoubleClickListener(fTreeViewer) != null)
- fTreeViewer.addDoubleClickListener(getConfiguration().getDoubleClickListener(fTreeViewer));
-
- // view toolbar
- IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(fTreeViewer);
- if (toolbarItems.length > 0 && getSite() != null && getSite().getActionBars() != null && getSite().getActionBars().getToolBarManager() != null) {
- IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
- for (int i = 0; i < toolbarItems.length; i++) {
- toolbar.add(toolbarItems[i]);
- }
- toolbar.update(true);
- }
- // view menu
- IContributionManager menu = getSite().getActionBars().getMenuManager();
- if (menu != null) {
- IContributionItem[] menuItems = getConfiguration().getMenuContributions(fTreeViewer);
- if (menuItems.length > 0) {
- for (int i = 0; i < menuItems.length; i++) {
- menuItems[i].setVisible(true);
- menu.add(menuItems[i]);
- menuItems[i].update();
- }
- menu.update(true);
- }
- }
- // add the allowed DnD listeners and types
- TransferDragSourceListener[] dragListeners = fConfiguration.getTransferDragSourceListeners(fTreeViewer);
- if (fDragAdapter != null && dragListeners.length > 0) {
- for (int i = 0; i < dragListeners.length; i++) {
- fDragAdapter.addDragSourceListener(dragListeners[i]);
- }
- fActiveDragListeners = dragListeners;
- fDragSource.addDragListener(fDragAdapter);
- fDragSource.setTransfer(fDragAdapter.getTransfers());
- }
- TransferDropTargetListener[] dropListeners = fConfiguration.getTransferDropTargetListeners(fTreeViewer);
- if (fDropAdapter != null && dropListeners.length > 0) {
- for (int i = 0; i < dropListeners.length; i++) {
- fDropAdapter.addDropTargetListener(dropListeners[i]);
- }
- fActiveDropListeners = dropListeners;
- fDropTarget.addDropListener(fDropAdapter);
- fDropTarget.setTransfer(fDropAdapter.getTransfers());
- }
- // add the key listeners
- KeyListener[] listeners = getConfiguration().getKeyListeners(fTreeViewer);
- for (int i = 0; i < listeners.length; i++) {
- fTreeViewer.getControl().addKeyListener(listeners[i]);
- }
- }
- }
-
- /**
- * Sets focus to a part in the page.
- */
- public void setFocus() {
- getTreeViewer().getControl().setFocus();
- }
-
- /**
- * Sets the input of the outline page
- */
- public void setModel(IStructuredModel newModel) {
- if (newModel != fModel) {
- // if (fModel != null) {
- // fModel.removeModelStateListener(fInternalModelStateListener);
- // }
- IJFaceNodeAdapterFactory adapterFactory = getViewerRefreshFactory();
- if (adapterFactory != null) {
- adapterFactory.removeListener(fTreeViewer);
- }
- fModel = newModel;
- if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
- setConfiguration(getConfiguration());
- fTreeViewer.setInput(fModel);
- update();
- }
- // fModel.addModelStateListener(fInternalModelStateListener);
- adapterFactory = getViewerRefreshFactory();
- if (adapterFactory != null) {
- adapterFactory.addListener(fTreeViewer);
- }
-
- // update outline view's context menu controls
- if (fModel != null) {
- updateContextMenuId(fModel.getContentTypeIdentifier());
- } else {
- updateContextMenuId(OUTLINE_CONTEXT_MENU_ID);
- }
- }
- }
-
- void setRedraw(boolean doRedraw) {
- Control control = getControl();
- if ((control != null) && (!control.isDisposed())) {
- control.setRedraw(doRedraw);
- }
- }
-
- public void setSelection(ISelection selection) {
- setSelection(selection, getConfiguration().isLinkedWithEditor(getTreeViewer()));
- }
-
- protected void setSelection(ISelection selection, boolean reveal) {
- if (getTreeViewer() != null && selection instanceof IStructuredSelection) {
- /**
- * Selection sent to the Tree widget comes back as a
- * selectionChanged event. To avoid bouncing an externally set
- * selection back to our listeners, track the last selection that
- * originated elsewhere so we can skip sending it back out. If
- * selection came from the Tree widget (by user interaction), it
- * will be different.
- */
- if (!fSelection.equals(selection)) {
- if (selection == null || ((IStructuredSelection) selection).getFirstElement() == null) {
- fSelection = StructuredSelection.EMPTY;
- }
- else {
- fSelection = selection;
- }
- getTreeViewer().setSelection(fSelection, reveal);
- }
- }
- }
-
- public void setViewerSelectionManager(ViewerSelectionManager viewerSelectionManager) {
- // disconnect from old one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.removeNodeSelectionListener(this);
- fViewerSelectionManager.removeTextSelectionListener(this);
- }
- fViewerSelectionManager = viewerSelectionManager;
- // connect to new one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.addNodeSelectionListener(this);
- fViewerSelectionManager.addTextSelectionListener(this);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.view.events.ITextSelectionListener#textSelectionChanged(org.eclipse.wst.sse.ui.view.events.TextSelectionChangedEvent)
- */
- public void textSelectionChanged(TextSelectionChangedEvent event) {
- if (getConfiguration().isLinkedWithEditor(getTreeViewer())) {
- int caretPosition = event.getTextSelectionStart();
- ((SourceEditorTreeViewer) getTreeViewer()).setCaretPosition(caretPosition);
- }
- }
-
- /**
- * redraws the tree
- */
- public void update() {
- if (getTreeViewer() != null) {
- Control control = getTreeViewer().getControl();
- control.setRedraw(false);
- getTreeViewer().refresh();
- control.setRedraw(true);
- }
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/properties/ConfigurablePropertySheetPage.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/properties/ConfigurablePropertySheetPage.java
index d6c4b6b..a250918 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/properties/ConfigurablePropertySheetPage.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/properties/ConfigurablePropertySheetPage.java
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.wst.sse.ui.internal.properties;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.action.IMenuManager;
@@ -24,19 +25,12 @@
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.views.properties.IPropertySheetEntry;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertySheetPage;
-import org.eclipse.wst.sse.core.internal.model.FactoryRegistry;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.ui.internal.ViewerSelectionManager;
-import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter;
-import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory;
import org.eclipse.wst.sse.ui.internal.provisional.views.properties.IPropertySourceExtension;
import org.eclipse.wst.sse.ui.internal.provisional.views.properties.PropertySheetConfiguration;
-import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
/**
@@ -44,99 +38,58 @@
* not expose its viewer field.
*/
-public class ConfigurablePropertySheetPage extends PropertySheetPage implements INodeSelectionListener {
+public class ConfigurablePropertySheetPage extends PropertySheetPage {
+ private static final boolean _DEBUG_ENTRY_SELECTION = false;
+ private static final boolean _DEBUG_SELECTION = false;
+ private long _DEBUG_TIME = 0;
private PropertySheetConfiguration fConfiguration;
- // has the widget been created?
- private boolean fIsRealized = false;
+
private IMenuManager fMenuManager;
-
- protected PageBook fParentPageBook = null;
- // are we refreshing the contents?
- protected boolean fRefreshing = false;
-
- protected RemoveAction fRemoveAction;
+ private RemoveAction fRemoveAction;
private IStatusLineManager fStatusLineManager;
- protected IStructuredModel fStructuredModel = null;
private IToolBarManager fToolBarManager;
- private ViewerSelectionManager fViewerSelectionManager;
-
private final PropertySheetConfiguration NULL_CONFIGURATION = new PropertySheetConfiguration();
+ private Object selectedEntry = null;
+
public ConfigurablePropertySheetPage() {
super();
}
public void createControl(Composite parent) {
- setPropertySourceProvider(getConfiguration().getPropertySourceProvider());
+ setPropertySourceProvider(getConfiguration().getPropertySourceProvider(this));
super.createControl(parent);
- if (parent instanceof PageBook)
- fParentPageBook = (PageBook) parent;
}
public void dispose() {
- // disconnect from the ViewerSelectionManager
- if (getViewerSelectionManager() != null) {
- getViewerSelectionManager().removeNodeSelectionListener(this);
- }
- setModel(null);
setConfiguration(null);
+ getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
super.dispose();
}
- /**
- * @return
- */
public PropertySheetConfiguration getConfiguration() {
if (fConfiguration == null)
fConfiguration = NULL_CONFIGURATION;
return fConfiguration;
}
- public IStructuredModel getModel() {
- return fStructuredModel;
- }
-
- protected IJFaceNodeAdapterFactory getViewerRefreshFactory() {
- if (getModel() == null)
- return null;
- FactoryRegistry factoryRegistry = getModel().getFactoryRegistry();
- IJFaceNodeAdapterFactory adapterFactory = (IJFaceNodeAdapterFactory) factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class);
- return adapterFactory;
- }
-
- /**
- * @return Returns the viewerSelectionManager.
- */
- public ViewerSelectionManager getViewerSelectionManager() {
- return fViewerSelectionManager;
- }
-
- /*
- * @see PropertySheetPage#handleEntrySelection(ISelection)
- */
public void handleEntrySelection(ISelection selection) {
- // Useful for enabling/disabling actions based on the
- // selection (or lack thereof). Also, ensure that the
- // control exists before sending selection to it.
- if (fIsRealized && selection != null) {
+ if (_DEBUG_ENTRY_SELECTION) {
+ System.out.println("(P:entry " + selection);
+ }
+ selectedEntry = selection;
+ if (getControl() != null && !getControl().isDisposed() && selection != null) {
super.handleEntrySelection(selection);
fRemoveAction.setEnabled(!selection.isEmpty());
- // if (selection != null && !selection.isEmpty() && selection
- // instanceof IStructuredSelection) {
- // IPropertySheetEntry entry = (IPropertySheetEntry)
- // ((IStructuredSelection) selection).getFirstElement();
- // }
}
}
- /**
- * @return Returns the isRealized.
- */
- public boolean isRealized() {
- return fIsRealized;
+ public void init(IPageSite pageSite) {
+ super.init(pageSite);
+ pageSite.getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
}
public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
@@ -151,44 +104,19 @@
getConfiguration().addContributions(menuManager, toolBarManager, statusLineManager);
menuManager.update(true);
- fIsRealized = true;
}
- public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
- selectionChanged(null, new StructuredSelection(event.getSelectedNodes()));
- }
-
- /**
- * @see org.eclipse.ui.views.properties.PropertySheetPage#refresh()
- */
- public void refresh() {
- /**
- * Avoid refreshing the property sheet if it is already doing so. A
- * refresh can prompt an active cell editor to close, applying the
- * value and altering the selected node. In that case, a loop could
- * occur.
- */
-
- if (!fRefreshing) {
- fRefreshing = true;
- super.refresh();
- fRefreshing = false;
- } else {
- // detected a loop in the property sheet (shouldn't happen)
- }
- }
-
- public void remove() {
+ void remove() {
if (getControl() instanceof Tree) {
TreeItem[] items = ((Tree) getControl()).getSelection();
- List selectedNodes = getViewerSelectionManager().getSelectedNodes();
+ List selectedNodes = new ArrayList(0);
if (items != null && items.length == 1 && selectedNodes != null) {
Object data = items[0].getData();
if (data instanceof IPropertySheetEntry) {
IPropertySheetEntry entry = (IPropertySheetEntry) data;
ISelection selection = getConfiguration().getSelection(null, new StructuredSelection(selectedNodes));
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
- IPropertySource source = getConfiguration().getPropertySourceProvider().getPropertySource(((IStructuredSelection) selection).getFirstElement());
+ IPropertySource source = getConfiguration().getPropertySourceProvider(this).getPropertySource(((IStructuredSelection) selection).getFirstElement());
if (source != null && source instanceof IPropertySourceExtension) {
((IPropertySourceExtension) source).removeProperty(entry.getDisplayName());
}
@@ -199,13 +127,24 @@
}
/*
- * (non-Javadoc)
+ * Filter the selection through the current Configuration. Not every
+ * selection received is a Structured selection nor are the Structured
+ * selection's elements all to be displayed.
*
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,
* org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- super.selectionChanged(part, getConfiguration().getSelection(part, selection));
+ _DEBUG_TIME = System.currentTimeMillis();
+ if (getControl() != null && getControl().isVisible() && selection != selectedEntry && !getControl().isFocusControl()) {
+ super.selectionChanged(part, getConfiguration().getSelection(part, selection));
+ if (_DEBUG_SELECTION) {
+ System.out.println("(P:service " + (System.currentTimeMillis() - _DEBUG_TIME) + "ms) " + part + " : " + selection);
+ }
+ }
+ else if (_DEBUG_SELECTION) {
+ System.out.println("[skipped] (P:" + (System.currentTimeMillis() - _DEBUG_TIME) + "ms) " + part + " : " + selection);
+ }
}
/**
@@ -213,7 +152,7 @@
* The configuration to set.
*/
public void setConfiguration(PropertySheetConfiguration configuration) {
- if (fConfiguration != null && isRealized()) {
+ if (fConfiguration != null) {
fConfiguration.removeContributions(fMenuManager, fToolBarManager, fStatusLineManager);
fConfiguration.unconfigure();
}
@@ -221,50 +160,8 @@
fConfiguration = configuration;
if (fConfiguration != null) {
- setPropertySourceProvider(fConfiguration.getPropertySourceProvider());
- if (isRealized())
- fConfiguration.addContributions(fMenuManager, fToolBarManager, fStatusLineManager);
+ setPropertySourceProvider(fConfiguration.getPropertySourceProvider(this));
+ fConfiguration.addContributions(fMenuManager, fToolBarManager, fStatusLineManager);
}
}
-
- /**
- * Asks this page to take focus within its pagebook view.
- */
- public void setFocus() {
- super.setFocus();
- if (fParentPageBook != null)
- fParentPageBook.showPage(getControl());
- }
-
- /**
- * Sets the model.
- *
- * @param model
- * The model to set
- */
- public void setModel(IStructuredModel model) {
- if (model != fStructuredModel) {
- IJFaceNodeAdapterFactory refresher = getViewerRefreshFactory();
- if (refresher != null)
- refresher.removeListener(this);
- fStructuredModel = model;
- refresher = getViewerRefreshFactory();
- if (refresher != null)
- refresher.addListener(this);
- }
- }
-
- public void setViewerSelectionManager(ViewerSelectionManager viewerSelectionManager) {
- // disconnect from old one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.removeNodeSelectionListener(this);
- }
-
- fViewerSelectionManager = viewerSelectionManager;
-
- // connect to new one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.addNodeSelectionListener(this);
- }
- }
-}
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/StructuredTextViewerUndoManager.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/StructuredTextViewerUndoManager.java
index 463d674..544a2a7 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/StructuredTextViewerUndoManager.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/StructuredTextViewerUndoManager.java
@@ -13,13 +13,14 @@
package org.eclipse.wst.sse.ui.internal.provisional;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.IUndoManager;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
-import org.eclipse.wst.sse.ui.internal.view.events.ITextSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.TextSelectionChangedEvent;
/**
@@ -28,11 +29,12 @@
* handles communication between IUndoManager and IStructuredTextUndoManager.
*/
class StructuredTextViewerUndoManager implements IUndoManager {
- class UndoNotifier implements ITextSelectionListener {
-
- public void textSelectionChanged(TextSelectionChangedEvent event) {
+ class UndoNotifier implements ISelectionChangedListener {
+ public void selectionChanged(SelectionChangedEvent event) {
if ((fUndoManager != null) && (event != null)) {
- fUndoManager.forceEndOfPendingCommand(this, event.getTextSelectionStart(), event.getTextSelectionEnd() - event.getTextSelectionStart());
+ if (event.getSelection() instanceof ITextSelection) {
+ fUndoManager.forceEndOfPendingCommand(this, ((ITextSelection) event.getSelection()).getOffset(), ((ITextSelection) event.getSelection()).getLength());
+ }
}
}
@@ -40,7 +42,7 @@
private StructuredTextViewer fTextViewer = null;
private IStructuredTextUndoManager fUndoManager = null;
- private ITextSelectionListener fUndoNotifier = new UndoNotifier();
+ private ISelectionChangedListener fUndoNotifier = new UndoNotifier();
/*
* (non-Javadoc)
@@ -84,7 +86,7 @@
public void disconnect() {
// disconnect the viewer from the undo manager
if (fUndoManager != null) {
- fTextViewer.getViewerSelectionManager().removeTextSelectionListener(fUndoNotifier);
+ fTextViewer.removeSelectionChangedListener(fUndoNotifier);
fUndoManager.disconnect(fTextViewer);
}
@@ -149,14 +151,14 @@
*/
public void setDocument(IStructuredDocument document) {
if (fUndoManager != null) {
- fTextViewer.getViewerSelectionManager().removeTextSelectionListener(fUndoNotifier);
+ fTextViewer.removeSelectionChangedListener(fUndoNotifier);
fUndoManager.disconnect(fTextViewer);
}
fUndoManager = document.getUndoManager();
if (fUndoManager != null) {
fUndoManager.connect(fTextViewer);
- fTextViewer.getViewerSelectionManager().addTextSelectionListener(fUndoNotifier);
+ fTextViewer.addSelectionChangedListener(fUndoNotifier);
}
}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/ContentOutlineConfiguration.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/ContentOutlineConfiguration.java
index 2d07844..744a1d8 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/ContentOutlineConfiguration.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/ContentOutlineConfiguration.java
@@ -12,32 +12,30 @@
*******************************************************************************/
package org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline;
-import java.util.List;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.util.TransferDragSourceListener;
import org.eclipse.jface.util.TransferDropTargetListener;
import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.events.KeyListener;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
/**
- * Configuration class for Outline Pages. Not finalized.
+ * Configuration class for Outline Pages. Not finalized.
*
* @plannedfor 1.0
- *
+ *
*/
public class ContentOutlineConfiguration implements IExecutableExtension, IAdaptable {
private IContentProvider fContentProvider;
@@ -95,13 +93,8 @@
return fContentProvider;
}
- /**
- * @param viewer
- * @return the IDoubleClickListener to be notified when the viewer
- * receives a double click event
- */
- public IDoubleClickListener getDoubleClickListener(TreeViewer viewer) {
- return null;
+ public String getContentTypeID(TreeViewer treeViewer) {
+ return IContentTypeManager.CT_TEXT;
}
/**
@@ -146,23 +139,23 @@
}
/**
- * @param nodes
- * @return The list of nodes from this List that should be seen in the
- * Outline. Possible uses include programmatic selection setting.
+ * @param viewer
+ * @return the ISelectionChangedListener to notify when the viewer's
+ * selection changes
*/
- public List getNodes(List nodes) {
- return nodes;
+ public ISelectionChangedListener getPostSelectionChangedListener(TreeViewer viewer) {
+ return null;
}
/**
* @param event
- * @return The (filtered) list of selected nodes from this event. Uses
- * include mapping model selection onto elements provided by the
- * content provider. Should only return elements that will be
- * shown in the Tree Control.
+ * @return The (filtered) selection from this event. Uses include mapping
+ * model selection onto elements provided by the content provider.
+ * Should only return elements that will be shown in the Tree
+ * Control.
*/
- public List getSelectedNodes(NodeSelectionChangedEvent event) {
- return event.getSelectedNodes();
+ public ISelection getSelection(TreeViewer viewer, ISelection selection) {
+ return selection;
}
/**
@@ -214,7 +207,7 @@
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
/*
* Currently no need for initialization data but is good practice to
- * implement IExecutableExtension since is a class that can be created
+ * implement IExecutableExtension since in a class that can be created
* by executable extension
*/
}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/StructuredContentOutlineConfiguration.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/StructuredContentOutlineConfiguration.java
index 10d75db..c4c98d1 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/StructuredContentOutlineConfiguration.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/contentoutline/StructuredContentOutlineConfiguration.java
@@ -13,35 +13,29 @@
package org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.part.IShowInSource;
import org.eclipse.ui.part.IShowInTargetList;
import org.eclipse.ui.part.ShowInContext;
-import org.eclipse.wst.sse.core.internal.model.FactoryRegistry;
-import org.eclipse.wst.sse.ui.internal.Logger;
import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
-import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
-import org.eclipse.wst.sse.ui.internal.ViewerSelectionManager;
-import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter;
-import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory;
import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateAction;
import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateActionContributionItem;
import org.eclipse.wst.sse.ui.internal.editor.EditorPluginImageHelper;
import org.eclipse.wst.sse.ui.internal.editor.EditorPluginImages;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
public class StructuredContentOutlineConfiguration extends ContentOutlineConfiguration {
+
/**
* Structured source files tend to have large/long tree structures. Add a
* collapse action to help with navigation.
@@ -79,18 +73,18 @@
}
protected ImageDescriptor COLLAPSE_D = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_DLCL_COLLAPSEALL);
- protected ImageDescriptor COLLAPSE_E = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_ELCL_COLLAPSEALL);
- private StructuredTextEditor fEditor = null;
+ protected ImageDescriptor COLLAPSE_E = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_ELCL_COLLAPSEALL);
+ private String fContentTypeIdentifier = null;
+
+ private IEditorPart fEditor = null;
private boolean fIsLinkWithEditor = false;
private Map fMenuContributions = null;
-
private Map fToolbarContributions = null;
-
private final String OUTLINE_LINK_PREF = "outline-link-editor"; //$NON-NLS-1$
-
ImageDescriptor SYNCED_D = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_DLCL_SYNCED);
+
ImageDescriptor SYNCED_E = EditorPluginImageHelper.getInstance().getImageDescriptor(EditorPluginImages.IMG_ELCL_SYNCED);
public StructuredContentOutlineConfiguration() {
@@ -117,6 +111,7 @@
return items;
}
+
protected IContributionItem[] createToolbarContributions(TreeViewer viewer) {
IContributionItem[] items;
IContributionItem collapseAllItem = new ActionContributionItem(new CollapseTreeAction(viewer));
@@ -144,41 +139,33 @@
if (key.equals(IShowInSource.class)) {
adapter = new IShowInSource() {
public ShowInContext getShowInContext() {
- return new ShowInContext(getEditor().getEditorInput(), getEditor().getSelectionProvider().getSelection());
+ return new ShowInContext(getEditor().getEditorInput(), getEditor().getEditorSite().getSelectionProvider().getSelection());
}
};
}
else if (key.equals(IShowInTargetList.class)) {
adapter = getEditor().getAdapter(key);
}
- else
+ else {
adapter = super.getAdapter(key);
+ }
return adapter;
}
- /**
- * @see org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.ContentOutlineConfiguration#getDoubleClickListener(org.eclipse.jface.viewers.TreeViewer)
- */
- public IDoubleClickListener getDoubleClickListener(TreeViewer viewer) {
- return (ViewerSelectionManager) getEditor().getAdapter(ViewerSelectionManager.class);
+ public String getContentTypeID(TreeViewer treeViewer) {
+ if (fContentTypeIdentifier != null) {
+ return fContentTypeIdentifier;
+ }
+ return super.getContentTypeID(treeViewer);
}
/**
* @return
*/
- public StructuredTextEditor getEditor() {
+ protected IEditorPart getEditor() {
return fEditor;
}
- protected IJFaceNodeAdapterFactory getFactory() {
- FactoryRegistry factoryRegistry = getEditor().getModel().getFactoryRegistry();
- IJFaceNodeAdapterFactory adapterFactory = (IJFaceNodeAdapterFactory) factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class);
- if (adapterFactory == null) {
- Logger.log(Logger.ERROR, "model has no JFace adapter factory"); //$NON-NLS-1$
- }
- return adapterFactory;
- }
-
/*
* (non-Javadoc)
*
@@ -197,23 +184,8 @@
return items;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getSelectedNodes(org.eclipse.wst.sse.ui.view.events.NodeSelectionChangedEvent)
- */
- public List getSelectedNodes(NodeSelectionChangedEvent event) {
- if (isLinkedWithEditor())
- return super.getSelectedNodes(event);
- else
- return null;
- }
-
- /**
- * @see org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.ContentOutlineConfiguration#getSelectionChangedListener(org.eclipse.jface.viewers.TreeViewer)
- */
- public ISelectionChangedListener getSelectionChangedListener(TreeViewer viewer) {
- return (ViewerSelectionManager) getEditor().getAdapter(ViewerSelectionManager.class);
+ protected IPreferenceStore getPreferenceStore() {
+ return SSEUIPlugin.getInstance().getPreferenceStore();
}
/*
@@ -250,10 +222,21 @@
/**
* @param editor
*/
- public void setEditor(StructuredTextEditor editor) {
+ public void setEditor(IEditorPart editor) {
fEditor = editor;
}
+ public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
+ super.setInitializationData(config, propertyName, data);
+
+ fContentTypeIdentifier = config.getAttribute("contentTypeId"); //$NON-NLS-1$
+ if (data != null) {
+ if (data instanceof String && data.toString().length() > 0) {
+ fContentTypeIdentifier = (String) data;
+ }
+ }
+ }
+
/**
* @param isLinkWithEditor
* The isLinkWithEditor to set.
@@ -288,7 +271,4 @@
}
}
- protected IPreferenceStore getPreferenceStore() {
- return SSEUIPlugin.getInstance().getPreferenceStore();
- }
}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/PropertySheetConfiguration.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/PropertySheetConfiguration.java
index d98aeb1..07b2c28 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/PropertySheetConfiguration.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/PropertySheetConfiguration.java
@@ -22,15 +22,16 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
/**
* Configuration class for Property Sheet Pages. Not finalized.
+ *
* @plannedfor 1.0
*/
-
public class PropertySheetConfiguration implements IExecutableExtension {
private class NullPropertySource implements IPropertySource {
@@ -121,7 +122,7 @@
/**
* @return
*/
- protected IPropertySourceProvider createPropertySourceProvider() {
+ protected IPropertySourceProvider createPropertySourceProvider(IPropertySheetPage page) {
return new NullPropertySourceProvider();
}
@@ -135,9 +136,9 @@
/**
* Returns the correct IPropertySourceProvider
*/
- public IPropertySourceProvider getPropertySourceProvider() {
+ public IPropertySourceProvider getPropertySourceProvider(IPropertySheetPage page) {
if (fPropertySourceProvider == null)
- fPropertySourceProvider = createPropertySourceProvider();
+ fPropertySourceProvider = createPropertySourceProvider(page);
return fPropertySourceProvider;
}
@@ -164,7 +165,7 @@
public void setEditor(IEditorPart editor) {
fEditor = editor;
}
-
+
public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException {
/*
* Currently no need for initialization data but is good practice to
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/StructuredPropertySheetConfiguration.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/StructuredPropertySheetConfiguration.java
index 8adabee..5aaa444 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/StructuredPropertySheetConfiguration.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/views/properties/StructuredPropertySheetConfiguration.java
@@ -12,17 +12,12 @@
*******************************************************************************/
package org.eclipse.wst.sse.ui.internal.provisional.views.properties;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
import org.eclipse.wst.sse.ui.internal.properties.AdapterPropertySourceProvider;
@@ -33,11 +28,6 @@
* @plannedfor 1.0
*/
public class StructuredPropertySheetConfiguration extends PropertySheetConfiguration {
- protected IStructuredModel fModel;
-
- /**
- *
- */
public StructuredPropertySheetConfiguration() {
super();
}
@@ -45,36 +35,12 @@
/*
* (non-Javadoc)
*
- * @see org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration#createPropertySourceProvider()
- */
- protected IPropertySourceProvider createPropertySourceProvider() {
- return new AdapterPropertySourceProvider();
- }
-
- /**
- * @return Returns the model.
- */
- public IStructuredModel getModel() {
- return fModel;
- }
-
- /*
- * (non-Javadoc)
- *
* @see org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration#getSelection(org.eclipse.jface.viewers.ISelection,
* org.eclipse.ui.IWorkbenchPart)
*/
public ISelection getSelection(IWorkbenchPart selectingPart, ISelection selection) {
ISelection preferredSelection = selection;
- if (selection instanceof ITextSelection && fModel != null) {
- // on text selection, find the appropriate IndexedRegion
- ITextSelection textSel = (ITextSelection) selection;
- Object inode = getModel().getIndexedRegion(textSel.getOffset());
- if (inode != null) {
- preferredSelection = new StructuredSelection(inode);
- }
- }
- else if (selection instanceof IStructuredSelection) {
+ if (selection instanceof IStructuredSelection) {
// don't support more than one selected node
if (((IStructuredSelection) selection).size() > 1)
preferredSelection = StructuredSelection.EMPTY;
@@ -82,31 +48,8 @@
return preferredSelection;
}
- /**
- * @return
- */
- public void setEditor(IEditorPart editor) {
- super.setEditor(editor);
- IStructuredModel model = null;
- if (editor != null) {
- ITextEditor textEditor = null;
- if (editor instanceof ITextEditor)
- textEditor = (ITextEditor) editor;
- else
- textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
- if (textEditor != null) {
- IDocument document = textEditor.getDocumentProvider().getDocument(editor.getEditorInput());
- if (document != null)
- model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
- else
- model = null;
- }
- }
- // as long as the editor remains valid, we won't be the last reference
- // to this model
- if (fModel != null)
- fModel.releaseFromRead();
- fModel = model;
+ protected IPropertySourceProvider createPropertySourceProvider(IPropertySheetPage page) {
+ return new AdapterPropertySourceProvider();
}
/*
@@ -118,5 +61,4 @@
super.unconfigure();
setEditor(null);
}
-
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java
index e3bf603..754d9bb 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/DOMPropertyDescriptorFactory.java
@@ -12,6 +12,7 @@
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.ui.internal.properties.EnumeratedStringPropertyDescriptor;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
@@ -27,10 +28,8 @@
public class DOMPropertyDescriptorFactory {
protected static final String HACK = "hack"; //$NON-NLS-1$
- private ModelQuery fModelQuery = null;
- public DOMPropertyDescriptorFactory(ModelQuery modelQuery) {
- fModelQuery = modelQuery;
+ public DOMPropertyDescriptorFactory() {
}
public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) {
@@ -38,11 +37,15 @@
String attributeName = attr.getName();
- CMAttributeDeclaration ad = fModelQuery.getCMAttributeDeclaration(attr);
- if (ad != null) {
- String[] valuesArray = fModelQuery.getPossibleDataTypeValues(attr.getOwnerElement(), ad);
- if (valuesArray != null && valuesArray.length > 0) {
- result = new EnumeratedStringPropertyDescriptor(attributeName, attributeName, valuesArray);
+ ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument());
+
+ if (mq != null) {
+ CMAttributeDeclaration ad = mq.getCMAttributeDeclaration(attr);
+ if (ad != null) {
+ String[] valuesArray = mq.getPossibleDataTypeValues(attr.getOwnerElement(), ad);
+ if (valuesArray != null && valuesArray.length > 0) {
+ result = new EnumeratedStringPropertyDescriptor(attributeName, attributeName, valuesArray);
+ }
}
}
@@ -66,7 +69,7 @@
}
public IPropertyDescriptor createDocumentTypePropertyDescriptor(DocumentType documentType) {
- return null; //new TextPropertyDescriptor(HACK, HACK);
+ return null; // new TextPropertyDescriptor(HACK, HACK);
}
public IPropertyDescriptor createElementPropertyDescriptor(Element element) {
@@ -127,10 +130,4 @@
public IPropertyDescriptor createTextPropertyDescriptor(Text text) {
return createDefaultPropertyDescriptor(HACK);
}
-
-
- public ModelQuery getModelQuery() {
- return fModelQuery;
- }
-
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewer.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewer.java
index 7af1137..8569407 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewer.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/IDesignViewer.java
@@ -8,12 +8,9 @@
****************************************************************************/
package org.eclipse.wst.xml.ui.internal.tabletree;
-
-
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.wst.sse.ui.internal.ViewerSelectionManager;
-
public interface IDesignViewer {
public Control getControl();
@@ -21,6 +18,6 @@
String getTitle();
void setDocument(IDocument document);
-
- void setViewerSelectionManager(ViewerSelectionManager viewerSelectionManager);
+
+ ISelectionProvider getSelectionProvider();
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java
index 96f4040..8c36e0f 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLMultiPageEditorPart.java
@@ -10,54 +10,129 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.jface.viewers.IPostSelectionProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorActionBarContributor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPartService;
import org.eclipse.ui.IPropertyListener;
-import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.ide.IGotoMarker;
-import org.eclipse.ui.part.MultiPageEditorPart;
-import org.eclipse.ui.part.MultiPageEditorSite;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.exceptions.SourceEditingRuntimeException;
+import org.eclipse.ui.part.MultiPageSelectionProvider;
+import org.eclipse.ui.progress.UIJob;
+import org.eclipse.wst.common.ui.provisional.editors.PostMultiPageEditorSite;
+import org.eclipse.wst.common.ui.provisional.editors.PostMultiPageSelectionProvider;
+import org.eclipse.wst.common.ui.provisional.editors.PostSelectionMultiPageEditorPart;
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
import org.eclipse.wst.xml.core.internal.provisional.IXMLPreferenceNames;
import org.eclipse.wst.xml.ui.internal.Logger;
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
import org.eclipse.wst.xml.ui.internal.provisional.StructuredTextEditorXML;
-public class XMLMultiPageEditorPart extends MultiPageEditorPart {
+public class XMLMultiPageEditorPart extends PostSelectionMultiPageEditorPart {
/**
- * Internal part activation listener
+ * Internal part activation listener, copied from AbstractTextEditor
*/
- class PartListener extends ShellAdapter implements IPartListener {
+ class ActivationListener implements IPartListener, IWindowListener {
+
+ /** Cache of the active workbench part. */
private IWorkbenchPart fActivePart;
+ /** Indicates whether activation handling is currently be done. */
private boolean fIsHandlingActivation = false;
+ /**
+ * The part service.
+ *
+ * @since 3.1
+ */
+ private IPartService fPartService;
+ /**
+ * Creates this activation listener.
+ *
+ * @param partService
+ * the part service on which to add the part listener
+ * @since 3.1
+ */
+ public ActivationListener(IPartService partService) {
+ fPartService = partService;
+ fPartService.addPartListener(this);
+ PlatformUI.getWorkbench().addWindowListener(this);
+ }
+
+ /**
+ * Disposes this activation listener.
+ *
+ * @since 3.1
+ */
+ public void dispose() {
+ fPartService.removePartListener(this);
+ PlatformUI.getWorkbench().removeWindowListener(this);
+ fPartService = null;
+ }
+
+ /*
+ * @see IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
+ */
+ public void partActivated(IWorkbenchPart part) {
+ fActivePart = part;
+ handleActivation();
+ }
+
+ /*
+ * @see IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
+ */
+ public void partBroughtToTop(IWorkbenchPart part) {
+ }
+
+ /*
+ * @see IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
+ */
+ public void partClosed(IWorkbenchPart part) {
+ }
+
+ /*
+ * @see IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
+ */
+ public void partDeactivated(IWorkbenchPart part) {
+ fActivePart = null;
+ }
+
+ /*
+ * @see IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
+ */
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ /**
+ * Handles the activation triggering a element state check in the
+ * editor.
+ */
private void handleActivation() {
-
if (fIsHandlingActivation)
return;
if (fActivePart == XMLMultiPageEditorPart.this) {
fIsHandlingActivation = true;
try {
- safelySanityCheckState();
+ getTextEditor().safelySanityCheckState(getEditorInput());
}
finally {
fIsHandlingActivation = false;
@@ -65,44 +140,77 @@
}
}
- /**
- * @see IPartListener#partActivated(IWorkbenchPart)
+ /*
+ * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
+ * @since 3.1
*/
- public void partActivated(IWorkbenchPart part) {
- fActivePart = part;
- handleActivation();
- }
-
- /**
- * @see IPartListener#partBroughtToTop(IWorkbenchPart)
- */
- public void partBroughtToTop(IWorkbenchPart part) {
- }
-
- /**
- * @see IPartListener#partClosed(IWorkbenchPart)
- */
- public void partClosed(IWorkbenchPart part) {
- }
-
- /**
- * @see IPartListener#partDeactivated(IWorkbenchPart)
- */
- public void partDeactivated(IWorkbenchPart part) {
- fActivePart = null;
- }
-
- /**
- * @see IPartListener#partOpened(IWorkbenchPart)
- */
- public void partOpened(IWorkbenchPart part) {
+ public void windowActivated(IWorkbenchWindow window) {
+ if (window == getEditorSite().getWorkbenchWindow()) {
+ /*
+ * Workaround for problem described in
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11731 Will be
+ * removed when SWT has solved the problem.
+ */
+ window.getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ handleActivation();
+ }
+ });
+ }
}
/*
- * @see ShellListener#shellActivated(ShellEvent)
+ * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
+ * @since 3.1
*/
- public void shellActivated(ShellEvent e) {
- handleActivation();
+ public void windowDeactivated(IWorkbenchWindow window) {
+ }
+
+ /*
+ * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
+ * @since 3.1
+ */
+ public void windowClosed(IWorkbenchWindow window) {
+ }
+
+ /*
+ * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
+ * @since 3.1
+ */
+ public void windowOpened(IWorkbenchWindow window) {
+ }
+ }
+
+ /**
+ * Listens for selection from the source page, applying it to the design
+ * viewer.
+ */
+ private class TextEditorPostSelectionAdapter extends UIJob implements ISelectionChangedListener {
+ boolean forcePostSelection = false;
+ ISelection selection = null;
+
+ public TextEditorPostSelectionAdapter() {
+ super(getTitle());
+ setUser(true);
+ }
+
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ if (selection != null) {
+ fDesignViewer.getSelectionProvider().setSelection(selection);
+ }
+ return Status.OK_STATUS;
+ }
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (fDesignViewer != null && !fDesignViewer.getControl().isFocusControl()) {
+ if (forcePostSelection) {
+ selection = event.getSelection();
+ schedule(200);
+ }
+ else {
+ fDesignViewer.getSelectionProvider().setSelection(event.getSelection());
+ }
+ }
}
}
@@ -136,7 +244,7 @@
* dirty property to get updated after other
* things on the queue are executed.
*/
- postOnDisplayQue(runnable);
+ ((Control) getTextEditor().getAdapter(Control.class)).getDisplay().asyncExec(runnable);
}
}
break;
@@ -176,9 +284,9 @@
private int fDesignPageIndex;
/** The design viewer */
- private IDesignViewer fDesignViewer;
+ IDesignViewer fDesignViewer;
- private PartListener fPartListener;
+ private ActivationListener fActivationListener;
IPropertyListener fPropertyListener = null;
@@ -188,6 +296,8 @@
/** The text editor. */
private StructuredTextEditor fTextEditor;
+ private TextEditorPostSelectionAdapter fTextEditorSelectionListener;
+
/**
* StructuredTextMultiPageEditorPart constructor comment.
*/
@@ -196,7 +306,7 @@
}
/*
- * This method is just to make firePropertyChanged accessbible from some
+ * This method is just to make firePropertyChanged accessible from some
* (anonomous) inner classes.
*/
void _firePropertyChange(int property) {
@@ -207,26 +317,18 @@
* Adds the source page of the multi-page editor.
*/
private void addSourcePage() throws PartInitException {
- try {
- fSourcePageIndex = addPage(fTextEditor, getEditorInput());
- setPageText(fSourcePageIndex, XMLEditorMessages.XMLMultiPageEditorPart_0);
- // the update's critical, to get viewer selection manager and
- // highlighting to work
- fTextEditor.update();
+ fSourcePageIndex = addPage(fTextEditor, getEditorInput());
+ setPageText(fSourcePageIndex, XMLEditorMessages.XMLMultiPageEditorPart_0);
+ // the update's critical, to get viewer selection manager and
+ // highlighting to work
+ fTextEditor.update();
- firePropertyChange(PROP_TITLE);
+ firePropertyChange(PROP_TITLE);
- // Changes to the Text Viewer's document instance should also
- // force an
- // input refresh
- fTextEditor.getTextViewer().addTextInputListener(new TextInputListener());
- }
- catch (PartInitException exception) {
- // dispose editor
- dispose();
- Logger.logException(exception);
- throw new SourceEditingRuntimeException(exception, XMLEditorMessages.An_error_has_occurred_when1_ERROR_);
- }
+ // Changes to the Text Viewer's document instance should also
+ // force an
+ // input refresh
+ fTextEditor.getTextViewer().addTextInputListener(new TextInputListener());
}
/**
@@ -237,9 +339,62 @@
*/
private void connectDesignPage() {
if (fDesignViewer != null) {
- fDesignViewer.setViewerSelectionManager(fTextEditor.getViewerSelectionManager());
fDesignViewer.setDocument(getDocument());
}
+
+ /*
+ * Connect selection from the design viewer to the selection provider
+ * for the XMLMultiPageEditorPart so that selection in the design
+ * viewer will propogate across the workbench.
+ */
+ if (fDesignViewer.getSelectionProvider() instanceof IPostSelectionProvider) {
+ ((IPostSelectionProvider) fDesignViewer.getSelectionProvider()).addPostSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ ((PostMultiPageSelectionProvider) getSite().getSelectionProvider()).firePostSelectionChanged(event);
+ }
+ });
+ }
+ fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ ((MultiPageSelectionProvider) getSite().getSelectionProvider()).fireSelectionChanged(event);
+ }
+ });
+
+ /*
+ * Connect selection from the design viewer to the selection provider
+ * of the source page so that selection in the design viewer will be
+ * applied to the source page. Prefer post selection.
+ */
+ if (fDesignViewer.getSelectionProvider() instanceof IPostSelectionProvider) {
+ ((IPostSelectionProvider) fDesignViewer.getSelectionProvider()).addPostSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ getTextEditor().getSelectionProvider().setSelection(event.getSelection());
+ }
+ });
+ }
+ else {
+ fDesignViewer.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ getTextEditor().getSelectionProvider().setSelection(event.getSelection());
+ }
+ });
+ }
+
+ /**
+ * Drive the design viewer from selection in the source page
+ */
+ ISelectionProvider provider = getTextEditor().getSelectionProvider();
+ if (fTextEditorSelectionListener == null) {
+ fTextEditorSelectionListener = new TextEditorPostSelectionAdapter();
+ }
+ if (provider instanceof IPostSelectionProvider) {
+ fTextEditorSelectionListener.forcePostSelection = false;
+ ((IPostSelectionProvider) provider).addPostSelectionChangedListener(fTextEditorSelectionListener);
+ }
+ else {
+ fTextEditorSelectionListener.forcePostSelection = true;
+ provider.addSelectionChangedListener(fTextEditorSelectionListener);
+ }
}
/**
@@ -247,14 +402,14 @@
*
*/
private void createAndAddDesignPage() {
- IDesignViewer tableTreeViewer = createDesignPage();
+ IDesignViewer designViewer = createDesignPage();
- fDesignViewer = tableTreeViewer;
+ fDesignViewer = designViewer;
// note: By adding the design page as a Control instead of an
// IEditorPart, page switches will indicate
// a "null" active editor when the design page is made active
- fDesignPageIndex = addPage(tableTreeViewer.getControl());
- setPageText(fDesignPageIndex, tableTreeViewer.getTitle());
+ fDesignPageIndex = addPage(designViewer.getControl());
+ setPageText(fDesignPageIndex, designViewer.getTitle());
}
protected IDesignViewer createDesignPage() {
@@ -275,27 +430,17 @@
try {
// source page MUST be created before design page, now
createSourcePage();
+
createAndAddDesignPage();
addSourcePage();
connectDesignPage();
- IStructuredModel model = null;
- try {
- model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument());
- if (model != null) {
- int activePageIndex = getPreferenceStore().getInt(IXMLPreferenceNames.LAST_ACTIVE_PAGE);
- if (activePageIndex >= 0 && activePageIndex < getPageCount()) {
- setActivePage(activePageIndex);
- }
- }
- else {
- setActivePage(fSourcePageIndex);
- }
+ int activePageIndex = getPreferenceStore().getInt(IXMLPreferenceNames.LAST_ACTIVE_PAGE);
+ if (activePageIndex >= 0 && activePageIndex < getPageCount()) {
+ setActivePage(activePageIndex);
}
- finally {
- if (model != null) {
- model.releaseFromRead();
- }
+ else {
+ setActivePage(fSourcePageIndex);
}
}
catch (PartInitException e) {
@@ -310,7 +455,7 @@
protected IEditorSite createSite(IEditorPart editor) {
IEditorSite site = null;
if (editor == fTextEditor) {
- site = new MultiPageEditorSite(this, editor) {
+ site = new PostMultiPageEditorSite(this, editor) {
/**
* @see org.eclipse.ui.part.MultiPageEditorSite#getActionBarContributor()
*/
@@ -355,18 +500,19 @@
private void disconnectDesignPage() {
if (fDesignViewer != null) {
fDesignViewer.setDocument(null);
- fDesignViewer.setViewerSelectionManager(null);
}
}
public void dispose() {
- Logger.trace("Source Editor", "StructuredTextMultiPageEditorPart::dispose entry"); //$NON-NLS-1$ //$NON-NLS-2$
+ Logger.trace("Source Editor", "XMLMultiPageEditorPart::dispose entry"); //$NON-NLS-1$ //$NON-NLS-2$
disconnectDesignPage();
- IWorkbenchWindow window = getSite().getWorkbenchWindow();
- window.getPartService().removePartListener(fPartListener);
- window.getShell().removeShellListener(fPartListener);
+ if (fActivationListener != null) {
+ fActivationListener.dispose();
+ fActivationListener = null;
+ }
+
if (fTextEditor != null && fPropertyListener != null) {
fTextEditor.removePropertyListener(fPropertyListener);
}
@@ -428,7 +574,7 @@
}
return result;
}
-
+
private IDocument getDocument() {
IDocument document = null;
if (fTextEditor != null)
@@ -479,13 +625,9 @@
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
try {
super.init(site, input);
- if (fPartListener == null) {
- fPartListener = new PartListener();
- }
+ site.setSelectionProvider(new PostMultiPageSelectionProvider(this));
// we want to listen for our own activation
- IWorkbenchWindow window = getSite().getWorkbenchWindow();
- window.getPartService().addPartListener(fPartListener);
- window.getShell().addShellListener(fPartListener);
+ fActivationListener = new ActivationListener(site.getWorkbenchWindow().getPartService());
}
catch (Exception e) {
Logger.logException("exception initializing " + getClass().getName(), e);
@@ -522,23 +664,18 @@
protected void pageChange(int newPageIndex) {
super.pageChange(newPageIndex);
saveLastActivePageIndex(newPageIndex);
- }
- /**
- * Posts the update code "behind" the running operation.
- */
- void postOnDisplayQue(Runnable runnable) {
- IWorkbench workbench = PlatformUI.getWorkbench();
- IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
- if (windows != null && windows.length > 0) {
- Display display = windows[0].getShell().getDisplay();
- display.asyncExec(runnable);
+ IEditorPart newlyActiveEditor = getEditor(newPageIndex);
+ if (newPageIndex == fDesignPageIndex) {
+ ISelectionProvider selectionProvider = fDesignViewer.getSelectionProvider();
+ if (selectionProvider != null) {
+ SelectionChangedEvent event = new SelectionChangedEvent(selectionProvider, selectionProvider.getSelection());
+ ((MultiPageSelectionProvider) getSite().getSelectionProvider()).fireSelectionChanged(event);
+ ((PostMultiPageSelectionProvider) getSite().getSelectionProvider()).firePostSelectionChanged(event);
+ }
}
- else
- runnable.run();
}
-
void safelySanityCheckState() {
// If we're called before editor is created, simply ignore since we
// delegate this function to our embedded TextEditor
diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java
index 05a5aa0..0228b87 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeContentProvider.java
@@ -45,7 +45,7 @@
protected ViewerNotifyingAdapterFactory viewerNotifyingAdapterFactory = new ViewerNotifyingAdapterFactory();
protected XMLTableTreePropertyDescriptorFactory propertyDescriptorFactory;
- // protected ImageFactory imageFactory =
+ // protected ImageFactory imageFactory =
// XMLCommonUIPlugin.getInstance().getImageFactory();
protected List viewerList = new Vector();
protected TreeContentHelper treeContentHelper = new TreeContentHelper();
@@ -81,7 +81,8 @@
Node node = (Node) o;
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
result = ((Attr) node).getOwnerElement();
- } else {
+ }
+ else {
result = node.getParentNode();
}
}
@@ -117,7 +118,7 @@
ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
if (mq != null) {
- propertyDescriptorFactory = new XMLTableTreePropertyDescriptorFactory(mq);
+ propertyDescriptorFactory = new XMLTableTreePropertyDescriptorFactory();
documentManager = mq.getCMDocumentManager();
if (documentManager != null) {
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
@@ -193,14 +194,14 @@
}
}
- // if (image != null) {
- // Image markerOverlayImage =
+ // if (image != null) {
+ // Image markerOverlayImage =
// overlayIconManager.getOverlayImageForObject(node);
- // if (markerOverlayImage != null) {
- // image = imageFactory.createCompositeImage(image,
+ // if (markerOverlayImage != null) {
+ // image = imageFactory.createCompositeImage(image,
// markerOverlayImage, ImageFactory.BOTTOM_LEFT);
- // }
- // }
+ // }
+ // }
}
return image;
}
@@ -240,7 +241,8 @@
String result = null;
if (column == 0) {
result = getText(object);
- } else if (column == 1 && object instanceof Node) {
+ }
+ else if (column == 1 && object instanceof Node) {
result = treeContentHelper.getNodeValue((Node) object);
}
return result != null ? result : ""; //$NON-NLS-1$
@@ -284,8 +286,8 @@
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
switch (eventType) {
- //case INodeNotifier.ADD: // ignore
- //case INodeNotifier.REMOVE: // ignore
+ // case INodeNotifier.ADD: // ignore
+ // case INodeNotifier.REMOVE: // ignore
case INodeNotifier.CHANGE :
case INodeNotifier.STRUCTURE_CHANGED :
case INodeNotifier.CONTENT_CHANGED : {
@@ -296,7 +298,8 @@
if (viewer instanceof StructuredViewer) {
((StructuredViewer) viewer).refresh(node);
- } else {
+ }
+ else {
// todo... consider doing a time delayed
// refresh here!!
viewer.refresh();
@@ -319,7 +322,8 @@
String data = ((Text) node).getData();
result = (data == null || data.trim().length() == 0);
}
- } catch (Exception e) {
+ }
+ catch (Exception e) {
Logger.logException(e);
}
return result;
diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java
index 38a202d..cffc2be 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreePropertyDescriptorFactory.java
@@ -18,6 +18,7 @@
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.ui.internal.properties.EnumeratedStringPropertyDescriptor;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
@@ -29,17 +30,24 @@
protected TreeContentHelper treeContentHelper = new TreeContentHelper();
- public XMLTableTreePropertyDescriptorFactory(ModelQuery modelQuery) {
- super(modelQuery);
+ public XMLTableTreePropertyDescriptorFactory() {
+ super();
}
protected IPropertyDescriptor createPropertyDescriptorHelper(String name, Element element, CMNode cmNode) {
IPropertyDescriptor result = null;
- String[] valuesArray = getModelQuery().getPossibleDataTypeValues(element, cmNode);
+ ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
+ String[] valuesArray = null;
+ if (mq != null) {
+ valuesArray = mq.getPossibleDataTypeValues(element, cmNode);
+ }
if (valuesArray != null && valuesArray.length > 0) {
result = new EnumeratedStringPropertyDescriptor(name, name, valuesArray);
}
+ else {
+ result = createDefaultPropertyDescriptor(name);
+ }
return result;
}
@@ -49,10 +57,17 @@
Node parentNode = text.getParentNode();
if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
Element parentElement = (Element) parentNode;
- CMElementDeclaration ed = getModelQuery().getCMElementDeclaration(parentElement);
+ ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument());
+ CMElementDeclaration ed = null;
+ if (mq != null) {
+ ed = mq.getCMElementDeclaration(parentElement);
+ }
if (ed != null) {
result = createPropertyDescriptorHelper(HACK, parentElement, ed);
}
+ else {
+ result = createDefaultPropertyDescriptor(parentElement.getNodeName());
+ }
}
if (result == null) {
@@ -66,8 +81,12 @@
IPropertyDescriptor result = null;
String attributeName = attr.getName();
+ ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument());
- CMAttributeDeclaration ad = getModelQuery().getCMAttributeDeclaration(attr);
+ CMAttributeDeclaration ad = null;
+ if (mq != null) {
+ ad = mq.getCMAttributeDeclaration(attr);
+ }
if (ad != null) {
result = createPropertyDescriptorHelper(attributeName, attr.getOwnerElement(), ad);
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java
index 9701856..ef0bb1d 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTableTreeViewer.java
@@ -8,32 +8,21 @@
****************************************************************************/
package org.eclipse.wst.xml.ui.internal.tabletree;
-import java.util.List;
-
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.wst.sse.core.internal.provisional.IModelStateListener;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
-import org.eclipse.wst.sse.ui.internal.ViewerSelectionManager;
-import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.ui.internal.actions.NodeAction;
import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager;
@@ -42,132 +31,20 @@
public class XMLTableTreeViewer extends TreeViewer implements IDesignViewer {
- /**
- * This class is used to improve source editing performance by coalescing
- * multiple notifications for an element change into a single refresh
- */
- class DelayedRefreshTimer implements Runnable {
- private final int delta = 2000;
- protected Object objectPendingRefresh;
- protected ISelection pendingSelection;
- protected Object prevObject;
- protected XMLTableTreeViewer viewer;
-
- public DelayedRefreshTimer(XMLTableTreeViewer treeViewer) {
- this.viewer = treeViewer;
- }
-
- public boolean isRefreshPending() {
- return objectPendingRefresh != null;
- }
-
- public void refresh(Object object) {
- if (prevObject == object) {
- objectPendingRefresh = object;
- getDisplay().timerExec(delta, this);
- }
- else {
- if (objectPendingRefresh != null) {
- viewer.doRefresh(objectPendingRefresh, false);
- objectPendingRefresh = null;
- }
- viewer.doRefresh(object, false);
- }
- prevObject = object;
- }
-
- private Display getDisplay() {
-
- return PlatformUI.getWorkbench().getDisplay();
- }
-
- public void run() {
- // defect 239677 ensure that the viewer's control is not disposed
- //
- if (objectPendingRefresh != null && !viewer.getTree().isDisposed()) {
- viewer.doRefresh(objectPendingRefresh, true);
- if (pendingSelection != null) {
- // see fireSelectionChanged comment about jumping cursor
- // problem
- //
- viewer.setSelection(pendingSelection, true);
- pendingSelection = null;
- }
- objectPendingRefresh = null;
- prevObject = null;
- }
- }
-
- public void setSelection(ISelection selection) {
- pendingSelection = selection;
- }
- }
-
- class DelayingNodeSelectionListener implements INodeSelectionListener {
- public void nodeSelectionChanged(NodeSelectionChangedEvent event) {
- // if (isNodeSelectionListenerEnabled &&
- // !event.getSource().equals(this)) {
- if (!event.getSource().equals(XMLTableTreeViewer.this)) {
- List selectedNodes = event.getSelectedNodes();
- ISelection selection = new StructuredSelection(selectedNodes);
-
- // for performance purposes avoid large multi-selections
- //
- if (selectedNodes.size() < 100) {
- if (timer.isRefreshPending()) {
- timer.setSelection(selection);
- }
- else {
- setSelection(selection, true);
- }
- }
- }
- }
- }
-
- class InternalModelStateListener implements IModelStateListener {
-
- public void modelAboutToBeChanged(IStructuredModel model) {
- ignoreRefresh = true;
- }
-
- public void modelChanged(IStructuredModel model) {
- ignoreRefresh = false;
- refresh();
- }
-
- public void modelDirtyStateChanged(IStructuredModel model, boolean isDirty) {
- }
-
- public void modelResourceDeleted(IStructuredModel model) {
- }
-
- public void modelResourceMoved(IStructuredModel originalmodel, IStructuredModel movedmodel) {
- }
-
- public void modelAboutToBeReinitialized(IStructuredModel structuredModel) {
- }
-
- public void modelReinitialized(IStructuredModel structuredModel) {
- }
- }
-
class NodeActionMenuListener implements IMenuListener {
public void menuAboutToShow(IMenuManager menuManager) {
- if (fModel != null) {
- // used to disable NodeSelection listening while running
- // NodeAction
- XMLNodeActionManager nodeActionManager = new XMLNodeActionManager(fModel, XMLTableTreeViewer.this) {
- public void beginNodeAction(NodeAction action) {
- super.beginNodeAction(action);
- }
+ // used to disable NodeSelection listening while running
+ // NodeAction
+ XMLNodeActionManager nodeActionManager = new XMLNodeActionManager(((IDOMDocument) getInput()).getModel(), XMLTableTreeViewer.this) {
+ public void beginNodeAction(NodeAction action) {
+ super.beginNodeAction(action);
+ }
- public void endNodeAction(NodeAction action) {
- super.endNodeAction(action);
- }
- };
- nodeActionManager.fillContextMenu(menuManager, getSelection());
- }
+ public void endNodeAction(NodeAction action) {
+ super.endNodeAction(action);
+ }
+ };
+ nodeActionManager.fillContextMenu(menuManager, getSelection());
}
}
@@ -175,15 +52,6 @@
int count = 0;
- protected IModelStateListener fInternalModelStateListener = new InternalModelStateListener();
- protected IStructuredModel fModel = null;
- protected INodeSelectionListener fNodeSelectionListener;
-
- protected ViewerSelectionManager fViewerSelectionManager;
-
- protected boolean ignoreRefresh;
-
- protected DelayedRefreshTimer timer;
protected XMLTreeExtension treeExtension;
public XMLTableTreeViewer(Composite parent) {
@@ -200,7 +68,6 @@
createContextMenu();
XMLDragAndDropManager.addDragAndDropSupport(this);
- timer = new DelayedRefreshTimer(this);
}
/**
@@ -221,38 +88,8 @@
super.refresh(o);
}
- protected void fireSelectionChanged(SelectionChangedEvent event) {
- if (!getTree().isDisposed() && !getTree().isFocusControl()) {
- // defect 246094
- // Various jumping cursor problems are caused when a selection
- // 'delayed' selection occurs.
- // These delayed selections are caused two ways:
- //
- // - when DelayedRefreshTimer calls doRefresh() ... the
- // 'preserveSelection' causes selection to occur
- // - when DelayedRefreshTimer performs a 'pending' selection
- //
- // Since we only want to update the selectionManager on an explict
- // user action
- // (and not some selection that is merely a resonse to the
- // selection manager)
- // we ensure that the tree has focus control before firing events
- // to the selectionManager.
- //
- removeSelectionChangedListener(fViewerSelectionManager);
- super.fireSelectionChanged(event);
- addSelectionChangedListener(fViewerSelectionManager);
- }
- else {
- super.fireSelectionChanged(event);
- }
- }
-
-
- public INodeSelectionListener getNodeSelectionListener() {
- if (fNodeSelectionListener == null)
- fNodeSelectionListener = new DelayingNodeSelectionListener();
- return fNodeSelectionListener;
+ public ISelectionProvider getSelectionProvider() {
+ return this;
}
public String getTitle() {
@@ -263,82 +100,28 @@
super.handleDispose(event);
treeExtension.dispose();
setDocument(null);
- setViewerSelectionManager(null);
}
public void refresh() {
- if (!ignoreRefresh && !getControl().isDisposed()) {
- if (Display.getCurrent() != null) {
- refreshTree();
- }
- else {
-
- final Display display = PlatformUI.getWorkbench().getDisplay();
-
- display.asyncExec(new Runnable() {
- public void run() {
- if (display != null && !display.isDisposed()) {
- refreshTree();
- }
- }
- });
- }
- }
- }
-
- void refreshTree() {
treeExtension.resetCachedData();
super.refresh();
- getTree().redraw(0, 0, getTree().getBounds().width, getTree().getBounds().height, false);
- getTree().update();
}
public void refresh(Object o) {
- if (!ignoreRefresh && !getControl().isDisposed() && timer != null) {
- if (Display.getCurrent() != null) {
- refreshTree(o);
- }
- else {
- final Object object = o;
- final Display display = PlatformUI.getWorkbench().getDisplay();
- display.asyncExec(new Runnable() {
- public void run() {
- if (display != null && !display.isDisposed()) {
- refreshTree(object);
- }
- }
- });
- }
- }
- }
-
- void refreshTree(Object o) {
- if (getTree().isVisible()) {
- doRefresh(o, false);
- }
- else {
- timer.refresh(o);
- }
+ treeExtension.resetCachedData();
+ super.refresh(o);
}
public void setDocument(IDocument document) {
- // remove
- if (fModel != null) {
- fModel.removeModelStateListener(fInternalModelStateListener);
- fModel.releaseFromEdit();
- }
-
- // get model for read and allow text editor to be the one that
- // getModelForEdit
+ /*
+ * let the text editor to be the one that manages the model's lifetime
+ */
IStructuredModel model = null;
- if (document != null) {
- model = StructuredModelManager.getModelManager().getExistingModelForEdit(document);
+ try {
+ model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null && model instanceof IDOMModel) {
Document domDoc = null;
- model.addModelStateListener(fInternalModelStateListener);
- ModelQuery mq = ModelQueryUtil.getModelQuery(model);
- treeExtension.setModelQuery(mq);
domDoc = ((IDOMModel) model).getDocument();
setInput(domDoc);
treeExtension.setIsUnsupportedInput(false);
@@ -347,27 +130,12 @@
treeExtension.setIsUnsupportedInput(true);
}
}
-
- fModel = model;
- }
-
- // the following methods implement the IDesignViewer interface
- // - getControl() is implemented via AdvancedTableTreeViewer
- //
- public void setViewerSelectionManager(ViewerSelectionManager viewerSelectionManager) {
- // disconnect from old one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.removeNodeSelectionListener(getNodeSelectionListener());
- removeSelectionChangedListener(fViewerSelectionManager);
+ finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
}
- fViewerSelectionManager = viewerSelectionManager;
-
- // connect to new one
- if (fViewerSelectionManager != null) {
- fViewerSelectionManager.addNodeSelectionListener(getNodeSelectionListener());
- addSelectionChangedListener(fViewerSelectionManager);
- }
}
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java
index b9635fd..9ca1c3b 100644
--- a/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java
+++ b/bundles/org.eclipse.wst.xml.ui/src-multipage/org/eclipse/wst/xml/ui/internal/tabletree/XMLTreeExtension.java
@@ -22,6 +22,7 @@
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDescriptionBuilder;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -38,7 +39,6 @@
protected Color f1, f2, b1, b2;
protected boolean cachedDataIsValid = true;
- private ModelQuery fModelQuery;
public XMLTreeExtension(Tree tree) {
super(tree);
@@ -58,6 +58,8 @@
f2 = new Color(tree.getDisplay(), r, g, b);
b1 = tree.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
b2 = background;
+
+ propertyDescriptorFactory = new XMLTableTreePropertyDescriptorFactory();
}
public void dispose() {
@@ -115,8 +117,9 @@
public String getElementValueHelper(Element element) {
String result = null;
- if (result == null && getModelQuery() != null) {
- CMElementDeclaration ed = getModelQuery().getCMElementDeclaration(element);
+ ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
+ if (result == null && mq != null) {
+ CMElementDeclaration ed = mq.getCMElementDeclaration(element);
if (ed != null && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) { //$NON-NLS-1$
result = decriptionBuilder.buildDescription(ed);
}
@@ -125,7 +128,7 @@
}
/**
- *
+ *
*/
public class MyCellModifier implements ICellModifier, TreeExtension.ICellEditorProvider {
public boolean canModify(Object element, String property) {
@@ -146,14 +149,14 @@
}
public void modify(Object element, String property, Object value) {
- //enableNodeSelectionListener(false);
+ // enableNodeSelectionListener(false);
Item item = (Item) element;
String oldValue = treeContentHelper.getNodeValue((Node) item.getData());
String newValue = value.toString();
if (newValue != null && !newValue.equals(oldValue)) {
treeContentHelper.setNodeValue((Node) item.getData(), value.toString());
}
- //enableNodeSelectionListener(true);
+ // enableNodeSelectionListener(true);
}
public CellEditor getCellEditor(Object o, int col) {
@@ -161,18 +164,4 @@
return pd != null ? pd.createPropertyEditor(control) : null;
}
}
-
-
- public ModelQuery getModelQuery() {
- return fModelQuery;
- }
-
- /**
- * @param query
- */
- public void setModelQuery(ModelQuery query) {
- fModelQuery = query;
- propertyDescriptorFactory = new XMLTableTreePropertyDescriptorFactory(query);
- }
-
}
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/BufferedOutlineUpdater.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/BufferedStructureUpdater.java
similarity index 86%
rename from bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/BufferedOutlineUpdater.java
rename to bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/BufferedStructureUpdater.java
index c3391ef..11583fb 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/BufferedOutlineUpdater.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/BufferedStructureUpdater.java
@@ -18,15 +18,15 @@
/**
* Can handle multiple subsequent calls to processNode(..) by buffering them
- * w/ a RefreshOutlineJob. Only one refresh is performed (on the UI Thread) on
+ * w/ a RefreshStructureJob. Only one refresh is performed (on the UI Thread) on
* the minimal affected area of the tree at the end of the batch of updates
* (after the last update is processed).
*
* @author pavery
*/
-public class BufferedOutlineUpdater {
+class BufferedStructureUpdater {
- private RefreshOutlineJob fRefreshJob = null;
+ private RefreshStructureJob fRefreshJob = null;
private StructuredViewer fViewer = null;
/**
@@ -36,7 +36,6 @@
* the specific node that changed
*/
public void processNode(final StructuredViewer structuredViewer, Node node) {
-
// refresh on structural and "unknown" changes
// it would be nice to not refresh the viewer if it's not visible
// but only refresh when it's brought back to the front
@@ -48,9 +47,9 @@
}
}
- private RefreshOutlineJob getRefreshJob() {
+ private RefreshStructureJob getRefreshJob() {
if (fRefreshJob == null)
- fRefreshJob = new RefreshOutlineJob(getViewer());
+ fRefreshJob = new RefreshStructureJob(getViewer());
return fRefreshJob;
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java
index 0ff8e4c..286b385 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java
@@ -14,38 +14,18 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.views.properties.PropertySheetPage;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
-import org.eclipse.wst.sse.core.internal.util.StringUtils;
import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter;
-import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
-import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener;
-import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
-import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
-import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
-import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
/**
@@ -53,73 +33,6 @@
*/
public class JFaceNodeAdapter implements IJFaceNodeAdapter {
- public class CMDocumentManagerListenerImpl implements CMDocumentManagerListener {
-
- List beingRefreshed = Collections.synchronizedList(new ArrayList());
-
- public void cacheCleared(org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache cache) {
- // nothing to do
- }
-
- public void cacheUpdated(CMDocumentCache cache, final String uri, int oldStatus, int newStatus, CMDocument cmDocument) {
-
- if (newStatus == CMDocumentCache.STATUS_LOADED || newStatus == CMDocumentCache.STATUS_ERROR) {
- refreshViewers();
- }
- }
-
- Display getDisplay() {
- Display display = null;
- // Note: the workbench should always have a display
- // (unless running headless), whereas Display.getCurrent()
- // only returns the display if the currently executing thread
- // has one.
- if (PlatformUI.isWorkbenchRunning()) {
- display = PlatformUI.getWorkbench().getDisplay();
- }
- return display;
- }
-
- public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) {
-
- if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) {
- refreshViewers();
- }
- }
-
- private void refreshViewers() {
-
- // we're counting on getListers returning a "copy" of the
- // listeners, so we'll be thread safe.
- Collection listeners = ((IJFaceNodeAdapterFactory) fAdapterFactory).getListeners();
- Iterator iterator = listeners.iterator();
- while (iterator.hasNext()) {
- Object listener = iterator.next();
- // now that we use aynchExec, we ourselves have to gaurd
- // against
- // agains adding some refreshes when its already being
- // refreshed.
- if (listener instanceof PropertySheetPage && (!beingRefreshed.contains(listener))) {
- final PropertySheetPage propertySheetPage = (PropertySheetPage) listener;
- beingRefreshed.add(propertySheetPage);
- getDisplay().asyncExec(new Runnable() {
-
- public void run() {
-
- if (getDisplay().isDisposed()) {
- return;
- }
- if (propertySheetPage.getControl() != null && !propertySheetPage.getControl().isDisposed()) {
- propertySheetPage.refresh();
- beingRefreshed.remove(propertySheetPage);
- }
- }
- });
- }
- }
- }
- }
-
final static Class ADAPTER_KEY = IJFaceNodeAdapter.class;
/**
@@ -133,18 +46,15 @@
return result;
}
- INodeAdapterFactory fAdapterFactory;
- private CMDocumentManagerListener cmDocumentManagerListener;
- private BufferedOutlineUpdater fUpdater = null;
+ JFaceNodeAdapterFactory fAdapterFactory;
+ private BufferedStructureUpdater fUpdater = null;
- public JFaceNodeAdapter(INodeAdapterFactory adapterFactory1) {
-
+ public JFaceNodeAdapter(JFaceNodeAdapterFactory adapterFactory) {
super();
- this.fAdapterFactory = adapterFactory1;
+ this.fAdapterFactory = adapterFactory;
}
protected Image createImage(Object object) {
-
Image image = null;
Node node = (Node) object;
switch (node.getNodeType()) {
@@ -206,7 +116,7 @@
// nodeList(item) for O(n) vs. O(n*n)
//
Node node = (Node) object;
- ArrayList v = new ArrayList(node.getChildNodes().getLength());
+ ArrayList v = new ArrayList();
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
Node n = child;
if (n.getNodeType() != Node.TEXT_NODE)
@@ -216,34 +126,10 @@
}
/**
- * Returns a CMDocumentManagerListener that can update JFace views when
- * notified of CMDocumentManager events
- */
- public org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener getCMDocumentManagerListener() {
-
- if (cmDocumentManagerListener == null)
- cmDocumentManagerListener = new CMDocumentManagerListenerImpl();
- return cmDocumentManagerListener;
- }
-
- Display getDisplay() {
- Display display = null;
- // Note: the workbench should always have a display
- // (unless running headless), whereas Display.getCurrent()
- // only returns the display if the currently executing thread
- // has one.
- if (PlatformUI.isWorkbenchRunning()) {
- display = PlatformUI.getWorkbench().getDisplay();
- }
- return display;
- }
-
- /**
* Returns an enumeration with the elements belonging to the passed
* element. These are the top level items in a list, tree, table, etc...
*/
public Object[] getElements(Object node) {
-
return getChildren(node);
}
@@ -251,7 +137,6 @@
* Fetches the label image specific to this object instance.
*/
public Image getLabelImage(Object node) {
-
Image image = CMImageUtil.getImage(CMImageUtil.getDeclaration((Node) node));
if (image == null && JFaceResources.getImageRegistry() != null) {
ImageRegistry imageRegistry = JFaceResources.getImageRegistry();
@@ -270,7 +155,6 @@
* Fetches the label text specific to this object instance.
*/
public String getLabelText(Object node) {
-
return getNodeName(node);
}
@@ -282,79 +166,22 @@
if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
nodeName.insert(0, "DOCTYPE:"); //$NON-NLS-1$
}
- else if (node.getNodeType() == Node.ELEMENT_NODE && getShowAttribute()) {
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444
- if (node.hasAttributes()) {
- Element element = (Element) node;
- NamedNodeMap attributes = element.getAttributes();
- Node attribute = null;
- Node attribute2 = null;
-
- // try to get content model element declaration
- CMElementDeclaration elementDecl = null;
- ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
- if (mq != null) {
- elementDecl = mq.getCMElementDeclaration(element);
- }
- // find an attribute of type ID
- if (elementDecl != null) {
- int i = 0;
- while (i < attributes.getLength() && attribute == null) {
- Node attr = attributes.item(i);
- String attrName = attr.getNodeName();
- CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) elementDecl.getAttributes().getNamedItem(attrName);
- if (attrDecl != null) {
- if ((attrDecl.getAttrType() != null) && (CMDataType.ID.equals(attrDecl.getAttrType().getDataTypeName()))) {
- attribute = attr;
- }
- else if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED) {
- // as a backup, keep tabs on any required
- // attributes
- attribute2 = attr;
- }
- }
- ++i;
- }
- }
-
- // if no suitable attribute found, try using a required
- // attribute, if none, then just use first attribute
- if (attribute == null) {
- if (attribute2 != null) {
- attribute = attribute2;
- }
- else
- attribute = attributes.item(0);
- }
-
- // display the attribute
- String attributeName = attribute.getNodeName();
- if (attributeName != null && attributeName.length() > 0) {
- nodeName.append(" " + attributeName); //$NON-NLS-1$
- String attributeValue = attribute.getNodeValue();
- if (attributeValue != null && attributeValue.length() > 0) {
- nodeName.append("=" + StringUtils.strip(attributeValue)); //$NON-NLS-1$
- }
- }
- }
- }
return nodeName.toString();
}
- private BufferedOutlineUpdater getOutlineUpdater() {
- if (fUpdater == null)
- fUpdater = new BufferedOutlineUpdater();
- return fUpdater;
- }
-
public Object getParent(Object object) {
-
Node node = (Node) object;
return node.getParentNode();
}
- public boolean hasChildren(Object object) {
+ private BufferedStructureUpdater getStructureUpdater() {
+ if (fUpdater == null) {
+ fUpdater = new BufferedStructureUpdater();
+ }
+ return fUpdater;
+ }
+ public boolean hasChildren(Object object) {
// (pa) 20021217
// cmvc defect 235554 > use child.getNextSibling() instead of
// nodeList(item) for O(n) vs. O(n*n)
@@ -382,7 +209,6 @@
* changed.
*/
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
-
// future_TODO: the 'uijobs' used in this method were added to solve
// threading problems when the dom
// is updated in the background while the editor is open. They may be
@@ -390,7 +216,7 @@
// (That is, may be be worthy of job manager management). If they are
// found to be important enough to leave in,
// there's probably some optimization that can be done.
- Collection listeners = ((JFaceNodeAdapterFactory) fAdapterFactory).getListeners();
+ Collection listeners = fAdapterFactory.getListeners();
Iterator iterator = listeners.iterator();
while (iterator.hasNext()) {
@@ -401,7 +227,6 @@
// INodeNotifier.STRUCTURE_CHANGED || (eventType ==
// INodeNotifier.CHANGE && changedFeature == null))) {
if (notifier instanceof Node && (listener instanceof StructuredViewer) && (eventType == INodeNotifier.STRUCTURE_CHANGED || (eventType == INodeNotifier.CHANGE))) {
-
if (DEBUG) {
System.out.println("JFaceNodeAdapter notified on event type > " + eventType); //$NON-NLS-1$
}
@@ -410,27 +235,9 @@
StructuredViewer structuredViewer = (StructuredViewer) listener;
// https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=5230
if (structuredViewer.getControl() != null) {
- getOutlineUpdater().processNode(structuredViewer, (Node) notifier);
- }
- }
- else if ((listener instanceof PropertySheetPage) && ((eventType == INodeNotifier.CHANGE) || (eventType == INodeNotifier.STRUCTURE_CHANGED))) {
- PropertySheetPage propertySheetPage = (PropertySheetPage) listener;
- if (propertySheetPage.getControl() != null) {
- RefreshPropertySheetJob refreshPropertySheetJob = new RefreshPropertySheetJob(getDisplay(), XMLUIMessages.JFaceNodeAdapter_1, propertySheetPage); //$NON-NLS-1$
- refreshPropertySheetJob.schedule();
+ getStructureUpdater().processNode(structuredViewer, (Node) notifier);
}
}
}
}
-
- /**
- * Retrieves info from JFaceNodeAdapterFactory on whether or not to show
- * attributes when getLabelText is called
- *
- * @return boolean
- */
- private boolean getShowAttribute() {
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444
- return ((JFaceNodeAdapterFactory) fAdapterFactory).getShowAttribute();
- }
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java
index 90cb8ac..0e53a3c 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java
@@ -12,20 +12,31 @@
*******************************************************************************/
package org.eclipse.wst.xml.ui.internal.contentoutline;
-
-
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.ui.progress.UIJob;
import org.eclipse.wst.sse.core.internal.provisional.AbstractAdapterFactory;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter;
import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener;
import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
+import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
/**
@@ -33,17 +44,64 @@
* with a JFaceAdapterContentProvider to display DOM nodes in a tree.
*/
public class JFaceNodeAdapterFactory extends AbstractAdapterFactory implements IJFaceNodeAdapterFactory {
+ public class CMDocumentManagerListenerImpl implements CMDocumentManagerListener {
+ private static final int UPDATE_DELAY = 200;
+
+ public void cacheCleared(CMDocumentCache cache) {
+ // nothing to do
+ }
+
+ public void cacheUpdated(CMDocumentCache cache, final String uri, int oldStatus, int newStatus, CMDocument cmDocument) {
+ if (newStatus == CMDocumentCache.STATUS_LOADED || newStatus == CMDocumentCache.STATUS_ERROR) {
+ refreshViewers();
+ }
+ }
+
+ public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) {
+ if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) {
+ refreshViewers();
+ }
+ }
+
+ private void refreshViewers() {
+ Object[] listeners = getListeners().toArray();
+ for (int i = 0; i < listeners.length; i++) {
+ if (listeners[i] instanceof StructuredViewer) {
+ final StructuredViewer viewer = (StructuredViewer) listeners[i];
+ Job refresh = new UIJob(XMLUIMessages.refreshoutline_0) {
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ viewer.refresh(true);
+ return Status.OK_STATUS;
+ };
+ };
+ refresh.setSystem(true);
+ refresh.setPriority(Job.SHORT);
+ refresh.schedule(UPDATE_DELAY);
+ }
+ else if (listeners[i] instanceof Viewer) {
+ final Viewer viewer = (Viewer) listeners[i];
+ Job refresh = new UIJob(XMLUIMessages.refreshoutline_0) {
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ viewer.refresh();
+ return Status.OK_STATUS;
+ };
+ };
+ refresh.setSystem(true);
+ refresh.setPriority(Job.SHORT);
+ refresh.schedule(UPDATE_DELAY);
+ }
+ }
+ }
+ }
+
protected CMDocumentManager cmDocumentManager;
+ private CMDocumentManagerListenerImpl fCMDocumentManagerListener = null;
/**
* This keeps track of all the listeners.
*/
- protected ArrayList fListeners = new ArrayList();
+ protected Set fListeners = new HashSet();
protected INodeAdapter singletonAdapter;
- /**
- * True if want to show attributes in label
- */
- private boolean fShowAttribute = false;
public JFaceNodeAdapterFactory() {
this(IJFaceNodeAdapter.class, true);
@@ -58,7 +116,6 @@
}
public INodeAdapterFactory copy() {
-
return new JFaceNodeAdapterFactory(this.adapterKey, this.shouldRegisterAdapter);
}
@@ -74,55 +131,36 @@
return singletonAdapter;
}
+
/**
- * returns "copy" so no one can modify our list. Its is a shallow copy.
+ * returns "copy" so no one can modify our list. It is a shallow copy.
*/
public synchronized Collection getListeners() {
- return (Collection) fListeners.clone();
+ return new ArrayList(fListeners);
}
protected void initAdapter(INodeAdapter adapter, INodeNotifier node) {
// register for CMDocumentManager events
- if (((JFaceNodeAdapter) adapter).getCMDocumentManagerListener() != null) {
- ModelQueryAdapter mqadapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class);
- if (mqadapter != null) {
- ModelQuery mquery = mqadapter.getModelQuery();
- if (mquery != null && mquery.getCMDocumentManager() != null) {
- cmDocumentManager = mquery.getCMDocumentManager();
- cmDocumentManager.addListener(((JFaceNodeAdapter) adapter).getCMDocumentManagerListener());
- }
+ ModelQueryAdapter mqadapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class);
+ if (mqadapter != null) {
+ ModelQuery mquery = mqadapter.getModelQuery();
+ if (mquery != null && mquery.getCMDocumentManager() != null) {
+ cmDocumentManager = mquery.getCMDocumentManager();
+ fCMDocumentManagerListener = new CMDocumentManagerListenerImpl();
+ cmDocumentManager.addListener(fCMDocumentManagerListener);
}
}
}
public void release() {
// deregister from CMDocumentManager events
- if (cmDocumentManager != null && singletonAdapter != null && ((JFaceNodeAdapter) singletonAdapter).getCMDocumentManagerListener() != null) {
- cmDocumentManager.removeListener(((JFaceNodeAdapter) singletonAdapter).getCMDocumentManagerListener());
+ if (cmDocumentManager != null && fCMDocumentManagerListener != null) {
+ cmDocumentManager.removeListener(fCMDocumentManagerListener);
}
+ fListeners.clear();
}
public synchronized void removeListener(Object listener) {
fListeners.remove(listener);
}
-
- /**
- * Set whether or not to show attributes when getLabelText is called
- *
- * @param showAttr
- */
- public void setShowAttribute(boolean showAttr) {
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444
- fShowAttribute = showAttr;
- }
-
- /**
- * Used by JFaceNodeAdapter in getLabelText
- *
- * @return true if want to show attribute when getLabelText is called
- */
- boolean getShowAttribute() {
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444
- return fShowAttribute;
- }
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java
index fe3fb0b..7327b15 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java
@@ -15,9 +15,10 @@
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter;
+import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
@@ -27,11 +28,9 @@
* nodes in the tree.
*/
public class JFaceNodeContentProvider implements ITreeContentProvider {
- protected INodeAdapterFactory adapterFactory;
- public JFaceNodeContentProvider(INodeAdapterFactory jfaceAdapterFactory) {
+ public JFaceNodeContentProvider() {
super();
- this.adapterFactory = jfaceAdapterFactory;
}
/**
@@ -49,7 +48,7 @@
*/
protected IJFaceNodeAdapter getAdapter(Object adaptable) {
if (adaptable instanceof INodeNotifier) {
- INodeAdapter adapter = adapterFactory.adapt((INodeNotifier) adaptable);
+ INodeAdapter adapter = ((INodeNotifier) adaptable).getAdapterFor(IJFaceNodeAdapter.class);
if (adapter instanceof IJFaceNodeAdapter)
return (IJFaceNodeAdapter) adapter;
}
@@ -99,5 +98,17 @@
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (oldInput != null && oldInput instanceof IStructuredModel) {
+ IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IStructuredModel) oldInput).getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
+ if (factory != null) {
+ factory.removeListener(viewer);
+ }
+ }
+ if (newInput != null && newInput instanceof IStructuredModel) {
+ IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IStructuredModel) newInput).getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
+ if (factory != null) {
+ factory.addListener(viewer);
+ }
+ }
}
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java
index dabb328..7472df9 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java
@@ -12,48 +12,21 @@
*******************************************************************************/
package org.eclipse.wst.xml.ui.internal.contentoutline;
-
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
+import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter;
-
/**
- * A class that uses a JFaceNodeAdapterFactory to provide adapters to provide
- * the labels and images for DOM nodes.
+ * A label provider backed by JFaceNodeAdapters.
*/
-public class JFaceNodeLabelProvider implements ILabelProvider {
-
- protected INodeAdapterFactory adapterFactory;
-
+public class JFaceNodeLabelProvider extends LabelProvider {
/**
* JFaceNodeLabelProvider constructor comment.
*/
- public JFaceNodeLabelProvider(INodeAdapterFactory adapterFactory) {
+ public JFaceNodeLabelProvider() {
super();
- this.adapterFactory = adapterFactory;
- }
-
- /**
- * Adds a listener to the label provider. A label provider should inform
- * its listener about state changes that enforces rendering of the visual
- * part that uses this label provider.
- */
- public void addListener(ILabelProviderListener listener) {
- // The label provider state never changes so we do not have
- // to implement this method.
- }
-
- /**
- * The visual part that is using this label provider is about to be
- * disposed. Deallocate all allocated SWT resources.
- */
- public void dispose() {
- // Nothing to dispose
}
/**
@@ -63,73 +36,39 @@
* java.lang.Object The object to get the adapter for
*/
protected IJFaceNodeAdapter getAdapter(Object adaptable) {
- return (IJFaceNodeAdapter) adapterFactory.adapt((INodeNotifier) adaptable);
+ if (adaptable instanceof INodeNotifier) {
+ INodeAdapter adapter = ((INodeNotifier) adaptable).getAdapterFor(IJFaceNodeAdapter.class);
+ if (adapter instanceof IJFaceNodeAdapter)
+ return (IJFaceNodeAdapter) adapter;
+ }
+ return null;
}
- /**
- * Returns the image for the label of the given element, for use in the
- * given viewer.
+ /*
+ * (non-Javadoc)
*
- * @param element
- * The element for which to provide the label image. Element
- * can be <code>null</code> indicating no input object is set
- * to the viewer.
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
public Image getImage(Object element) {
return getAdapter(element).getLabelImage(element);
}
- /**
- * Returns the text for the label of the given element, for use in the
- * given viewer.
+ /*
+ * (non-Javadoc)
*
- * @param element
- * The element for which to provide the label text. Element can
- * be <code>null</code> indicating no input object is set to
- * the viewer.
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
- public java.lang.String getText(Object element) {
- // This was returning null, on occasion ... probably should not be,
- // but
- // took the quick and easy way out for now. (dmw 3/8/01)
- String result = getAdapter(element).getLabelText(element);
- if (result == null)
- result = "";//$NON-NLS-1$
- return result;
+ public String getText(Object element) {
+ return getAdapter(element).getLabelText(element);
}
- /**
- * Checks whether this label provider is affected by the given domain
- * event.
- */
- public boolean isAffected(Object dummy) {//DomainEvent event) {
- //return event.isModifier(DomainEvent.NON_STRUCTURE_CHANGE);
- return true;
-
- }
-
- /**
- * Returns whether the label would be affected by a change to the given
- * property of the given element. This can be used to optimize a
- * non-structural viewer update. If the property mentioned in the update
- * does not affect the label, then the viewer need not update the label.
+ /*
+ * (non-Javadoc)
*
- * @param element
- * the element
- * @param property
- * the property
- * @return <code>true</code> if the label would be affected, and
- * <code>false</code> if it would be unaffected
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object,
+ * java.lang.String)
*/
public boolean isLabelProperty(Object element, String property) {
return false;
}
-
- /**
- * Removes a listener from the label provider.
- */
- public void removeListener(ILabelProviderListener listener) {
- // The label provider state never changes so we do not have
- // to implement this method.
- }
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshPropertySheetJob.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshPropertySheetJob.java
deleted file mode 100644
index d6aabb5..0000000
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshPropertySheetJob.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are 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:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.xml.ui.internal.contentoutline;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.progress.UIJob;
-import org.eclipse.ui.views.properties.PropertySheetPage;
-
-
-public class RefreshPropertySheetJob extends UIJob {
-
-
- private PropertySheetPage fPropertySheetPage;
-
- /**
- * @param jobDisplay
- * @param name
- */
- public RefreshPropertySheetJob(Display jobDisplay, String name, PropertySheetPage propertySheetPage) {
- super(jobDisplay, name);
- setPriority(Job.SHORT);
- fPropertySheetPage = propertySheetPage;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
- */
- public IStatus runInUIThread(IProgressMonitor monitor) {
- IStatus result = Status.OK_STATUS;
- try {
- Control control = fPropertySheetPage.getControl();
- // we should have check before even scheduling this, but even if
- // ok then, need to check again, right before executing.
- if (control != null && !control.isDisposed()) {
- fPropertySheetPage.refresh();
- }
- } catch (Exception e) {
- result = errorStatus(e);
- } finally {
- monitor.done();
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshOutlineJob.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java
similarity index 94%
rename from bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshOutlineJob.java
rename to bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java
index 8f84592..5fa2f66 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshOutlineJob.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java
@@ -30,27 +30,27 @@
import org.w3c.dom.Node;
/**
- * This job holds a queue of updates (affected nodes) for the outline.
- * When a new request comes in, the current run is canceled, the new
+ * This job holds a queue of updates (affected nodes) for a structure viewer.
+ * When a new request comes in, the current run is cancelled, the new
* request is added to the queue, then the job is re-scheduled.
*
* @author pavery
*/
-public class RefreshOutlineJob extends Job {
+class RefreshStructureJob extends Job {
- private static final long UPDATE_DELAY = 200;
- /** List of refresh requests (Nodes)*/
- private final List fRequests;
- /** the tree viewer */
- final StructuredViewer fViewer;
/** debug flag */
private static final boolean DEBUG;
+ private static final long UPDATE_DELAY = 200;
static {
String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/outline"); //$NON-NLS-1$
DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$
}
+ /** List of refresh requests (Nodes)*/
+ private final List fRequests;
+ /** the tree viewer */
+ final StructuredViewer fViewer;
- public RefreshOutlineJob(StructuredViewer viewer) {
+ public RefreshStructureJob(StructuredViewer viewer) {
super(XMLUIMessages.refreshoutline_0); //$NON-NLS-1$
setPriority(Job.LONG);
setSystem(true);
@@ -75,36 +75,10 @@
fRequests.add(node);
}
/**
- * This method also synchronized because it accesses the fRequests queue
- * @return an array of the currently requested Nodes to refresh
- */
- private synchronized Node[] getRequests() {
-
- Node[] toRefresh = (Node[]) fRequests.toArray(new Node[fRequests.size()]);
- fRequests.clear();
- return toRefresh;
- }
-
- /**
- * Invoke a refresh on the viewer on the given node.
- * @param node
- */
- public void refresh(Node node) {
-
- if (node == null)
- return;
-
- cancel();
- addRequest(node);
- schedule(UPDATE_DELAY);
- }
-
- /**
* @return if the root is parent of possible, return true, otherwise
* return false
*/
private boolean contains(Node root, Node possible) {
-
if (DEBUG) {
System.out.println("=============================================================================================================="); //$NON-NLS-1$
System.out.println("recursive call w/ root: " + root.getNodeName() + " and possible: " + possible); //$NON-NLS-1$ //$NON-NLS-2$
@@ -150,22 +124,6 @@
return false;
}
- protected IStatus run(IProgressMonitor monitor) {
- IStatus status = Status.OK_STATUS;
- try {
- Node[] toRefresh = getRequests();
- for (int i = 0; i < toRefresh.length; i++) {
- if (monitor.isCanceled())
- throw new OperationCanceledException();
- doRefresh(toRefresh[i]);
- }
- }
- finally {
- monitor.done();
- }
- return status;
- }
-
/**
* Refresh must be on UI thread because it's on a SWT widget.
* @param node
@@ -189,5 +147,44 @@
}
});
}
+
+ /**
+ * This method also synchronized because it accesses the fRequests queue
+ * @return an array of the currently requested Nodes to refresh
+ */
+ private synchronized Node[] getRequests() {
+ Node[] toRefresh = (Node[]) fRequests.toArray(new Node[fRequests.size()]);
+ fRequests.clear();
+ return toRefresh;
+ }
+
+ /**
+ * Invoke a refresh on the viewer on the given node.
+ * @param node
+ */
+ public void refresh(Node node) {
+ if (node == null)
+ return;
+
+ cancel();
+ addRequest(node);
+ schedule(UPDATE_DELAY);
+ }
+
+ protected IStatus run(IProgressMonitor monitor) {
+ IStatus status = Status.OK_STATUS;
+ try {
+ Node[] toRefresh = getRequests();
+ for (int i = 0; i < toRefresh.length; i++) {
+ if (monitor.isCanceled())
+ throw new OperationCanceledException();
+ doRefresh(toRefresh[i]);
+ }
+ }
+ finally {
+ monitor.done();
+ }
+ return status;
+ }
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/XMLSourceEditingTextTools.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/XMLSourceEditingTextTools.java
index 18a2681..fadc6f5 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/XMLSourceEditingTextTools.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/provisional/XMLSourceEditingTextTools.java
@@ -12,23 +12,15 @@
*******************************************************************************/
package org.eclipse.wst.xml.ui.internal.provisional;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.TextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.ui.internal.StructuredTextEditor;
import org.eclipse.wst.sse.ui.internal.StructuredTextViewer;
-import org.eclipse.wst.sse.ui.internal.ViewerSelectionManager;
import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools;
import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NodeLocation;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
@@ -74,46 +66,14 @@
}
}
- class StructuredTextSelection extends TextSelection implements IStructuredSelection {
- List selectedNodes = null;
-
- public StructuredTextSelection(ITextSelection selection) {
- super(fTextEditor.getDocumentProvider().getDocument(fTextEditor.getEditorInput()), selection.getOffset(), selection.getLength());
- selectedNodes = ((ViewerSelectionManager) fTextEditor.getAdapter(ViewerSelectionManager.class)).getSelectedNodes();
- }
-
- public Object getFirstElement() {
- return selectedNodes.size() > 0 ? selectedNodes.get(0) : null;
- }
-
- public Iterator iterator() {
- return selectedNodes.iterator();
- }
-
- public int size() {
- return selectedNodes.size();
- }
-
- public Object[] toArray() {
- return selectedNodes.toArray();
- }
-
- public List toList() {
- return new ArrayList(selectedNodes);
- }
- }
-
StructuredTextEditor fTextEditor = null;
public int getCaretOffset() {
- ViewerSelectionManager vsm = (ViewerSelectionManager) fTextEditor.getAdapter(ViewerSelectionManager.class);
- if (vsm == null)
- return -1;
StructuredTextViewer stv = fTextEditor.getTextViewer();
- if (stv != null && stv.getControl() != null && !stv.getControl().isDisposed()) {
- return stv.widgetOffset2ModelOffset(vsm.getCaretPosition());
+ if (stv != null && stv.getTextWidget() != null && !stv.getTextWidget().isDisposed()) {
+ return stv.widgetOffset2ModelOffset(stv.getTextWidget().getCaretOffset());
}
- return vsm.getCaretPosition();
+ return 0;
}
public IDocument getDocument() {
@@ -174,12 +134,7 @@
}
public ITextSelection getSelection() {
- ISelection selection = fTextEditor.getSelectionProvider().getSelection();
- if (selection instanceof ITextSelection) {
- ITextSelection structuredTextSelection = new StructuredTextSelection((ITextSelection) selection);
- return structuredTextSelection;
- }
- return TextSelection.emptySelection();
+ return (ITextSelection) fTextEditor.getSelectionProvider().getSelection();
}
/**
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentoutline/XMLContentOutlineConfiguration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentoutline/XMLContentOutlineConfiguration.java
index a9e837e..13fc6af 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentoutline/XMLContentOutlineConfiguration.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/contentoutline/XMLContentOutlineConfiguration.java
@@ -12,9 +12,6 @@
*******************************************************************************/
package org.eclipse.wst.xml.ui.internal.views.contentoutline;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
@@ -23,6 +20,9 @@
import org.eclipse.jface.util.TransferDropTargetListener;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DropTargetEvent;
@@ -30,49 +30,55 @@
import org.eclipse.wst.common.ui.internal.dnd.ObjectTransfer;
import org.eclipse.wst.common.ui.internal.dnd.ViewerDragAdapter;
import org.eclipse.wst.common.ui.internal.dnd.ViewerDropAdapter;
-import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.util.StringUtils;
import org.eclipse.wst.sse.ui.internal.IReleasable;
import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateAction;
import org.eclipse.wst.sse.ui.internal.contentoutline.PropertyChangeUpdateActionContributionItem;
import org.eclipse.wst.sse.ui.internal.editor.EditorPluginImageHelper;
import org.eclipse.wst.sse.ui.internal.editor.EditorPluginImages;
import org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.StructuredContentOutlineConfiguration;
-import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDataType;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
-import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeAdapterFactory;
import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeContentProvider;
import org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeLabelProvider;
import org.eclipse.wst.xml.ui.internal.contentoutline.XMLNodeActionManager;
import org.eclipse.wst.xml.ui.internal.dnd.XMLDragAndDropManager;
import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
+/**
+ * Configuration for XML, expects that the viewer's input will be the DOM
+ * Model
+ */
public class XMLContentOutlineConfiguration extends StructuredContentOutlineConfiguration {
- private IContentProvider fContentProvider = null;
- private ILabelProvider fLabelProvider = null;
- /*
- * Preference key for Show Attributes
- */
- private final String OUTLINE_SHOW_ATTRIBUTE_PREF = "outline-show-attribute-editor"; //$NON-NLS-1$
-
private class ActionManagerMenuListener implements IMenuListener, IReleasable {
private XMLNodeActionManager fActionManager;
private TreeViewer fTreeViewer;
public ActionManagerMenuListener(TreeViewer viewer) {
fTreeViewer = viewer;
- fActionManager = createNodeActionManager(fTreeViewer);
}
public void menuAboutToShow(IMenuManager manager) {
- if (fActionManager != null)
- fActionManager.fillContextMenu(manager, fTreeViewer.getSelection());
+ if (fActionManager == null) {
+ fActionManager = createNodeActionManager(fTreeViewer);
+ }
+ fActionManager.fillContextMenu(manager, fTreeViewer.getSelection());
}
public void release() {
fTreeViewer = null;
- fActionManager.setModel(null);
+ if (fActionManager != null) {
+ fActionManager.setModel(null);
+ }
}
}
@@ -84,7 +90,7 @@
private TreeViewer fTreeViewer;
public ToggleShowAttributeAction(IPreferenceStore store, String preference, TreeViewer treeViewer) {
- super(XMLUIMessages.XMLContentOutlineConfiguration_0, store, preference, false);
+ super(XMLUIMessages.XMLContentOutlineConfiguration_0, store, preference, true);
setToolTipText(getText());
// images needed
// setDisabledImageDescriptor(SYNCED_D);
@@ -96,14 +102,25 @@
public void update() {
super.update();
- updateForShowAttributes(isChecked(), fTreeViewer);
+ updateShowAttributes(isChecked(), fTreeViewer);
}
}
+ private IContentProvider fContentProvider = null;
+
protected ActionManagerMenuListener fContextMenuFiller = null;
+ private ILabelProvider fLabelProvider = null;
+
private TransferDragSourceListener[] fTransferDragSourceListeners;
+
private TransferDropTargetListener[] fTransferDropTargetListeners;
+ /*
+ * Preference key for Show Attributes
+ */
+ private final String OUTLINE_SHOW_ATTRIBUTE_PREF = "outline-show-attribute-editor"; //$NON-NLS-1$
+
+ private boolean fShowAttributes = false;
public XMLContentOutlineConfiguration() {
super();
@@ -127,32 +144,130 @@
}
protected XMLNodeActionManager createNodeActionManager(TreeViewer treeViewer) {
- return new XMLNodeActionManager(getEditor().getModel(), treeViewer);
+ return new XMLNodeActionManager((IStructuredModel) treeViewer.getInput(), treeViewer);
}
public IContentProvider getContentProvider(TreeViewer viewer) {
if (fContentProvider == null) {
- if (getFactory() != null) {
- fContentProvider = new JFaceNodeContentProvider((INodeAdapterFactory) getFactory());
- }
- else {
- fContentProvider = super.getContentProvider(viewer);
- }
+ fContentProvider = new JFaceNodeContentProvider();
}
return fContentProvider;
}
+ private Object getFilteredNode(Object object) {
+ if (object instanceof Node) {
+ Node node = (Node) object;
+
+ // replace attribute node in selection with its parent
+ if (node.getNodeType() == Node.ATTRIBUTE_NODE)
+ node = ((Attr) node).getOwnerElement();
+ // replace TextNode in selection with its parent
+ else if (node.getNodeType() == Node.TEXT_NODE)
+ node = node.getParentNode();
+ return node;
+ }
+ return object;
+ }
+
+ private Object[] getFilteredNodes(Object[] filteredNodes) {
+ for (int i = 0; i < filteredNodes.length; i++) {
+ filteredNodes[i] = getFilteredNode(filteredNodes[i]);
+ }
+ return filteredNodes;
+ }
+
/**
* @see org.eclipse.wst.sse.ui.internal.provisional.views.contentoutline.ContentOutlineConfiguration#getLabelProvider(org.eclipse.jface.viewers.TreeViewer)
*/
public ILabelProvider getLabelProvider(TreeViewer viewer) {
if (fLabelProvider == null) {
- if (getFactory() != null) {
- fLabelProvider = new JFaceNodeLabelProvider((INodeAdapterFactory) getFactory());
- }
- else {
- fLabelProvider = super.getLabelProvider(viewer);
- }
+ fLabelProvider = new JFaceNodeLabelProvider() {
+ public String getText(Object o) {
+ StringBuffer text = new StringBuffer(super.getText(o));
+ if (o instanceof Node) {
+ Node node = (Node) o;
+ if (node.getNodeType() == Node.ELEMENT_NODE && fShowAttributes) {
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88444
+ if (node.hasAttributes()) {
+ Element element = (Element) node;
+ NamedNodeMap attributes = element.getAttributes();
+ Node idTypedAttribute = null;
+ Node requiredAttribute = null;
+ boolean hasId = false;
+ boolean hasName = false;
+ Node shownAttribute = null;
+
+ // try to get content model element
+ // declaration
+ CMElementDeclaration elementDecl = null;
+ ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
+ if (mq != null) {
+ elementDecl = mq.getCMElementDeclaration(element);
+ }
+ // find an attribute of type (or just named)
+ // ID
+ if (elementDecl != null) {
+ int i = 0;
+ while (i < attributes.getLength() && idTypedAttribute == null) {
+ Node attr = attributes.item(i);
+ String attrName = attr.getNodeName();
+ CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) elementDecl.getAttributes().getNamedItem(attrName);
+ if (attrDecl != null) {
+ if ((attrDecl.getAttrType() != null) && (CMDataType.ID.equals(attrDecl.getAttrType().getDataTypeName()))) {
+ idTypedAttribute = attr;
+ }
+ else if (attrDecl.getUsage() == CMAttributeDeclaration.REQUIRED && requiredAttribute == null) {
+ // as a backup, keep tabs on
+ // any required
+ // attributes
+ requiredAttribute = attr;
+ }
+ else {
+ hasId = hasId || attrName.equals("id"); //$NON-NLS-1$
+ hasName = hasName || attrName.equals("name"); //$NON-NLS-1$
+ }
+ }
+ ++i;
+ }
+ }
+
+ /*
+ * If no suitable attribute was found, try
+ * using a required attribute, if none, then
+ * prefer "id" or "name", otherwise just use
+ * first attribute
+ */
+ if (idTypedAttribute != null) {
+ shownAttribute = idTypedAttribute;
+ }
+ else if (requiredAttribute != null) {
+ shownAttribute = requiredAttribute;
+ }
+ else if (hasId) {
+ shownAttribute = attributes.getNamedItem("id"); //$NON-NLS-1$
+ }
+ else if (hasName) {
+ shownAttribute = attributes.getNamedItem("name"); //$NON-NLS-1$
+ }
+ if (shownAttribute == null) {
+ shownAttribute = attributes.item(0);
+ }
+
+ // display the attribute
+ String attributeName = shownAttribute.getNodeName();
+ if (attributeName != null && attributeName.length() > 0) {
+ text.append(" " + attributeName); //$NON-NLS-1$
+ String attributeValue = shownAttribute.getNodeValue();
+ if (attributeValue != null && attributeValue.length() > 0) {
+ text.append("=" + StringUtils.strip(attributeValue)); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ return text.toString();
+ }
+ };
}
return fLabelProvider;
}
@@ -170,32 +285,19 @@
/*
* (non-Javadoc)
*
- * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getNodes(java.util.List)
+ * @see org.eclipse.wst.sse.ui.views.contentoutline.StructuredContentOutlineConfiguration#getPreferenceStore()
*/
- public List getNodes(List nodes) {
- List filteredNodes = new ArrayList(super.getNodes(nodes));
- for (int i = 0; i < filteredNodes.size(); i++) {
- Object selectedNode = filteredNodes.get(i);
- if (selectedNode instanceof Node) {
- Node eachNode = (Node) selectedNode;
- // replace attribute node in selection with its parent
- if (eachNode.getNodeType() == Node.ATTRIBUTE_NODE)
- filteredNodes.set(i, ((Attr) eachNode).getOwnerElement());
- // replace TextNode in selection with its parent
- else if (eachNode.getNodeType() == Node.TEXT_NODE)
- filteredNodes.set(i, eachNode.getParentNode());
- }
- }
- return filteredNodes;
+ protected IPreferenceStore getPreferenceStore() {
+ return XMLUIPlugin.getDefault().getPreferenceStore();
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration#getSelectedNodes(org.eclipse.wst.sse.ui.view.events.NodeSelectionChangedEvent)
- */
- public List getSelectedNodes(NodeSelectionChangedEvent event) {
- return getNodes(super.getSelectedNodes(event));
+ public ISelection getSelection(TreeViewer viewer, ISelection selection) {
+ ISelection filteredSelection = selection;
+ if (selection instanceof IStructuredSelection) {
+ Object[] filteredNodes = getFilteredNodes(((IStructuredSelection) selection).toArray());
+ filteredSelection = new StructuredSelection(filteredNodes);
+ }
+ return filteredSelection;
}
/**
@@ -285,15 +387,6 @@
// XMLDragAndDropManager.addDragAndDropSupport(fTreeViewer);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.wst.sse.ui.views.contentoutline.StructuredContentOutlineConfiguration#getPreferenceStore()
- */
- protected IPreferenceStore getPreferenceStore() {
- return XMLUIPlugin.getDefault().getPreferenceStore();
- }
-
/**
* Updates show attributes flag in JFaceNodeAdapter to indicate whether or
* not to show attributes in outline view. Also refreshes tree view due to
@@ -302,8 +395,8 @@
* @param showAttr
* @param viewer
*/
- void updateForShowAttributes(boolean showAttr, TreeViewer viewer) {
- ((JFaceNodeAdapterFactory) getFactory()).setShowAttribute(showAttr);
+ void updateShowAttributes(boolean showAttr, TreeViewer viewer) {
+ fShowAttributes = showAttr;
// refresh the outline view
viewer.refresh();
}
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/properties/XMLPropertySheetConfiguration.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/properties/XMLPropertySheetConfiguration.java
index a39f27e..3af0b0a 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/properties/XMLPropertySheetConfiguration.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/views/properties/XMLPropertySheetConfiguration.java
@@ -13,76 +13,172 @@
package org.eclipse.wst.xml.ui.internal.views.properties;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
-import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.progress.UIJob;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.IPropertySourceProvider;
+import org.eclipse.ui.views.properties.PropertySheetPage;
import org.eclipse.wst.sse.ui.internal.provisional.views.properties.StructuredPropertySheetConfiguration;
+import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManagerListener;
+import org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery;
+import org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache;
+import org.eclipse.wst.xml.core.internal.modelquery.ModelQueryUtil;
+import org.eclipse.wst.xml.ui.internal.XMLUIMessages;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
-
public class XMLPropertySheetConfiguration extends StructuredPropertySheetConfiguration {
+ public class CMDocumentManagerListenerImpl implements CMDocumentManagerListener {
+ public void cacheCleared(CMDocumentCache cache) {
+ // nothing to do
+ }
- /**
- *
- */
- public XMLPropertySheetConfiguration() {
- super();
+ public void cacheUpdated(CMDocumentCache cache, final String uri, int oldStatus, int newStatus, CMDocument cmDocument) {
+ if (newStatus == CMDocumentCache.STATUS_LOADED || newStatus == CMDocumentCache.STATUS_ERROR) {
+ refreshPages();
+ }
+ }
+
+ public void propertyChanged(CMDocumentManager cmDocumentManager, String propertyName) {
+ if (cmDocumentManager.getPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD)) {
+ refreshPages();
+ }
+ }
+
+ private void refreshPages() {
+ PropertySheetPage[] pages = getPages();
+ for (int i = 0; i < pages.length; i++) {
+ getPropertiesRefreshJob().addPropertySheetPage(pages[i]);
+ getPropertiesRefreshJob().schedule(PropertiesRefreshJob.UPDATE_DELAY);
+ }
+ }
}
- /**
- * @see org.eclipse.wst.sse.ui.internal.provisional.views.properties.PropertySheetConfiguration#getSelection(org.eclipse.ui.IWorkbenchPart,
- * org.eclipse.jface.viewers.ISelection)
- */
+ private class PropertiesRefreshJob extends UIJob {
+ public static final int UPDATE_DELAY = 200;
+
+ private List propertySheetPages = null;
+
+ public PropertiesRefreshJob() {
+ super(XMLUIMessages.JFaceNodeAdapter_1);
+ setSystem(true);
+ setPriority(Job.SHORT);
+ propertySheetPages = new ArrayList(1);
+ }
+
+ void addPropertySheetPage(PropertySheetPage page) {
+ propertySheetPages.add(page);
+ }
+
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ List pages = propertySheetPages;
+ propertySheetPages = new ArrayList(1);
+
+ for (int i = 0; i < propertySheetPages.size(); i++) {
+ PropertySheetPage page = (PropertySheetPage) propertySheetPages.get(i);
+ if (page.getControl() != null && !page.getControl().isDisposed()) {
+ page.refresh();
+ }
+ }
+
+ return Status.OK_STATUS;
+ }
+ }
+
+ private CMDocumentManagerListenerImpl fCMDocumentManagerListener = null;
+ private PropertiesRefreshJob fPropertiesRefreshJob = null;
+ private Set fPropertySheetPages = null;
+ private CMDocumentManager[] fSelectedCMDocumentManagers;
+
+ public XMLPropertySheetConfiguration() {
+ super();
+ fPropertySheetPages = new HashSet(2);
+ fSelectedCMDocumentManagers = new CMDocumentManager[0];
+ // register for CMDocumentManager events
+ fCMDocumentManagerListener = new CMDocumentManagerListenerImpl();
+ }
+
+ protected IPropertySourceProvider createPropertySourceProvider(IPropertySheetPage page) {
+ fPropertySheetPages.add(page);
+ return super.createPropertySourceProvider(page);
+ }
+
+ public PropertySheetPage[] getPages() {
+ PropertySheetPage[] pages = (PropertySheetPage[]) fPropertySheetPages.toArray(new PropertySheetPage[fPropertySheetPages.size()]);
+ return pages;
+ }
+
+ public PropertiesRefreshJob getPropertiesRefreshJob() {
+ if (fPropertiesRefreshJob != null) {
+ fPropertiesRefreshJob = new PropertiesRefreshJob();
+ }
+ return fPropertiesRefreshJob;
+ }
+
public ISelection getSelection(IWorkbenchPart selectingPart, ISelection selection) {
// On Attr nodes, select the owner Element. On Text nodes, select the
// parent Element.
ISelection preferredSelection = selection;
- if (selection instanceof ITextSelection) {
- // on text selection, find the appropriate Node
- ITextSelection textSel = (ITextSelection) selection;
- if (getModel() != null) {
- Object inode = getModel().getIndexedRegion(textSel.getOffset());
+ if (selection instanceof IStructuredSelection) {
+ for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) {
+ fSelectedCMDocumentManagers[i].removeListener(fCMDocumentManagerListener);
+ }
+ Set managers = new HashSet(1);
+
+ IStructuredSelection structuredSel = (IStructuredSelection) selection;
+
+ List inputList = new ArrayList(structuredSel.toList());
+ for (int i = 0; i < inputList.size(); i++) {
+ Object inode = inputList.get(i);
if (inode instanceof Node) {
- Node node = (Node) inode;
+ Node node = (Node) inputList.get(i);
// replace Attribute Node with its owner
- if (node.getNodeType() == Node.ATTRIBUTE_NODE)
- inode = ((Attr) node).getOwnerElement();
+ if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
+ inputList.set(i, ((Attr) node).getOwnerElement());
+ ModelQuery q = ModelQueryUtil.getModelQuery(((Attr) node).getOwnerElement().getOwnerDocument());
+ if (q != null) {
+ managers.add(q.getCMDocumentManager());
+ }
+ }
// replace Text Node with its parent
else if ((node.getNodeType() == Node.TEXT_NODE || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && node.getParentNode() != null) {
- inode = node.getParentNode();
- }
- }
- if (inode != null) {
- List inputList = new ArrayList(1);
- inputList.add(inode);
- preferredSelection = new StructuredSelection(inputList);
- }
- }
- } else if (selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSel = (IStructuredSelection) selection;
- if (getModel() != null) {
- List inputList = new ArrayList(structuredSel.toList());
- for (int i = 0; i < inputList.size(); i++) {
- Object inode = inputList.get(i);
- if (inode instanceof Node) {
- Node node = (Node) inputList.get(i);
- // replace Attribute Node with its owner
- if (node.getNodeType() == Node.ATTRIBUTE_NODE)
- inputList.set(i, ((Attr) node).getOwnerElement());
- // replace Text Node with its parent
- else if ((node.getNodeType() == Node.TEXT_NODE || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && node.getParentNode() != null) {
- inputList.set(i, node.getParentNode());
+ inputList.set(i, node.getParentNode());
+ ModelQuery query = ModelQueryUtil.getModelQuery(node.getParentNode().getOwnerDocument());
+ if (query != null) {
+ managers.add(query.getCMDocumentManager());
}
}
}
- preferredSelection = new StructuredSelection(inputList);
}
+
+ fSelectedCMDocumentManagers = (CMDocumentManager[]) managers.toArray(new CMDocumentManager[managers.size()]);
+ for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) {
+ fSelectedCMDocumentManagers[i].addListener(fCMDocumentManagerListener);
+ }
+
+ preferredSelection = new StructuredSelection(inputList);
}
return preferredSelection;
}
+
+ public void unconfigure() {
+ super.unconfigure();
+ for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) {
+ fSelectedCMDocumentManagers[i].removeListener(fCMDocumentManagerListener);
+ }
+ fPropertySheetPages.clear();
+ }
}