Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 28810 Details for
Bug 112884
Get rid of XSDTextEditor (no subclassing of StructuredTextEditor allowed)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
org.eclipse.wst.xsd.ui.patch
org.eclipse.wst.xsd.ui.patch (text/plain), 127.55 KB, created by
Amy Wu
on 2005-10-26 13:59:47 EDT
(
hide
)
Description:
org.eclipse.wst.xsd.ui.patch
Filename:
MIME Type:
Creator:
Amy Wu
Created:
2005-10-26 13:59:47 EDT
Size:
127.55 KB
patch
obsolete
>Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/plugin.xml,v >retrieving revision 1.27 >diff -u -r1.27 plugin.xml >--- plugin.xml 7 Oct 2005 21:17:31 -0000 1.27 >+++ plugin.xml 26 Oct 2005 17:56:00 -0000 >@@ -90,6 +90,12 @@ > type="preferencepages" > value="org.eclipse.wst.xsd.ui.internal.preferences.XSDPreferencePage" > target="org.eclipse.wst.xsd.ui.internal.XSDEditor.source" /> >+ <sourceViewerConfiguration >+ class="org.eclipse.wst.xsd.ui.internal.StructuredTextViewerConfigurationXSD" >+ target="org.eclipse.wst.xsd.core.xsdsource" /> >+ <contentOutlineConfiguration >+ class="org.eclipse.wst.xsd.ui.internal.XSDContentOutlineConfiguration" >+ target="org.eclipse.wst.xsd.core.xsdsource" /> > </extension> > > <!-- ==================================================== --> >Index: src/org/eclipse/wst/xsd/ui/internal/XSDActionBarContributor.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/XSDActionBarContributor.java,v >retrieving revision 1.9 >diff -u -r1.9 XSDActionBarContributor.java >--- src/org/eclipse/wst/xsd/ui/internal/XSDActionBarContributor.java 3 Oct 2005 22:42:34 -0000 1.9 >+++ src/org/eclipse/wst/xsd/ui/internal/XSDActionBarContributor.java 26 Oct 2005 17:56:00 -0000 >@@ -201,7 +201,7 @@ > xsdEditor = (XSDEditor) targetEditor; > reloadDependenciesAction.setEditor((XSDEditor)targetEditor); > >- textEditor = ((XSDEditor)targetEditor).getXSDTextEditor(); >+ textEditor = ((XSDEditor)targetEditor).getTextEditor(); > if (textEditor != null) > { > >Index: src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlinePage.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlinePage.java,v >retrieving revision 1.4 >diff -u -r1.4 XSDContentOutlinePage.java >--- src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlinePage.java 3 Oct 2005 22:42:34 -0000 1.4 >+++ src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlinePage.java 26 Oct 2005 17:56:00 -0000 >@@ -10,11 +10,15 @@ > *******************************************************************************/ > package org.eclipse.wst.xsd.ui.internal; > >+import org.eclipse.core.runtime.Platform; > import org.eclipse.jface.action.Action; > import org.eclipse.jface.action.IMenuManager; > import org.eclipse.jface.action.MenuManager; > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.util.ListenerList; >+import org.eclipse.jface.util.SafeRunnable; > import org.eclipse.jface.viewers.ILabelProvider; >+import org.eclipse.jface.viewers.IPostSelectionProvider; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.ISelectionChangedListener; > import org.eclipse.jface.viewers.IStructuredSelection; >@@ -34,6 +38,9 @@ > import org.eclipse.swt.widgets.Tree; > import org.eclipse.swt.widgets.TreeItem; > import org.eclipse.ui.IActionBars; >+import org.eclipse.ui.ISelectionListener; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.part.IPageSite; > import org.eclipse.ui.views.contentoutline.ContentOutlinePage; > import org.eclipse.wst.xsd.ui.internal.actions.OpenSchemaAction; > import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter; >@@ -42,7 +49,11 @@ > import org.eclipse.xsd.XSDSchemaDirective; > import org.w3c.dom.Element; > >-public class XSDContentOutlinePage extends ContentOutlinePage >+/** >+ * @deprecated Using SSE's ConfiguratbleContentOutlinePage >+ * instead via XSDContentOutlineCOnfiguration >+ */ >+public class XSDContentOutlinePage extends ContentOutlinePage implements ISelectionListener > { > protected XSDEditor xsdEditor; > protected int level = 0; >@@ -52,18 +63,33 @@ > protected XSDSelectionManager selectionManager; > protected SelectionManagerSelectionChangeListener selectionManagerSelectionChangeListener = new SelectionManagerSelectionChangeListener(); > protected TreeSelectionChangeListener treeSelectionChangeListener = new TreeSelectionChangeListener(); >- XSDTextEditor xsdTextEditor; >+ XSDEditor xsdTextEditor; > XSDMenuListener menuListener; >- >+ SelectionProvider fSelectionProvider = null; >+ > /** > * > */ >- public XSDContentOutlinePage(XSDTextEditor xsdTextEditor) >+ public XSDContentOutlinePage(XSDEditor xsdTextEditor) > { > super(); > this.xsdTextEditor = xsdTextEditor; >+ fSelectionProvider = new SelectionProvider(); > } > >+ public void init(IPageSite pageSite) >+ { >+ super.init(pageSite); >+ getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this); >+ getSite().setSelectionProvider(fSelectionProvider); >+ } >+ >+ public void dispose() >+ { >+ super.dispose(); >+ getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(this); >+ } >+ > public void setModel(Object newModel) > { > model = newModel; >@@ -91,19 +117,19 @@ > getTreeViewer().setContentProvider(contentProvider); > getTreeViewer().setLabelProvider(labelProvider); > getTreeViewer().setInput(model); >- getTreeViewer().addSelectionChangedListener(this); >+// getTreeViewer().addSelectionChangedListener(this); > MenuManager menuManager = new MenuManager("#popup");//$NON-NLS-1$ > menuManager.setRemoveAllWhenShown(true); > Menu menu = menuManager.createContextMenu(getTreeViewer().getControl()); > getTreeViewer().getControl().setMenu(menu); >- menuListener = new XSDMenuListener(xsdTextEditor.getXSDEditor().getSelectionManager()); >+ menuListener = new XSDMenuListener(xsdTextEditor.getSelectionManager()); > // menuListener.setSelectionProvider(getTreeViewer()); > menuManager.addMenuListener(menuListener); > > // enable popupMenus extension >- getSite().registerContextMenu("org.eclipse.wst.xsd.ui.popup.outline", menuManager, xsdTextEditor.getXSDEditor().getSelectionManager()); >- >- setSelectionManager(xsdTextEditor.getXSDEditor().getSelectionManager()); >+ getSite().registerContextMenu("org.eclipse.wst.xsd.ui.popup.outline", menuManager, xsdTextEditor.getSelectionManager()); >+ >+ setSelectionManager(xsdTextEditor.getSelectionManager()); > // cs... why are we doing this from the outline view? > // > //xsdTextEditor.getXSDEditor().getSelectionManager().setSelection(new >@@ -125,13 +151,18 @@ > XSDConcreteComponent comp = (XSDConcreteComponent)obj; > if (comp.getContainer() instanceof XSDSchema) > { >- xsdTextEditor.getXSDEditor().getGraphViewer().setInput(obj); >+ xsdTextEditor.getGraphViewer().setInput(obj); > } > } > } > > } > }); >+ >+ >+ getTreeViewer().addPostSelectionChangedListener(fSelectionProvider.getPostSelectionChangedListener()); >+ getTreeViewer().addSelectionChangedListener(fSelectionProvider.getSelectionChangedListener()); >+ > } > class XSDKeyListener extends KeyAdapter > { >@@ -186,12 +217,67 @@ > getTreeViewer().expandToLevel(level); > } > >- // public ISelection getSelection() >- // { >- // if (getTreeViewer() == null) >- // return StructuredSelection.EMPTY; >- // return getTreeViewer().getSelection(); >- // } >+ public void selectionChanged(IWorkbenchPart part, ISelection selection) >+ { >+ if (selectionManager != null) >+ { >+ if (selection instanceof IStructuredSelection) >+ { >+ IStructuredSelection structuredSelection = (IStructuredSelection) selection; >+ Object o = structuredSelection.getFirstElement(); >+ // TODO ... >+ // we need to implement a selectionManagerMapping extension point >+ // so that extensions can specify how they'd like to map view objects >+ // to selection objects >+ // >+ if (o instanceof Element) >+ { >+ try >+ { >+ Object modelObject = xsdTextEditor.getXSDSchema().getCorrespondingComponent((Element) o); >+ if (modelObject != null) >+ { >+ o = modelObject; >+ } >+ } >+ catch (Exception e) >+ { >+ } >+ } >+ else if (o instanceof CategoryAdapter) >+ { >+ // todo... we need to ensure we eliminate the propagation >+ // of 'view' specific objects into the SelectionManager. >+ // We need to do some work to ensure all views utilize the 'Category' model object >+ // so we can get rid of this CategoryAdapter class. >+// CategoryAdapter adapter = (CategoryAdapter) o; >+// o = adapter.getXSDSchema(); >+ } >+ if (o != null) >+ { >+ if (getControl() != null && !getControl().isDisposed() && !getControl().isFocusControl() && getControl().isVisible()) { >+ /* >+ * 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. >+ */ >+ getTreeViewer().setSelection(new StructuredSelection(o), true); >+ } >+ selectionManager.setSelection(new StructuredSelection(o), getTreeViewer()); >+// selectionManager.selectionChanged(new SelectionChangedEvent(getTreeViewer(),new StructuredSelection(o))); >+ } >+ else >+ { >+ // selectionManager.setSelection(new StructuredSelection(), >+ // getTreeViewer()); >+ } >+ } >+ } >+ } >+ > public void setSelectionManager(XSDSelectionManager newSelectionManager) > { > TreeViewer treeViewer = getTreeViewer(); >@@ -209,6 +295,7 @@ > treeViewer.addSelectionChangedListener(treeSelectionChangeListener); > } > } >+ > class SelectionManagerSelectionChangeListener implements ISelectionChangedListener > { > public void selectionChanged(SelectionChangedEvent event) >@@ -263,11 +350,6 @@ > selectionManager.setSelection(new StructuredSelection(o), getTreeViewer()); > // selectionManager.selectionChanged(new SelectionChangedEvent(getTreeViewer(),new StructuredSelection(o))); > } >- else >- { >- // selectionManager.setSelection(new StructuredSelection(), >- // getTreeViewer()); >- } > } > } > } >@@ -378,4 +460,102 @@ > return true; > } > } >+ >+ /** >+ * Forwards post-selection from the tree viewer to the listeners while >+ * acting as this page's selection provider. >+ */ >+ private class SelectionProvider implements IPostSelectionProvider { >+ private class PostSelectionChangedListener implements ISelectionChangedListener { >+ public void selectionChanged(SelectionChangedEvent event) { >+ if (!isFiringSelection()) { >+ fireSelectionChanged(event, postListeners); >+ } >+ } >+ } >+ >+ private class SelectionChangedListener implements ISelectionChangedListener { >+ public void selectionChanged(SelectionChangedEvent event) { >+ if (!isFiringSelection()) { >+ fireSelectionChanged(event, listeners); >+ } >+ } >+ } >+ >+ private boolean isFiringSelection = false; >+ private ListenerList listeners = new ListenerList(); >+ private ListenerList postListeners = new ListenerList(); >+ private ISelectionChangedListener postSelectionChangedListener = new PostSelectionChangedListener(); >+ private ISelectionChangedListener selectionChangedListener = new SelectionChangedListener(); >+ >+ public void addPostSelectionChangedListener(ISelectionChangedListener listener) { >+ postListeners.add(listener); >+ } >+ >+ public void addSelectionChangedListener(ISelectionChangedListener listener) { >+ listeners.add(listener); >+ } >+ >+ public void fireSelectionChanged(final SelectionChangedEvent event, ListenerList listenerList) { >+ isFiringSelection = true; >+ 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); >+ } >+ }); >+ } >+ isFiringSelection = false; >+ } >+ >+ public void fireSelectionChanged(final SelectionChangedEvent event) { >+ isFiringSelection = true; >+ Object[] listeners = postListeners.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); >+ } >+ }); >+ } >+ isFiringSelection = false; >+ } >+ >+ public ISelectionChangedListener getPostSelectionChangedListener() { >+ return postSelectionChangedListener; >+ } >+ >+ public ISelection getSelection() { >+ if (getTreeViewer() != null) { >+ return getTreeViewer().getSelection(); >+ } >+ return StructuredSelection.EMPTY; >+ } >+ >+ public ISelectionChangedListener getSelectionChangedListener() { >+ return selectionChangedListener; >+ } >+ >+ public boolean isFiringSelection() { >+ return isFiringSelection; >+ } >+ >+ public void removePostSelectionChangedListener(ISelectionChangedListener listener) { >+ postListeners.remove(listener); >+ } >+ >+ public void removeSelectionChangedListener(ISelectionChangedListener listener) { >+ listeners.remove(listener); >+ }; >+ >+ public void setSelection(ISelection selection) { >+ if (isFiringSelection) { >+ getTreeViewer().setSelection(selection); >+ } >+ }; >+ } >+ > } >\ No newline at end of file >Index: src/org/eclipse/wst/xsd/ui/internal/XSDEditor.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/XSDEditor.java,v >retrieving revision 1.25 >diff -u -r1.25 XSDEditor.java >--- src/org/eclipse/wst/xsd/ui/internal/XSDEditor.java 3 Oct 2005 23:16:53 -0000 1.25 >+++ src/org/eclipse/wst/xsd/ui/internal/XSDEditor.java 26 Oct 2005 17:56:00 -0000 >@@ -12,6 +12,8 @@ > > import java.util.ArrayList; > import java.util.EventObject; >+import java.util.Iterator; >+import java.util.List; > > import org.eclipse.core.resources.IFile; > import org.eclipse.core.runtime.IPath; >@@ -21,8 +23,13 @@ > import org.eclipse.jface.text.IDocument; > import org.eclipse.jface.util.IPropertyChangeListener; > import org.eclipse.jface.util.PropertyChangeEvent; >+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.jface.viewers.StructuredSelection; > import org.eclipse.swt.widgets.Control; >@@ -37,586 +44,823 @@ > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; > import org.eclipse.ui.editors.text.ILocationProvider; >+import org.eclipse.ui.views.contentoutline.IContentOutlinePage; >+import org.eclipse.ui.views.properties.IPropertySheetPage; > import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor; > import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier; > 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.events.IStructuredDocumentListener; > import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; > import org.eclipse.wst.sse.ui.StructuredTextEditor; >+import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage; > import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; > import org.eclipse.wst.xsd.ui.internal.graph.XSDGraphViewer; >+import org.eclipse.wst.xsd.ui.internal.properties.section.XSDTabbedPropertySheetPage; >+import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter; >+import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider; >+import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl; > import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; > import org.eclipse.wst.xsd.ui.internal.util.OpenOnSelectionHelper; >+import org.eclipse.xsd.XSDComponent; > import org.eclipse.xsd.XSDConcreteComponent; > import org.eclipse.xsd.XSDSchema; > import org.eclipse.xsd.util.XSDConstants; >+import org.w3c.dom.Attr; > import org.w3c.dom.Document; > import org.w3c.dom.Element; >+import org.w3c.dom.Node; > import org.w3c.dom.ProcessingInstruction; > > // public class XSDEditor extends StructuredTextMultiPageEditorPart >-public class XSDEditor extends XSDMultiPageEditorPart implements ITabbedPropertySheetPageContributor >-{ >- protected XSDTextEditor textEditor; >- IFile resourceFile; >- XSDSelectionManager xsdSelectionManager; >- XSDModelAdapter schemalNodeAdapter; >- >- private IStructuredModel result; >- >- public XSDEditor() >- { >- super(); >- xsdSelectionManager = new XSDSelectionManager(); >- } >- >- InternalPartListener partListener = new InternalPartListener(this); >- >- // show outline view - defect 266116 >- public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException >- { >- super.init(site, editorInput); >- IWorkbenchWindow dw=PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >- IWorkbenchPage page=dw.getActivePage(); >- getSite().getPage().addPartListener(partListener); >- try >- { >- if (page != null) >- { >-// page.showView("org.eclipse.ui.views.ContentOutline"); >- page.showView("org.eclipse.ui.views.PropertySheet"); >- } >- } catch (PartInitException e) >- { >-// e.printStackTrace(); >- } >- } >- >- // For team support >- // protected PropertyDirtyChangeListener propertyChangeListener; >- >- /** >- * Creates the pages of this multi-page editor. >- * <p> >- * Subclasses of <code>MultiPageEditor</code> must implement this method. >- * </p> >- */ >- protected void createPages() >- { >- try >- { >- if (!loadFile()) >- return; >- >- // source page MUST be created before design page, now >- createSourcePage(); >- >- addSourcePage(); >- buildXSDModel(); >- >- // comment this line out to hide the graph page >- // >- createAndAddGraphPage(); >- >- int pageIndexToShow = getDefaultPageTypeIndex(); >- setActivePage(pageIndexToShow); >- >- addCommandStackListener(); >- >- XSDEditorPlugin.getPlugin().getPreferenceStore().addPropertyChangeListener(preferenceStoreListener); >- } >- catch (PartInitException e) >- { >- // log for now, unless we find reason not to >- Logger.log(Logger.INFO, e.getMessage()); >- } >- } >- >- >- public void buildXSDModel() >- { >- try >- { >- Document document = ((IDOMModel)getModel()).getDocument(); >- >- boolean schemaNodeExists = document.getElementsByTagNameNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "schema").getLength() == 1; >- >- if (document.getChildNodes().getLength() == 0 || !schemaNodeExists) >- { >- createDefaultSchemaNode(document); >- } >- >- if (document instanceof INodeNotifier) >- { >- INodeNotifier notifier = (INodeNotifier)document; >- schemalNodeAdapter = (XSDModelAdapter)notifier.getAdapterFor(XSDModelAdapter.class); >- if (schemalNodeAdapter == null) >- { >- schemalNodeAdapter = new XSDModelAdapter(); >- notifier.addAdapter(schemalNodeAdapter); >- schemalNodeAdapter.createSchema(document.getDocumentElement()); >- } >- } >- } >- catch (Exception e) >- { >-// XSDEditorPlugin.getPlugin().getMsgLogger().write("Failed to create Model"); >-// XSDEditorPlugin.getPlugin().getMsgLogger().write(e); >-// e.printStackTrace(); >- } >- >- >- >-// XSDResourceFactoryImpl.validate(xsdSchema, input.getFile().getContents(true)); >- } >- >- public String[] getPropertyCategories() >- { >- return new String[] { "general", "namespace", "other", "attributes", "documentation", "facets" }; //$NON-NLS-1$ >- } >+public class XSDEditor extends XSDMultiPageEditorPart implements ITabbedPropertySheetPageContributor { >+ protected StructuredTextEditor textEditor; >+ IFile resourceFile; >+ XSDSelectionManager xsdSelectionManager; >+ XSDModelAdapter schemalNodeAdapter; >+ >+ private IStructuredModel result; >+ >+ /** >+ * Listener on SSE's outline page's selections that converts DOM >+ * selections into wsdl selections and notifies WSDL selection manager >+ */ >+ class OutlineTreeSelectionChangeListener implements ISelectionChangedListener, IDoubleClickListener { >+ public OutlineTreeSelectionChangeListener() { >+ } >+ >+ private ISelection getXSDSelection(ISelection selection) { >+ ISelection sel = null; >+ if (selection instanceof IStructuredSelection) { >+ IStructuredSelection structuredSelection = (IStructuredSelection) selection; >+ Object o = structuredSelection.getFirstElement(); >+ if (o != null) >+ sel = new StructuredSelection(o); >+ } >+ return sel; >+ } >+ >+ /** >+ * Determines DOM node based on object (xsd node) >+ * >+ * @param object >+ * @return >+ */ >+ private Object getObjectForOtherModel(Object object) { >+ Node node = null; >+ >+ if (object instanceof Node) { >+ node = (Node) object; >+ } >+ else if (object instanceof XSDComponent) { >+ node = ((XSDComponent) object).getElement(); >+ } >+ else if (object instanceof CategoryAdapter) { >+ node = ((CategoryAdapter) object).getXSDSchema().getElement(); >+ } >+ >+ // the text editor can only accept sed nodes! >+ // >+ if (!(node instanceof IDOMNode)) { >+ node = null; >+ } >+ return node; >+ } >+ >+ public void doubleClick(DoubleClickEvent event) { >+ /* >+ * Selection in outline tree changed so set outline tree's >+ * selection into editor's selection and say it came from outline >+ * tree >+ */ >+ if (getSelectionManager() != null && getSelectionManager().enableNotify) { >+ ISelection selection = getXSDSelection(event.getSelection()); >+ if (selection != null) { >+ getSelectionManager().setSelection(selection, fOutlinePage); >+ } >+ >+ if (getTextEditor() != null && selection instanceof IStructuredSelection) { >+ int start = -1; >+ int length = 0; >+ Object o = ((IStructuredSelection) selection).getFirstElement(); >+ if (o != null) >+ o = getObjectForOtherModel(o); >+ if (o instanceof IndexedRegion) { >+ start = ((IndexedRegion) o).getStartOffset(); >+ length = ((IndexedRegion) o).getEndOffset() - start; >+ } >+ if (start > -1) { >+ getTextEditor().selectAndReveal(start, length); >+ } >+ } >+ } >+ } >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ /* >+ * Selection in outline tree changed so set outline tree's >+ * selection into editor's selection and say it came from outline >+ * tree >+ */ >+ if (getSelectionManager() != null && getSelectionManager().enableNotify) { >+ ISelection selection = getXSDSelection(event.getSelection()); >+ if (selection != null) { >+ getSelectionManager().setSelection(selection, fOutlinePage); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Listener on SSE's source editor's selections that converts DOM >+ * selections into xsd selections and notifies XSD selection manager >+ */ >+ private class SourceEditorSelectionListener implements ISelectionChangedListener { >+ /** >+ * Determines XSD node based on object (DOM node) >+ * >+ * @param object >+ * @return >+ */ >+ private Object getXSDNode(Object object) { >+ // get the element node >+ Element element = null; >+ if (object instanceof Node) { >+ Node node = (Node) object; >+ if (node != null) { >+ if (node.getNodeType() == Node.ELEMENT_NODE) { >+ element = (Element) node; >+ } >+ else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { >+ element = ((Attr) node).getOwnerElement(); >+ } >+ } >+ } >+ Object o = element; >+ if (element != null) { >+ Object modelObject = getXSDSchema().getCorrespondingComponent(element); >+ if (modelObject != null) { >+ o = modelObject; >+ } >+ } >+ return o; >+ } >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ ISelection selection = event.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ List xsdSelections = new ArrayList(); >+ for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { >+ Object domNode = i.next(); >+ Object xsdNode = getXSDNode(domNode); >+ if (xsdNode != null) { >+ xsdSelections.add(xsdNode); >+ } >+ } >+ >+ if (!xsdSelections.isEmpty()) { >+ StructuredSelection xsdSelection = new StructuredSelection(xsdSelections); >+ getSelectionManager().setSelection(xsdSelection, getTextEditor().getSelectionProvider()); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Listener on XSD's selection manager's selections that converts XSD >+ * selections into DOM selections and notifies SSE's selection provider >+ */ >+ private class XSDSelectionManagerSelectionListener implements ISelectionChangedListener { >+ /** >+ * Determines DOM node based on object (xsd node) >+ * >+ * @param object >+ * @return >+ */ >+ private Object getObjectForOtherModel(Object object) { >+ Node node = null; >+ >+ if (object instanceof Node) { >+ node = (Node) object; >+ } >+ else if (object instanceof XSDComponent) { >+ node = ((XSDComponent) object).getElement(); >+ } >+ else if (object instanceof CategoryAdapter) { >+ node = ((CategoryAdapter) object).getXSDSchema().getElement(); >+ } >+ >+ // the text editor can only accept sed nodes! >+ // >+ if (!(node instanceof IDOMNode)) { >+ node = null; >+ } >+ return node; >+ } >+ >+ public void selectionChanged(SelectionChangedEvent event) { >+ // do not fire selection in source editor if selection event came >+ // from source editor >+ if (event.getSource() != getTextEditor().getSelectionProvider()) { >+ ISelection selection = event.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ List otherModelObjectList = new ArrayList(); >+ for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { >+ Object modelObject = i.next(); >+ Object otherModelObject = getObjectForOtherModel(modelObject); >+ if (otherModelObject != null) { >+ otherModelObjectList.add(otherModelObject); >+ } >+ } >+ if (!otherModelObjectList.isEmpty()) { >+ StructuredSelection nodeSelection = new StructuredSelection(otherModelObjectList); >+ getTextEditor().getSelectionProvider().setSelection(nodeSelection); >+ } >+ } >+ } >+ } >+ } >+ >+ public XSDEditor() { >+ super(); >+ xsdSelectionManager = new XSDSelectionManager(); >+ } >+ >+ InternalPartListener partListener = new InternalPartListener(this); >+ >+ // show outline view - defect 266116 >+ public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException { >+ super.init(site, editorInput); >+ IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ IWorkbenchPage page = dw.getActivePage(); >+ getSite().getPage().addPartListener(partListener); >+ try { >+ if (page != null) { >+ // page.showView("org.eclipse.ui.views.ContentOutline"); >+ page.showView("org.eclipse.ui.views.PropertySheet"); >+ } >+ } >+ catch (PartInitException e) { >+ // e.printStackTrace(); >+ } >+ } >+ >+ // For team support >+ // protected PropertyDirtyChangeListener propertyChangeListener; >+ >+ /** >+ * Creates the pages of this multi-page editor. >+ * <p> >+ * Subclasses of <code>MultiPageEditor</code> must implement this >+ * method. >+ * </p> >+ */ >+ protected void createPages() { >+ try { >+ if (!loadFile()) >+ return; >+ >+ xsdModelAdapterFactory = XSDModelAdapterFactoryImpl.getInstance(); >+ adapterFactoryLabelProvider = new XSDAdapterFactoryLabelProvider(xsdModelAdapterFactory); >+ >+ // source page MUST be created before design page, now >+ createSourcePage(); >+ >+ addSourcePage(); >+ buildXSDModel(); >+ >+ // comment this line out to hide the graph page >+ // >+ createAndAddGraphPage(); >+ >+ int pageIndexToShow = getDefaultPageTypeIndex(); >+ setActivePage(pageIndexToShow); >+ >+ openOnSelectionHelper = new OpenOnSelectionHelper(textEditor, getXSDSchema()); >+ // added selection listeners after setting selection to avoid >+ // navigation exception >+ ISelectionProvider provider = getTextEditor().getSelectionProvider(); >+ fSourceEditorSelectionListener = new SourceEditorSelectionListener(); >+ if (provider instanceof IPostSelectionProvider) { >+ ((IPostSelectionProvider) provider).addPostSelectionChangedListener(fSourceEditorSelectionListener); >+ } >+ else { >+ provider.addSelectionChangedListener(fSourceEditorSelectionListener); >+ } >+ fXSDSelectionListener = new XSDSelectionManagerSelectionListener(); >+ getSelectionManager().addSelectionChangedListener(fXSDSelectionListener); >+ >+ addCommandStackListener(); >+ >+ XSDEditorPlugin.getPlugin().getPreferenceStore().addPropertyChangeListener(preferenceStoreListener); >+ } >+ catch (PartInitException e) { >+ // log for now, unless we find reason not to >+ Logger.log(Logger.INFO, e.getMessage()); >+ } >+ } >+ >+ >+ public void buildXSDModel() { >+ try { >+ Document document = ((IDOMModel) getModel()).getDocument(); >+ >+ boolean schemaNodeExists = document.getElementsByTagNameNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "schema").getLength() == 1; >+ >+ if (document.getChildNodes().getLength() == 0 || !schemaNodeExists) { >+ createDefaultSchemaNode(document); >+ } >+ >+ if (document instanceof INodeNotifier) { >+ INodeNotifier notifier = (INodeNotifier) document; >+ schemalNodeAdapter = (XSDModelAdapter) notifier.getAdapterFor(XSDModelAdapter.class); >+ if (schemalNodeAdapter == null) { >+ schemalNodeAdapter = new XSDModelAdapter(); >+ notifier.addAdapter(schemalNodeAdapter); >+ schemalNodeAdapter.createSchema(document.getDocumentElement()); >+ } >+ } >+ } >+ catch (Exception e) { >+ // XSDEditorPlugin.getPlugin().getMsgLogger().write("Failed to >+ // create Model"); >+ // XSDEditorPlugin.getPlugin().getMsgLogger().write(e); >+ // e.printStackTrace(); >+ } >+ >+ >+ >+ // XSDResourceFactoryImpl.validate(xsdSchema, >+ // input.getFile().getContents(true)); >+ } >+ >+ public String[] getPropertyCategories() { >+ return new String[]{"general", "namespace", "other", "attributes", "documentation", "facets"}; //$NON-NLS-1$ >+ } > > /** > * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor#getContributorId() >- */ >- public String getContributorId() >- { >- return "org.eclipse.wst.xsd.ui.internal.XSDEditor"; >- //return getSite().getId(); >- } >- >- protected CommandStackListener commandStackListener; >- protected void addCommandStackListener() >- { >- if (commandStackListener == null) >- { >- IStructuredTextUndoManager undoManager = getModel().getUndoManager(); >- commandStackListener = new CommandStackListener() >- { >- /** >- * @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(EventObject) >- */ >- public void commandStackChanged(EventObject event) >- { >- Object obj = event.getSource(); >- if (obj instanceof BasicCommandStack) >- { >- BasicCommandStack stack = (BasicCommandStack) obj; >- Command recentCommand = stack.getMostRecentCommand(); >- Command redoCommand = stack.getRedoCommand(); >- Command undoCommand = stack.getUndoCommand(); >- if (recentCommand == redoCommand) >- { >- // there must have been an undo reset info tasks >- resetInformationTasks(); >- } >- } >- } >- }; >- >-//TODO WTP Port undoManager.getCommandStack().addCommandStackListener(commandStackListener); >- >- } >- } >- >- protected void pageChange(int arg) >- { >- super.pageChange(arg); >- } >- >- protected void removeCommandStackListener() >- { >- if (commandStackListener != null) >- { >- IStructuredTextUndoManager undoManager = getModel().getUndoManager(); >-//TODO WTP Port undoManager.getCommandStack().removeCommandStackListener(commandStackListener); >- } >- } >- >- // This is from the IValidateEditEditor interface >-/* public void undoChange() >- { >- StructuredTextUndoManager undoManager = textEditor.getModel().getUndoManager(); >- undoManager.undo(); >- // Make the editor clean >- textEditor.getModel().setDirtyState(false); >- } */ >- >- private class PreferenceStoreListener implements IPropertyChangeListener >- { >- /** >- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent) >- */ >- public void propertyChange(PropertyChangeEvent event) >- { >- } >- } >- >- protected IPropertyChangeListener preferenceStoreListener = new PreferenceStoreListener(); >- >- protected int getDefaultPageTypeIndex() >- { >- int pageIndex = sourcePageIndex; >- >- if (XSDEditorPlugin.getPlugin().getDefaultPage().equals(XSDEditorPlugin.GRAPH_PAGE)) >- { >- if (graphPageIndex != -1) >- pageIndex = graphPageIndex; >- } >- >- return pageIndex; >- } >- >- int currentPage = -1; >- public String getCurrentPageType() >- { >+ */ >+ public String getContributorId() { >+ return "org.eclipse.wst.xsd.ui.internal.XSDEditor"; >+ // return getSite().getId(); >+ } >+ >+ protected CommandStackListener commandStackListener; >+ >+ protected void addCommandStackListener() { >+ if (commandStackListener == null) { >+ IStructuredTextUndoManager undoManager = getModel().getUndoManager(); >+ commandStackListener = new CommandStackListener() { >+ /** >+ * @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(EventObject) >+ */ >+ public void commandStackChanged(EventObject event) { >+ Object obj = event.getSource(); >+ if (obj instanceof BasicCommandStack) { >+ BasicCommandStack stack = (BasicCommandStack) obj; >+ Command recentCommand = stack.getMostRecentCommand(); >+ Command redoCommand = stack.getRedoCommand(); >+ Command undoCommand = stack.getUndoCommand(); >+ if (recentCommand == redoCommand) { >+ // there must have been an undo reset info tasks >+ resetInformationTasks(); >+ } >+ } >+ } >+ }; >+ >+ // TODO WTP Port >+ // undoManager.getCommandStack().addCommandStackListener(commandStackListener); >+ >+ } >+ } >+ >+ protected void pageChange(int arg) { >+ super.pageChange(arg); >+ } >+ >+ protected void removeCommandStackListener() { >+ if (commandStackListener != null) { >+ IStructuredTextUndoManager undoManager = getModel().getUndoManager(); >+ // TODO WTP Port >+ // undoManager.getCommandStack().removeCommandStackListener(commandStackListener); >+ } >+ } >+ >+ // This is from the IValidateEditEditor interface >+ /* >+ * public void undoChange() { StructuredTextUndoManager undoManager = >+ * textEditor.getModel().getUndoManager(); undoManager.undo(); // Make the >+ * editor clean textEditor.getModel().setDirtyState(false); } >+ */ >+ >+ private class PreferenceStoreListener implements IPropertyChangeListener { >+ /** >+ * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent) >+ */ >+ public void propertyChange(PropertyChangeEvent event) { >+ } >+ } >+ >+ protected IPropertyChangeListener preferenceStoreListener = new PreferenceStoreListener(); >+ >+ protected int getDefaultPageTypeIndex() { >+ int pageIndex = sourcePageIndex; >+ >+ if (XSDEditorPlugin.getPlugin().getDefaultPage().equals(XSDEditorPlugin.GRAPH_PAGE)) { >+ if (graphPageIndex != -1) >+ pageIndex = graphPageIndex; >+ } >+ >+ return pageIndex; >+ } >+ >+ int currentPage = -1; >+ >+ public String getCurrentPageType() { > // should update pref. for valid pages >- if (getActivePage() != -1) >- { >+ if (getActivePage() != -1) { > currentPage = getActivePage(); > } >- if (currentPage == graphPageIndex) >- { >+ if (currentPage == graphPageIndex) { > return XSDEditorPlugin.GRAPH_PAGE; > } >- else >- { >+ else { > return XSDEditorPlugin.SOURCE_PAGE; >- } >+ } >+ } >+ >+ public Object getActivePart() { >+ return getSite().getWorkbenchWindow().getActivePage().getActivePart(); >+ } >+ >+ public void dispose() { >+ // some things in the configuration need to clean >+ // up after themselves >+ if (fOutlinePage != null) { >+ if (fOutlinePage instanceof ConfigurableContentOutlinePage && fOutlineListener != null) { >+ ((ConfigurableContentOutlinePage) fOutlinePage).removeDoubleClickListener(fOutlineListener); >+ } >+ if (fOutlineListener != null) { >+ fOutlinePage.removeSelectionChangedListener(fOutlineListener); >+ } >+ } >+ ISelectionProvider provider = getTextEditor().getSelectionProvider(); >+ if (provider instanceof IPostSelectionProvider) { >+ ((IPostSelectionProvider) provider).removePostSelectionChangedListener(fSourceEditorSelectionListener); >+ } >+ else { >+ provider.removeSelectionChangedListener(fSourceEditorSelectionListener); >+ } >+ getSelectionManager().removeSelectionChangedListener(fXSDSelectionListener); >+ >+ // propertyChangeListener.dispose(); >+ removeCommandStackListener(); >+ >+ XSDEditorPlugin.getPlugin().setDefaultPage(getCurrentPageType()); >+ XSDEditorPlugin.getPlugin().getPreferenceStore().removePropertyChangeListener(preferenceStoreListener); >+ >+ getSite().getPage().removePartListener(partListener); >+ >+ // KB: Temporary solution for bug 99468 >+ IStructuredModel myModel = textEditor.getModel(); >+ if (myModel != null && myModel instanceof IStructuredDocumentListener) >+ myModel.getStructuredDocument().removeDocumentChangingListener((IStructuredDocumentListener) myModel); >+ >+ textEditor = null; >+ resourceFile = null; >+ xsdSelectionManager = null; >+ schemalNodeAdapter = null; >+ result = null; >+ partListener = null; >+ commandStackListener = null; >+ preferenceStoreListener = null; >+ openOnSelectionHelper = null; >+ graphViewer = null; >+ >+ super.dispose(); >+ >+ // release the schema model >+ // >+ if (schemalNodeAdapter != null) { >+ schemalNodeAdapter.clear(); >+ schemalNodeAdapter = null; >+ } >+ } >+ >+ protected boolean loadFile() { >+ Object input = getEditorInput(); >+ >+ if (input instanceof IFileEditorInput) { >+ resourceFile = ((IFileEditorInput) input).getFile(); >+ } >+ else if (input instanceof ILocationProvider) { >+ IPath path = ((ILocationProvider) input).getPath(input); >+ String ext = path.getFileExtension(); >+ if (ext != null && ext.equals("xsd")) { >+ return true; >+ } >+ return false; >+ } >+ else { >+ return false; >+ } >+ return true; >+ } >+ >+ /** >+ * Method openOnGlobalReference. The comp argument is a resolved xsd >+ * schema object from another file. This is created and called from >+ * another schema model to allow F3 navigation to open a new editor and >+ * choose the referenced object within that editor context >+ * >+ * @param comp >+ */ >+ public void openOnGlobalReference(XSDConcreteComponent comp) { >+ openOnSelectionHelper.openOnGlobalReference(comp); >+ } >+ >+ protected OpenOnSelectionHelper openOnSelectionHelper; >+ >+ public OpenOnSelectionHelper getOpenOnSelectionHelper() { >+ return openOnSelectionHelper; >+ } >+ >+ /** >+ * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#createTextEditor() >+ */ >+ protected StructuredTextEditor createTextEditor() { >+ textEditor = new StructuredTextEditor(); >+ return textEditor; >+ } >+ >+ /* >+ * @see StructuredTextMultiPageEditorPart#createSourcePage() >+ */ >+ protected void createSourcePage() throws PartInitException { >+ super.createSourcePage(); >+ } >+ >+ int sourcePageIndex = -1; >+ >+ /** >+ * Adds the source page of the multi-page editor. >+ */ >+ protected void addSourcePage() throws PartInitException { >+ >+ sourcePageIndex = addPage(textEditor, getEditorInput()); >+ setPageText(sourcePageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_SOURCE")); >+ >+ // the update's critical, to get viewer selection manager and >+ // highlighting to work >+ textEditor.update(); >+ firePropertyChange(PROP_TITLE); >+ } >+ >+ int graphPageIndex = -1; >+ XSDGraphViewer graphViewer; >+ >+ /** >+ * Creates the graph page and adds it to the multi-page editor. >+ */ >+ protected void createAndAddGraphPage() throws PartInitException { >+ graphViewer = new XSDGraphViewer(this); >+ graphViewer.setSchema(getXSDSchema()); >+ Control graphControl = graphViewer.createControl(getContainer()); >+ graphPageIndex = addPage(graphControl); >+ setPageText(graphPageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_GRAPH")); >+ >+ // graphViewer.setViewerSelectionManager(textEditor.getViewerSelectionManager()); >+ graphViewer.setSelectionManager(getSelectionManager()); >+ >+ // this forces the editor to initially select the top level schema >+ // object >+ // >+ if (getXSDSchema() != null) { >+ getSelectionManager().setSelection(new StructuredSelection(getXSDSchema())); >+ } >+ } >+ >+ protected XSDModelAdapterFactoryImpl xsdModelAdapterFactory; >+ protected XSDAdapterFactoryLabelProvider adapterFactoryLabelProvider; >+ private IPropertySheetPage fPropertySheetPage; >+ private IContentOutlinePage fOutlinePage; >+ private OutlineTreeSelectionChangeListener fOutlineListener; >+ private SourceEditorSelectionListener fSourceEditorSelectionListener; >+ private XSDSelectionManagerSelectionListener fXSDSelectionListener; >+ >+ /* >+ * @see IAdaptable#getAdapter(Class) >+ */ >+ public Object getAdapter(Class key) { >+ Object result = null; >+ if (key == ISelectionProvider.class) { >+ result = xsdSelectionManager; >+ } >+ if (IPropertySheetPage.class.equals(key)) { >+ fPropertySheetPage = new XSDTabbedPropertySheetPage(this); >+ >+ ((XSDTabbedPropertySheetPage) fPropertySheetPage).setXSDModelAdapterFactory(xsdModelAdapterFactory); >+ ((XSDTabbedPropertySheetPage) fPropertySheetPage).setSelectionManager(getSelectionManager()); >+ ((XSDTabbedPropertySheetPage) fPropertySheetPage).setXSDSchema(getXSDSchema()); >+ >+ return fPropertySheetPage; >+ } >+ else if (IContentOutlinePage.class.equals(key)) { >+ if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) { >+ IContentOutlinePage page = (IContentOutlinePage) super.getAdapter(key); >+ if (page != null) { >+ fOutlineListener = new OutlineTreeSelectionChangeListener(); >+ page.addSelectionChangedListener(fOutlineListener); >+ if (page instanceof ConfigurableContentOutlinePage) { >+ ((ConfigurableContentOutlinePage) page).addDoubleClickListener(fOutlineListener); >+ } >+ } >+ fOutlinePage = page; >+ // XSDContentOutlinePage outlinePage = new >+ // XSDContentOutlinePage(this); >+ // XSDContentProvider xsdContentProvider = new >+ // XSDContentProvider(xsdModelAdapterFactory); >+ // xsdContentProvider.setXSDSchema(getXSDSchema()); >+ // outlinePage.setContentProvider(xsdContentProvider); >+ // outlinePage.setLabelProvider(adapterFactoryLabelProvider); >+ // outlinePage.setModel(getXSDSchema().getDocument()); >+ // >+ // fOutlinePage = outlinePage; >+ } >+ return fOutlinePage; >+ } >+ else { >+ result = super.getAdapter(key); >+ } >+ return result; >+ } >+ >+ >+ public XSDModelAdapterFactoryImpl getXSDModelAdapterFactory() { >+ return xsdModelAdapterFactory; >+ } >+ >+ public XSDAdapterFactoryLabelProvider getLabelProvider() { >+ return adapterFactoryLabelProvider; >+ } >+ >+ >+ public XSDSelectionManager getSelectionManager() { >+ return xsdSelectionManager; >+ } >+ >+ /** >+ * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#doSaveAs() >+ */ >+ public void doSaveAs() { >+ super.doSaveAs(); >+ } >+ >+ public void doSave(org.eclipse.core.runtime.IProgressMonitor monitor) { >+ super.doSave(monitor); >+ } >+ >+ public void reparseSchema() { >+ // TODO cs : Are there no better ways to make the model >+ // reload it's dependencies? This seems rather extreme. >+ // >+ Document document = ((IDOMModel) getModel()).getDocument(); >+ if (schemalNodeAdapter != null) { >+ schemalNodeAdapter.createSchema(document.getDocumentElement()); >+ } >+ } >+ >+ /** >+ * Returns the xsdSchema. >+ * >+ * @return XSDSchema >+ */ >+ public XSDSchema getXSDSchema() { >+ return schemalNodeAdapter != null ? schemalNodeAdapter.getSchema() : null; >+ } >+ >+ >+ /** >+ * Returns the resourceFile. >+ * >+ * @return IFile >+ */ >+ public IFile getFileResource() { >+ return resourceFile; >+ } >+ >+ /** >+ * Get the IDocument from the text viewer >+ */ >+ public IDocument getEditorIDocument() { >+ IDocument document = textEditor.getTextViewer().getDocument(); >+ return document; >+ } >+ >+ /** >+ * Create ref integrity tasks in task list >+ */ >+ public void createTasksInTaskList(ArrayList messages) { >+ // DisplayErrorInTaskList tasks = new >+ // DisplayErrorInTaskList(getEditorIDocument(), getFileResource(), >+ // messages); >+ // tasks.run(); >+ } >+ >+ public void resetInformationTasks() { >+ // DisplayErrorInTaskList.removeInfoMarkers(getFileResource()); >+ } >+ >+ public XSDGraphViewer getGraphViewer() { >+ return graphViewer; >+ } >+ >+ public IEditorPart getActiveEditorPage() { >+ return getActiveEditor(); >+ } >+ >+ public StructuredTextEditor getTextEditor() { >+ return textEditor; >+ } >+ >+ class InternalPartListener implements IPartListener { >+ XSDEditor editor; >+ >+ public InternalPartListener(XSDEditor editor) { >+ this.editor = editor; >+ } >+ >+ public void partActivated(IWorkbenchPart part) { >+ if (part == editor) { >+ ISelection selection = getSelectionManager().getSelection(); >+ if (selection != null) { >+ if (getCurrentPageType().equals(XSDEditorPlugin.GRAPH_PAGE)) { >+ getSelectionManager().selectionChanged(new SelectionChangedEvent(editor.getGraphViewer().getComponentViewer(), selection)); >+ } >+ else if (getCurrentPageType().equals(XSDEditorPlugin.SOURCE_PAGE)) { >+ getSelectionManager().setSelection(selection); >+ } >+ } >+ } >+ } >+ >+ public void partBroughtToTop(IWorkbenchPart part) { >+ } >+ >+ public void partClosed(IWorkbenchPart part) { >+ } >+ >+ public void partDeactivated(IWorkbenchPart part) { >+ } >+ >+ public void partOpened(IWorkbenchPart part) { >+ } >+ } >+ >+ >+ /** >+ * Method createDefaultSchemaNode. Should only be called to insert a >+ * schema node into an empty document >+ */ >+ public void createDefaultSchemaNode(Document document) { >+ if (document.getChildNodes().getLength() == 0) { >+ // if it is a completely empty file, then add the encoding and >+ // version processing instruction >+ // TODO String encoding = EncodingHelper.getDefaultEncodingTag(); >+ String encoding = "UTF-8"; >+ ProcessingInstruction instr = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + encoding + "\""); >+ document.appendChild(instr); >+ } >+ >+ // Create a default schema tag now >+ >+ // String defaultPrefixForTargetNamespace = >+ // getFileResource().getProjectRelativePath().removeFileExtension().lastSegment(); >+ String defaultPrefixForTargetNamespace = "tns"; >+ String prefixForSchemaNamespace = ""; >+ String schemaNamespaceAttribute = "xmlns"; >+ if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage()) { >+ // Added this if check before disallowing blank prefixes in the >+ // preferences... >+ // Can take this out. See also NewXSDWizard >+ if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0) { >+ prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":"; >+ schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix(); >+ } >+ } >+ >+ document.appendChild(document.createTextNode("\n")); >+ Element element = document.createElement(prefixForSchemaNamespace + XSDConstants.SCHEMA_ELEMENT_TAG); >+ >+ element.setAttribute(schemaNamespaceAttribute, "http://www.w3.org/2001/XMLSchema"); >+ >+ String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace(); >+ element.setAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE, defaultTargetURI); >+ element.setAttribute("xmlns:" + defaultPrefixForTargetNamespace, defaultTargetURI); >+ >+ document.appendChild(element); > } >- >- public Object getActivePart() >- { >- return getSite().getWorkbenchWindow().getActivePage().getActivePart(); >- } >- >- public void dispose() >- { >-// propertyChangeListener.dispose(); >- removeCommandStackListener(); >- >- XSDEditorPlugin.getPlugin().setDefaultPage(getCurrentPageType()); >- XSDEditorPlugin.getPlugin().getPreferenceStore().removePropertyChangeListener(preferenceStoreListener); >- >- getSite().getPage().removePartListener(partListener); >- >- // KB: Temporary solution for bug 99468 >- IStructuredModel myModel = textEditor.getModel(); >- if (myModel != null && myModel instanceof IStructuredDocumentListener) >- myModel.getStructuredDocument().removeDocumentChangingListener((IStructuredDocumentListener)myModel); >- >- textEditor = null; >- resourceFile = null; >- xsdSelectionManager = null; >- schemalNodeAdapter = null; >- result = null; >- partListener = null; >- commandStackListener = null; >- preferenceStoreListener = null; >- openOnSelectionHelper = null; >- graphViewer = null; >- >- super.dispose(); >- >- // release the schema model >- // >- if (schemalNodeAdapter != null) >- { >- schemalNodeAdapter.clear(); >- schemalNodeAdapter = null; >- } >- } >- >- protected boolean loadFile() >- { >- Object input = getEditorInput(); >- >- if (input instanceof IFileEditorInput) >- { >- resourceFile = ((IFileEditorInput) input).getFile(); >- } >- else if (input instanceof ILocationProvider) >- { >- IPath path = ((ILocationProvider)input).getPath(input); >- String ext = path.getFileExtension(); >- if (ext != null && ext.equals("xsd")) >- { >- return true; >- } >- return false; >- } >- else >- { >- return false; >- } >- return true; >- } >- >- /** >- * Method openOnGlobalReference. >- * The comp argument is a resolved xsd schema object from another file. This is created and called from another >- * schema model to allow F3 navigation to open a new editor and choose the referenced object within that editor context >- * @param comp >- */ >- public void openOnGlobalReference(XSDConcreteComponent comp) >- { >- openOnSelectionHelper.openOnGlobalReference(comp); >- } >- >- protected OpenOnSelectionHelper openOnSelectionHelper; >- >- public OpenOnSelectionHelper getOpenOnSelectionHelper() >- { >- return openOnSelectionHelper; >- } >- >- /** >- * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#createTextEditor() >- */ >- protected StructuredTextEditor createTextEditor() >- { >- return new XSDTextEditor(this); >- } >- >- /* >- * @see StructuredTextMultiPageEditorPart#createSourcePage() >- */ >- protected void createSourcePage() throws PartInitException >- { >- super.createSourcePage(); >- >- textEditor = (XSDTextEditor) getTextEditor(); >- >- openOnSelectionHelper = new OpenOnSelectionHelper(textEditor); >- } >- >- int sourcePageIndex = -1; >- /** >- * Adds the source page of the multi-page editor. >- */ >- protected void addSourcePage() throws PartInitException { >- >- sourcePageIndex = addPage(textEditor, getEditorInput()); >- setPageText(sourcePageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_SOURCE")); >- >- // the update's critical, to get viewer selection manager and highlighting to work >- textEditor.update(); >- firePropertyChange(PROP_TITLE); >- } >- >- int graphPageIndex = -1; >- XSDGraphViewer graphViewer; >- >- /** >- * Creates the graph page and adds it to the multi-page editor. >- */ >- protected void createAndAddGraphPage() throws PartInitException >- { >- graphViewer = new XSDGraphViewer(this); >- graphViewer.setSchema(getXSDSchema()); >- Control graphControl = graphViewer.createControl(getContainer()); >- graphPageIndex = addPage(graphControl); >- setPageText(graphPageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_GRAPH")); >- >- // graphViewer.setViewerSelectionManager(textEditor.getViewerSelectionManager()); >- graphViewer.setSelectionManager(getSelectionManager()); >- >- // this forces the editor to initially select the top level schema object >- // >- if (textEditor.getXSDSchema() != null) >- { >- getSelectionManager().setSelection(new StructuredSelection(textEditor.getXSDSchema())); >- } >- } >- >- /* >- * @see IAdaptable#getAdapter(Class) >- */ >- public Object getAdapter(Class key) >- { >- Object result = null; >- if (key == ISelectionProvider.class) >- { >- result = xsdSelectionManager; >- } >- else >- { >- result = textEditor.getAdapter(key); >- } >- return result; >- } >- >- public XSDSelectionManager getSelectionManager() >- { >- return xsdSelectionManager; >- } >- >- /** >- * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#doSaveAs() >- */ >- public void doSaveAs() >- { >- super.doSaveAs(); >- } >- >- public void doSave(org.eclipse.core.runtime.IProgressMonitor monitor) >- { >- super.doSave(monitor); >- } >- >- public void reparseSchema() >- { >- // TODO cs : Are there no better ways to make the model >- // reload it's dependencies? This seems rather extreme. >- // >- Document document = ((IDOMModel)getModel()).getDocument(); >- if (schemalNodeAdapter != null) >- { >- schemalNodeAdapter.createSchema(document.getDocumentElement()); >- } >- } >- >- /** >- * Returns the xsdSchema. >- * @return XSDSchema >- */ >- public XSDSchema getXSDSchema() >- { >- return schemalNodeAdapter != null ? schemalNodeAdapter.getSchema() : null; >- } >- >- >- /** >- * Returns the resourceFile. >- * @return IFile >- */ >- public IFile getFileResource() >- { >- return resourceFile; >- } >- >- /** >- * Get the IDocument from the text viewer >- */ >- public IDocument getEditorIDocument() >- { >- IDocument document = textEditor.getTextViewer().getDocument(); >- return document; >- } >- >- /** >- * Create ref integrity tasks in task list >- */ >- public void createTasksInTaskList(ArrayList messages) >- { >-// DisplayErrorInTaskList tasks = new DisplayErrorInTaskList(getEditorIDocument(), getFileResource(), messages); >-// tasks.run(); >- } >- >- public void resetInformationTasks() >- { >-// DisplayErrorInTaskList.removeInfoMarkers(getFileResource()); >- } >- >- public XSDGraphViewer getGraphViewer() >- { >- return graphViewer; >- } >- >- public IEditorPart getActiveEditorPage() >- { >- return getActiveEditor(); >- } >- >- public XSDTextEditor getXSDTextEditor() >- { >- return textEditor; >- } >- >- class InternalPartListener implements IPartListener >- { >- XSDEditor editor; >- public InternalPartListener(XSDEditor editor) >- { >- this.editor = editor; >- } >- >- public void partActivated(IWorkbenchPart part) >- { >- if (part == editor) >- { >- ISelection selection = getSelectionManager().getSelection(); >- if (selection != null) >- { >- if (getCurrentPageType().equals(XSDEditorPlugin.GRAPH_PAGE)) >- { >- getSelectionManager().selectionChanged(new SelectionChangedEvent(editor.getGraphViewer().getComponentViewer(), selection)); >- } >- else if (getCurrentPageType().equals(XSDEditorPlugin.SOURCE_PAGE)) >- { >- getSelectionManager().setSelection(selection); >- } >- } >- } >- } >- >- public void partBroughtToTop(IWorkbenchPart part) >- { >- } >- >- public void partClosed(IWorkbenchPart part) >- { >- } >- >- public void partDeactivated(IWorkbenchPart part) >- { >- } >- >- public void partOpened(IWorkbenchPart part) >- { >- } >- } >- >- >- /** >- * Method createDefaultSchemaNode. Should only be called to insert a schema node into an empty document >- */ >- public void createDefaultSchemaNode(Document document) >- { >- if (document.getChildNodes().getLength() == 0) >- { >- // if it is a completely empty file, then add the encoding and version processing instruction >-//TODO String encoding = EncodingHelper.getDefaultEncodingTag(); >- String encoding = "UTF-8"; >- ProcessingInstruction instr = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + encoding + "\""); >- document.appendChild(instr); >- } >- >- // Create a default schema tag now >- >- // String defaultPrefixForTargetNamespace = getFileResource().getProjectRelativePath().removeFileExtension().lastSegment(); >- String defaultPrefixForTargetNamespace = "tns"; >- String prefixForSchemaNamespace = ""; >- String schemaNamespaceAttribute = "xmlns"; >- if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage()) >- { >- // Added this if check before disallowing blank prefixes in the preferences... >- // Can take this out. See also NewXSDWizard >- if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0) >- { >- prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":"; >- schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix(); >- } >- } >- >- document.appendChild(document.createTextNode("\n")); >- Element element = document.createElement(prefixForSchemaNamespace + XSDConstants.SCHEMA_ELEMENT_TAG); >- >- element.setAttribute(schemaNamespaceAttribute,"http://www.w3.org/2001/XMLSchema"); >- >- String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace(); >- element.setAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE, defaultTargetURI); >- element.setAttribute("xmlns:" + defaultPrefixForTargetNamespace, defaultTargetURI); >- >- document.appendChild(element); >- } > } >Index: src/org/eclipse/wst/xsd/ui/internal/XSDTextEditor.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/XSDTextEditor.java,v >retrieving revision 1.21 >diff -u -r1.21 XSDTextEditor.java >--- src/org/eclipse/wst/xsd/ui/internal/XSDTextEditor.java 3 Oct 2005 19:28:33 -0000 1.21 >+++ src/org/eclipse/wst/xsd/ui/internal/XSDTextEditor.java 26 Oct 2005 17:56:01 -0000 >@@ -36,10 +36,8 @@ > 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.provisional.document.IDOMNode; >-import org.eclipse.wst.xsd.ui.internal.properties.section.XSDTabbedPropertySheetPage; > import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter; > import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider; >-import org.eclipse.wst.xsd.ui.internal.provider.XSDContentProvider; > import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl; > import org.eclipse.wst.xsd.ui.internal.refactor.actions.RefactorActionGroup; > import org.eclipse.wst.xsd.ui.internal.util.SelectionAdapter; >@@ -49,7 +47,9 @@ > import org.w3c.dom.Element; > import org.w3c.dom.Node; > >- >+/** >+ * @deprecated Do not use subclass of StructuredTextEditor >+ */ > public class XSDTextEditor extends StructuredTextEditor implements INodeSelectionListener, ISelectionChangedListener > { > protected XSDSelectionManager xsdSelectionManager; >@@ -58,7 +58,7 @@ > protected InternalSelectionProvider internalSelectionProvider = new InternalSelectionProvider(); > private IPropertySheetPage fPropertySheetPage; > private IContentOutlinePage fOutlinePage; >- >+ > public XSDTextEditor(XSDEditor xsdEditor) > { > super(); >@@ -70,7 +70,6 @@ > xsdModelAdapterFactory = XSDModelAdapterFactoryImpl.getInstance(); > adapterFactoryLabelProvider = new XSDAdapterFactoryLabelProvider(xsdModelAdapterFactory); > } >- > public void dispose() > { > super.dispose(); >@@ -80,51 +79,51 @@ > xsdModelAdapterFactory = null; > } > >- public XSDModelAdapterFactoryImpl getXSDModelAdapterFactory() >- { >- return xsdModelAdapterFactory; >- } >- >- public static XSDAdapterFactoryLabelProvider getLabelProvider() >- { >- return adapterFactoryLabelProvider; >- } >- >- public Object getAdapter(Class required) { >- >- if (IPropertySheetPage.class.equals(required)) >- { >- fPropertySheetPage = new XSDTabbedPropertySheetPage(getXSDEditor()); >- >- ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDModelAdapterFactory(xsdModelAdapterFactory); >- ((XSDTabbedPropertySheetPage)fPropertySheetPage).setSelectionManager(getXSDEditor().getSelectionManager()); >- ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDSchema(getXSDSchema()); >- >- return fPropertySheetPage; >- } >- else if (IContentOutlinePage.class.equals(required)) >- { >- if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) >- { >- XSDContentOutlinePage outlinePage = new XSDContentOutlinePage(this); >- XSDContentProvider xsdContentProvider = new XSDContentProvider(xsdModelAdapterFactory); >- xsdContentProvider.setXSDSchema(getXSDSchema()); >- outlinePage.setContentProvider(xsdContentProvider); >- outlinePage.setLabelProvider(adapterFactoryLabelProvider); >- outlinePage.setModel(getXSDSchema().getDocument()); >- >- // Update outline selection from source editor selection: >- getViewerSelectionManager().addNodeSelectionListener(this); >- internalSelectionProvider.addSelectionChangedListener(getViewerSelectionManager()); >- internalSelectionProvider.setEventSource(outlinePage); >- >- fOutlinePage = outlinePage; >- } >- return fOutlinePage; >- } >- >- return super.getAdapter(required); >- } >+// public XSDModelAdapterFactoryImpl getXSDModelAdapterFactory() >+// { >+// return xsdModelAdapterFactory; >+// } >+// >+// public static XSDAdapterFactoryLabelProvider getLabelProvider() >+// { >+// return adapterFactoryLabelProvider; >+// } >+ >+// public Object getAdapter(Class required) { >+// >+// if (IPropertySheetPage.class.equals(required)) >+// { >+// fPropertySheetPage = new XSDTabbedPropertySheetPage(getXSDEditor()); >+// >+// ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDModelAdapterFactory(xsdModelAdapterFactory); >+// ((XSDTabbedPropertySheetPage)fPropertySheetPage).setSelectionManager(getXSDEditor().getSelectionManager()); >+// ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDSchema(getXSDSchema()); >+// >+// return fPropertySheetPage; >+// } >+// else if (IContentOutlinePage.class.equals(required)) >+// { >+// if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) >+// { >+// XSDContentOutlinePage outlinePage = new XSDContentOutlinePage(getXSDEditor()); >+// XSDContentProvider xsdContentProvider = new XSDContentProvider(xsdModelAdapterFactory); >+// xsdContentProvider.setXSDSchema(getXSDSchema()); >+// outlinePage.setContentProvider(xsdContentProvider); >+// outlinePage.setLabelProvider(adapterFactoryLabelProvider); >+// outlinePage.setModel(getXSDSchema().getDocument()); >+// >+// // Update outline selection from source editor selection: >+// getViewerSelectionManager().addNodeSelectionListener(this); >+// internalSelectionProvider.addSelectionChangedListener(getViewerSelectionManager()); >+// internalSelectionProvider.setEventSource(outlinePage); >+// >+// fOutlinePage = outlinePage; >+// } >+// return fOutlinePage; >+// } >+// >+// return super.getAdapter(required); >+// } > > > protected XSDContentOutlinePage outlinePage; >@@ -326,6 +325,6 @@ > fRefactorMenuGroup.setContext(context); > fRefactorMenuGroup.fillContextMenu(menu); > fRefactorMenuGroup.setContext(null); >- } >+ } > } > >Index: src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDSectionLabelProvider.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDSectionLabelProvider.java,v >retrieving revision 1.4 >diff -u -r1.4 XSDSectionLabelProvider.java >--- src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDSectionLabelProvider.java 18 Apr 2005 17:37:46 -0000 1.4 >+++ src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDSectionLabelProvider.java 26 Oct 2005 17:56:01 -0000 >@@ -15,9 +15,12 @@ > import org.eclipse.jface.viewers.LabelProvider; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.swt.graphics.Image; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode; >+import org.eclipse.wst.xsd.ui.internal.XSDEditor; > import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin; >-import org.eclipse.wst.xsd.ui.internal.XSDTextEditor; > import org.eclipse.xsd.XSDAttributeDeclaration; > import org.eclipse.xsd.XSDConcreteComponent; > import org.eclipse.xsd.XSDElementDeclaration; >@@ -50,7 +53,13 @@ > > if (selected instanceof XSDConcreteComponent) > { >- return XSDTextEditor.getLabelProvider().getImage((XSDConcreteComponent)selected); >+ IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench(); >+ IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); >+ IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor(); >+ if (editorPart instanceof XSDEditor) >+ { >+ return ((XSDEditor)editorPart).getLabelProvider().getImage((XSDConcreteComponent)selected); >+ } > } > > // selected = typeMapper.remapObject(selected); >Index: src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDTabbedPropertySheetPage.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDTabbedPropertySheetPage.java,v >retrieving revision 1.4 >diff -u -r1.4 XSDTabbedPropertySheetPage.java >--- src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDTabbedPropertySheetPage.java 3 Oct 2005 22:42:31 -0000 1.4 >+++ src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDTabbedPropertySheetPage.java 26 Oct 2005 17:56:01 -0000 >@@ -15,9 +15,11 @@ > import org.eclipse.jface.text.TextSelection; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.ISelectionChangedListener; >+import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.viewers.SelectionChangedEvent; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.part.IPageSite; > import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor; > import org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetPage; > import org.eclipse.wst.xsd.ui.internal.XSDSelectionManager; >@@ -25,10 +27,15 @@ > import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter; > import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl; > import org.eclipse.xsd.XSDSchema; >+import org.w3c.dom.Element; >+import org.w3c.dom.Node; >+import org.w3c.dom.ProcessingInstruction; >+import org.w3c.dom.Text; > > public class XSDTabbedPropertySheetPage extends TabbedPropertySheetPage > implements ISelectionChangedListener, INotifyChangedListener > { >+ XSDSchema xsdSchema; > private XSDSelectionManager selectionManager; > private XSDModelAdapterFactoryImpl adapterFactory; > /** >@@ -39,7 +46,12 @@ > super(tabbedPropertySheetPageContributor); > } > >- XSDSchema xsdSchema; >+ public void init(IPageSite pageSite) >+ { >+ super.init(pageSite); >+ getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this); >+ } >+ > public void setXSDSchema(XSDSchema xsdSchema) > { > this.xsdSchema = xsdSchema; >@@ -81,22 +93,51 @@ > // override for category > if (selection != null) > { >- if (selection instanceof StructuredSelection) >+ if (selection instanceof IStructuredSelection) > { >- StructuredSelection structuredSelection = (StructuredSelection)selection; >+ IStructuredSelection structuredSelection = (IStructuredSelection) selection; > if (structuredSelection.isEmpty()) > { > return; > } >- Object obj = structuredSelection.getFirstElement(); >- if (obj instanceof CategoryAdapter) >+ Object obj = structuredSelection.getFirstElement(); >+ if (obj instanceof Element) >+ { >+ try >+ { >+ Object modelObject = xsdSchema.getCorrespondingComponent((Element) obj); >+ if (modelObject != null) >+ { >+ obj = modelObject; >+ selection = new StructuredSelection(obj); >+ } >+ } >+ catch (Exception e) >+ { >+ } >+ } >+ else if (obj instanceof Text) >+ { >+ Node parent = ((Text)obj).getParentNode(); >+ Object modelObject = xsdSchema.getCorrespondingComponent(parent); >+ if (modelObject != null) >+ { >+ obj = modelObject; >+ selection = new StructuredSelection(obj); >+ } >+ } >+ else if (obj instanceof CategoryAdapter) > { > selection = new StructuredSelection(((CategoryAdapter)obj).getXSDSchema()); > } > else if (obj instanceof Category) > { > selection = new StructuredSelection(((Category)obj).getXSDSchema()); >- } >+ } >+ else if (obj instanceof ProcessingInstruction) >+ { >+ selection = new StructuredSelection(xsdSchema); >+ } > } > else if (selection instanceof TextSelection) > { >@@ -125,6 +166,7 @@ > { > adapterFactory.removeListener(this); > } >+ getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(this); > super.dispose(); > } > >Index: src/org/eclipse/wst/xsd/ui/internal/provider/XSDContentProvider.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/provider/XSDContentProvider.java,v >retrieving revision 1.4 >diff -u -r1.4 XSDContentProvider.java >--- src/org/eclipse/wst/xsd/ui/internal/provider/XSDContentProvider.java 3 Oct 2005 22:42:34 -0000 1.4 >+++ src/org/eclipse/wst/xsd/ui/internal/provider/XSDContentProvider.java 26 Oct 2005 17:56:01 -0000 >@@ -20,23 +20,27 @@ > import org.eclipse.emf.edit.provider.IChangeNotifier; > import org.eclipse.emf.edit.provider.INotifyChangedListener; > import org.eclipse.emf.edit.provider.ITreeItemContentProvider; >+import org.eclipse.jface.text.IDocument; > import org.eclipse.jface.viewers.ITreeContentProvider; > import org.eclipse.jface.viewers.StructuredViewer; > import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; >+import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; >+import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; > import org.eclipse.xsd.XSDConcreteComponent; > import org.eclipse.xsd.XSDElementDeclaration; > import org.eclipse.xsd.XSDModelGroup; > import org.eclipse.xsd.XSDParticleContent; > import org.eclipse.xsd.XSDSchema; > import org.eclipse.xsd.XSDWildcard; >-import org.w3c.dom.Document; > import org.w3c.dom.Node; > > public class XSDContentProvider implements ITreeContentProvider, INotifyChangedListener > { > XSDModelAdapterFactoryImpl xsdModelAdapterFactory; > >- XSDSchema xsdSchema; > public XSDContentProvider(XSDModelAdapterFactoryImpl xsdModelAdapterFactoryImpl) > { > this.xsdModelAdapterFactory = xsdModelAdapterFactoryImpl; >@@ -47,11 +51,6 @@ > } > } > >- public void setXSDSchema(XSDSchema xsdSchema) >- { >- this.xsdSchema = xsdSchema; >- } >- > /* > * @see ITreeContentProvider#getChildren(Object) > */ >@@ -59,15 +58,28 @@ > { > XSDConcreteComponent xsdComp = null; > List list = null; >- if (parentElement instanceof Document) >- { >- xsdComp = xsdSchema; >- >- xsdModelAdapterFactory.adapt(xsdComp, xsdModelAdapterFactory); >- >- list = new ArrayList(); >- list.add(xsdComp); >- return list.toArray(); >+ >+ // root/input is structuredmodel >+ if (parentElement instanceof IDOMModel) { >+ IDOMDocument domDoc = ((IDOMModel) parentElement).getDocument(); >+ if (domDoc != null) { >+ XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class); >+ /* >+ * ISSUE: Didn't want to go through initializing >+ * schema if it does not already exist, so just >+ * attempted to get existing adapter. If doesn't >+ * exist, just don't bother working. >+ */ >+ if (modelAdapter != null) >+ xsdComp = modelAdapter.getSchema(); >+ if (xsdComp != null) { >+ xsdModelAdapterFactory.adapt(xsdComp, xsdModelAdapterFactory); >+ >+ list = new ArrayList(); >+ list.add(xsdComp); >+ return list.toArray(); >+ } >+ } > } > else if (parentElement instanceof XSDConcreteComponent) > { >@@ -181,4 +193,36 @@ > this.viewer = viewer; > } > >+ /** >+ * Gets the xsd schema from document >+ * >+ * @param document >+ * @return XSDSchema or null of one does not exist yet for document >+ */ >+ private XSDSchema getXSDSchema(IDocument document) { >+ XSDSchema schema = null; >+ IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document); >+ if (model != null) { >+ try { >+ if (model instanceof IDOMModel) { >+ IDOMDocument domDoc = ((IDOMModel) model).getDocument(); >+ if (domDoc != null) { >+ XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class); >+ /* >+ * ISSUE: Didn't want to go through initializing >+ * schema if it does not already exist, so just >+ * attempted to get existing adapter. If doesn't >+ * exist, just don't bother working. >+ */ >+ if (modelAdapter != null) >+ schema = modelAdapter.getSchema(); >+ } >+ } >+ } >+ finally { >+ model.releaseFromRead(); >+ } >+ } >+ return schema; >+ } > } >Index: src/org/eclipse/wst/xsd/ui/internal/provider/XSDSchemaAdapter.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/provider/XSDSchemaAdapter.java,v >retrieving revision 1.1 >diff -u -r1.1 XSDSchemaAdapter.java >--- src/org/eclipse/wst/xsd/ui/internal/provider/XSDSchemaAdapter.java 24 Nov 2004 21:13:41 -0000 1.1 >+++ src/org/eclipse/wst/xsd/ui/internal/provider/XSDSchemaAdapter.java 26 Oct 2005 17:56:01 -0000 >@@ -16,6 +16,7 @@ > > import org.eclipse.emf.common.notify.AdapterFactory; > import org.eclipse.emf.common.notify.Notification; >+import org.eclipse.emf.common.notify.Notifier; > import org.eclipse.emf.common.notify.impl.NotificationImpl; > import org.eclipse.emf.common.util.URI; > import org.eclipse.swt.graphics.Image; >@@ -33,373 +34,346 @@ > import org.eclipse.xsd.XSDTypeDefinition; > > >-public class XSDSchemaAdapter extends XSDAbstractAdapter >-{ >- protected XSDPackage xsdPackage; >- /** >- * @param adapterFactory >- */ >- public XSDSchemaAdapter(AdapterFactory adapterFactory) >- { >- super(adapterFactory); >- xsdPackage = XSDPackage.eINSTANCE; >- } >- >- public Image getImage(Object element) >- { >- return XSDEditorPlugin.getXSDImage("icons/XSDFile.gif"); >- } >- >- public String getText(Object element) >- { >- XSDSchema xsdSchema = (XSDSchema)element; >- String result = xsdSchema.getSchemaLocation(); >- if (result == null) >- { >- return ""; >- } >- else >- { >- return URI.createURI(result).lastSegment(); >- } >- } >- List children; >- public Object[] getChildren(Object parentElement) >- { >- XSDSchema xsdSchema = ((XSDSchema)parentElement); >- >- children = new ArrayList(); >- >- List directivesList = getDirectives(xsdSchema); >- >- List elementsList = getGlobalElements(xsdSchema); >- >- List attributeGroupList = getAttributeGroupList(xsdSchema); >- >- List attributesList = getAttributeList(xsdSchema); >- >- List groups = getGroups(xsdSchema); >- >- List notations = getNotations(xsdSchema); >- >- List types = getComplexTypes(xsdSchema); >- types.addAll(getSimpleTypes(xsdSchema)); >- >- children.add >- (new CategoryAdapter >- ( //XSDEditPlugin.getString("_UI_Elements_label"), >- XSDEditorPlugin.getXSDString("_UI_GRAPH_DIRECTIVES"), >- XSDEditorPlugin.getPlugin().getIconImage("obj16/directivesheader"), >- directivesList, xsdSchema, CategoryAdapter.DIRECTIVES)); >- children.add >- (new CategoryAdapter >- ( //XSDEditPlugin.getString("_UI_Elements_label"), >- XSDEditorPlugin.getXSDString("_UI_GRAPH_ELEMENTS"), >- XSDEditorPlugin.getPlugin().getIconImage("obj16/elementsheader"), >- elementsList, xsdSchema, CategoryAdapter.ELEMENTS)); >- children.add >- (new CategoryAdapter >- ( //XSDEditPlugin.getString("_UI_Attributes_label"), >- XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTES"), >- XSDEditorPlugin.getPlugin().getIconImage("obj16/attributesheader"), >- attributesList, xsdSchema, CategoryAdapter.ATTRIBUTES)); >- children.add >- (new CategoryAdapter >- (//XSDEditPlugin.getString("_UI_AttributeGroups_label"), >- XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTE_GROUPS"), >- XSDEditorPlugin.getPlugin().getIconImage("obj16/attributegroupsheader"), >- attributeGroupList, xsdSchema, CategoryAdapter.ATTRIBUTE_GROUPS)); >- children.add >- (new CategoryAdapter >- ( //XSDEditPlugin.getString("_UI_Types_label"), >- XSDEditorPlugin.getXSDString("_UI_GRAPH_TYPES"), >- XSDEditorPlugin.getPlugin().getIconImage("obj16/typesheader"), >- types, xsdSchema, CategoryAdapter.TYPES)); >- children.add >- (new CategoryAdapter >- ( // XSDEditPlugin.getString("_UI_ModelGroups_label"), >- XSDEditorPlugin.getXSDString("_UI_GRAPH_GROUPS"), >- XSDEditorPlugin.getPlugin().getIconImage("obj16/groupsheader"), >- groups, xsdSchema, CategoryAdapter.GROUPS)); >- children.add >- (new CategoryAdapter >- ( // XSDEditPlugin.getString("_UI_Notations_label"), >- XSDEditorPlugin.getXSDString("_UI_GRAPH_NOTATIONS"), >- XSDEditorPlugin.getPlugin().getIconImage("obj16/notationsheader"), >- notations, xsdSchema, CategoryAdapter.NOTATIONS)); >-// children.add >-// (new CategoryAdapter >-// ( //XSDEditPlugin.getString("_UI_IdentityConstraints_label"), >-// "Identity Constraints", >-// XSDEditorPlugin.getPlugin().getIconImage("full/obj16/XSDIdentityConstraintDefinitionKey"), >-// xsdSchema.getIdentityConstraintDefinitions(), xsdSchema, CategoryAdapter.IDENTITY_CONSTRAINTS)); >-// children.add >-// (new CategoryAdapter >-// ( // XSDEditPlugin.getString("_UI_Annotations_label"), >-// "Annotations", >-// XSDEditorPlugin.getPlugin().getIconImage("obj16/annotationsheader"), >-// xsdSchema.getAnnotations(), xsdSchema, CategoryAdapter.ANNOTATIONS)); >- >- return children.toArray(); >- >- } >- >- public boolean hasChildren(Object object) >- { >- return true; >- } >- >- public Object getParent(Object object) >- { >- return null; >- } >- >- public void notifyChanged(final Notification msg) >- { >- class CategoryNotification extends NotificationImpl >- { >- protected Object category; >- public CategoryNotification(Object category) >- { >- super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition()); >- this.category = category; >- } >- >- public Object getNotifier() >- { >- return category; >- } >- public Object getFeature() >- { >- return msg.getFeature(); >- } >- } >- >- if (children == null) { >- getChildren(target); >- } >- >- if (msg.getFeature() == xsdPackage.getXSDSchema_Contents()) >- { >- CategoryAdapter adapter = (CategoryAdapter)children.get(0); >- XSDSchema xsdSchema = adapter.getXSDSchema(); >- adapter.setChildren(getDirectives(xsdSchema)); >- this.fireNotifyChanged(new CategoryNotification(adapter)); >- return; >- } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_ElementDeclarations()) >- { >- CategoryAdapter adapter = (CategoryAdapter)children.get(1); >- XSDSchema xsdSchema = adapter.getXSDSchema(); >- adapter.setChildren(getGlobalElements(xsdSchema)); >- this.fireNotifyChanged(new CategoryNotification(adapter)); >- return; >- } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeDeclarations()) >- { >- CategoryAdapter adapter = (CategoryAdapter)children.get(2); >- XSDSchema xsdSchema = adapter.getXSDSchema(); >- adapter.setChildren(getAttributeList(xsdSchema)); >- this.fireNotifyChanged(new CategoryNotification(adapter)); >- return; >- } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeGroupDefinitions()) >- { >- CategoryAdapter adapter = (CategoryAdapter)children.get(3); >- XSDSchema xsdSchema = adapter.getXSDSchema(); >- adapter.setChildren(getAttributeGroupList(xsdSchema)); >- this.fireNotifyChanged(new CategoryNotification(adapter)); >- return; >- } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_TypeDefinitions()) >- { >- CategoryAdapter adapter = (CategoryAdapter)children.get(4); >- XSDSchema xsdSchema = adapter.getXSDSchema(); >- List types = getComplexTypes(xsdSchema); >- types.addAll(getSimpleTypes(xsdSchema)); >- >- adapter.setChildren(types); >- this.fireNotifyChanged(new CategoryNotification(adapter)); >- return; >- } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_ModelGroupDefinitions()) >- { >- CategoryAdapter adapter = (CategoryAdapter)children.get(5); >- XSDSchema xsdSchema = adapter.getXSDSchema(); >- adapter.setChildren(getGroups(xsdSchema)); >- this.fireNotifyChanged(new CategoryNotification(adapter)); >- return; >- } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_NotationDeclarations()) >- { >- CategoryAdapter adapter = (CategoryAdapter)children.get(6); >- XSDSchema xsdSchema = adapter.getXSDSchema(); >- adapter.setChildren(getNotations(xsdSchema)); >- this.fireNotifyChanged(new CategoryNotification(adapter)); >- return; >- } >-// else if (msg.getFeature() == xsdPackage.getXSDSchema_IdentityConstraintDefinitions()) >-// { >-// this.fireNotifyChanged(new CategoryNotification(children.get(7))); >-// return; >-// } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_Annotations()) >- { >-// this.fireNotifyChanged(new CategoryNotification(children.get(7))); >- return; >- } >- else if (msg.getFeature() == xsdPackage.getXSDSchema_SchemaLocation()) >- { >- this.fireNotifyChanged(msg); >- return; >- } >- >- super.notifyChanged(msg); >- } >- >- protected List getDirectives(XSDSchema schema) >- { >- List list = new ArrayList(); >- for (Iterator i = schema.getContents().iterator(); i.hasNext(); ) >- { >- Object o = i.next(); >- if (o instanceof XSDSchemaDirective) >- { >- list.add(o); >- } >- } >- return list; >- } >- >- protected List getAttributeGroupList(XSDSchema xsdSchema) >- { >- List attributeGroupList = new ArrayList(); >- for (Iterator i = xsdSchema.getAttributeGroupDefinitions().iterator(); i.hasNext(); ) >- { >- XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition)i.next(); >- if (attrGroup.getRootContainer() == xsdSchema) >- { >- attributeGroupList.add(attrGroup); >- } >- } >- return attributeGroupList; >- } >- >- protected List getAttributeList(XSDSchema xsdSchema) >- { >- List attributesList = new ArrayList(); >- for (Iterator iter = xsdSchema.getAttributeDeclarations().iterator(); iter.hasNext(); ) >- { >- Object o = iter.next(); >- if (o instanceof XSDAttributeDeclaration) >- { >- XSDAttributeDeclaration attr = (XSDAttributeDeclaration)o; >- if (attr != null) >- { >- if (attr.getTargetNamespace() != null) >- { >- if (!(attr.getTargetNamespace().equals("http://www.w3.org/2001/XMLSchema-instance"))) >- { >- if (attr.getRootContainer() == xsdSchema) >- { >- attributesList.add(attr); >- } >- } >- } >- else >- { >- if (attr.getRootContainer() == xsdSchema) >- { >- attributesList.add(attr); >- } >- } >- } >- } >- } >- return attributesList; >- } >- >- protected List getGlobalElements(XSDSchema schema) >- { >- List elements = schema.getElementDeclarations(); >- List list = new ArrayList(); >- for (Iterator i = elements.iterator(); i.hasNext(); ) >- { >- XSDElementDeclaration elem = (XSDElementDeclaration)i.next(); >- if (elem.getRootContainer() == schema) >- { >- list.add(elem); >- } >- } >- return list; >- } >- >- protected List getComplexTypes(XSDSchema schema) >- { >- List allTypes = schema.getTypeDefinitions(); >- List list = new ArrayList(); >- for (Iterator i = allTypes.iterator(); i.hasNext(); ) >- { >- XSDTypeDefinition td = (XSDTypeDefinition)i.next(); >- if (td instanceof XSDComplexTypeDefinition) >- { >- XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition)td; >- if (ct.getRootContainer() == schema) >- { >- list.add(ct); >- } >- } >- } >- return list; >- } >- >- protected List getSimpleTypes(XSDSchema schema) >- { >- List allTypes = schema.getTypeDefinitions(); >- List list = new ArrayList(); >- for (Iterator i = allTypes.iterator(); i.hasNext(); ) >- { >- XSDTypeDefinition td = (XSDTypeDefinition)i.next(); >- if (td instanceof XSDSimpleTypeDefinition) >- { >- XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition)td; >- if (st.getRootContainer() == schema) >- { >- list.add(st); >- } >- } >- } >- return list; >- } >- >- protected List getGroups(XSDSchema schema) >- { >- List groups = schema.getModelGroupDefinitions(); >- List list = new ArrayList(); >- for (Iterator i = groups.iterator(); i.hasNext(); ) >- { >- XSDModelGroupDefinition group = (XSDModelGroupDefinition)i.next(); >- if (group.getRootContainer() == schema) >- { >- list.add(group); >- } >- } >- return list; >- } >- >- protected List getNotations(XSDSchema schema) >- { >- List notations = schema.getNotationDeclarations(); >- List list = new ArrayList(); >- for (Iterator i = notations.iterator(); i.hasNext(); ) >- { >- XSDNotationDeclaration notation = (XSDNotationDeclaration)i.next(); >- if (notation.getRootContainer() == schema) >- { >- list.add(notation); >- } >- } >- return list; >- } >+public class XSDSchemaAdapter extends XSDAbstractAdapter { >+ protected XSDPackage xsdPackage; >+ >+ /** >+ * @param adapterFactory >+ */ >+ public XSDSchemaAdapter(AdapterFactory adapterFactory) { >+ super(adapterFactory); >+ xsdPackage = XSDPackage.eINSTANCE; >+ } >+ >+ public Image getImage(Object element) { >+ return XSDEditorPlugin.getXSDImage("icons/XSDFile.gif"); >+ } >+ >+ public String getText(Object element) { >+ XSDSchema xsdSchema = (XSDSchema) element; >+ String result = xsdSchema.getSchemaLocation(); >+ if (result == null) { >+ return ""; >+ } >+ else { >+ return URI.createURI(result).lastSegment(); >+ } >+ } >+ >+ List children; >+ private CategoryAdapter fDirectivesCategory; >+ private CategoryAdapter fElementsCategory; >+ private CategoryAdapter fAttributesCategory; >+ private CategoryAdapter fAttributeGroupsCategory; >+ private CategoryAdapter fTypesCategory; >+ private CategoryAdapter fGroupsCategory; >+ private CategoryAdapter fNotationsCategory; >+ >+ /** >+ * Create all the category adapters >+ * >+ * @param xsdSchema >+ */ >+ private void createCategoryAdapters(XSDSchema xsdSchema) { >+ List directivesList = getDirectives(xsdSchema); >+ List elementsList = getGlobalElements(xsdSchema); >+ List attributeGroupList = getAttributeGroupList(xsdSchema); >+ List attributesList = getAttributeList(xsdSchema); >+ List groups = getGroups(xsdSchema); >+ List notations = getNotations(xsdSchema); >+ List types = getComplexTypes(xsdSchema); >+ types.addAll(getSimpleTypes(xsdSchema)); >+ >+ fDirectivesCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Elements_label"), >+ XSDEditorPlugin.getXSDString("_UI_GRAPH_DIRECTIVES"), XSDEditorPlugin.getPlugin().getIconImage("obj16/directivesheader"), directivesList, xsdSchema, CategoryAdapter.DIRECTIVES); >+ fElementsCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Elements_label"), >+ XSDEditorPlugin.getXSDString("_UI_GRAPH_ELEMENTS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/elementsheader"), elementsList, xsdSchema, CategoryAdapter.ELEMENTS); >+ fAttributesCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Attributes_label"), >+ XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTES"), XSDEditorPlugin.getPlugin().getIconImage("obj16/attributesheader"), attributesList, xsdSchema, CategoryAdapter.ATTRIBUTES); >+ fAttributeGroupsCategory = new CategoryAdapter(// XSDEditPlugin.getString("_UI_AttributeGroups_label"), >+ XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTE_GROUPS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/attributegroupsheader"), attributeGroupList, xsdSchema, CategoryAdapter.ATTRIBUTE_GROUPS); >+ fTypesCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Types_label"), >+ XSDEditorPlugin.getXSDString("_UI_GRAPH_TYPES"), XSDEditorPlugin.getPlugin().getIconImage("obj16/typesheader"), types, xsdSchema, CategoryAdapter.TYPES); >+ fGroupsCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_ModelGroups_label"), >+ XSDEditorPlugin.getXSDString("_UI_GRAPH_GROUPS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/groupsheader"), groups, xsdSchema, CategoryAdapter.GROUPS); >+ fNotationsCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Notations_label"), >+ XSDEditorPlugin.getXSDString("_UI_GRAPH_NOTATIONS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/notationsheader"), notations, xsdSchema, CategoryAdapter.NOTATIONS); >+ } >+ >+ public void setTarget(Notifier newTarget) { >+ super.setTarget(newTarget); >+ >+ XSDSchema xsdSchema = ((XSDSchema) newTarget); >+ createCategoryAdapters(xsdSchema); >+ } >+ >+ public Object[] getChildren(Object parentElement) { >+ XSDSchema xsdSchema = ((XSDSchema) parentElement); >+ >+ children = new ArrayList(); >+ >+ // just set categoryadapters' children if category adapters are >+ // already created >+ if (fDirectivesCategory != null) { >+ List directivesList = getDirectives(xsdSchema); >+ List elementsList = getGlobalElements(xsdSchema); >+ List attributeGroupList = getAttributeGroupList(xsdSchema); >+ List attributesList = getAttributeList(xsdSchema); >+ List groups = getGroups(xsdSchema); >+ List notations = getNotations(xsdSchema); >+ List types = getComplexTypes(xsdSchema); >+ types.addAll(getSimpleTypes(xsdSchema)); >+ >+ fDirectivesCategory.setChildren(directivesList); >+ fElementsCategory.setChildren(elementsList); >+ fAttributesCategory.setChildren(attributesList); >+ fAttributeGroupsCategory.setChildren(attributeGroupList); >+ fTypesCategory.setChildren(types); >+ fGroupsCategory.setChildren(groups); >+ fNotationsCategory.setChildren(notations); >+ >+ // children.add >+ // (new CategoryAdapter >+ // ( //XSDEditPlugin.getString("_UI_IdentityConstraints_label"), >+ // "Identity Constraints", >+ // XSDEditorPlugin.getPlugin().getIconImage("full/obj16/XSDIdentityConstraintDefinitionKey"), >+ // xsdSchema.getIdentityConstraintDefinitions(), xsdSchema, >+ // CategoryAdapter.IDENTITY_CONSTRAINTS)); >+ // children.add >+ // (new CategoryAdapter >+ // ( // XSDEditPlugin.getString("_UI_Annotations_label"), >+ // "Annotations", >+ // XSDEditorPlugin.getPlugin().getIconImage("obj16/annotationsheader"), >+ // xsdSchema.getAnnotations(), xsdSchema, >+ // CategoryAdapter.ANNOTATIONS)); >+ } >+ else { >+ createCategoryAdapters(xsdSchema); >+ } >+ >+ children.add(fDirectivesCategory); >+ children.add(fElementsCategory); >+ children.add(fAttributesCategory); >+ children.add(fAttributeGroupsCategory); >+ children.add(fTypesCategory); >+ children.add(fGroupsCategory); >+ children.add(fNotationsCategory); >+ >+ return children.toArray(); >+ } >+ >+ public boolean hasChildren(Object object) { >+ return true; >+ } >+ >+ public Object getParent(Object object) { >+ return null; >+ } >+ >+ public void notifyChanged(final Notification msg) { >+ class CategoryNotification extends NotificationImpl { >+ protected Object category; >+ >+ public CategoryNotification(Object category) { >+ super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition()); >+ this.category = category; >+ } >+ >+ public Object getNotifier() { >+ return category; >+ } >+ >+ public Object getFeature() { >+ return msg.getFeature(); >+ } >+ } >+ >+ if (children == null) { >+ getChildren(target); >+ } >+ >+ if (msg.getFeature() == xsdPackage.getXSDSchema_Contents()) { >+ CategoryAdapter adapter = (CategoryAdapter) children.get(0); >+ XSDSchema xsdSchema = adapter.getXSDSchema(); >+ adapter.setChildren(getDirectives(xsdSchema)); >+ this.fireNotifyChanged(new CategoryNotification(adapter)); >+ return; >+ } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_ElementDeclarations()) { >+ CategoryAdapter adapter = (CategoryAdapter) children.get(1); >+ XSDSchema xsdSchema = adapter.getXSDSchema(); >+ adapter.setChildren(getGlobalElements(xsdSchema)); >+ this.fireNotifyChanged(new CategoryNotification(adapter)); >+ return; >+ } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeDeclarations()) { >+ CategoryAdapter adapter = (CategoryAdapter) children.get(2); >+ XSDSchema xsdSchema = adapter.getXSDSchema(); >+ adapter.setChildren(getAttributeList(xsdSchema)); >+ this.fireNotifyChanged(new CategoryNotification(adapter)); >+ return; >+ } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeGroupDefinitions()) { >+ CategoryAdapter adapter = (CategoryAdapter) children.get(3); >+ XSDSchema xsdSchema = adapter.getXSDSchema(); >+ adapter.setChildren(getAttributeGroupList(xsdSchema)); >+ this.fireNotifyChanged(new CategoryNotification(adapter)); >+ return; >+ } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_TypeDefinitions()) { >+ CategoryAdapter adapter = (CategoryAdapter) children.get(4); >+ XSDSchema xsdSchema = adapter.getXSDSchema(); >+ List types = getComplexTypes(xsdSchema); >+ types.addAll(getSimpleTypes(xsdSchema)); >+ >+ adapter.setChildren(types); >+ this.fireNotifyChanged(new CategoryNotification(adapter)); >+ return; >+ } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_ModelGroupDefinitions()) { >+ CategoryAdapter adapter = (CategoryAdapter) children.get(5); >+ XSDSchema xsdSchema = adapter.getXSDSchema(); >+ adapter.setChildren(getGroups(xsdSchema)); >+ this.fireNotifyChanged(new CategoryNotification(adapter)); >+ return; >+ } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_NotationDeclarations()) { >+ CategoryAdapter adapter = (CategoryAdapter) children.get(6); >+ XSDSchema xsdSchema = adapter.getXSDSchema(); >+ adapter.setChildren(getNotations(xsdSchema)); >+ this.fireNotifyChanged(new CategoryNotification(adapter)); >+ return; >+ } >+ // else if (msg.getFeature() == >+ // xsdPackage.getXSDSchema_IdentityConstraintDefinitions()) >+ // { >+ // this.fireNotifyChanged(new CategoryNotification(children.get(7))); >+ // return; >+ // } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_Annotations()) { >+ // this.fireNotifyChanged(new >+ // CategoryNotification(children.get(7))); >+ return; >+ } >+ else if (msg.getFeature() == xsdPackage.getXSDSchema_SchemaLocation()) { >+ this.fireNotifyChanged(msg); >+ return; >+ } >+ >+ super.notifyChanged(msg); >+ } >+ >+ protected List getDirectives(XSDSchema schema) { >+ List list = new ArrayList(); >+ for (Iterator i = schema.getContents().iterator(); i.hasNext();) { >+ Object o = i.next(); >+ if (o instanceof XSDSchemaDirective) { >+ list.add(o); >+ } >+ } >+ return list; >+ } >+ >+ protected List getAttributeGroupList(XSDSchema xsdSchema) { >+ List attributeGroupList = new ArrayList(); >+ for (Iterator i = xsdSchema.getAttributeGroupDefinitions().iterator(); i.hasNext();) { >+ XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) i.next(); >+ if (attrGroup.getRootContainer() == xsdSchema) { >+ attributeGroupList.add(attrGroup); >+ } >+ } >+ return attributeGroupList; >+ } >+ >+ protected List getAttributeList(XSDSchema xsdSchema) { >+ List attributesList = new ArrayList(); >+ for (Iterator iter = xsdSchema.getAttributeDeclarations().iterator(); iter.hasNext();) { >+ Object o = iter.next(); >+ if (o instanceof XSDAttributeDeclaration) { >+ XSDAttributeDeclaration attr = (XSDAttributeDeclaration) o; >+ if (attr != null) { >+ if (attr.getTargetNamespace() != null) { >+ if (!(attr.getTargetNamespace().equals("http://www.w3.org/2001/XMLSchema-instance"))) { >+ if (attr.getRootContainer() == xsdSchema) { >+ attributesList.add(attr); >+ } >+ } >+ } >+ else { >+ if (attr.getRootContainer() == xsdSchema) { >+ attributesList.add(attr); >+ } >+ } >+ } >+ } >+ } >+ return attributesList; >+ } >+ >+ protected List getGlobalElements(XSDSchema schema) { >+ List elements = schema.getElementDeclarations(); >+ List list = new ArrayList(); >+ for (Iterator i = elements.iterator(); i.hasNext();) { >+ XSDElementDeclaration elem = (XSDElementDeclaration) i.next(); >+ if (elem.getRootContainer() == schema) { >+ list.add(elem); >+ } >+ } >+ return list; >+ } >+ >+ protected List getComplexTypes(XSDSchema schema) { >+ List allTypes = schema.getTypeDefinitions(); >+ List list = new ArrayList(); >+ for (Iterator i = allTypes.iterator(); i.hasNext();) { >+ XSDTypeDefinition td = (XSDTypeDefinition) i.next(); >+ if (td instanceof XSDComplexTypeDefinition) { >+ XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) td; >+ if (ct.getRootContainer() == schema) { >+ list.add(ct); >+ } >+ } >+ } >+ return list; >+ } >+ >+ protected List getSimpleTypes(XSDSchema schema) { >+ List allTypes = schema.getTypeDefinitions(); >+ List list = new ArrayList(); >+ for (Iterator i = allTypes.iterator(); i.hasNext();) { >+ XSDTypeDefinition td = (XSDTypeDefinition) i.next(); >+ if (td instanceof XSDSimpleTypeDefinition) { >+ XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) td; >+ if (st.getRootContainer() == schema) { >+ list.add(st); >+ } >+ } >+ } >+ return list; >+ } >+ >+ protected List getGroups(XSDSchema schema) { >+ List groups = schema.getModelGroupDefinitions(); >+ List list = new ArrayList(); >+ for (Iterator i = groups.iterator(); i.hasNext();) { >+ XSDModelGroupDefinition group = (XSDModelGroupDefinition) i.next(); >+ if (group.getRootContainer() == schema) { >+ list.add(group); >+ } >+ } >+ return list; >+ } >+ >+ protected List getNotations(XSDSchema schema) { >+ List notations = schema.getNotationDeclarations(); >+ List list = new ArrayList(); >+ for (Iterator i = notations.iterator(); i.hasNext();) { >+ XSDNotationDeclaration notation = (XSDNotationDeclaration) i.next(); >+ if (notation.getRootContainer() == schema) { >+ list.add(notation); >+ } >+ } >+ return list; >+ } > > } >Index: src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/xsd/plugins/org.eclipse.wst.xsd.ui/src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java,v >retrieving revision 1.5 >diff -u -r1.5 OpenOnSelectionHelper.java >--- src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java 3 Oct 2005 22:42:33 -0000 1.5 >+++ src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java 26 Oct 2005 17:56:01 -0000 >@@ -24,6 +24,7 @@ > import org.eclipse.ui.part.FileEditorInput; > import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; > import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; > import org.eclipse.wst.xsd.ui.internal.XSDEditor; > import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin; > import org.eclipse.wst.xsd.ui.internal.XSDTextEditor; >@@ -46,15 +47,22 @@ > public class OpenOnSelectionHelper > { > >- protected XSDTextEditor textEditor; >- >+ protected StructuredTextEditor textEditor; >+ protected XSDSchema xsdSchema; >+ > /** >- * Constructor for OpenOnSelectionHelper. >+ * @deprecated Constructor for OpenOnSelectionHelper. > */ > public OpenOnSelectionHelper(XSDTextEditor textEditor) > { >- this.textEditor = textEditor; > } >+ >+ public OpenOnSelectionHelper(StructuredTextEditor textEditor, XSDSchema xsdSchema) >+ { >+ this.textEditor = textEditor; >+ this.xsdSchema = xsdSchema; >+ } >+ > > boolean lastResult; > >@@ -94,7 +102,7 @@ > > protected boolean revealObject(final XSDConcreteComponent component) > { >- if (component.getRootContainer().equals(textEditor.getXSDSchema())) >+ if (component.getRootContainer().equals(xsdSchema)) > { > Node element = component.getElement(); > if (element instanceof IndexedRegion) >@@ -125,7 +133,8 @@ > { > try > { >- IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), textEditor.getXSDEditor().getEditorSite().getId()); >+ // IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), textEditor.getXSDEditor().getEditorSite().getId()); >+ IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.getPlugin().PLUGIN_ID); > if (editorPart instanceof XSDEditor) > { > ((XSDEditor)editorPart).openOnGlobalReference(component); >@@ -146,7 +155,7 @@ > > public void openOnGlobalReference(XSDConcreteComponent comp) > { >- XSDSchema schema = textEditor.getXSDSchema(); >+ XSDSchema schema = xsdSchema; > String name = null; > if (comp instanceof XSDNamedComponent) > { >@@ -191,7 +200,6 @@ > for (Iterator i = selectedNodes.iterator(); i.hasNext();) > { > Object obj = i.next(); >- XSDSchema xsdSchema = textEditor.getXSDSchema(); > if (xsdSchema != null) > { > XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node)obj); >Index: src/org/eclipse/wst/xsd/ui/internal/StructuredTextViewerConfigurationXSD.java >=================================================================== >RCS file: src/org/eclipse/wst/xsd/ui/internal/StructuredTextViewerConfigurationXSD.java >diff -N src/org/eclipse/wst/xsd/ui/internal/StructuredTextViewerConfigurationXSD.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xsd/ui/internal/StructuredTextViewerConfigurationXSD.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,44 @@ >+/* >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * Jens Lukowski/Innoopract - initial renaming/restructuring >+ * >+ */ >+package org.eclipse.wst.xsd.ui.internal; >+ >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; >+import org.eclipse.jface.text.source.ISourceViewer; >+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; >+import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML; >+ >+/** >+ * Configuration for editing XSD content type >+ */ >+public class StructuredTextViewerConfigurationXSD extends StructuredTextViewerConfigurationXML { >+ public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { >+ if (sourceViewer == null || !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED)) >+ return null; >+ >+ List allDetectors = new ArrayList(0); >+ // add XSD Hyperlink detector >+ allDetectors.add(new XSDHyperlinkDetector()); >+ >+ IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer); >+ for (int m = 0; m < superDetectors.length; m++) { >+ IHyperlinkDetector detector = superDetectors[m]; >+ if (!allDetectors.contains(detector)) { >+ allDetectors.add(detector); >+ } >+ } >+ return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]); >+ } >+} >Index: src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlineConfiguration.java >=================================================================== >RCS file: src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlineConfiguration.java >diff -N src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlineConfiguration.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlineConfiguration.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,216 @@ >+/* >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * Jens Lukowski/Innoopract - initial renaming/restructuring >+ * >+ */ >+package org.eclipse.wst.xsd.ui.internal; >+ >+import java.util.ArrayList; >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.jface.action.IMenuListener; >+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.SWT; >+import org.eclipse.swt.events.KeyAdapter; >+import org.eclipse.swt.events.KeyEvent; >+import org.eclipse.swt.events.KeyListener; >+import org.eclipse.swt.widgets.Tree; >+import org.eclipse.swt.widgets.TreeItem; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; >+import org.eclipse.wst.xsd.ui.internal.actions.OpenSchemaAction; >+import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider; >+import org.eclipse.wst.xsd.ui.internal.provider.XSDContentProvider; >+import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl; >+import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; >+import org.eclipse.xsd.XSDSchema; >+import org.eclipse.xsd.XSDSchemaDirective; >+import org.w3c.dom.Attr; >+import org.w3c.dom.Element; >+import org.w3c.dom.Node; >+ >+/** >+ * Outline configuration for XSD >+ */ >+public class XSDContentOutlineConfiguration extends ContentOutlineConfiguration { >+ private XSDContentProvider fContentProvider; >+ private ILabelProvider fLabelProvider; >+ private KeyListener[] fKeyListeners = null; >+ private IMenuListener fMenuListener = null; >+ private XSDEditor fEditor = null; >+ >+ public IContentProvider getContentProvider(TreeViewer viewer) { >+ if (fContentProvider == null) { >+ fContentProvider = new XSDContentProvider(XSDModelAdapterFactoryImpl.getInstance()); >+ } >+ return fContentProvider; >+ } >+ >+ public ILabelProvider getLabelProvider(TreeViewer viewer) { >+ if (fLabelProvider == null) { >+ fLabelProvider = new XSDAdapterFactoryLabelProvider(XSDModelAdapterFactoryImpl.getInstance()); >+ } >+ return fLabelProvider; >+ } >+ >+ public IMenuListener getMenuListener(TreeViewer viewer) { >+ if (fMenuListener == null) { >+ // ISSUE: what happens if cannot get XSD Editor? (See >+ // getXSDEditor comment) >+ if (getXSDEditor() != null) >+ fMenuListener = new XSDMenuListener(getXSDEditor().getSelectionManager()); >+ } >+ return fMenuListener; >+ } >+ >+ public KeyListener[] getKeyListeners(TreeViewer viewer) { >+ if (fKeyListeners == null) { >+ final TreeViewer finalViewer = viewer; >+ KeyAdapter keyListener = new KeyAdapter() { >+ public void keyReleased(KeyEvent e) { >+ if (e.character == SWT.DEL) { >+ IMenuListener menuListener = getMenuListener(finalViewer); >+ if (menuListener instanceof XSDMenuListener) >+ ((XSDMenuListener) menuListener).getDeleteAction().run(); >+ } >+ else if (e.keyCode == SWT.F3) // open editor on any >+ // include/import/redefine >+ { >+ if (e.widget instanceof Tree) { >+ Tree tree = (Tree) e.widget; >+ TreeItem[] selection = tree.getSelection(); >+ if (selection.length > 0) { >+ if (selection[0].getData() instanceof XSDSchemaDirective) { >+ XSDSchemaDirective comp = (XSDSchemaDirective) selection[0].getData(); >+ OpenSchemaAction openSchema = new OpenSchemaAction(XSDEditorPlugin.getXSDString("_UI_ACTION_OPEN_SCHEMA"), comp); >+ openSchema.run(); >+ } >+ } >+ } >+ } >+ } >+ }; >+ fKeyListeners = new KeyListener[]{keyListener}; >+ } >+ >+ return fKeyListeners; >+ } >+ >+ public ISelection getSelection(TreeViewer viewer, ISelection selection) { >+ ISelection sel = selection; >+ >+ if (selection instanceof IStructuredSelection) { >+ List xsdSelections = new ArrayList(); >+ for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { >+ Object domNode = i.next(); >+ Object xsdNode = getXSDNode(domNode, viewer); >+ if (xsdNode != null) { >+ xsdSelections.add(xsdNode); >+ } >+ } >+ >+ if (!xsdSelections.isEmpty()) { >+ sel = new StructuredSelection(xsdSelections); >+ } >+ } >+ return sel; >+ } >+ >+ /** >+ * Determines XSD node based on object (DOM node) >+ * >+ * @param object >+ * @return >+ */ >+ private Object getXSDNode(Object object, TreeViewer viewer) { >+ // get the element node >+ Element element = null; >+ if (object instanceof Node) { >+ Node node = (Node) object; >+ if (node != null) { >+ if (node.getNodeType() == Node.ELEMENT_NODE) { >+ element = (Element) node; >+ } >+ else if (node.getNodeType() == Node.ATTRIBUTE_NODE) { >+ element = ((Attr) node).getOwnerElement(); >+ } >+ } >+ } >+ Object o = element; >+ if (element != null) { >+ Object modelObject = getXSDSchema(viewer).getCorrespondingComponent(element); >+ if (modelObject != null) { >+ o = modelObject; >+ } >+ } >+ return o; >+ } >+ >+ /** >+ * Gets the xsd schema from treeviewer's input >+ * >+ * @param model >+ * (of type Object but really should be IStructuredModel) >+ * @return Definition >+ */ >+ private XSDSchema getXSDSchema(TreeViewer viewer) { >+ XSDSchema xsdSchema = null; >+ Object model = null; >+ if (viewer != null) >+ model = viewer.getInput(); >+ >+ if (model instanceof IDOMModel) { >+ IDOMDocument domDoc = ((IDOMModel) model).getDocument(); >+ if (domDoc != null) { >+ XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class); >+ /* >+ * ISSUE: Didn't want to go through initializing schema if it >+ * does not already exist, so just attempted to get existing >+ * adapter. If doesn't exist, just don't bother working. >+ */ >+ if (modelAdapter != null) >+ xsdSchema = modelAdapter.getSchema(); >+ } >+ } >+ return xsdSchema; >+ } >+ >+ // ISSUE: There are some cases where outline comes up before editor >+ private XSDEditor getXSDEditor() { >+ if (fEditor == null) { >+ IWorkbench workbench = PlatformUI.getWorkbench(); >+ if (workbench != null) { >+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); >+ if (window != null) { >+ IWorkbenchPage page = window.getActivePage(); >+ if (page != null) { >+ IEditorPart editor = page.getActiveEditor(); >+ if (editor instanceof XSDEditor) >+ fEditor = (XSDEditor) editor; >+ } >+ } >+ } >+ } >+ return fEditor; >+ } >+ >+} >Index: src/org/eclipse/wst/xsd/ui/internal/XSDHyperlink.java >=================================================================== >RCS file: src/org/eclipse/wst/xsd/ui/internal/XSDHyperlink.java >diff -N src/org/eclipse/wst/xsd/ui/internal/XSDHyperlink.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xsd/ui/internal/XSDHyperlink.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/* >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * Jens Lukowski/Innoopract - initial renaming/restructuring >+ * >+ */ >+package org.eclipse.wst.xsd.ui.internal; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.ide.IDE; >+import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; >+import org.eclipse.xsd.XSDConcreteComponent; >+ >+/** >+ * WSDL Hyperlink that knows how to open links from wsdl files >+ */ >+public class XSDHyperlink implements IHyperlink { >+ private IRegion fRegion; >+ private XSDConcreteComponent fComponent; >+ >+ public XSDHyperlink(IRegion region, XSDConcreteComponent component) { >+ fRegion = region; >+ fComponent = component; >+ } >+ >+ public IRegion getHyperlinkRegion() { >+ return fRegion; >+ } >+ >+ public String getTypeLabel() { >+ return null; >+ } >+ >+ public String getHyperlinkText() { >+ return null; >+ } >+ >+ public void open() { >+ // if hyperlink points to schema already in editor, select the correct >+ // node >+ // if (fComponent.getRootContainer().equals(xsdSchema)) { >+ // Node element = fComponent.getElement(); >+ // if (element instanceof IndexedRegion) { >+ // IndexedRegion indexNode = (IndexedRegion) element; >+ // textEditor.getTextViewer().setRangeIndication(indexNode.getStartOffset(), >+ // indexNode.getEndOffset() - indexNode.getStartOffset(), true); >+ // } >+ // } >+ // else { >+ if (fComponent.getSchema() != null) { >+ String schemaLocation = URIHelper.removePlatformResourceProtocol(fComponent.getSchema().getSchemaLocation()); >+ IPath schemaPath = new Path(schemaLocation); >+ IFile schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath); >+ if (schemaFile != null && schemaFile.exists()) { >+ IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ if (workbenchWindow != null) { >+ IWorkbenchPage page = workbenchWindow.getActivePage(); >+ try { >+ IEditorPart editorPart = IDE.openEditor(page, schemaFile, true); >+ if (editorPart instanceof XSDEditor) { >+ ((XSDEditor) editorPart).openOnGlobalReference(fComponent); >+ } >+ } >+ catch (PartInitException pie) { >+ Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie); >+ } >+ } >+ } >+ } >+ } >+} >Index: src/org/eclipse/wst/xsd/ui/internal/XSDHyperlinkDetector.java >=================================================================== >RCS file: src/org/eclipse/wst/xsd/ui/internal/XSDHyperlinkDetector.java >diff -N src/org/eclipse/wst/xsd/ui/internal/XSDHyperlinkDetector.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xsd/ui/internal/XSDHyperlinkDetector.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,252 @@ >+/* >+ * Copyright (c) 2005 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Common Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/cpl-v10.html >+ * >+ * Contributors: >+ * IBM - Initial API and implementation >+ * Jens Lukowski/Innoopract - initial renaming/restructuring >+ * >+ */ >+package org.eclipse.wst.xsd.ui.internal; >+ >+import java.util.ArrayList; >+import java.util.List; >+ >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.ITextViewer; >+import org.eclipse.jface.text.Region; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; >+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.xml.core.internal.provisional.document.IDOMDocument; >+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; >+import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter; >+import org.eclipse.xsd.XSDAttributeDeclaration; >+import org.eclipse.xsd.XSDAttributeGroupDefinition; >+import org.eclipse.xsd.XSDConcreteComponent; >+import org.eclipse.xsd.XSDElementDeclaration; >+import org.eclipse.xsd.XSDIdentityConstraintDefinition; >+import org.eclipse.xsd.XSDModelGroupDefinition; >+import org.eclipse.xsd.XSDSchema; >+import org.eclipse.xsd.XSDSchemaDirective; >+import org.eclipse.xsd.XSDSimpleTypeDefinition; >+import org.eclipse.xsd.XSDTypeDefinition; >+import org.eclipse.xsd.util.XSDConstants; >+import org.w3c.dom.Attr; >+import org.w3c.dom.Node; >+ >+/** >+ * Detects hyperlinks for XSD files >+ */ >+public class XSDHyperlinkDetector implements IHyperlinkDetector { >+ /** >+ * Gets the xsd schema from document >+ * >+ * @param document >+ * @return XSDSchema or null of one does not exist yet for document >+ */ >+ private XSDSchema getXSDSchema(IDocument document) { >+ XSDSchema schema = null; >+ IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document); >+ if (model != null) { >+ try { >+ if (model instanceof IDOMModel) { >+ IDOMDocument domDoc = ((IDOMModel) model).getDocument(); >+ if (domDoc != null) { >+ XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class); >+ /* >+ * ISSUE: Didn't want to go through initializing >+ * schema if it does not already exist, so just >+ * attempted to get existing adapter. If doesn't >+ * exist, just don't bother working. >+ */ >+ if (modelAdapter != null) >+ schema = modelAdapter.getSchema(); >+ } >+ } >+ } >+ finally { >+ model.releaseFromRead(); >+ } >+ } >+ return schema; >+ } >+ >+ /** >+ * >+ * @param xsdSchema >+ * cannot be null >+ * @param node >+ * cannot be null >+ * @return XSDConcreteComponent >+ */ >+ private XSDConcreteComponent getXSDComponent(XSDSchema xsdSchema, Node node) { >+ XSDConcreteComponent objectToReveal = null; >+ >+ XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node) node); >+ if (xsdComp instanceof XSDElementDeclaration) { >+ XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp; >+ if (elementDecl.isElementDeclarationReference()) { >+ objectToReveal = elementDecl.getResolvedElementDeclaration(); >+ } >+ else { >+ XSDConcreteComponent typeDef = null; >+ if (elementDecl.getAnonymousTypeDefinition() == null) { >+ typeDef = elementDecl.getTypeDefinition(); >+ } >+ >+ XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation(); >+ >+ if (typeDef != null && subGroupAffiliation != null) { >+ // we have 2 things we can navigate to, if the >+ // cursor is anywhere on the substitution >+ // attribute >+ // then jump to that, otherwise just go to the >+ // typeDef. >+ if (node instanceof Attr && ((Attr) node).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) { >+ objectToReveal = subGroupAffiliation; >+ } >+ else { >+ // try to reveal the type now. On success, >+ // then we return true. >+ // if we fail, set the substitution group >+ // as >+ // the object to reveal as a backup plan. >+ // ISSUE: how to set backup? >+ // if (revealObject(typeDef)) { >+ objectToReveal = typeDef; >+ // } >+ // else { >+ // objectToReveal = subGroupAffiliation; >+ // } >+ } >+ } >+ else { >+ // one or more of these is null. If the >+ // typeDef is >+ // non-null, use it. Otherwise >+ // try and use the substitution group >+ objectToReveal = typeDef != null ? typeDef : subGroupAffiliation; >+ } >+ } >+ } >+ else if (xsdComp instanceof XSDModelGroupDefinition) { >+ XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp; >+ if (elementDecl.isModelGroupDefinitionReference()) { >+ objectToReveal = elementDecl.getResolvedModelGroupDefinition(); >+ } >+ } >+ else if (xsdComp instanceof XSDAttributeDeclaration) { >+ XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp; >+ if (attrDecl.isAttributeDeclarationReference()) { >+ objectToReveal = attrDecl.getResolvedAttributeDeclaration(); >+ } >+ else if (attrDecl.getAnonymousTypeDefinition() == null) { >+ objectToReveal = attrDecl.getTypeDefinition(); >+ } >+ } >+ else if (xsdComp instanceof XSDAttributeGroupDefinition) { >+ XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp; >+ if (attrGroupDef.isAttributeGroupDefinitionReference()) { >+ objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition(); >+ } >+ } >+ else if (xsdComp instanceof XSDIdentityConstraintDefinition) { >+ XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp; >+ if (idConstraintDef.getReferencedKey() != null) { >+ objectToReveal = idConstraintDef.getReferencedKey(); >+ } >+ } >+ else if (xsdComp instanceof XSDSimpleTypeDefinition) { >+ XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp; >+ objectToReveal = typeDef.getItemTypeDefinition(); >+ if (objectToReveal == null) { >+ // if itemType attribute is not set, then check >+ // for memberType >+ List memberTypes = typeDef.getMemberTypeDefinitions(); >+ if (memberTypes != null && memberTypes.size() > 0) { >+ objectToReveal = (XSDConcreteComponent) memberTypes.get(0); >+ } >+ } >+ } >+ else if (xsdComp instanceof XSDTypeDefinition) { >+ XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp; >+ objectToReveal = typeDef.getBaseType(); >+ } >+ else if (xsdComp instanceof XSDSchemaDirective) { >+ XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp; >+ // String schemaLocation = >+ // URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation()); >+ // openXSDEditor(schemaLocation); >+ // return false; >+ objectToReveal = directive.getResolvedSchema(); >+ } >+ return objectToReveal; >+ } >+ >+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { >+ // for now, only capable of creating 1 hyperlink >+ List hyperlinks = new ArrayList(0); >+ >+ if (region != null && textViewer != null) { >+ IDocument document = textViewer.getDocument(); >+ Node node = getCurrentNode(document, region.getOffset()); >+ if (node != null) { >+ XSDSchema xsdSchema = getXSDSchema(textViewer.getDocument()); >+ if (xsdSchema != null) { >+ XSDConcreteComponent objectToReveal = getXSDComponent(xsdSchema, node); >+ // now reveal the object if this isn't null >+ if (objectToReveal != null) { >+ IRegion nodeRegion = region; >+ if (node instanceof IndexedRegion) { >+ IndexedRegion indexed = (IndexedRegion) node; >+ int start = indexed.getStartOffset(); >+ int end = indexed.getEndOffset(); >+ nodeRegion = new Region(start, end - start); >+ } >+ hyperlinks.add(new XSDHyperlink(nodeRegion, objectToReveal)); >+ } >+ } >+ } >+ } >+ >+ if (hyperlinks.size() == 0) >+ return null; >+ return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[0]); >+ } >+ >+ /** >+ * Returns the node the cursor is currently on in the document. null if no >+ * node is selected >+ * >+ * @param offset >+ * @return Node either element, doctype, text, or null >+ */ >+ private Node getCurrentNode(IDocument document, int offset) { >+ // get the current node at the offset (returns either: element, >+ // doctype, text) >+ IndexedRegion inode = null; >+ IStructuredModel sModel = null; >+ try { >+ sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); >+ inode = sModel.getIndexedRegion(offset); >+ if (inode == null) >+ inode = sModel.getIndexedRegion(offset - 1); >+ } >+ finally { >+ if (sModel != null) >+ sModel.releaseFromRead(); >+ } >+ >+ if (inode instanceof Node) { >+ return (Node) inode; >+ } >+ return null; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 112884
:
28524
| 28810