diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline')
6 files changed, 0 insertions, 890 deletions
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 deleted file mode 100644 index 02e4c46980..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapter.java +++ /dev/null @@ -1,246 +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 java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -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.wst.sse.core.internal.provisional.INodeNotifier; -import org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter; -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.Node; - -/** - * Adapts a DOM node to a JFace viewer. - */ -public class JFaceNodeAdapter implements IJFaceNodeAdapter { - - final static Class ADAPTER_KEY = IJFaceNodeAdapter.class; - - /** - * debug .option - */ - private static final boolean DEBUG = getDebugValue(); - - private static boolean getDebugValue() { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/outline"); //$NON-NLS-1$ - boolean result = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - return result; - } - - JFaceNodeAdapterFactory fAdapterFactory; - private RefreshStructureJob fRefreshJob = null; - - public JFaceNodeAdapter(JFaceNodeAdapterFactory adapterFactory) { - super(); - this.fAdapterFactory = adapterFactory; - } - - protected Image createImage(Object object) { - Image image = null; - Node node = (Node) object; - switch (node.getNodeType()) { - case Node.ELEMENT_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT); - break; - } - case Node.ATTRIBUTE_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); - break; - } - case Node.TEXT_NODE : { // actually, TEXT should never be seen in - // the tree - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT); - break; - } - case Node.CDATA_SECTION_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_CDATASECTION); - break; - } - case Node.ENTITY_REFERENCE_NODE : - case Node.ENTITY_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ENTITY); - break; - } - case Node.PROCESSING_INSTRUCTION_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION); - break; - } - case Node.COMMENT_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_COMMENT); - break; - } - case Node.DOCUMENT_TYPE_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_DOCTYPE); - break; - } - case Node.NOTATION_NODE : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_NOTATION); - break; - } - default : { - image = createXMLImageDescriptor(XMLEditorPluginImages.IMG_OBJ_ELEMENT); - break; - } - } - return image; - } - - protected Image createXMLImageDescriptor(String imageResourceName) { - return XMLEditorPluginImageHelper.getInstance().getImage(imageResourceName); - } - - public Object[] getChildren(Object object) { - - // (pa) 20021217 - // cmvc defect 235554 - // performance enhancement: using child.getNextSibling() rather than - // nodeList(item) for O(n) vs. O(n*n) - // - Node node = (Node) object; - ArrayList v = new ArrayList(); - for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { - Node n = child; - if (n.getNodeType() != Node.TEXT_NODE) - v.add(n); - } - return v.toArray(); - } - - /** - * 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); - } - - /** - * 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(); - String nodeName = getNodeName(node); - image = imageRegistry.get(nodeName); - if (image == null) { - image = createImage(node); - if (image != null) - imageRegistry.put(nodeName, image); - } - } - return image; - } - - /** - * Fetches the label text specific to this object instance. - */ - public String getLabelText(Object node) { - return getNodeName(node); - } - - private String getNodeName(Object object) { - StringBuffer nodeName = new StringBuffer(); - Node node = (Node) object; - nodeName.append(node.getNodeName()); - - if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - nodeName.insert(0, "DOCTYPE:"); //$NON-NLS-1$ - } - return nodeName.toString(); - } - - - public Object getParent(Object object) { - Node node = (Node) object; - return node.getParentNode(); - } - - private synchronized RefreshStructureJob getRefreshJob() { - if (fRefreshJob == null) - fRefreshJob = new RefreshStructureJob(); - return fRefreshJob; - } - - - public boolean hasChildren(Object object) { - // (pa) 20021217 - // cmvc defect 235554 > use child.getNextSibling() instead of - // nodeList(item) for O(n) vs. O(n*n) - Node node = (Node) object; - for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { - if (child.getNodeType() != Node.TEXT_NODE) - return true; - } - return false; - } - - /** - * Allowing the INodeAdapter to compare itself against the type allows it - * to return true in more than one case. - */ - public boolean isAdapterForType(Object type) { - if (type == null) { - return false; - } - return type.equals(ADAPTER_KEY); - } - - /** - * Called by the object being adapter (the notifier) when something has - * 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 - // a bit overkill and not that useful. - // (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. - if (notifier instanceof Node) { - Collection listeners = fAdapterFactory.getListeners(); - Iterator iterator = listeners.iterator(); - - while (iterator.hasNext()) { - Object listener = iterator.next(); - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90637 - // if (notifier instanceof Node && (listener instanceof - // StructuredViewer) && (eventType == - // INodeNotifier.STRUCTURE_CHANGED || (eventType == - // INodeNotifier.CHANGE && changedFeature == null))) { - if ((listener instanceof StructuredViewer) && (eventType == INodeNotifier.STRUCTURE_CHANGED || eventType == INodeNotifier.CONTENT_CHANGED || (eventType == INodeNotifier.CHANGE))) { - if (DEBUG) { - System.out.println("JFaceNodeAdapter notified on event type > " + eventType); //$NON-NLS-1$ - } - - // refresh on structural and "unknown" changes - StructuredViewer structuredViewer = (StructuredViewer) listener; - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=5230 - if (structuredViewer.getControl() != null) { - getRefreshJob().refresh(structuredViewer, (Node) notifier); - } - } - } - } - } -} 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 deleted file mode 100644 index 8ee8b42571..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeAdapterFactory.java +++ /dev/null @@ -1,173 +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 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.swt.widgets.Control; -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; - - -/** - * An adapter factory to create JFaceNodeAdapters. Use this adapter factory - * 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) { - Control refreshControl = viewer.getControl(); - if (refreshControl != null && !refreshControl.isDisposed()) { - 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) { - Control refreshControl = viewer.getControl(); - if (refreshControl != null && !refreshControl.isDisposed()) { - viewer.refresh(); - } - return Status.OK_STATUS; - } - }; - refresh.setSystem(true); - refresh.setPriority(Job.SHORT); - refresh.schedule(UPDATE_DELAY); - } - } - } - } - - private CMDocumentManager cmDocumentManager; - private CMDocumentManagerListenerImpl fCMDocumentManagerListener = null; - /** - * This keeps track of all the listeners. - */ - private Set fListeners = new HashSet(); - - protected INodeAdapter singletonAdapter; - - public JFaceNodeAdapterFactory() { - this(IJFaceNodeAdapter.class, true); - } - - public JFaceNodeAdapterFactory(Object adapterKey, boolean registerAdapters) { - super(adapterKey, registerAdapters); - } - - public synchronized void addListener(Object listener) { - fListeners.add(listener); - } - - public INodeAdapterFactory copy() { - return new JFaceNodeAdapterFactory(getAdapterKey(), isShouldRegisterAdapter()); - } - - /** - * Create a new JFace adapter for the DOM node passed in - */ - protected INodeAdapter createAdapter(INodeNotifier node) { - if (singletonAdapter == null) { - // create the JFaceNodeAdapter - singletonAdapter = new JFaceNodeAdapter(this); - initAdapter(singletonAdapter, node); - } - return singletonAdapter; - } - - - /** - * returns "copy" so no one can modify our list. It is a shallow copy. - */ - public synchronized Collection getListeners() { - return new ArrayList(fListeners); - } - - protected void initAdapter(INodeAdapter adapter, INodeNotifier node) { - // register for CMDocumentManager events - 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 && fCMDocumentManagerListener != null) { - cmDocumentManager.removeListener(fCMDocumentManagerListener); - } - fListeners.clear(); - } - - public synchronized void removeListener(Object listener) { - fListeners.remove(listener); - } -} 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 deleted file mode 100644 index 7327b15702..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeContentProvider.java +++ /dev/null @@ -1,114 +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.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.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; - - -/** - * An ITreeContentProvider for a TreeViewers used to display DOM nodes. This - * content provider takes an adapter factory to create JFace adapters for the - * nodes in the tree. - */ -public class JFaceNodeContentProvider implements ITreeContentProvider { - - public JFaceNodeContentProvider() { - super(); - } - - /** - * The visual part that is using this content provider is about to be - * disposed. Deallocate all allocated SWT resources. - */ - public void dispose() { - } - - /** - * Returns the JFace adapter for the specified object. - * - * @param adaptable - * java.lang.Object The object to get the adapter for - */ - protected IJFaceNodeAdapter getAdapter(Object adaptable) { - if (adaptable instanceof INodeNotifier) { - INodeAdapter adapter = ((INodeNotifier) adaptable).getAdapterFor(IJFaceNodeAdapter.class); - if (adapter instanceof IJFaceNodeAdapter) - return (IJFaceNodeAdapter) adapter; - } - return null; - } - - public Object[] getChildren(Object object) { - IJFaceNodeAdapter adapter = getAdapter(object); - - if (adapter != null) - return adapter.getChildren(object); - - return new Object[0]; - } - - public Object[] getElements(Object object) { - // The root is usually an instance of an XMLStructuredModel in - // which case we want to extract the document. - Object topNode = object; - if (object instanceof IDOMModel) - topNode = ((IDOMModel) object).getDocument(); - - IJFaceNodeAdapter adapter = getAdapter(topNode); - - if (adapter != null) - return adapter.getElements(topNode); - - return new Object[0]; - } - - public Object getParent(Object object) { - IJFaceNodeAdapter adapter = getAdapter(object); - - if (adapter != null) - return adapter.getParent(object); - - return null; - } - - public boolean hasChildren(Object object) { - IJFaceNodeAdapter adapter = getAdapter(object); - - if (adapter != null) - return adapter.hasChildren(object); - - return false; - } - - 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 deleted file mode 100644 index 7472df90fe..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/JFaceNodeLabelProvider.java +++ /dev/null @@ -1,74 +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.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -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 label provider backed by JFaceNodeAdapters. - */ -public class JFaceNodeLabelProvider extends LabelProvider { - /** - * JFaceNodeLabelProvider constructor comment. - */ - public JFaceNodeLabelProvider() { - super(); - } - - /** - * Returns the JFace adapter for the specified object. - * - * @param adaptable - * java.lang.Object The object to get the adapter for - */ - protected IJFaceNodeAdapter getAdapter(Object adaptable) { - if (adaptable instanceof INodeNotifier) { - INodeAdapter adapter = ((INodeNotifier) adaptable).getAdapterFor(IJFaceNodeAdapter.class); - if (adapter instanceof IJFaceNodeAdapter) - return (IJFaceNodeAdapter) adapter; - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) - */ - public Image getImage(Object element) { - return getAdapter(element).getLabelImage(element); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) - */ - public String getText(Object element) { - return getAdapter(element).getLabelText(element); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, - * java.lang.String) - */ - public boolean isLabelProperty(Object element, String property) { - return false; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java deleted file mode 100644 index 2fb90bb8b2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/RefreshStructureJob.java +++ /dev/null @@ -1,231 +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 java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.xml.ui.internal.XMLUIMessages; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * This job holds a queue of updates (affected nodes) for multiple structured - * viewers. 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. Support for - * multiple structured viewers is required because refresh updates are usually - * triggered by model changes, and the model may be visible in more than one - * viewer. - * - * @author pavery - */ -class RefreshStructureJob extends Job { - - /** debug flag */ - static final boolean DEBUG; - private static final long UPDATE_DELAY = 250; - static { - String value = Platform.getDebugOption("org.eclipse.wst.sse.ui/debug/refreshStructure"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - /** List of refresh requests (Nodes) */ - private final List fRequests; - /** the structured viewers */ - List fViewers = new ArrayList(3); - - public RefreshStructureJob() { - super(XMLUIMessages.refreshoutline_0); //$NON-NLS-1$ - setPriority(Job.LONG); - setSystem(true); - fRequests = new ArrayList(2); - } - - private synchronized void addRequest(Node node) { - int size = fRequests.size(); - if (size > 0) { - for (int i = 0; i < size; i++) { - /* - * If we already have a request which contains the new - * request, discard the new request - */ - Node node2 = (Node) fRequests.get(i); - if (contains(node2, node)) - return; - /* - * If new request contains any existing requests, replace it - * with new request - */ - if (contains(node, node2)) { - fRequests.set(i, node); - return; - } - /** - * None of the above, have a separate refresh subtree, then. - */ - fRequests.add(node); - - } - } - else { - fRequests.add(node); - } - } - - private synchronized void addViewer(StructuredViewer viewer) { - if (!fViewers.contains(viewer)) { - fViewers.add(viewer); - } - } - - /** - * @param root - * @param possible - * @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$ - System.out.println("--------------------------------------------------------------------------------------------------------------"); //$NON-NLS-1$ - } - - // the following checks are important - // #document node will break the algorithm otherwise - - // can't contain the child if it's null - if (root == null) { - if (DEBUG) - System.out.println("returning false: root is null"); //$NON-NLS-1$ - return false; - } - // nothing can be parent of Document node - if (possible instanceof Document) { - if (DEBUG) - System.out.println("returning false: possible is Document node"); //$NON-NLS-1$ - return false; - } - // document contains everything - if (root instanceof Document) { - if (DEBUG) - System.out.println("returning true: root is Document node"); //$NON-NLS-1$ - return true; - } - - // check parentage - Node current = possible; - // loop parents - while (current != null && current.getNodeType() != Node.DOCUMENT_NODE) { - // found it - if (root.equals(current)) { - if (DEBUG) - System.out.println(" !!! found: " + possible.getNodeName() + " in subelement of: " + root.getNodeName()); //$NON-NLS-1$ //$NON-NLS-2$ - return true; - } - current = current.getParentNode(); - } - // never found it - return false; - } - - /** - * Refresh must be on UI thread because it's on a SWT widget. - * - * @param node - */ - private void doRefresh(final Node node, final StructuredViewer[] viewers) { - final Display display = PlatformUI.getWorkbench().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - if (DEBUG) - System.out.println("refresh on: [" + node.getNodeName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ - - for (int i = 0; i < viewers.length; i++) { - if (!viewers[i].getControl().isDisposed()) { - if (node.getNodeType() == Node.DOCUMENT_NODE) { - viewers[i].refresh(true); - } - else { - viewers[i].refresh(node, true); - } - } - else { - if (DEBUG) - System.out.println(" !!! skipped refreshing disposed viewer: " + viewers[i]); //$NON-NLS-1$ - } - } - } - }); - } - - /** - * This method also synchronized because it accesses the fRequests queue - * and fViewers list - * - * @return an array containing and array of the currently requested Nodes - * to refresh and the viewers in which to refresh them - */ - private synchronized Object[] getRequests() { - Node[] toRefresh = (Node[]) fRequests.toArray(new Node[fRequests.size()]); - fRequests.clear(); - - StructuredViewer[] viewers = (StructuredViewer[]) fViewers.toArray(new StructuredViewer[fViewers.size()]); - fViewers.clear(); - - return new Object[]{toRefresh, viewers}; - } - - /** - * Invoke a refresh on the viewer on the given node. - * - * @param node - */ - public void refresh(StructuredViewer viewer, Node node) { - if (node == null) - return; - - addViewer(viewer); - addRequest(node); - schedule(UPDATE_DELAY); - } - - protected IStatus run(IProgressMonitor monitor) { - IStatus status = Status.OK_STATUS; - try { - // Retrieve BOTH viewers and Nodes on one block - Object[] requests = getRequests(); - Node[] nodes = (Node[]) requests[0]; - StructuredViewer[] viewers = (StructuredViewer[]) requests[1]; - - for (int i = 0; i < nodes.length; i++) { - if (monitor.isCanceled()) - throw new OperationCanceledException(); - doRefresh(nodes[i], viewers); - } - } - finally { - monitor.done(); - } - return status; - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLNodeActionManager.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLNodeActionManager.java deleted file mode 100644 index 4b3b00f5ae..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/contentoutline/XMLNodeActionManager.java +++ /dev/null @@ -1,52 +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.jface.viewers.Viewer; -import org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -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.format.FormatProcessorXML; -import org.eclipse.wst.xml.ui.internal.actions.AbstractNodeActionManager; -import org.w3c.dom.Node; - - -public class XMLNodeActionManager extends AbstractNodeActionManager { - public XMLNodeActionManager(IStructuredModel model, Viewer viewer) { - super(model, ModelQueryUtil.getModelQuery(model), viewer); - } - - public void reformat(Node newElement, boolean deep) { - try { - // tell the model that we are about to make a big model change - fModel.aboutToChangeModel(); - - // format selected node - IStructuredFormatProcessor formatProcessor = new FormatProcessorXML(); - formatProcessor.formatNode(newElement); - } finally { - // tell the model that we are done with the big model change - fModel.changedModel(); - } - } - - public void setModel(IStructuredModel newModel) { - fModel = newModel; - setModelQuery(ModelQueryUtil.getModelQuery(newModel)); - } - - protected void setModelQuery(ModelQuery newModelQuery) { - modelQuery = newModelQuery; - } -} |