Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 112884 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+6 lines)
Lines 90-95 Link Here
90
			type="preferencepages"
90
			type="preferencepages"
91
			value="org.eclipse.wst.xsd.ui.internal.preferences.XSDPreferencePage"
91
			value="org.eclipse.wst.xsd.ui.internal.preferences.XSDPreferencePage"
92
			target="org.eclipse.wst.xsd.ui.internal.XSDEditor.source" />
92
			target="org.eclipse.wst.xsd.ui.internal.XSDEditor.source" />
93
		<sourceViewerConfiguration
94
			class="org.eclipse.wst.xsd.ui.internal.StructuredTextViewerConfigurationXSD"
95
			target="org.eclipse.wst.xsd.core.xsdsource" />
96
		<contentOutlineConfiguration
97
			class="org.eclipse.wst.xsd.ui.internal.XSDContentOutlineConfiguration"
98
			target="org.eclipse.wst.xsd.core.xsdsource" />
93
	</extension>
99
	</extension>
94
100
95
	<!-- ==================================================== -->
101
	<!-- ==================================================== -->
(-)src/org/eclipse/wst/xsd/ui/internal/XSDActionBarContributor.java (-1 / +1 lines)
Lines 201-207 Link Here
201
      xsdEditor = (XSDEditor) targetEditor;
201
      xsdEditor = (XSDEditor) targetEditor;
202
      reloadDependenciesAction.setEditor((XSDEditor)targetEditor);
202
      reloadDependenciesAction.setEditor((XSDEditor)targetEditor);
203
203
204
      textEditor = ((XSDEditor)targetEditor).getXSDTextEditor();
204
      textEditor = ((XSDEditor)targetEditor).getTextEditor();
205
      if (textEditor != null)
205
      if (textEditor != null)
206
      {      
206
      {      
207
         
207
         
(-)src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlinePage.java (-21 / +201 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.xsd.ui.internal;
11
package org.eclipse.wst.xsd.ui.internal;
12
12
13
import org.eclipse.core.runtime.Platform;
13
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.Action;
14
import org.eclipse.jface.action.IMenuManager;
15
import org.eclipse.jface.action.IMenuManager;
15
import org.eclipse.jface.action.MenuManager;
16
import org.eclipse.jface.action.MenuManager;
16
import org.eclipse.jface.resource.ImageDescriptor;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.util.ListenerList;
19
import org.eclipse.jface.util.SafeRunnable;
17
import org.eclipse.jface.viewers.ILabelProvider;
20
import org.eclipse.jface.viewers.ILabelProvider;
21
import org.eclipse.jface.viewers.IPostSelectionProvider;
18
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.ISelectionChangedListener;
23
import org.eclipse.jface.viewers.ISelectionChangedListener;
20
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 34-39 Link Here
34
import org.eclipse.swt.widgets.Tree;
38
import org.eclipse.swt.widgets.Tree;
35
import org.eclipse.swt.widgets.TreeItem;
39
import org.eclipse.swt.widgets.TreeItem;
36
import org.eclipse.ui.IActionBars;
40
import org.eclipse.ui.IActionBars;
41
import org.eclipse.ui.ISelectionListener;
42
import org.eclipse.ui.IWorkbenchPart;
43
import org.eclipse.ui.part.IPageSite;
37
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
44
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
38
import org.eclipse.wst.xsd.ui.internal.actions.OpenSchemaAction;
45
import org.eclipse.wst.xsd.ui.internal.actions.OpenSchemaAction;
39
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter;
46
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter;
Lines 42-48 Link Here
42
import org.eclipse.xsd.XSDSchemaDirective;
49
import org.eclipse.xsd.XSDSchemaDirective;
43
import org.w3c.dom.Element;
50
import org.w3c.dom.Element;
44
51
45
public class XSDContentOutlinePage extends ContentOutlinePage
52
/**
53
 * @deprecated Using SSE's ConfiguratbleContentOutlinePage 
54
 * instead via XSDContentOutlineCOnfiguration
55
 */
56
public class XSDContentOutlinePage extends ContentOutlinePage implements ISelectionListener
46
{
57
{
47
  protected XSDEditor xsdEditor;
58
  protected XSDEditor xsdEditor;
48
  protected int level = 0;
59
  protected int level = 0;
Lines 52-69 Link Here
52
  protected XSDSelectionManager selectionManager;
63
  protected XSDSelectionManager selectionManager;
53
  protected SelectionManagerSelectionChangeListener selectionManagerSelectionChangeListener = new SelectionManagerSelectionChangeListener();
64
  protected SelectionManagerSelectionChangeListener selectionManagerSelectionChangeListener = new SelectionManagerSelectionChangeListener();
54
  protected TreeSelectionChangeListener treeSelectionChangeListener = new TreeSelectionChangeListener();
65
  protected TreeSelectionChangeListener treeSelectionChangeListener = new TreeSelectionChangeListener();
55
  XSDTextEditor xsdTextEditor;
66
  XSDEditor xsdTextEditor;
56
  XSDMenuListener menuListener;
67
  XSDMenuListener menuListener;
57
68
  SelectionProvider fSelectionProvider = null;
69
  
58
  /**
70
  /**
59
   *  
71
   *  
60
   */
72
   */
61
  public XSDContentOutlinePage(XSDTextEditor xsdTextEditor)
73
  public XSDContentOutlinePage(XSDEditor xsdTextEditor)
62
  {
74
  {
63
    super();
75
    super();
64
    this.xsdTextEditor = xsdTextEditor;
76
    this.xsdTextEditor = xsdTextEditor;
77
    fSelectionProvider = new SelectionProvider();
65
  }
78
  }
66
79
80
  public void init(IPageSite pageSite)
81
  {
82
  	super.init(pageSite);
83
  	getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
84
  	getSite().setSelectionProvider(fSelectionProvider);
85
  }
86
  
87
  public void dispose()
88
  {
89
  	super.dispose();
90
  	getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
91
  }
92
  
67
  public void setModel(Object newModel)
93
  public void setModel(Object newModel)
68
  {
94
  {
69
    model = newModel;
95
    model = newModel;
Lines 91-109 Link Here
91
    getTreeViewer().setContentProvider(contentProvider);
117
    getTreeViewer().setContentProvider(contentProvider);
92
    getTreeViewer().setLabelProvider(labelProvider);
118
    getTreeViewer().setLabelProvider(labelProvider);
93
    getTreeViewer().setInput(model);
119
    getTreeViewer().setInput(model);
94
    getTreeViewer().addSelectionChangedListener(this);
120
//    getTreeViewer().addSelectionChangedListener(this);
95
    MenuManager menuManager = new MenuManager("#popup");//$NON-NLS-1$
121
    MenuManager menuManager = new MenuManager("#popup");//$NON-NLS-1$
96
    menuManager.setRemoveAllWhenShown(true);
122
    menuManager.setRemoveAllWhenShown(true);
97
    Menu menu = menuManager.createContextMenu(getTreeViewer().getControl());
123
    Menu menu = menuManager.createContextMenu(getTreeViewer().getControl());
98
    getTreeViewer().getControl().setMenu(menu);
124
    getTreeViewer().getControl().setMenu(menu);
99
    menuListener = new XSDMenuListener(xsdTextEditor.getXSDEditor().getSelectionManager());
125
    menuListener = new XSDMenuListener(xsdTextEditor.getSelectionManager());
100
//  menuListener.setSelectionProvider(getTreeViewer());
126
//  menuListener.setSelectionProvider(getTreeViewer());
101
    menuManager.addMenuListener(menuListener);
127
    menuManager.addMenuListener(menuListener);
102
    
128
    
103
    // enable popupMenus extension
129
    // enable popupMenus extension
104
    getSite().registerContextMenu("org.eclipse.wst.xsd.ui.popup.outline", menuManager, xsdTextEditor.getXSDEditor().getSelectionManager());
130
    getSite().registerContextMenu("org.eclipse.wst.xsd.ui.popup.outline", menuManager, xsdTextEditor.getSelectionManager());
105
    
131
106
    setSelectionManager(xsdTextEditor.getXSDEditor().getSelectionManager());
132
    setSelectionManager(xsdTextEditor.getSelectionManager());
107
    // cs... why are we doing this from the outline view?
133
    // cs... why are we doing this from the outline view?
108
    //
134
    //
109
    //xsdTextEditor.getXSDEditor().getSelectionManager().setSelection(new
135
    //xsdTextEditor.getXSDEditor().getSelectionManager().setSelection(new
Lines 125-137 Link Here
125
            XSDConcreteComponent comp = (XSDConcreteComponent)obj;
151
            XSDConcreteComponent comp = (XSDConcreteComponent)obj;
126
            if (comp.getContainer() instanceof XSDSchema)
152
            if (comp.getContainer() instanceof XSDSchema)
127
            {
153
            {
128
              xsdTextEditor.getXSDEditor().getGraphViewer().setInput(obj);
154
              xsdTextEditor.getGraphViewer().setInput(obj);
129
            }
155
            }
130
          }
156
          }
131
        }
157
        }
132
158
133
      }
159
      }
134
    });
160
    });
161
    
162
    
163
		getTreeViewer().addPostSelectionChangedListener(fSelectionProvider.getPostSelectionChangedListener());
164
		getTreeViewer().addSelectionChangedListener(fSelectionProvider.getSelectionChangedListener());
165
135
  }
166
  }
136
  class XSDKeyListener extends KeyAdapter
167
  class XSDKeyListener extends KeyAdapter
137
  {
168
  {
Lines 186-197 Link Here
186
    getTreeViewer().expandToLevel(level);
217
    getTreeViewer().expandToLevel(level);
187
  }
218
  }
188
219
189
  //	public ISelection getSelection()
220
  public void selectionChanged(IWorkbenchPart part, ISelection selection)
190
  //	{
221
  {
191
  //		if (getTreeViewer() == null)
222
    if (selectionManager != null)
192
  //			return StructuredSelection.EMPTY;
223
    {
193
  //		return getTreeViewer().getSelection();
224
      if (selection instanceof IStructuredSelection)
194
  //	}
225
      {
226
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
227
        Object o = structuredSelection.getFirstElement();
228
        // TODO ...
229
        // we need to implement a selectionManagerMapping extension point
230
        // so that extensions can specify how they'd like to map view objects
231
        // to selection objects
232
        //                                        
233
        if (o instanceof Element)
234
        {
235
          try
236
          {
237
            Object modelObject = xsdTextEditor.getXSDSchema().getCorrespondingComponent((Element) o);
238
            if (modelObject != null)
239
            {
240
              o = modelObject;
241
            }
242
          }
243
          catch (Exception e)
244
          {
245
          }
246
        }
247
        else if (o instanceof CategoryAdapter)
248
        {
249
          // todo... we need to ensure we eliminate the propagation 
250
          // of 'view' specific objects into the SelectionManager.                     
251
          // We need to do some work to ensure all views utilize the 'Category' model object  
252
          // so we can get rid of this CategoryAdapter class.
253
//           CategoryAdapter adapter = (CategoryAdapter) o;
254
//           o = adapter.getXSDSchema();
255
        }
256
        if (o != null)
257
        {
258
    			if (getControl() != null && !getControl().isDisposed() && !getControl().isFocusControl() && getControl().isVisible()) {
259
    				/*
260
    				 * Do not allow selection from other parts to affect selection
261
    				 * in the tree widget if it has focus. Selection events
262
    				 * "bouncing" off of other parts are all that we can receive
263
    				 * if we have focus (since we forward selection to the
264
    				 * service), and only the user should affect selection if we
265
    				 * have focus.
266
    				 */
267
            getTreeViewer().setSelection(new StructuredSelection(o), true);
268
    			}
269
          selectionManager.setSelection(new StructuredSelection(o), getTreeViewer());
270
//        selectionManager.selectionChanged(new SelectionChangedEvent(getTreeViewer(),new StructuredSelection(o)));
271
        }
272
        else
273
        {
274
          // selectionManager.setSelection(new StructuredSelection(),
275
          // getTreeViewer());
276
        }
277
      }
278
    }
279
  }
280
  
195
  public void setSelectionManager(XSDSelectionManager newSelectionManager)
281
  public void setSelectionManager(XSDSelectionManager newSelectionManager)
196
  {
282
  {
197
    TreeViewer treeViewer = getTreeViewer();
283
    TreeViewer treeViewer = getTreeViewer();
Lines 209-214 Link Here
209
      treeViewer.addSelectionChangedListener(treeSelectionChangeListener);
295
      treeViewer.addSelectionChangedListener(treeSelectionChangeListener);
210
    }
296
    }
211
  }
297
  }
298
  
212
  class SelectionManagerSelectionChangeListener implements ISelectionChangedListener
299
  class SelectionManagerSelectionChangeListener implements ISelectionChangedListener
213
  {
300
  {
214
    public void selectionChanged(SelectionChangedEvent event)
301
    public void selectionChanged(SelectionChangedEvent event)
Lines 263-273 Link Here
263
            selectionManager.setSelection(new StructuredSelection(o), getTreeViewer());
350
            selectionManager.setSelection(new StructuredSelection(o), getTreeViewer());
264
//          selectionManager.selectionChanged(new SelectionChangedEvent(getTreeViewer(),new StructuredSelection(o)));
351
//          selectionManager.selectionChanged(new SelectionChangedEvent(getTreeViewer(),new StructuredSelection(o)));
265
          }
352
          }
266
          else
267
          {
268
            //            selectionManager.setSelection(new StructuredSelection(),
269
            // getTreeViewer());
270
          }
271
        }
353
        }
272
      }
354
      }
273
    }
355
    }
Lines 378-381 Link Here
378
      return true;
460
      return true;
379
    }
461
    }
380
  }
462
  }
463
  
464
	/**
465
	 * Forwards post-selection from the tree viewer to the listeners while
466
	 * acting as this page's selection provider.
467
	 */
468
	private class SelectionProvider implements IPostSelectionProvider {
469
		private class PostSelectionChangedListener implements ISelectionChangedListener {
470
			public void selectionChanged(SelectionChangedEvent event) {
471
				if (!isFiringSelection()) {
472
					fireSelectionChanged(event, postListeners);
473
				}
474
			}
475
		}
476
477
		private class SelectionChangedListener implements ISelectionChangedListener {
478
			public void selectionChanged(SelectionChangedEvent event) {
479
				if (!isFiringSelection()) {
480
					fireSelectionChanged(event, listeners);
481
				}
482
			}
483
		}
484
485
		private boolean isFiringSelection = false;
486
		private ListenerList listeners = new ListenerList();
487
		private ListenerList postListeners = new ListenerList();
488
		private ISelectionChangedListener postSelectionChangedListener = new PostSelectionChangedListener();
489
		private ISelectionChangedListener selectionChangedListener = new SelectionChangedListener();
490
491
		public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
492
			postListeners.add(listener);
493
		}
494
495
		public void addSelectionChangedListener(ISelectionChangedListener listener) {
496
			listeners.add(listener);
497
		}
498
499
		public void fireSelectionChanged(final SelectionChangedEvent event, ListenerList listenerList) {
500
			isFiringSelection = true;
501
			Object[] listeners = listenerList.getListeners();
502
			for (int i = 0; i < listeners.length; ++i) {
503
				final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
504
				Platform.run(new SafeRunnable() {
505
					public void run() {
506
						l.selectionChanged(event);
507
					}
508
				});
509
			}
510
			isFiringSelection = false;
511
		}
512
513
		public void fireSelectionChanged(final SelectionChangedEvent event) {
514
			isFiringSelection = true;
515
			Object[] listeners = postListeners.getListeners();
516
			for (int i = 0; i < listeners.length; ++i) {
517
				final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
518
				Platform.run(new SafeRunnable() {
519
					public void run() {
520
						l.selectionChanged(event);
521
					}
522
				});
523
			}
524
			isFiringSelection = false;
525
		}
526
527
		public ISelectionChangedListener getPostSelectionChangedListener() {
528
			return postSelectionChangedListener;
529
		}
530
531
		public ISelection getSelection() {
532
			if (getTreeViewer() != null) {
533
				return getTreeViewer().getSelection();
534
			}
535
			return StructuredSelection.EMPTY;
536
		}
537
538
		public ISelectionChangedListener getSelectionChangedListener() {
539
			return selectionChangedListener;
540
		}
541
542
		public boolean isFiringSelection() {
543
			return isFiringSelection;
544
		}
545
546
		public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
547
			postListeners.remove(listener);
548
		}
549
550
		public void removeSelectionChangedListener(ISelectionChangedListener listener) {
551
			listeners.remove(listener);
552
		};
553
554
		public void setSelection(ISelection selection) {
555
			if (isFiringSelection) {
556
				getTreeViewer().setSelection(selection);
557
			}
558
		};
559
	}
560
381
}
561
}
(-)src/org/eclipse/wst/xsd/ui/internal/XSDEditor.java (-554 / +798 lines)
Lines 12-17 Link Here
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.EventObject;
14
import java.util.EventObject;
15
import java.util.Iterator;
16
import java.util.List;
15
17
16
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
Lines 21-28 Link Here
21
import org.eclipse.jface.text.IDocument;
23
import org.eclipse.jface.text.IDocument;
22
import org.eclipse.jface.util.IPropertyChangeListener;
24
import org.eclipse.jface.util.IPropertyChangeListener;
23
import org.eclipse.jface.util.PropertyChangeEvent;
25
import org.eclipse.jface.util.PropertyChangeEvent;
26
import org.eclipse.jface.viewers.DoubleClickEvent;
27
import org.eclipse.jface.viewers.IDoubleClickListener;
28
import org.eclipse.jface.viewers.IPostSelectionProvider;
24
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.ISelectionChangedListener;
25
import org.eclipse.jface.viewers.ISelectionProvider;
31
import org.eclipse.jface.viewers.ISelectionProvider;
32
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.viewers.SelectionChangedEvent;
33
import org.eclipse.jface.viewers.SelectionChangedEvent;
27
import org.eclipse.jface.viewers.StructuredSelection;
34
import org.eclipse.jface.viewers.StructuredSelection;
28
import org.eclipse.swt.widgets.Control;
35
import org.eclipse.swt.widgets.Control;
Lines 37-622 Link Here
37
import org.eclipse.ui.PartInitException;
44
import org.eclipse.ui.PartInitException;
38
import org.eclipse.ui.PlatformUI;
45
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.editors.text.ILocationProvider;
46
import org.eclipse.ui.editors.text.ILocationProvider;
47
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
48
import org.eclipse.ui.views.properties.IPropertySheetPage;
40
import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor;
49
import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor;
41
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
50
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
42
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
51
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
52
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
43
import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener;
53
import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener;
44
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;
54
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;
45
import org.eclipse.wst.sse.ui.StructuredTextEditor;
55
import org.eclipse.wst.sse.ui.StructuredTextEditor;
56
import org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage;
46
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
57
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
58
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
47
import org.eclipse.wst.xsd.ui.internal.graph.XSDGraphViewer;
59
import org.eclipse.wst.xsd.ui.internal.graph.XSDGraphViewer;
60
import org.eclipse.wst.xsd.ui.internal.properties.section.XSDTabbedPropertySheetPage;
61
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter;
62
import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider;
63
import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl;
48
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter;
64
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter;
49
import org.eclipse.wst.xsd.ui.internal.util.OpenOnSelectionHelper;
65
import org.eclipse.wst.xsd.ui.internal.util.OpenOnSelectionHelper;
66
import org.eclipse.xsd.XSDComponent;
50
import org.eclipse.xsd.XSDConcreteComponent;
67
import org.eclipse.xsd.XSDConcreteComponent;
51
import org.eclipse.xsd.XSDSchema;
68
import org.eclipse.xsd.XSDSchema;
52
import org.eclipse.xsd.util.XSDConstants;
69
import org.eclipse.xsd.util.XSDConstants;
70
import org.w3c.dom.Attr;
53
import org.w3c.dom.Document;
71
import org.w3c.dom.Document;
54
import org.w3c.dom.Element;
72
import org.w3c.dom.Element;
73
import org.w3c.dom.Node;
55
import org.w3c.dom.ProcessingInstruction;
74
import org.w3c.dom.ProcessingInstruction;
56
75
57
// public class XSDEditor extends StructuredTextMultiPageEditorPart
76
// public class XSDEditor extends StructuredTextMultiPageEditorPart
58
public class XSDEditor extends XSDMultiPageEditorPart implements ITabbedPropertySheetPageContributor
77
public class XSDEditor extends XSDMultiPageEditorPart implements ITabbedPropertySheetPageContributor {
59
{
78
	protected StructuredTextEditor textEditor;
60
  protected XSDTextEditor textEditor;
79
	IFile resourceFile;
61
  IFile resourceFile;
80
	XSDSelectionManager xsdSelectionManager;
62
  XSDSelectionManager xsdSelectionManager;
81
	XSDModelAdapter schemalNodeAdapter;
63
  XSDModelAdapter schemalNodeAdapter;
82
64
83
	private IStructuredModel result;
65
  private IStructuredModel result;
84
66
85
	/**
67
  public XSDEditor()
86
	 * Listener on SSE's outline page's selections that converts DOM
68
  {
87
	 * selections into wsdl selections and notifies WSDL selection manager
69
    super();
88
	 */
70
    xsdSelectionManager = new XSDSelectionManager();
89
	class OutlineTreeSelectionChangeListener implements ISelectionChangedListener, IDoubleClickListener {
71
  }
90
		public OutlineTreeSelectionChangeListener() {
72
91
		}
73
  InternalPartListener partListener = new InternalPartListener(this);
92
74
  
93
		private ISelection getXSDSelection(ISelection selection) {
75
  // show outline view - defect 266116
94
			ISelection sel = null;
76
  public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException
95
			if (selection instanceof IStructuredSelection) {
77
  {
96
				IStructuredSelection structuredSelection = (IStructuredSelection) selection;
78
    super.init(site, editorInput);
97
				Object o = structuredSelection.getFirstElement();
79
    IWorkbenchWindow dw=PlatformUI.getWorkbench().getActiveWorkbenchWindow();
98
				if (o != null)
80
    IWorkbenchPage page=dw.getActivePage();
99
					sel = new StructuredSelection(o);
81
    getSite().getPage().addPartListener(partListener);
100
			}
82
    try
101
			return sel;
83
    {
102
		}
84
      if (page != null)
103
85
      {
104
		/**
86
//      page.showView("org.eclipse.ui.views.ContentOutline");
105
		 * Determines DOM node based on object (xsd node)
87
        page.showView("org.eclipse.ui.views.PropertySheet");
106
		 * 
88
      }
107
		 * @param object
89
    } catch (PartInitException e) 
108
		 * @return
90
    {
109
		 */
91
//       e.printStackTrace();
110
		private Object getObjectForOtherModel(Object object) {
92
    }      
111
			Node node = null;
93
   }
112
94
  
113
			if (object instanceof Node) {
95
  // For team support
114
				node = (Node) object;
96
  //  protected PropertyDirtyChangeListener propertyChangeListener;
115
			}
97
116
			else if (object instanceof XSDComponent) {
98
  /**
117
				node = ((XSDComponent) object).getElement();
99
   * Creates the pages of this multi-page editor.
118
			}
100
   * <p>
119
			else if (object instanceof CategoryAdapter) {
101
   * Subclasses of <code>MultiPageEditor</code> must implement this method.
120
				node = ((CategoryAdapter) object).getXSDSchema().getElement();
102
   * </p>
121
			}
103
   */
122
104
  protected void createPages()
123
			// the text editor can only accept sed nodes!
105
  {
124
			//
106
    try
125
			if (!(node instanceof IDOMNode)) {
107
    {
126
				node = null;
108
      if (!loadFile())
127
			}
109
        return;
128
			return node;
110
129
		}
111
      // source page MUST be created before design page, now
130
112
      createSourcePage();
131
		public void doubleClick(DoubleClickEvent event) {
113
132
			/*
114
      addSourcePage();
133
			 * Selection in outline tree changed so set outline tree's
115
      buildXSDModel();
134
			 * selection into editor's selection and say it came from outline
116
135
			 * tree
117
      // comment this line out to hide the graph page 
136
			 */
118
      // 
137
			if (getSelectionManager() != null && getSelectionManager().enableNotify) {
119
      createAndAddGraphPage();
138
				ISelection selection = getXSDSelection(event.getSelection());
120
139
				if (selection != null) {
121
      int pageIndexToShow = getDefaultPageTypeIndex();
140
					getSelectionManager().setSelection(selection, fOutlinePage);
122
      setActivePage(pageIndexToShow);
141
				}
123
      
142
124
      addCommandStackListener();
143
				if (getTextEditor() != null && selection instanceof IStructuredSelection) {
125
      
144
					int start = -1;
126
      XSDEditorPlugin.getPlugin().getPreferenceStore().addPropertyChangeListener(preferenceStoreListener);
145
					int length = 0;
127
    }
146
					Object o = ((IStructuredSelection) selection).getFirstElement();
128
    catch (PartInitException e)
147
					if (o != null)
129
    {
148
						o = getObjectForOtherModel(o);
130
		// log for now, unless we find reason not to
149
					if (o instanceof IndexedRegion) {
131
		Logger.log(Logger.INFO, e.getMessage());
150
						start = ((IndexedRegion) o).getStartOffset();
132
    }
151
						length = ((IndexedRegion) o).getEndOffset() - start;
133
  }
152
					}
134
  
153
					if (start > -1) {
135
  
154
						getTextEditor().selectAndReveal(start, length);
136
  public void buildXSDModel()
155
					}
137
  {
156
				}
138
    try
157
			}
139
    {
158
		}
140
      Document document  = ((IDOMModel)getModel()).getDocument();
159
141
      
160
		public void selectionChanged(SelectionChangedEvent event) {
142
      boolean schemaNodeExists = document.getElementsByTagNameNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "schema").getLength() == 1;
161
			/*
143
      
162
			 * Selection in outline tree changed so set outline tree's
144
      if (document.getChildNodes().getLength() == 0 || !schemaNodeExists)
163
			 * selection into editor's selection and say it came from outline
145
      {
164
			 * tree
146
        createDefaultSchemaNode(document);
165
			 */
147
      }
166
			if (getSelectionManager() != null && getSelectionManager().enableNotify) {
148
167
				ISelection selection = getXSDSelection(event.getSelection());
149
      if (document instanceof INodeNotifier)
168
				if (selection != null) {
150
      {
169
					getSelectionManager().setSelection(selection, fOutlinePage);
151
        INodeNotifier notifier = (INodeNotifier)document;
170
				}
152
        schemalNodeAdapter = (XSDModelAdapter)notifier.getAdapterFor(XSDModelAdapter.class);
171
			}
153
        if (schemalNodeAdapter == null)
172
		}
154
        {
173
	}
155
          schemalNodeAdapter = new XSDModelAdapter();
174
156
          notifier.addAdapter(schemalNodeAdapter);        
175
	/**
157
          schemalNodeAdapter.createSchema(document.getDocumentElement()); 
176
	 * Listener on SSE's source editor's selections that converts DOM
158
        }    
177
	 * selections into xsd selections and notifies XSD selection manager
159
      }          
178
	 */
160
    }
179
	private class SourceEditorSelectionListener implements ISelectionChangedListener {
161
    catch (Exception e)
180
		/**
162
    {
181
		 * Determines XSD node based on object (DOM node)
163
//      XSDEditorPlugin.getPlugin().getMsgLogger().write("Failed to create Model");
182
		 * 
164
//      XSDEditorPlugin.getPlugin().getMsgLogger().write(e);
183
		 * @param object
165
//      e.printStackTrace();
184
		 * @return
166
    }
185
		 */
167
186
		private Object getXSDNode(Object object) {
168
187
			// get the element node
169
188
			Element element = null;
170
//      XSDResourceFactoryImpl.validate(xsdSchema, input.getFile().getContents(true));
189
			if (object instanceof Node) {
171
  }  
190
				Node node = (Node) object;
172
191
				if (node != null) {
173
  public String[] getPropertyCategories()
192
					if (node.getNodeType() == Node.ELEMENT_NODE) {
174
  {
193
						element = (Element) node;
175
    return new String[] { "general", "namespace", "other", "attributes", "documentation", "facets" }; //$NON-NLS-1$
194
					}
176
  }
195
					else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
196
						element = ((Attr) node).getOwnerElement();
197
					}
198
				}
199
			}
200
			Object o = element;
201
			if (element != null) {
202
				Object modelObject = getXSDSchema().getCorrespondingComponent(element);
203
				if (modelObject != null) {
204
					o = modelObject;
205
				}
206
			}
207
			return o;
208
		}
209
210
		public void selectionChanged(SelectionChangedEvent event) {
211
			ISelection selection = event.getSelection();
212
			if (selection instanceof IStructuredSelection) {
213
				List xsdSelections = new ArrayList();
214
				for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
215
					Object domNode = i.next();
216
					Object xsdNode = getXSDNode(domNode);
217
					if (xsdNode != null) {
218
						xsdSelections.add(xsdNode);
219
					}
220
				}
221
222
				if (!xsdSelections.isEmpty()) {
223
					StructuredSelection xsdSelection = new StructuredSelection(xsdSelections);
224
					getSelectionManager().setSelection(xsdSelection, getTextEditor().getSelectionProvider());
225
				}
226
			}
227
		}
228
	}
229
230
	/**
231
	 * Listener on XSD's selection manager's selections that converts XSD
232
	 * selections into DOM selections and notifies SSE's selection provider
233
	 */
234
	private class XSDSelectionManagerSelectionListener implements ISelectionChangedListener {
235
		/**
236
		 * Determines DOM node based on object (xsd node)
237
		 * 
238
		 * @param object
239
		 * @return
240
		 */
241
		private Object getObjectForOtherModel(Object object) {
242
			Node node = null;
243
244
			if (object instanceof Node) {
245
				node = (Node) object;
246
			}
247
			else if (object instanceof XSDComponent) {
248
				node = ((XSDComponent) object).getElement();
249
			}
250
			else if (object instanceof CategoryAdapter) {
251
				node = ((CategoryAdapter) object).getXSDSchema().getElement();
252
			}
253
254
			// the text editor can only accept sed nodes!
255
			//
256
			if (!(node instanceof IDOMNode)) {
257
				node = null;
258
			}
259
			return node;
260
		}
261
262
		public void selectionChanged(SelectionChangedEvent event) {
263
			// do not fire selection in source editor if selection event came
264
			// from source editor
265
			if (event.getSource() != getTextEditor().getSelectionProvider()) {
266
				ISelection selection = event.getSelection();
267
				if (selection instanceof IStructuredSelection) {
268
					List otherModelObjectList = new ArrayList();
269
					for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
270
						Object modelObject = i.next();
271
						Object otherModelObject = getObjectForOtherModel(modelObject);
272
						if (otherModelObject != null) {
273
							otherModelObjectList.add(otherModelObject);
274
						}
275
					}
276
					if (!otherModelObjectList.isEmpty()) {
277
						StructuredSelection nodeSelection = new StructuredSelection(otherModelObjectList);
278
						getTextEditor().getSelectionProvider().setSelection(nodeSelection);
279
					}
280
				}
281
			}
282
		}
283
	}
284
285
	public XSDEditor() {
286
		super();
287
		xsdSelectionManager = new XSDSelectionManager();
288
	}
289
290
	InternalPartListener partListener = new InternalPartListener(this);
291
292
	// show outline view - defect 266116
293
	public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
294
		super.init(site, editorInput);
295
		IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
296
		IWorkbenchPage page = dw.getActivePage();
297
		getSite().getPage().addPartListener(partListener);
298
		try {
299
			if (page != null) {
300
				// page.showView("org.eclipse.ui.views.ContentOutline");
301
				page.showView("org.eclipse.ui.views.PropertySheet");
302
			}
303
		}
304
		catch (PartInitException e) {
305
			// e.printStackTrace();
306
		}
307
	}
308
309
	// For team support
310
	// protected PropertyDirtyChangeListener propertyChangeListener;
311
312
	/**
313
	 * Creates the pages of this multi-page editor.
314
	 * <p>
315
	 * Subclasses of <code>MultiPageEditor</code> must implement this
316
	 * method.
317
	 * </p>
318
	 */
319
	protected void createPages() {
320
		try {
321
			if (!loadFile())
322
				return;
323
324
			xsdModelAdapterFactory = XSDModelAdapterFactoryImpl.getInstance();
325
			adapterFactoryLabelProvider = new XSDAdapterFactoryLabelProvider(xsdModelAdapterFactory);
326
327
			// source page MUST be created before design page, now
328
			createSourcePage();
329
330
			addSourcePage();
331
			buildXSDModel();
332
333
			// comment this line out to hide the graph page
334
			// 
335
			createAndAddGraphPage();
336
337
			int pageIndexToShow = getDefaultPageTypeIndex();
338
			setActivePage(pageIndexToShow);
339
340
			openOnSelectionHelper = new OpenOnSelectionHelper(textEditor, getXSDSchema());
341
			// added selection listeners after setting selection to avoid
342
			// navigation exception
343
			ISelectionProvider provider = getTextEditor().getSelectionProvider();
344
			fSourceEditorSelectionListener = new SourceEditorSelectionListener();
345
			if (provider instanceof IPostSelectionProvider) {
346
				((IPostSelectionProvider) provider).addPostSelectionChangedListener(fSourceEditorSelectionListener);
347
			}
348
			else {
349
				provider.addSelectionChangedListener(fSourceEditorSelectionListener);
350
			}
351
			fXSDSelectionListener = new XSDSelectionManagerSelectionListener();
352
			getSelectionManager().addSelectionChangedListener(fXSDSelectionListener);
353
			
354
			addCommandStackListener();
355
356
			XSDEditorPlugin.getPlugin().getPreferenceStore().addPropertyChangeListener(preferenceStoreListener);
357
		}
358
		catch (PartInitException e) {
359
			// log for now, unless we find reason not to
360
			Logger.log(Logger.INFO, e.getMessage());
361
		}
362
	}
363
364
365
	public void buildXSDModel() {
366
		try {
367
			Document document = ((IDOMModel) getModel()).getDocument();
368
369
			boolean schemaNodeExists = document.getElementsByTagNameNS(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "schema").getLength() == 1;
370
371
			if (document.getChildNodes().getLength() == 0 || !schemaNodeExists) {
372
				createDefaultSchemaNode(document);
373
			}
374
375
			if (document instanceof INodeNotifier) {
376
				INodeNotifier notifier = (INodeNotifier) document;
377
				schemalNodeAdapter = (XSDModelAdapter) notifier.getAdapterFor(XSDModelAdapter.class);
378
				if (schemalNodeAdapter == null) {
379
					schemalNodeAdapter = new XSDModelAdapter();
380
					notifier.addAdapter(schemalNodeAdapter);
381
					schemalNodeAdapter.createSchema(document.getDocumentElement());
382
				}
383
			}
384
		}
385
		catch (Exception e) {
386
			// XSDEditorPlugin.getPlugin().getMsgLogger().write("Failed to
387
			// create Model");
388
			// XSDEditorPlugin.getPlugin().getMsgLogger().write(e);
389
			// e.printStackTrace();
390
		}
391
392
393
394
		// XSDResourceFactoryImpl.validate(xsdSchema,
395
		// input.getFile().getContents(true));
396
	}
397
398
	public String[] getPropertyCategories() {
399
		return new String[]{"general", "namespace", "other", "attributes", "documentation", "facets"}; //$NON-NLS-1$
400
	}
177
401
178
	/**
402
	/**
179
	 * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor#getContributorId()
403
	 * @see org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor#getContributorId()
180
	 */ 
404
	 */
181
  public String getContributorId()
405
	public String getContributorId() {
182
	{
406
		return "org.eclipse.wst.xsd.ui.internal.XSDEditor";
183
    return "org.eclipse.wst.xsd.ui.internal.XSDEditor";
407
		// return getSite().getId();
184
    //return getSite().getId();
408
	}
185
  }
409
186
410
	protected CommandStackListener commandStackListener;
187
  protected CommandStackListener commandStackListener;
411
188
  protected void addCommandStackListener()
412
	protected void addCommandStackListener() {
189
  {
413
		if (commandStackListener == null) {
190
    if (commandStackListener == null)
414
			IStructuredTextUndoManager undoManager = getModel().getUndoManager();
191
    {
415
			commandStackListener = new CommandStackListener() {
192
      IStructuredTextUndoManager undoManager = getModel().getUndoManager();
416
				/**
193
        commandStackListener = new CommandStackListener()
417
				 * @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(EventObject)
194
        {
418
				 */
195
          /**
419
				public void commandStackChanged(EventObject event) {
196
           * @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(EventObject)
420
					Object obj = event.getSource();
197
           */
421
					if (obj instanceof BasicCommandStack) {
198
          public void commandStackChanged(EventObject event)
422
						BasicCommandStack stack = (BasicCommandStack) obj;
199
          {
423
						Command recentCommand = stack.getMostRecentCommand();
200
            Object obj = event.getSource();
424
						Command redoCommand = stack.getRedoCommand();
201
            if (obj instanceof BasicCommandStack)
425
						Command undoCommand = stack.getUndoCommand();
202
            {
426
						if (recentCommand == redoCommand) {
203
              BasicCommandStack stack = (BasicCommandStack) obj;
427
							// there must have been an undo reset info tasks
204
              Command recentCommand = stack.getMostRecentCommand();
428
							resetInformationTasks();
205
              Command redoCommand = stack.getRedoCommand();
429
						}
206
              Command undoCommand = stack.getUndoCommand();
430
					}
207
              if (recentCommand == redoCommand)
431
				}
208
              {
432
			};
209
                // there must have been an undo reset info tasks 
433
210
                resetInformationTasks();
434
			// TODO WTP Port
211
              }
435
			// undoManager.getCommandStack().addCommandStackListener(commandStackListener);
212
            }
436
213
          }
437
		}
214
        };
438
	}
215
439
216
//TODO WTP Port        undoManager.getCommandStack().addCommandStackListener(commandStackListener);
440
	protected void pageChange(int arg) {
217
      
441
		super.pageChange(arg);
218
    }
442
	}
219
  } 
443
220
444
	protected void removeCommandStackListener() {
221
  protected void pageChange(int arg)
445
		if (commandStackListener != null) {
222
  {
446
			IStructuredTextUndoManager undoManager = getModel().getUndoManager();
223
    super.pageChange(arg);
447
			// TODO WTP Port
224
  }
448
			// undoManager.getCommandStack().removeCommandStackListener(commandStackListener);
225
449
		}
226
  protected void removeCommandStackListener()
450
	}
227
  {
451
228
    if (commandStackListener != null)
452
	// This is from the IValidateEditEditor interface
229
    {
453
	/*
230
      IStructuredTextUndoManager undoManager = getModel().getUndoManager();
454
	 * public void undoChange() { StructuredTextUndoManager undoManager =
231
//TODO WTP Port      undoManager.getCommandStack().removeCommandStackListener(commandStackListener);
455
	 * textEditor.getModel().getUndoManager(); undoManager.undo(); // Make the
232
    }
456
	 * editor clean textEditor.getModel().setDirtyState(false); }
233
  }
457
	 */
234
458
235
  // This is from the IValidateEditEditor interface
459
	private class PreferenceStoreListener implements IPropertyChangeListener {
236
/*  public void undoChange()
460
		/**
237
  {
461
		 * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent)
238
    StructuredTextUndoManager undoManager = textEditor.getModel().getUndoManager();   
462
		 */
239
    undoManager.undo();
463
		public void propertyChange(PropertyChangeEvent event) {
240
    // Make the editor clean
464
		}
241
    textEditor.getModel().setDirtyState(false);
465
	}
242
  } */
466
243
467
	protected IPropertyChangeListener preferenceStoreListener = new PreferenceStoreListener();
244
  private class PreferenceStoreListener implements IPropertyChangeListener
468
245
  {
469
	protected int getDefaultPageTypeIndex() {
246
    /**
470
		int pageIndex = sourcePageIndex;
247
     * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent)
471
248
     */
472
		if (XSDEditorPlugin.getPlugin().getDefaultPage().equals(XSDEditorPlugin.GRAPH_PAGE)) {
249
    public void propertyChange(PropertyChangeEvent event)
473
			if (graphPageIndex != -1)
250
    {
474
				pageIndex = graphPageIndex;
251
    }
475
		}
252
  }
476
253
477
		return pageIndex;
254
  protected IPropertyChangeListener preferenceStoreListener = new PreferenceStoreListener();
478
	}
255
479
256
  protected int getDefaultPageTypeIndex()
480
	int currentPage = -1;
257
  {
481
258
    int pageIndex = sourcePageIndex;
482
	public String getCurrentPageType() {
259
    
260
    if (XSDEditorPlugin.getPlugin().getDefaultPage().equals(XSDEditorPlugin.GRAPH_PAGE))
261
    {
262
      if (graphPageIndex != -1)
263
        pageIndex = graphPageIndex;
264
    }
265
    
266
    return pageIndex;
267
  }
268
      
269
	int currentPage = -1;      
270
	public String getCurrentPageType()
271
	{
272
		// should update pref. for valid pages
483
		// should update pref. for valid pages
273
		if (getActivePage() != -1)
484
		if (getActivePage() != -1) {
274
		{
275
			currentPage = getActivePage();
485
			currentPage = getActivePage();
276
		}
486
		}
277
		if (currentPage == graphPageIndex)
487
		if (currentPage == graphPageIndex) {
278
		{
279
			return XSDEditorPlugin.GRAPH_PAGE;
488
			return XSDEditorPlugin.GRAPH_PAGE;
280
		}
489
		}
281
		else
490
		else {
282
		{
283
			return XSDEditorPlugin.SOURCE_PAGE;
491
			return XSDEditorPlugin.SOURCE_PAGE;
284
    }
492
		}
493
	}
494
495
	public Object getActivePart() {
496
		return getSite().getWorkbenchWindow().getActivePage().getActivePart();
497
	}
498
499
	public void dispose() {
500
		// some things in the configuration need to clean
501
		// up after themselves
502
		if (fOutlinePage != null) {
503
			if (fOutlinePage instanceof ConfigurableContentOutlinePage && fOutlineListener != null) {
504
				((ConfigurableContentOutlinePage) fOutlinePage).removeDoubleClickListener(fOutlineListener);
505
			}
506
			if (fOutlineListener != null) {
507
				fOutlinePage.removeSelectionChangedListener(fOutlineListener);
508
			}
509
		}
510
		ISelectionProvider provider = getTextEditor().getSelectionProvider();
511
		if (provider instanceof IPostSelectionProvider) {
512
			((IPostSelectionProvider) provider).removePostSelectionChangedListener(fSourceEditorSelectionListener);
513
		}
514
		else {
515
			provider.removeSelectionChangedListener(fSourceEditorSelectionListener);
516
		}
517
		getSelectionManager().removeSelectionChangedListener(fXSDSelectionListener);
518
		
519
		// propertyChangeListener.dispose();
520
		removeCommandStackListener();
521
522
		XSDEditorPlugin.getPlugin().setDefaultPage(getCurrentPageType());
523
		XSDEditorPlugin.getPlugin().getPreferenceStore().removePropertyChangeListener(preferenceStoreListener);
524
525
		getSite().getPage().removePartListener(partListener);
526
527
		// KB: Temporary solution for bug 99468
528
		IStructuredModel myModel = textEditor.getModel();
529
		if (myModel != null && myModel instanceof IStructuredDocumentListener)
530
			myModel.getStructuredDocument().removeDocumentChangingListener((IStructuredDocumentListener) myModel);
531
532
		textEditor = null;
533
		resourceFile = null;
534
		xsdSelectionManager = null;
535
		schemalNodeAdapter = null;
536
		result = null;
537
		partListener = null;
538
		commandStackListener = null;
539
		preferenceStoreListener = null;
540
		openOnSelectionHelper = null;
541
		graphViewer = null;
542
543
		super.dispose();
544
545
		// release the schema model
546
		//
547
		if (schemalNodeAdapter != null) {
548
			schemalNodeAdapter.clear();
549
			schemalNodeAdapter = null;
550
		}
551
	}
552
553
	protected boolean loadFile() {
554
		Object input = getEditorInput();
555
556
		if (input instanceof IFileEditorInput) {
557
			resourceFile = ((IFileEditorInput) input).getFile();
558
		}
559
		else if (input instanceof ILocationProvider) {
560
			IPath path = ((ILocationProvider) input).getPath(input);
561
			String ext = path.getFileExtension();
562
			if (ext != null && ext.equals("xsd")) {
563
				return true;
564
			}
565
			return false;
566
		}
567
		else {
568
			return false;
569
		}
570
		return true;
571
	}
572
573
	/**
574
	 * Method openOnGlobalReference. The comp argument is a resolved xsd
575
	 * schema object from another file. This is created and called from
576
	 * another schema model to allow F3 navigation to open a new editor and
577
	 * choose the referenced object within that editor context
578
	 * 
579
	 * @param comp
580
	 */
581
	public void openOnGlobalReference(XSDConcreteComponent comp) {
582
		openOnSelectionHelper.openOnGlobalReference(comp);
583
	}
584
585
	protected OpenOnSelectionHelper openOnSelectionHelper;
586
587
	public OpenOnSelectionHelper getOpenOnSelectionHelper() {
588
		return openOnSelectionHelper;
589
	}
590
591
	/**
592
	 * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#createTextEditor()
593
	 */
594
	protected StructuredTextEditor createTextEditor() {
595
		textEditor = new StructuredTextEditor();
596
		return textEditor;
597
	}
598
599
	/*
600
	 * @see StructuredTextMultiPageEditorPart#createSourcePage()
601
	 */
602
	protected void createSourcePage() throws PartInitException {
603
		super.createSourcePage();
604
	}
605
606
	int sourcePageIndex = -1;
607
608
	/**
609
	 * Adds the source page of the multi-page editor.
610
	 */
611
	protected void addSourcePage() throws PartInitException {
612
613
		sourcePageIndex = addPage(textEditor, getEditorInput());
614
		setPageText(sourcePageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_SOURCE"));
615
616
		// the update's critical, to get viewer selection manager and
617
		// highlighting to work
618
		textEditor.update();
619
		firePropertyChange(PROP_TITLE);
620
	}
621
622
	int graphPageIndex = -1;
623
	XSDGraphViewer graphViewer;
624
625
	/**
626
	 * Creates the graph page and adds it to the multi-page editor.
627
	 */
628
	protected void createAndAddGraphPage() throws PartInitException {
629
		graphViewer = new XSDGraphViewer(this);
630
		graphViewer.setSchema(getXSDSchema());
631
		Control graphControl = graphViewer.createControl(getContainer());
632
		graphPageIndex = addPage(graphControl);
633
		setPageText(graphPageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_GRAPH"));
634
635
		// graphViewer.setViewerSelectionManager(textEditor.getViewerSelectionManager());
636
		graphViewer.setSelectionManager(getSelectionManager());
637
638
		// this forces the editor to initially select the top level schema
639
		// object
640
		//
641
		if (getXSDSchema() != null) {
642
			getSelectionManager().setSelection(new StructuredSelection(getXSDSchema()));
643
		}
644
	}
645
646
	protected XSDModelAdapterFactoryImpl xsdModelAdapterFactory;
647
	protected XSDAdapterFactoryLabelProvider adapterFactoryLabelProvider;
648
	private IPropertySheetPage fPropertySheetPage;
649
	private IContentOutlinePage fOutlinePage;
650
	private OutlineTreeSelectionChangeListener fOutlineListener;
651
	private SourceEditorSelectionListener fSourceEditorSelectionListener;
652
	private XSDSelectionManagerSelectionListener fXSDSelectionListener;
653
654
	/*
655
	 * @see IAdaptable#getAdapter(Class)
656
	 */
657
	public Object getAdapter(Class key) {
658
		Object result = null;
659
		if (key == ISelectionProvider.class) {
660
			result = xsdSelectionManager;
661
		}
662
		if (IPropertySheetPage.class.equals(key)) {
663
			fPropertySheetPage = new XSDTabbedPropertySheetPage(this);
664
665
			((XSDTabbedPropertySheetPage) fPropertySheetPage).setXSDModelAdapterFactory(xsdModelAdapterFactory);
666
			((XSDTabbedPropertySheetPage) fPropertySheetPage).setSelectionManager(getSelectionManager());
667
			((XSDTabbedPropertySheetPage) fPropertySheetPage).setXSDSchema(getXSDSchema());
668
669
			return fPropertySheetPage;
670
		}
671
		else if (IContentOutlinePage.class.equals(key)) {
672
			if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) {
673
				IContentOutlinePage page = (IContentOutlinePage) super.getAdapter(key);
674
				if (page != null) {
675
					fOutlineListener = new OutlineTreeSelectionChangeListener();
676
					page.addSelectionChangedListener(fOutlineListener);
677
					if (page instanceof ConfigurableContentOutlinePage) {
678
						((ConfigurableContentOutlinePage) page).addDoubleClickListener(fOutlineListener);
679
					}
680
				}
681
				fOutlinePage = page;
682
				// XSDContentOutlinePage outlinePage = new
683
				// XSDContentOutlinePage(this);
684
				// XSDContentProvider xsdContentProvider = new
685
				// XSDContentProvider(xsdModelAdapterFactory);
686
				// xsdContentProvider.setXSDSchema(getXSDSchema());
687
				// outlinePage.setContentProvider(xsdContentProvider);
688
				// outlinePage.setLabelProvider(adapterFactoryLabelProvider);
689
				// outlinePage.setModel(getXSDSchema().getDocument());
690
				//
691
				// fOutlinePage = outlinePage;
692
			}
693
			return fOutlinePage;
694
		}
695
		else {
696
			result = super.getAdapter(key);
697
		}
698
		return result;
699
	}
700
701
702
	public XSDModelAdapterFactoryImpl getXSDModelAdapterFactory() {
703
		return xsdModelAdapterFactory;
704
	}
705
706
	public XSDAdapterFactoryLabelProvider getLabelProvider() {
707
		return adapterFactoryLabelProvider;
708
	}
709
710
711
	public XSDSelectionManager getSelectionManager() {
712
		return xsdSelectionManager;
713
	}
714
715
	/**
716
	 * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#doSaveAs()
717
	 */
718
	public void doSaveAs() {
719
		super.doSaveAs();
720
	}
721
722
	public void doSave(org.eclipse.core.runtime.IProgressMonitor monitor) {
723
		super.doSave(monitor);
724
	}
725
726
	public void reparseSchema() {
727
		// TODO cs : Are there no better ways to make the model
728
		// reload it's dependencies? This seems rather extreme.
729
		//
730
		Document document = ((IDOMModel) getModel()).getDocument();
731
		if (schemalNodeAdapter != null) {
732
			schemalNodeAdapter.createSchema(document.getDocumentElement());
733
		}
734
	}
735
736
	/**
737
	 * Returns the xsdSchema.
738
	 * 
739
	 * @return XSDSchema
740
	 */
741
	public XSDSchema getXSDSchema() {
742
		return schemalNodeAdapter != null ? schemalNodeAdapter.getSchema() : null;
743
	}
744
745
746
	/**
747
	 * Returns the resourceFile.
748
	 * 
749
	 * @return IFile
750
	 */
751
	public IFile getFileResource() {
752
		return resourceFile;
753
	}
754
755
	/**
756
	 * Get the IDocument from the text viewer
757
	 */
758
	public IDocument getEditorIDocument() {
759
		IDocument document = textEditor.getTextViewer().getDocument();
760
		return document;
761
	}
762
763
	/**
764
	 * Create ref integrity tasks in task list
765
	 */
766
	public void createTasksInTaskList(ArrayList messages) {
767
		// DisplayErrorInTaskList tasks = new
768
		// DisplayErrorInTaskList(getEditorIDocument(), getFileResource(),
769
		// messages);
770
		// tasks.run();
771
	}
772
773
	public void resetInformationTasks() {
774
		// DisplayErrorInTaskList.removeInfoMarkers(getFileResource());
775
	}
776
777
	public XSDGraphViewer getGraphViewer() {
778
		return graphViewer;
779
	}
780
781
	public IEditorPart getActiveEditorPage() {
782
		return getActiveEditor();
783
	}
784
785
	public StructuredTextEditor getTextEditor() {
786
		return textEditor;
787
	}
788
789
	class InternalPartListener implements IPartListener {
790
		XSDEditor editor;
791
792
		public InternalPartListener(XSDEditor editor) {
793
			this.editor = editor;
794
		}
795
796
		public void partActivated(IWorkbenchPart part) {
797
			if (part == editor) {
798
				ISelection selection = getSelectionManager().getSelection();
799
				if (selection != null) {
800
					if (getCurrentPageType().equals(XSDEditorPlugin.GRAPH_PAGE)) {
801
						getSelectionManager().selectionChanged(new SelectionChangedEvent(editor.getGraphViewer().getComponentViewer(), selection));
802
					}
803
					else if (getCurrentPageType().equals(XSDEditorPlugin.SOURCE_PAGE)) {
804
						getSelectionManager().setSelection(selection);
805
					}
806
				}
807
			}
808
		}
809
810
		public void partBroughtToTop(IWorkbenchPart part) {
811
		}
812
813
		public void partClosed(IWorkbenchPart part) {
814
		}
815
816
		public void partDeactivated(IWorkbenchPart part) {
817
		}
818
819
		public void partOpened(IWorkbenchPart part) {
820
		}
821
	}
822
823
824
	/**
825
	 * Method createDefaultSchemaNode. Should only be called to insert a
826
	 * schema node into an empty document
827
	 */
828
	public void createDefaultSchemaNode(Document document) {
829
		if (document.getChildNodes().getLength() == 0) {
830
			// if it is a completely empty file, then add the encoding and
831
			// version processing instruction
832
			// TODO String encoding = EncodingHelper.getDefaultEncodingTag();
833
			String encoding = "UTF-8";
834
			ProcessingInstruction instr = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + encoding + "\"");
835
			document.appendChild(instr);
836
		}
837
838
		// Create a default schema tag now
839
840
		// String defaultPrefixForTargetNamespace =
841
		// getFileResource().getProjectRelativePath().removeFileExtension().lastSegment();
842
		String defaultPrefixForTargetNamespace = "tns";
843
		String prefixForSchemaNamespace = "";
844
		String schemaNamespaceAttribute = "xmlns";
845
		if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage()) {
846
			// Added this if check before disallowing blank prefixes in the
847
			// preferences...
848
			// Can take this out. See also NewXSDWizard
849
			if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0) {
850
				prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":";
851
				schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix();
852
			}
853
		}
854
855
		document.appendChild(document.createTextNode("\n"));
856
		Element element = document.createElement(prefixForSchemaNamespace + XSDConstants.SCHEMA_ELEMENT_TAG);
857
858
		element.setAttribute(schemaNamespaceAttribute, "http://www.w3.org/2001/XMLSchema");
859
860
		String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace();
861
		element.setAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE, defaultTargetURI);
862
		element.setAttribute("xmlns:" + defaultPrefixForTargetNamespace, defaultTargetURI);
863
864
		document.appendChild(element);
285
	}
865
	}
286
	
287
	public Object getActivePart()
288
  {
289
		return getSite().getWorkbenchWindow().getActivePage().getActivePart();	
290
	}
291
292
  public void dispose()
293
  {
294
//    propertyChangeListener.dispose();
295
    removeCommandStackListener();
296
    
297
    XSDEditorPlugin.getPlugin().setDefaultPage(getCurrentPageType());
298
    XSDEditorPlugin.getPlugin().getPreferenceStore().removePropertyChangeListener(preferenceStoreListener);
299
    
300
    getSite().getPage().removePartListener(partListener);
301
302
    // KB: Temporary solution for bug 99468
303
    IStructuredModel myModel = textEditor.getModel();
304
    if (myModel != null && myModel instanceof IStructuredDocumentListener)
305
    	myModel.getStructuredDocument().removeDocumentChangingListener((IStructuredDocumentListener)myModel);
306
307
    textEditor = null;
308
    resourceFile = null;
309
    xsdSelectionManager = null;
310
    schemalNodeAdapter = null;
311
    result = null;
312
    partListener = null;
313
    commandStackListener = null;
314
    preferenceStoreListener = null;
315
    openOnSelectionHelper = null;
316
    graphViewer = null;
317
318
    super.dispose();
319
    
320
    // release the schema model
321
    //
322
    if (schemalNodeAdapter != null)
323
    {
324
      schemalNodeAdapter.clear();
325
      schemalNodeAdapter = null;
326
    }
327
  }
328
329
  protected boolean loadFile()
330
  {
331
    Object input = getEditorInput();
332
333
    if (input instanceof IFileEditorInput)
334
    {
335
      resourceFile = ((IFileEditorInput) input).getFile();
336
    }
337
    else if (input instanceof ILocationProvider)
338
    {
339
      IPath path = ((ILocationProvider)input).getPath(input);
340
      String ext = path.getFileExtension();
341
      if (ext != null && ext.equals("xsd"))
342
      {
343
        return true;
344
      }
345
      return false;
346
    }
347
    else
348
    {
349
      return false;
350
    }
351
    return true;
352
  }
353
354
  /**
355
   * Method openOnGlobalReference.
356
   * The comp argument is a resolved xsd schema object from another file.  This is created and called from another
357
   * schema model to allow F3 navigation to open a new editor and choose the referenced object within that editor context
358
   * @param comp
359
   */
360
  public void openOnGlobalReference(XSDConcreteComponent comp)
361
  {
362
    openOnSelectionHelper.openOnGlobalReference(comp);
363
  }
364
  
365
  protected OpenOnSelectionHelper openOnSelectionHelper;
366
367
  public OpenOnSelectionHelper getOpenOnSelectionHelper()
368
  {
369
    return openOnSelectionHelper;
370
  }
371
  
372
  /**
373
   * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#createTextEditor()
374
   */
375
  protected StructuredTextEditor createTextEditor()
376
  {
377
    return new XSDTextEditor(this);
378
  }
379
380
  /*
381
   * @see StructuredTextMultiPageEditorPart#createSourcePage()
382
   */
383
  protected void createSourcePage() throws PartInitException
384
  {
385
    super.createSourcePage();
386
    
387
    textEditor = (XSDTextEditor) getTextEditor();
388
389
		openOnSelectionHelper = new OpenOnSelectionHelper(textEditor);
390
  }
391
 
392
  int sourcePageIndex = -1;
393
  /**
394
   * Adds the source page of the multi-page editor.
395
   */
396
  protected void addSourcePage() throws PartInitException {
397
  
398
    sourcePageIndex = addPage(textEditor, getEditorInput());
399
    setPageText(sourcePageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_SOURCE"));
400
401
	// the update's critical, to get viewer selection manager and highlighting to work
402
    textEditor.update();
403
	firePropertyChange(PROP_TITLE);
404
  }                       
405
406
  int graphPageIndex = -1;            
407
  XSDGraphViewer graphViewer;
408
409
  /**
410
   * Creates the graph page and adds it to the multi-page editor.
411
   */
412
  protected void createAndAddGraphPage() throws PartInitException 
413
  {                         
414
    graphViewer = new XSDGraphViewer(this);                              
415
    graphViewer.setSchema(getXSDSchema());
416
    Control graphControl = graphViewer.createControl(getContainer());
417
    graphPageIndex = addPage(graphControl);
418
    setPageText(graphPageIndex, XSDEditorPlugin.getXSDString("_UI_TAB_GRAPH"));
419
420
    // graphViewer.setViewerSelectionManager(textEditor.getViewerSelectionManager());    
421
    graphViewer.setSelectionManager(getSelectionManager());
422
    
423
    // this forces the editor to initially select the top level schema object
424
    //
425
    if (textEditor.getXSDSchema() != null)
426
    {
427
      getSelectionManager().setSelection(new StructuredSelection(textEditor.getXSDSchema()));    
428
    }
429
  }
430
431
  /*
432
   * @see IAdaptable#getAdapter(Class)
433
   */
434
  public Object getAdapter(Class key)
435
  {
436
    Object result = null;
437
    if (key == ISelectionProvider.class)
438
    {
439
      result = xsdSelectionManager;
440
    }
441
    else 
442
    {
443
      result = textEditor.getAdapter(key);
444
    }
445
    return result;
446
  }
447
448
  public XSDSelectionManager getSelectionManager()
449
  {
450
    return xsdSelectionManager;
451
  }
452
 
453
  /**
454
   * @see org.eclipse.wst.xsd.ui.internal.XSDMultiPageEditorPart#doSaveAs()
455
   */
456
  public void doSaveAs()
457
  {
458
    super.doSaveAs();
459
  }
460
461
  public void doSave(org.eclipse.core.runtime.IProgressMonitor monitor)
462
  {
463
    super.doSave(monitor);
464
  }
465
466
  public void reparseSchema()
467
  {
468
    // TODO cs : Are there no better ways to make the model
469
    // reload it's dependencies?  This seems rather extreme.
470
    //
471
    Document document  = ((IDOMModel)getModel()).getDocument();
472
    if (schemalNodeAdapter != null)
473
    {  
474
      schemalNodeAdapter.createSchema(document.getDocumentElement());
475
    }  
476
  }
477
  
478
  /**
479
   * Returns the xsdSchema.
480
   * @return XSDSchema
481
   */
482
  public XSDSchema getXSDSchema()
483
  {
484
    return schemalNodeAdapter != null ? schemalNodeAdapter.getSchema() : null;
485
  }
486
487
488
  /**
489
   * Returns the resourceFile.
490
   * @return IFile
491
   */
492
  public IFile getFileResource()
493
  {
494
    return resourceFile;
495
  }
496
497
  /**
498
   * Get the IDocument from the text viewer
499
   */
500
  public IDocument getEditorIDocument()
501
  {
502
    IDocument document = textEditor.getTextViewer().getDocument();
503
    return document;
504
  }
505
506
  /**
507
   * Create ref integrity tasks in task list
508
   */
509
  public void createTasksInTaskList(ArrayList messages)
510
  {
511
//    DisplayErrorInTaskList tasks = new DisplayErrorInTaskList(getEditorIDocument(), getFileResource(), messages);
512
//    tasks.run();
513
  }
514
515
  public void resetInformationTasks()
516
  {
517
// DisplayErrorInTaskList.removeInfoMarkers(getFileResource());
518
  }
519
  
520
  public XSDGraphViewer getGraphViewer()
521
  {
522
    return graphViewer;
523
  }
524
525
  public IEditorPart getActiveEditorPage()
526
  {
527
    return getActiveEditor();
528
  }
529
  
530
  public XSDTextEditor getXSDTextEditor()
531
	{
532
    return textEditor;
533
  }
534
535
	class InternalPartListener implements IPartListener
536
	{
537
	  XSDEditor editor;
538
	  public InternalPartListener(XSDEditor editor)
539
	  {
540
	    this.editor = editor; 
541
	  }
542
	  
543
		public void partActivated(IWorkbenchPart part)
544
		{
545
			if (part == editor)
546
			{
547
        ISelection selection = getSelectionManager().getSelection();
548
        if (selection != null)
549
        {
550
          if (getCurrentPageType().equals(XSDEditorPlugin.GRAPH_PAGE))
551
          {
552
            getSelectionManager().selectionChanged(new SelectionChangedEvent(editor.getGraphViewer().getComponentViewer(), selection));
553
          }
554
          else if (getCurrentPageType().equals(XSDEditorPlugin.SOURCE_PAGE))
555
          {
556
            getSelectionManager().setSelection(selection);
557
          }
558
        }
559
			}
560
		}
561
562
		public void partBroughtToTop(IWorkbenchPart part)
563
		{
564
		}
565
566
		public void partClosed(IWorkbenchPart part)
567
		{
568
		}
569
   
570
		public void partDeactivated(IWorkbenchPart part)
571
		{
572
		}
573
574
		public void partOpened(IWorkbenchPart part)
575
		{
576
		}
577
	}
578
  
579
  
580
  /**
581
   * Method createDefaultSchemaNode.  Should only be called to insert a schema node into an empty document
582
   */
583
  public void createDefaultSchemaNode(Document document)
584
  {
585
    if (document.getChildNodes().getLength() == 0)
586
    {
587
      // if it is a completely empty file, then add the encoding and version processing instruction
588
//TODO  String encoding = EncodingHelper.getDefaultEncodingTag();
589
      String encoding = "UTF-8";
590
      ProcessingInstruction instr = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + encoding + "\"");
591
      document.appendChild(instr);
592
    }
593
594
    // Create a default schema tag now
595
596
    // String defaultPrefixForTargetNamespace = getFileResource().getProjectRelativePath().removeFileExtension().lastSegment();
597
    String defaultPrefixForTargetNamespace = "tns";
598
    String prefixForSchemaNamespace = "";
599
    String schemaNamespaceAttribute = "xmlns";
600
    if (XSDEditorPlugin.getPlugin().isQualifyXMLSchemaLanguage())
601
    {
602
      // Added this if check before disallowing blank prefixes in the preferences...
603
      // Can take this out.  See also NewXSDWizard
604
      if (XSDEditorPlugin.getPlugin().getXMLSchemaPrefix().trim().length() > 0)
605
      {
606
        prefixForSchemaNamespace = XSDEditorPlugin.getPlugin().getXMLSchemaPrefix() + ":";
607
        schemaNamespaceAttribute += ":" + XSDEditorPlugin.getPlugin().getXMLSchemaPrefix();
608
      }
609
    }
610
    
611
    document.appendChild(document.createTextNode("\n"));
612
    Element element = document.createElement(prefixForSchemaNamespace + XSDConstants.SCHEMA_ELEMENT_TAG);
613
    
614
    element.setAttribute(schemaNamespaceAttribute,"http://www.w3.org/2001/XMLSchema");
615
    
616
    String defaultTargetURI = XSDEditorPlugin.getPlugin().getXMLSchemaTargetNamespace();
617
    element.setAttribute(XSDConstants.TARGETNAMESPACE_ATTRIBUTE, defaultTargetURI);
618
    element.setAttribute("xmlns:" + defaultPrefixForTargetNamespace, defaultTargetURI);
619
    
620
    document.appendChild(element);
621
  }   
622
}
866
}
(-)src/org/eclipse/wst/xsd/ui/internal/XSDTextEditor.java (-51 / +50 lines)
Lines 36-45 Link Here
36
import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
36
import org.eclipse.wst.sse.ui.internal.view.events.INodeSelectionListener;
37
import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
37
import org.eclipse.wst.sse.ui.internal.view.events.NodeSelectionChangedEvent;
38
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
38
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
39
import org.eclipse.wst.xsd.ui.internal.properties.section.XSDTabbedPropertySheetPage;
40
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter;
39
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter;
41
import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider;
40
import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider;
42
import org.eclipse.wst.xsd.ui.internal.provider.XSDContentProvider;
43
import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl;
41
import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl;
44
import org.eclipse.wst.xsd.ui.internal.refactor.actions.RefactorActionGroup;
42
import org.eclipse.wst.xsd.ui.internal.refactor.actions.RefactorActionGroup;
45
import org.eclipse.wst.xsd.ui.internal.util.SelectionAdapter;
43
import org.eclipse.wst.xsd.ui.internal.util.SelectionAdapter;
Lines 49-55 Link Here
49
import org.w3c.dom.Element;
47
import org.w3c.dom.Element;
50
import org.w3c.dom.Node;
48
import org.w3c.dom.Node;
51
49
52
50
/**
51
 * @deprecated Do not use subclass of StructuredTextEditor
52
 */
53
public class XSDTextEditor extends StructuredTextEditor implements INodeSelectionListener, ISelectionChangedListener
53
public class XSDTextEditor extends StructuredTextEditor implements INodeSelectionListener, ISelectionChangedListener
54
{
54
{
55
  protected XSDSelectionManager xsdSelectionManager;
55
  protected XSDSelectionManager xsdSelectionManager;
Lines 58-64 Link Here
58
  protected InternalSelectionProvider internalSelectionProvider = new InternalSelectionProvider();
58
  protected InternalSelectionProvider internalSelectionProvider = new InternalSelectionProvider();
59
  private IPropertySheetPage fPropertySheetPage;
59
  private IPropertySheetPage fPropertySheetPage;
60
  private IContentOutlinePage fOutlinePage;
60
  private IContentOutlinePage fOutlinePage;
61
61
  
62
  public XSDTextEditor(XSDEditor xsdEditor)
62
  public XSDTextEditor(XSDEditor xsdEditor)
63
  {
63
  {
64
    super();
64
    super();
Lines 70-76 Link Here
70
    xsdModelAdapterFactory = XSDModelAdapterFactoryImpl.getInstance();
70
    xsdModelAdapterFactory = XSDModelAdapterFactoryImpl.getInstance();
71
    adapterFactoryLabelProvider = new XSDAdapterFactoryLabelProvider(xsdModelAdapterFactory);
71
    adapterFactoryLabelProvider = new XSDAdapterFactoryLabelProvider(xsdModelAdapterFactory);
72
  }
72
  }
73
  
74
  public void dispose()
73
  public void dispose()
75
  {
74
  {
76
    super.dispose();
75
    super.dispose();
Lines 80-130 Link Here
80
    xsdModelAdapterFactory = null;
79
    xsdModelAdapterFactory = null;
81
  }
80
  }
82
  
81
  
83
  public XSDModelAdapterFactoryImpl getXSDModelAdapterFactory()
82
//  public XSDModelAdapterFactoryImpl getXSDModelAdapterFactory()
84
  {
83
//  {
85
    return xsdModelAdapterFactory;
84
//    return xsdModelAdapterFactory;
86
  }
85
//  }
87
86
//
88
  public static XSDAdapterFactoryLabelProvider getLabelProvider()
87
//  public static XSDAdapterFactoryLabelProvider getLabelProvider()
89
  {
88
//  {
90
    return adapterFactoryLabelProvider;
89
//    return adapterFactoryLabelProvider;
91
  }
90
//  }
92
91
93
	public Object getAdapter(Class required) {
92
//	public Object getAdapter(Class required) {
94
	  
93
//	  
95
		if (IPropertySheetPage.class.equals(required))
94
//		if (IPropertySheetPage.class.equals(required))
96
    {
95
//    {
97
	    fPropertySheetPage = new XSDTabbedPropertySheetPage(getXSDEditor());
96
//	    fPropertySheetPage = new XSDTabbedPropertySheetPage(getXSDEditor());
98
      
97
//      
99
	    ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDModelAdapterFactory(xsdModelAdapterFactory);
98
//	    ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDModelAdapterFactory(xsdModelAdapterFactory);
100
      ((XSDTabbedPropertySheetPage)fPropertySheetPage).setSelectionManager(getXSDEditor().getSelectionManager());
99
//      ((XSDTabbedPropertySheetPage)fPropertySheetPage).setSelectionManager(getXSDEditor().getSelectionManager());
101
	    ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDSchema(getXSDSchema());
100
//	    ((XSDTabbedPropertySheetPage)fPropertySheetPage).setXSDSchema(getXSDSchema());
102
101
//
103
      return fPropertySheetPage;
102
//      return fPropertySheetPage;
104
		}
103
//		}
105
		else if (IContentOutlinePage.class.equals(required))
104
//		else if (IContentOutlinePage.class.equals(required))
106
		{
105
//		{
107
			if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed())
106
//			if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed())
108
			{
107
//			{
109
				XSDContentOutlinePage outlinePage = new XSDContentOutlinePage(this);
108
//				XSDContentOutlinePage outlinePage = new XSDContentOutlinePage(getXSDEditor());
110
        XSDContentProvider xsdContentProvider = new XSDContentProvider(xsdModelAdapterFactory);
109
//        XSDContentProvider xsdContentProvider = new XSDContentProvider(xsdModelAdapterFactory);
111
        xsdContentProvider.setXSDSchema(getXSDSchema());
110
//        xsdContentProvider.setXSDSchema(getXSDSchema());
112
	      outlinePage.setContentProvider(xsdContentProvider);
111
//	      outlinePage.setContentProvider(xsdContentProvider);
113
	      outlinePage.setLabelProvider(adapterFactoryLabelProvider);
112
//	      outlinePage.setLabelProvider(adapterFactoryLabelProvider);
114
				outlinePage.setModel(getXSDSchema().getDocument());
113
//				outlinePage.setModel(getXSDSchema().getDocument());
115
				
114
//				
116
				// Update outline selection from source editor selection:
115
//				// Update outline selection from source editor selection:
117
	      getViewerSelectionManager().addNodeSelectionListener(this);
116
//	      getViewerSelectionManager().addNodeSelectionListener(this);
118
	      internalSelectionProvider.addSelectionChangedListener(getViewerSelectionManager());
117
//	      internalSelectionProvider.addSelectionChangedListener(getViewerSelectionManager());
119
	      internalSelectionProvider.setEventSource(outlinePage);
118
//	      internalSelectionProvider.setEventSource(outlinePage);
120
119
//
121
				fOutlinePage = outlinePage;
120
//				fOutlinePage = outlinePage;
122
			}
121
//			}
123
			return fOutlinePage;
122
//			return fOutlinePage;
124
		}
123
//		}
125
	
124
//	
126
		return super.getAdapter(required);
125
//		return super.getAdapter(required);
127
	}
126
//	}
128
  
127
  
129
 
128
 
130
  protected XSDContentOutlinePage outlinePage;
129
  protected XSDContentOutlinePage outlinePage;
Lines 326-331 Link Here
326
		fRefactorMenuGroup.setContext(context);
325
		fRefactorMenuGroup.setContext(context);
327
		fRefactorMenuGroup.fillContextMenu(menu);
326
		fRefactorMenuGroup.fillContextMenu(menu);
328
		fRefactorMenuGroup.setContext(null);
327
		fRefactorMenuGroup.setContext(null);
329
	}   
328
	}
330
}
329
}
331
330
(-)src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDSectionLabelProvider.java (-2 / +11 lines)
Lines 15-23 Link Here
15
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.jface.viewers.LabelProvider;
16
import org.eclipse.jface.viewers.StructuredSelection;
16
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.ui.IEditorPart;
19
import org.eclipse.ui.IWorkbench;
20
import org.eclipse.ui.IWorkbenchWindow;
18
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
21
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
22
import org.eclipse.wst.xsd.ui.internal.XSDEditor;
19
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
23
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
20
import org.eclipse.wst.xsd.ui.internal.XSDTextEditor;
21
import org.eclipse.xsd.XSDAttributeDeclaration;
24
import org.eclipse.xsd.XSDAttributeDeclaration;
22
import org.eclipse.xsd.XSDConcreteComponent;
25
import org.eclipse.xsd.XSDConcreteComponent;
23
import org.eclipse.xsd.XSDElementDeclaration;
26
import org.eclipse.xsd.XSDElementDeclaration;
Lines 50-56 Link Here
50
      
53
      
51
      if (selected instanceof XSDConcreteComponent)
54
      if (selected instanceof XSDConcreteComponent)
52
      {
55
      {
53
        return XSDTextEditor.getLabelProvider().getImage((XSDConcreteComponent)selected);
56
        IWorkbench workbench = XSDEditorPlugin.getPlugin().getWorkbench();
57
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
58
        IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
59
        if (editorPart instanceof XSDEditor)
60
        {
61
          return ((XSDEditor)editorPart).getLabelProvider().getImage((XSDConcreteComponent)selected);
62
        }
54
      }
63
      }
55
      
64
      
56
//      selected  = typeMapper.remapObject(selected);
65
//      selected  = typeMapper.remapObject(selected);
(-)src/org/eclipse/wst/xsd/ui/internal/properties/section/XSDTabbedPropertySheetPage.java (-6 / +48 lines)
Lines 15-23 Link Here
15
import org.eclipse.jface.text.TextSelection;
15
import org.eclipse.jface.text.TextSelection;
16
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.ISelectionChangedListener;
17
import org.eclipse.jface.viewers.ISelectionChangedListener;
18
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.SelectionChangedEvent;
19
import org.eclipse.jface.viewers.SelectionChangedEvent;
19
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.ui.IWorkbenchPart;
21
import org.eclipse.ui.IWorkbenchPart;
22
import org.eclipse.ui.part.IPageSite;
21
import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor;
23
import org.eclipse.wst.common.ui.properties.internal.provisional.ITabbedPropertySheetPageContributor;
22
import org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetPage;
24
import org.eclipse.wst.common.ui.properties.internal.provisional.TabbedPropertySheetPage;
23
import org.eclipse.wst.xsd.ui.internal.XSDSelectionManager;
25
import org.eclipse.wst.xsd.ui.internal.XSDSelectionManager;
Lines 25-34 Link Here
25
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter;
27
import org.eclipse.wst.xsd.ui.internal.provider.CategoryAdapter;
26
import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl;
28
import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl;
27
import org.eclipse.xsd.XSDSchema;
29
import org.eclipse.xsd.XSDSchema;
30
import org.w3c.dom.Element;
31
import org.w3c.dom.Node;
32
import org.w3c.dom.ProcessingInstruction;
33
import org.w3c.dom.Text;
28
34
29
public class XSDTabbedPropertySheetPage extends TabbedPropertySheetPage
35
public class XSDTabbedPropertySheetPage extends TabbedPropertySheetPage
30
  implements ISelectionChangedListener, INotifyChangedListener 
36
  implements ISelectionChangedListener, INotifyChangedListener 
31
{
37
{
38
  XSDSchema xsdSchema;
32
  private XSDSelectionManager selectionManager;
39
  private XSDSelectionManager selectionManager;
33
  private XSDModelAdapterFactoryImpl adapterFactory;
40
  private XSDModelAdapterFactoryImpl adapterFactory;
34
  /**
41
  /**
Lines 39-45 Link Here
39
    super(tabbedPropertySheetPageContributor);
46
    super(tabbedPropertySheetPageContributor);
40
  }
47
  }
41
  
48
  
42
  XSDSchema xsdSchema;
49
  public void init(IPageSite pageSite)
50
  {
51
  	super.init(pageSite);
52
  	getSite().getWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
53
  }
54
43
  public void setXSDSchema(XSDSchema xsdSchema)
55
  public void setXSDSchema(XSDSchema xsdSchema)
44
  {
56
  {
45
    this.xsdSchema = xsdSchema;
57
    this.xsdSchema = xsdSchema;
Lines 81-102 Link Here
81
    // override for category
93
    // override for category
82
    if (selection != null)
94
    if (selection != null)
83
    {
95
    {
84
      if (selection instanceof StructuredSelection)
96
      if (selection instanceof IStructuredSelection)
85
      {
97
      {
86
        StructuredSelection structuredSelection = (StructuredSelection)selection;
98
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
87
        if (structuredSelection.isEmpty())
99
        if (structuredSelection.isEmpty())
88
        {
100
        {
89
          return;
101
          return;
90
        }
102
        }
91
        Object obj = structuredSelection.getFirstElement();        
103
        Object obj = structuredSelection.getFirstElement();
92
        if (obj instanceof CategoryAdapter)
104
        if (obj instanceof Element)
105
        {
106
          try
107
          {
108
            Object modelObject = xsdSchema.getCorrespondingComponent((Element) obj);
109
            if (modelObject != null)
110
            {
111
              obj = modelObject;
112
              selection = new StructuredSelection(obj);
113
            }
114
          }
115
          catch (Exception e)
116
          {
117
          }
118
        }
119
        else if (obj instanceof Text)
120
        {
121
        	Node parent = ((Text)obj).getParentNode();
122
          Object modelObject = xsdSchema.getCorrespondingComponent(parent);
123
          if (modelObject != null)
124
          {
125
            obj = modelObject;
126
            selection = new StructuredSelection(obj);
127
          }
128
        }
129
        else if (obj instanceof CategoryAdapter)
93
        {
130
        {
94
          selection = new StructuredSelection(((CategoryAdapter)obj).getXSDSchema());
131
          selection = new StructuredSelection(((CategoryAdapter)obj).getXSDSchema());
95
        }
132
        }
96
        else if (obj instanceof Category)
133
        else if (obj instanceof Category)
97
        {
134
        {
98
          selection = new StructuredSelection(((Category)obj).getXSDSchema());
135
          selection = new StructuredSelection(((Category)obj).getXSDSchema());
99
        }  
136
        }
137
        else if (obj instanceof ProcessingInstruction)
138
        {
139
        	selection = new StructuredSelection(xsdSchema);
140
        }
100
      }
141
      }
101
      else if (selection instanceof TextSelection)
142
      else if (selection instanceof TextSelection)
102
      {
143
      {
Lines 125-130 Link Here
125
    {
166
    {
126
      adapterFactory.removeListener(this);
167
      adapterFactory.removeListener(this);
127
    }
168
    }
169
    getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(this);
128
    super.dispose();
170
    super.dispose();
129
  }
171
  }
130
  
172
  
(-)src/org/eclipse/wst/xsd/ui/internal/provider/XSDContentProvider.java (-16 / +60 lines)
Lines 20-42 Link Here
20
import org.eclipse.emf.edit.provider.IChangeNotifier;
20
import org.eclipse.emf.edit.provider.IChangeNotifier;
21
import org.eclipse.emf.edit.provider.INotifyChangedListener;
21
import org.eclipse.emf.edit.provider.INotifyChangedListener;
22
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
22
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
23
import org.eclipse.jface.text.IDocument;
23
import org.eclipse.jface.viewers.ITreeContentProvider;
24
import org.eclipse.jface.viewers.ITreeContentProvider;
24
import org.eclipse.jface.viewers.StructuredViewer;
25
import org.eclipse.jface.viewers.StructuredViewer;
25
import org.eclipse.jface.viewers.Viewer;
26
import org.eclipse.jface.viewers.Viewer;
27
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
28
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
29
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
30
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
31
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter;
26
import org.eclipse.xsd.XSDConcreteComponent;
32
import org.eclipse.xsd.XSDConcreteComponent;
27
import org.eclipse.xsd.XSDElementDeclaration;
33
import org.eclipse.xsd.XSDElementDeclaration;
28
import org.eclipse.xsd.XSDModelGroup;
34
import org.eclipse.xsd.XSDModelGroup;
29
import org.eclipse.xsd.XSDParticleContent;
35
import org.eclipse.xsd.XSDParticleContent;
30
import org.eclipse.xsd.XSDSchema;
36
import org.eclipse.xsd.XSDSchema;
31
import org.eclipse.xsd.XSDWildcard;
37
import org.eclipse.xsd.XSDWildcard;
32
import org.w3c.dom.Document;
33
import org.w3c.dom.Node;
38
import org.w3c.dom.Node;
34
39
35
public class XSDContentProvider implements ITreeContentProvider, INotifyChangedListener
40
public class XSDContentProvider implements ITreeContentProvider, INotifyChangedListener
36
{
41
{
37
  XSDModelAdapterFactoryImpl xsdModelAdapterFactory;
42
  XSDModelAdapterFactoryImpl xsdModelAdapterFactory;
38
43
39
  XSDSchema xsdSchema;
40
  public XSDContentProvider(XSDModelAdapterFactoryImpl xsdModelAdapterFactoryImpl)
44
  public XSDContentProvider(XSDModelAdapterFactoryImpl xsdModelAdapterFactoryImpl)
41
  {
45
  {
42
    this.xsdModelAdapterFactory = xsdModelAdapterFactoryImpl;
46
    this.xsdModelAdapterFactory = xsdModelAdapterFactoryImpl;
Lines 47-57 Link Here
47
    }
51
    }
48
  }
52
  }
49
  
53
  
50
  public void setXSDSchema(XSDSchema xsdSchema)
51
  {
52
    this.xsdSchema = xsdSchema;
53
  }
54
  
55
  /*
54
  /*
56
   * @see ITreeContentProvider#getChildren(Object)
55
   * @see ITreeContentProvider#getChildren(Object)
57
   */
56
   */
Lines 59-73 Link Here
59
  {
58
  {
60
    XSDConcreteComponent xsdComp = null;
59
    XSDConcreteComponent xsdComp = null;
61
    List list = null;
60
    List list = null;
62
    if (parentElement instanceof Document)
61
    
63
    {
62
    // root/input is structuredmodel
64
      xsdComp = xsdSchema;
63
    if (parentElement instanceof IDOMModel) {
65
 	    
64
		IDOMDocument domDoc = ((IDOMModel) parentElement).getDocument();
66
      xsdModelAdapterFactory.adapt(xsdComp, xsdModelAdapterFactory);
65
		if (domDoc != null) {
67
66
			XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class);
68
      list = new ArrayList();
67
			/*
69
      list.add(xsdComp);
68
			 * ISSUE: Didn't want to go through initializing
70
      return list.toArray();
69
			 * schema if it does not already exist, so just
70
			 * attempted to get existing adapter. If doesn't
71
			 * exist, just don't bother working.
72
			 */
73
			if (modelAdapter != null)
74
				xsdComp = modelAdapter.getSchema();
75
			if (xsdComp != null) {
76
		      xsdModelAdapterFactory.adapt(xsdComp, xsdModelAdapterFactory);
77
78
		      list = new ArrayList();
79
		      list.add(xsdComp);
80
		      return list.toArray();
81
			}
82
		}
71
    }
83
    }
72
    else if (parentElement instanceof XSDConcreteComponent)
84
    else if (parentElement instanceof XSDConcreteComponent)
73
    {
85
    {
Lines 181-184 Link Here
181
    this.viewer = viewer;
193
    this.viewer = viewer;
182
  }
194
  }
183
  
195
  
196
	/**
197
	 * Gets the xsd schema from document
198
	 * 
199
	 * @param document
200
	 * @return XSDSchema or null of one does not exist yet for document
201
	 */
202
	private XSDSchema getXSDSchema(IDocument document) {
203
		XSDSchema schema = null;
204
		IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
205
		if (model != null) {
206
			try {
207
				if (model instanceof IDOMModel) {
208
					IDOMDocument domDoc = ((IDOMModel) model).getDocument();
209
					if (domDoc != null) {
210
						XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class);
211
						/*
212
						 * ISSUE: Didn't want to go through initializing
213
						 * schema if it does not already exist, so just
214
						 * attempted to get existing adapter. If doesn't
215
						 * exist, just don't bother working.
216
						 */
217
						if (modelAdapter != null)
218
							schema = modelAdapter.getSchema();
219
					}
220
				}
221
			}
222
			finally {
223
				model.releaseFromRead();
224
			}
225
		}
226
		return schema;
227
	}
184
}
228
}
(-)src/org/eclipse/wst/xsd/ui/internal/provider/XSDSchemaAdapter.java (-368 / +342 lines)
Lines 16-21 Link Here
16
16
17
import org.eclipse.emf.common.notify.AdapterFactory;
17
import org.eclipse.emf.common.notify.AdapterFactory;
18
import org.eclipse.emf.common.notify.Notification;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notifier;
19
import org.eclipse.emf.common.notify.impl.NotificationImpl;
20
import org.eclipse.emf.common.notify.impl.NotificationImpl;
20
import org.eclipse.emf.common.util.URI;
21
import org.eclipse.emf.common.util.URI;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Image;
Lines 33-405 Link Here
33
import org.eclipse.xsd.XSDTypeDefinition;
34
import org.eclipse.xsd.XSDTypeDefinition;
34
35
35
36
36
public class XSDSchemaAdapter extends XSDAbstractAdapter
37
public class XSDSchemaAdapter extends XSDAbstractAdapter {
37
{
38
	protected XSDPackage xsdPackage;
38
  protected XSDPackage xsdPackage;
39
39
  /**
40
	/**
40
   * @param adapterFactory
41
	 * @param adapterFactory
41
   */
42
	 */
42
  public XSDSchemaAdapter(AdapterFactory adapterFactory)
43
	public XSDSchemaAdapter(AdapterFactory adapterFactory) {
43
  {
44
		super(adapterFactory);
44
    super(adapterFactory);
45
		xsdPackage = XSDPackage.eINSTANCE;
45
    xsdPackage = XSDPackage.eINSTANCE;
46
	}
46
  }
47
47
48
	public Image getImage(Object element) {
48
  public Image getImage(Object element)
49
		return XSDEditorPlugin.getXSDImage("icons/XSDFile.gif");
49
  {
50
	}
50
    return XSDEditorPlugin.getXSDImage("icons/XSDFile.gif");
51
51
  }
52
	public String getText(Object element) {
52
  
53
		XSDSchema xsdSchema = (XSDSchema) element;
53
  public String getText(Object element)
54
		String result = xsdSchema.getSchemaLocation();
54
  {
55
		if (result == null) {
55
    XSDSchema xsdSchema = (XSDSchema)element;
56
			return "";
56
    String result = xsdSchema.getSchemaLocation();
57
		}
57
    if (result == null)
58
		else {
58
    {
59
			return URI.createURI(result).lastSegment();
59
      return "";
60
		}
60
    } 
61
	}
61
    else
62
62
    {
63
	List children;
63
      return URI.createURI(result).lastSegment();
64
	private CategoryAdapter fDirectivesCategory;
64
    }
65
	private CategoryAdapter fElementsCategory;
65
  }
66
	private CategoryAdapter fAttributesCategory;
66
  List children;
67
	private CategoryAdapter fAttributeGroupsCategory;
67
  public Object[] getChildren(Object parentElement)
68
	private CategoryAdapter fTypesCategory;
68
  {
69
	private CategoryAdapter fGroupsCategory;
69
    XSDSchema xsdSchema = ((XSDSchema)parentElement);
70
	private CategoryAdapter fNotationsCategory;
70
71
71
    children = new ArrayList();
72
	/**
72
    
73
	 * Create all the category adapters
73
    List directivesList = getDirectives(xsdSchema);
74
	 * 
74
    
75
	 * @param xsdSchema
75
    List elementsList = getGlobalElements(xsdSchema);
76
	 */
76
    
77
	private void createCategoryAdapters(XSDSchema xsdSchema) {
77
    List attributeGroupList = getAttributeGroupList(xsdSchema);
78
		List directivesList = getDirectives(xsdSchema);
78
    
79
		List elementsList = getGlobalElements(xsdSchema);
79
    List attributesList = getAttributeList(xsdSchema);
80
		List attributeGroupList = getAttributeGroupList(xsdSchema);
80
    
81
		List attributesList = getAttributeList(xsdSchema);
81
    List groups = getGroups(xsdSchema);
82
		List groups = getGroups(xsdSchema);
82
    
83
		List notations = getNotations(xsdSchema);
83
    List notations = getNotations(xsdSchema);
84
		List types = getComplexTypes(xsdSchema);
84
85
		types.addAll(getSimpleTypes(xsdSchema));
85
    List types = getComplexTypes(xsdSchema);
86
86
    types.addAll(getSimpleTypes(xsdSchema));
87
		fDirectivesCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Elements_label"),
87
    
88
					XSDEditorPlugin.getXSDString("_UI_GRAPH_DIRECTIVES"), XSDEditorPlugin.getPlugin().getIconImage("obj16/directivesheader"), directivesList, xsdSchema, CategoryAdapter.DIRECTIVES);
88
    children.add
89
		fElementsCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Elements_label"),
89
    (new CategoryAdapter
90
					XSDEditorPlugin.getXSDString("_UI_GRAPH_ELEMENTS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/elementsheader"), elementsList, xsdSchema, CategoryAdapter.ELEMENTS);
90
      ( //XSDEditPlugin.getString("_UI_Elements_label"), 
91
		fAttributesCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Attributes_label"),
91
        XSDEditorPlugin.getXSDString("_UI_GRAPH_DIRECTIVES"),
92
					XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTES"), XSDEditorPlugin.getPlugin().getIconImage("obj16/attributesheader"), attributesList, xsdSchema, CategoryAdapter.ATTRIBUTES);
92
        XSDEditorPlugin.getPlugin().getIconImage("obj16/directivesheader"),
93
		fAttributeGroupsCategory = new CategoryAdapter(// XSDEditPlugin.getString("_UI_AttributeGroups_label"),
93
        directivesList, xsdSchema, CategoryAdapter.DIRECTIVES));
94
					XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTE_GROUPS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/attributegroupsheader"), attributeGroupList, xsdSchema, CategoryAdapter.ATTRIBUTE_GROUPS);
94
    children.add
95
		fTypesCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Types_label"),
95
        (new CategoryAdapter
96
					XSDEditorPlugin.getXSDString("_UI_GRAPH_TYPES"), XSDEditorPlugin.getPlugin().getIconImage("obj16/typesheader"), types, xsdSchema, CategoryAdapter.TYPES);
96
          ( //XSDEditPlugin.getString("_UI_Elements_label"), 
97
		fGroupsCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_ModelGroups_label"),
97
            XSDEditorPlugin.getXSDString("_UI_GRAPH_ELEMENTS"),
98
					XSDEditorPlugin.getXSDString("_UI_GRAPH_GROUPS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/groupsheader"), groups, xsdSchema, CategoryAdapter.GROUPS);
98
            XSDEditorPlugin.getPlugin().getIconImage("obj16/elementsheader"),
99
		fNotationsCategory = new CategoryAdapter( // XSDEditPlugin.getString("_UI_Notations_label"),
99
            elementsList, xsdSchema, CategoryAdapter.ELEMENTS));
100
					XSDEditorPlugin.getXSDString("_UI_GRAPH_NOTATIONS"), XSDEditorPlugin.getPlugin().getIconImage("obj16/notationsheader"), notations, xsdSchema, CategoryAdapter.NOTATIONS);
100
      children.add
101
	}
101
        (new CategoryAdapter
102
102
          ( //XSDEditPlugin.getString("_UI_Attributes_label"),
103
	public void setTarget(Notifier newTarget) {
103
            XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTES"),
104
		super.setTarget(newTarget);
104
            XSDEditorPlugin.getPlugin().getIconImage("obj16/attributesheader"),
105
105
            attributesList, xsdSchema, CategoryAdapter.ATTRIBUTES));
106
		XSDSchema xsdSchema = ((XSDSchema) newTarget);
106
      children.add
107
		createCategoryAdapters(xsdSchema);
107
        (new CategoryAdapter
108
	}
108
          (//XSDEditPlugin.getString("_UI_AttributeGroups_label"),
109
109
            XSDEditorPlugin.getXSDString("_UI_GRAPH_ATTRIBUTE_GROUPS"),
110
	public Object[] getChildren(Object parentElement) {
110
            XSDEditorPlugin.getPlugin().getIconImage("obj16/attributegroupsheader"),
111
		XSDSchema xsdSchema = ((XSDSchema) parentElement);
111
            attributeGroupList, xsdSchema, CategoryAdapter.ATTRIBUTE_GROUPS));
112
112
      children.add
113
		children = new ArrayList();
113
        (new CategoryAdapter
114
114
          ( //XSDEditPlugin.getString("_UI_Types_label"), 
115
		// just set categoryadapters' children if category adapters are
115
            XSDEditorPlugin.getXSDString("_UI_GRAPH_TYPES"),
116
		// already created
116
            XSDEditorPlugin.getPlugin().getIconImage("obj16/typesheader"),
117
		if (fDirectivesCategory != null) {
117
            types, xsdSchema, CategoryAdapter.TYPES));
118
			List directivesList = getDirectives(xsdSchema);
118
      children.add
119
			List elementsList = getGlobalElements(xsdSchema);
119
        (new CategoryAdapter
120
			List attributeGroupList = getAttributeGroupList(xsdSchema);
120
          ( // XSDEditPlugin.getString("_UI_ModelGroups_label"), 
121
			List attributesList = getAttributeList(xsdSchema);
121
            XSDEditorPlugin.getXSDString("_UI_GRAPH_GROUPS"),
122
			List groups = getGroups(xsdSchema);
122
            XSDEditorPlugin.getPlugin().getIconImage("obj16/groupsheader"),
123
			List notations = getNotations(xsdSchema);
123
            groups, xsdSchema, CategoryAdapter.GROUPS));
124
			List types = getComplexTypes(xsdSchema);
124
      children.add
125
			types.addAll(getSimpleTypes(xsdSchema));
125
        (new CategoryAdapter
126
126
          ( // XSDEditPlugin.getString("_UI_Notations_label"), 
127
			fDirectivesCategory.setChildren(directivesList);
127
            XSDEditorPlugin.getXSDString("_UI_GRAPH_NOTATIONS"),
128
			fElementsCategory.setChildren(elementsList);
128
            XSDEditorPlugin.getPlugin().getIconImage("obj16/notationsheader"),
129
			fAttributesCategory.setChildren(attributesList);
129
            notations, xsdSchema, CategoryAdapter.NOTATIONS));
130
			fAttributeGroupsCategory.setChildren(attributeGroupList);
130
//      children.add
131
			fTypesCategory.setChildren(types);
131
//        (new CategoryAdapter
132
			fGroupsCategory.setChildren(groups);
132
//          ( //XSDEditPlugin.getString("_UI_IdentityConstraints_label"), 
133
			fNotationsCategory.setChildren(notations);
133
//              "Identity Constraints",
134
134
//            XSDEditorPlugin.getPlugin().getIconImage("full/obj16/XSDIdentityConstraintDefinitionKey"),
135
			// children.add
135
//            xsdSchema.getIdentityConstraintDefinitions(), xsdSchema, CategoryAdapter.IDENTITY_CONSTRAINTS));
136
			// (new CategoryAdapter
136
//      children.add
137
			// ( //XSDEditPlugin.getString("_UI_IdentityConstraints_label"),
137
//        (new CategoryAdapter
138
			// "Identity Constraints",
138
//          ( // XSDEditPlugin.getString("_UI_Annotations_label"), 
139
			// XSDEditorPlugin.getPlugin().getIconImage("full/obj16/XSDIdentityConstraintDefinitionKey"),
139
//              "Annotations",
140
			// xsdSchema.getIdentityConstraintDefinitions(), xsdSchema,
140
//            XSDEditorPlugin.getPlugin().getIconImage("obj16/annotationsheader"),
141
			// CategoryAdapter.IDENTITY_CONSTRAINTS));
141
//            xsdSchema.getAnnotations(), xsdSchema, CategoryAdapter.ANNOTATIONS));
142
			// children.add
142
143
			// (new CategoryAdapter
143
    return children.toArray();
144
			// ( // XSDEditPlugin.getString("_UI_Annotations_label"),
144
  
145
			// "Annotations",
145
  }
146
			// XSDEditorPlugin.getPlugin().getIconImage("obj16/annotationsheader"),
146
  
147
			// xsdSchema.getAnnotations(), xsdSchema,
147
  public boolean hasChildren(Object object)
148
			// CategoryAdapter.ANNOTATIONS));
148
  {
149
		}
149
    return true;
150
		else {
150
  }
151
			createCategoryAdapters(xsdSchema);
151
152
		}
152
  public Object getParent(Object object)
153
153
  {
154
		children.add(fDirectivesCategory);
154
    return null;
155
		children.add(fElementsCategory);
155
  }
156
		children.add(fAttributesCategory);
156
  
157
		children.add(fAttributeGroupsCategory);
157
  public void notifyChanged(final Notification msg)
158
		children.add(fTypesCategory);
158
  {
159
		children.add(fGroupsCategory);
159
    class CategoryNotification extends NotificationImpl
160
		children.add(fNotationsCategory);
160
    {
161
161
      protected Object category;
162
		return children.toArray();
162
      public CategoryNotification(Object category)
163
	}
163
      {
164
164
        super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition());
165
	public boolean hasChildren(Object object) {
165
        this.category = category;
166
		return true;
166
      }
167
	}
167
168
168
      public Object getNotifier()
169
	public Object getParent(Object object) {
169
      {
170
		return null;
170
        return category;
171
	}
171
      }
172
172
      public Object getFeature()
173
	public void notifyChanged(final Notification msg) {
173
      {
174
		class CategoryNotification extends NotificationImpl {
174
        return msg.getFeature();
175
			protected Object category;
175
      }
176
176
    }
177
			public CategoryNotification(Object category) {
177
    
178
				super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition());
178
    if (children == null) {
179
				this.category = category;
179
    	getChildren(target);
180
			}
180
    }
181
181
182
			public Object getNotifier() {
182
    if (msg.getFeature() == xsdPackage.getXSDSchema_Contents())
183
				return category;
183
    {
184
			}
184
      CategoryAdapter adapter = (CategoryAdapter)children.get(0);
185
185
      XSDSchema xsdSchema = adapter.getXSDSchema();
186
			public Object getFeature() {
186
      adapter.setChildren(getDirectives(xsdSchema));
187
				return msg.getFeature();
187
      this.fireNotifyChanged(new CategoryNotification(adapter));
188
			}
188
      return;
189
		}
189
    }
190
190
    else if (msg.getFeature() == xsdPackage.getXSDSchema_ElementDeclarations())
191
		if (children == null) {
191
    {
192
			getChildren(target);
192
      CategoryAdapter adapter = (CategoryAdapter)children.get(1);
193
		}
193
      XSDSchema xsdSchema = adapter.getXSDSchema();
194
194
      adapter.setChildren(getGlobalElements(xsdSchema));
195
		if (msg.getFeature() == xsdPackage.getXSDSchema_Contents()) {
195
      this.fireNotifyChanged(new CategoryNotification(adapter));
196
			CategoryAdapter adapter = (CategoryAdapter) children.get(0);
196
      return;
197
			XSDSchema xsdSchema = adapter.getXSDSchema();
197
    }
198
			adapter.setChildren(getDirectives(xsdSchema));
198
    else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeDeclarations())
199
			this.fireNotifyChanged(new CategoryNotification(adapter));
199
    {
200
			return;
200
      CategoryAdapter adapter = (CategoryAdapter)children.get(2);
201
		}
201
      XSDSchema xsdSchema = adapter.getXSDSchema();
202
		else if (msg.getFeature() == xsdPackage.getXSDSchema_ElementDeclarations()) {
202
      adapter.setChildren(getAttributeList(xsdSchema));
203
			CategoryAdapter adapter = (CategoryAdapter) children.get(1);
203
      this.fireNotifyChanged(new CategoryNotification(adapter));
204
			XSDSchema xsdSchema = adapter.getXSDSchema();
204
      return;
205
			adapter.setChildren(getGlobalElements(xsdSchema));
205
    }
206
			this.fireNotifyChanged(new CategoryNotification(adapter));
206
    else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeGroupDefinitions())
207
			return;
207
    {
208
		}
208
      CategoryAdapter adapter = (CategoryAdapter)children.get(3);
209
		else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeDeclarations()) {
209
      XSDSchema xsdSchema = adapter.getXSDSchema();
210
			CategoryAdapter adapter = (CategoryAdapter) children.get(2);
210
      adapter.setChildren(getAttributeGroupList(xsdSchema));
211
			XSDSchema xsdSchema = adapter.getXSDSchema();
211
      this.fireNotifyChanged(new CategoryNotification(adapter));
212
			adapter.setChildren(getAttributeList(xsdSchema));
212
      return;
213
			this.fireNotifyChanged(new CategoryNotification(adapter));
213
    }
214
			return;
214
    else if (msg.getFeature() == xsdPackage.getXSDSchema_TypeDefinitions())
215
		}
215
    {
216
		else if (msg.getFeature() == xsdPackage.getXSDSchema_AttributeGroupDefinitions()) {
216
      CategoryAdapter adapter = (CategoryAdapter)children.get(4);
217
			CategoryAdapter adapter = (CategoryAdapter) children.get(3);
217
      XSDSchema xsdSchema = adapter.getXSDSchema();
218
			XSDSchema xsdSchema = adapter.getXSDSchema();
218
      List types = getComplexTypes(xsdSchema);
219
			adapter.setChildren(getAttributeGroupList(xsdSchema));
219
      types.addAll(getSimpleTypes(xsdSchema));
220
			this.fireNotifyChanged(new CategoryNotification(adapter));
220
221
			return;
221
      adapter.setChildren(types);
222
		}
222
      this.fireNotifyChanged(new CategoryNotification(adapter));
223
		else if (msg.getFeature() == xsdPackage.getXSDSchema_TypeDefinitions()) {
223
      return;
224
			CategoryAdapter adapter = (CategoryAdapter) children.get(4);
224
    }
225
			XSDSchema xsdSchema = adapter.getXSDSchema();
225
    else if (msg.getFeature() == xsdPackage.getXSDSchema_ModelGroupDefinitions())
226
			List types = getComplexTypes(xsdSchema);
226
    {
227
			types.addAll(getSimpleTypes(xsdSchema));
227
      CategoryAdapter adapter = (CategoryAdapter)children.get(5);
228
228
      XSDSchema xsdSchema = adapter.getXSDSchema();
229
			adapter.setChildren(types);
229
      adapter.setChildren(getGroups(xsdSchema));
230
			this.fireNotifyChanged(new CategoryNotification(adapter));
230
      this.fireNotifyChanged(new CategoryNotification(adapter));
231
			return;
231
      return;
232
		}
232
    }
233
		else if (msg.getFeature() == xsdPackage.getXSDSchema_ModelGroupDefinitions()) {
233
    else if (msg.getFeature() == xsdPackage.getXSDSchema_NotationDeclarations())
234
			CategoryAdapter adapter = (CategoryAdapter) children.get(5);
234
    {
235
			XSDSchema xsdSchema = adapter.getXSDSchema();
235
      CategoryAdapter adapter = (CategoryAdapter)children.get(6);
236
			adapter.setChildren(getGroups(xsdSchema));
236
      XSDSchema xsdSchema = adapter.getXSDSchema();
237
			this.fireNotifyChanged(new CategoryNotification(adapter));
237
      adapter.setChildren(getNotations(xsdSchema));
238
			return;
238
      this.fireNotifyChanged(new CategoryNotification(adapter));
239
		}
239
      return;
240
		else if (msg.getFeature() == xsdPackage.getXSDSchema_NotationDeclarations()) {
240
    }
241
			CategoryAdapter adapter = (CategoryAdapter) children.get(6);
241
//    else if (msg.getFeature() == xsdPackage.getXSDSchema_IdentityConstraintDefinitions())
242
			XSDSchema xsdSchema = adapter.getXSDSchema();
242
//    {
243
			adapter.setChildren(getNotations(xsdSchema));
243
//      this.fireNotifyChanged(new CategoryNotification(children.get(7)));
244
			this.fireNotifyChanged(new CategoryNotification(adapter));
244
//      return;
245
			return;
245
//    }
246
		}
246
    else if (msg.getFeature() == xsdPackage.getXSDSchema_Annotations())
247
		// else if (msg.getFeature() ==
247
    {
248
		// xsdPackage.getXSDSchema_IdentityConstraintDefinitions())
248
//      this.fireNotifyChanged(new CategoryNotification(children.get(7)));
249
		// {
249
      return;
250
		// this.fireNotifyChanged(new CategoryNotification(children.get(7)));
250
    }
251
		// return;
251
    else if (msg.getFeature() == xsdPackage.getXSDSchema_SchemaLocation())
252
		// }
252
    {
253
		else if (msg.getFeature() == xsdPackage.getXSDSchema_Annotations()) {
253
      this.fireNotifyChanged(msg);
254
			// this.fireNotifyChanged(new
254
      return;
255
			// CategoryNotification(children.get(7)));
255
    }
256
			return;
256
257
		}
257
    super.notifyChanged(msg);
258
		else if (msg.getFeature() == xsdPackage.getXSDSchema_SchemaLocation()) {
258
  }
259
			this.fireNotifyChanged(msg);
259
260
			return;
260
  protected List getDirectives(XSDSchema schema)
261
		}
261
  {                 
262
262
    List list = new ArrayList();
263
		super.notifyChanged(msg);
263
    for (Iterator i = schema.getContents().iterator(); i.hasNext(); )
264
	}
264
    {
265
265
      Object o = i.next();
266
	protected List getDirectives(XSDSchema schema) {
266
      if (o instanceof XSDSchemaDirective)
267
		List list = new ArrayList();
267
      {
268
		for (Iterator i = schema.getContents().iterator(); i.hasNext();) {
268
        list.add(o);
269
			Object o = i.next();
269
      }
270
			if (o instanceof XSDSchemaDirective) {
270
    } 
271
				list.add(o);
271
    return list;
272
			}
272
  }
273
		}
273
  
274
		return list;
274
  protected List getAttributeGroupList(XSDSchema xsdSchema)
275
	}
275
  {
276
276
    List attributeGroupList = new ArrayList();
277
	protected List getAttributeGroupList(XSDSchema xsdSchema) {
277
    for (Iterator i = xsdSchema.getAttributeGroupDefinitions().iterator(); i.hasNext(); )
278
		List attributeGroupList = new ArrayList();
278
    {
279
		for (Iterator i = xsdSchema.getAttributeGroupDefinitions().iterator(); i.hasNext();) {
279
      XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition)i.next();
280
			XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) i.next();
280
      if (attrGroup.getRootContainer() == xsdSchema)
281
			if (attrGroup.getRootContainer() == xsdSchema) {
281
      {
282
				attributeGroupList.add(attrGroup);
282
        attributeGroupList.add(attrGroup);
283
			}
283
      }
284
		}
284
    }
285
		return attributeGroupList;
285
    return attributeGroupList;
286
	}
286
  }
287
287
  
288
	protected List getAttributeList(XSDSchema xsdSchema) {
288
  protected List getAttributeList(XSDSchema xsdSchema)
289
		List attributesList = new ArrayList();
289
  {
290
		for (Iterator iter = xsdSchema.getAttributeDeclarations().iterator(); iter.hasNext();) {
290
    List attributesList = new ArrayList();
291
			Object o = iter.next();
291
    for (Iterator iter = xsdSchema.getAttributeDeclarations().iterator(); iter.hasNext(); )
292
			if (o instanceof XSDAttributeDeclaration) {
292
    {
293
				XSDAttributeDeclaration attr = (XSDAttributeDeclaration) o;
293
      Object o = iter.next();
294
				if (attr != null) {
294
      if (o instanceof XSDAttributeDeclaration)
295
					if (attr.getTargetNamespace() != null) {
295
      {
296
						if (!(attr.getTargetNamespace().equals("http://www.w3.org/2001/XMLSchema-instance"))) {
296
        XSDAttributeDeclaration attr = (XSDAttributeDeclaration)o;
297
							if (attr.getRootContainer() == xsdSchema) {
297
        if (attr != null)
298
								attributesList.add(attr);
298
        {
299
							}
299
          if (attr.getTargetNamespace() != null)
300
						}
300
          {
301
					}
301
            if (!(attr.getTargetNamespace().equals("http://www.w3.org/2001/XMLSchema-instance")))
302
					else {
302
            {
303
						if (attr.getRootContainer() == xsdSchema) {
303
              if (attr.getRootContainer() == xsdSchema)
304
							attributesList.add(attr);
304
              {
305
						}
305
                attributesList.add(attr);
306
					}
306
              }
307
				}
307
            }
308
			}
308
          }
309
		}
309
          else
310
		return attributesList;
310
          {
311
	}
311
            if (attr.getRootContainer() == xsdSchema)
312
312
            {
313
	protected List getGlobalElements(XSDSchema schema) {
313
              attributesList.add(attr);
314
		List elements = schema.getElementDeclarations();
314
            }
315
		List list = new ArrayList();
315
          }
316
		for (Iterator i = elements.iterator(); i.hasNext();) {
316
        }
317
			XSDElementDeclaration elem = (XSDElementDeclaration) i.next();
317
      }
318
			if (elem.getRootContainer() == schema) {
318
    }
319
				list.add(elem);
319
    return attributesList;
320
			}
320
  }
321
		}
321
  
322
		return list;
322
  protected List getGlobalElements(XSDSchema schema)
323
	}
323
  {
324
324
    List elements = schema.getElementDeclarations();
325
	protected List getComplexTypes(XSDSchema schema) {
325
    List list = new ArrayList();
326
		List allTypes = schema.getTypeDefinitions();
326
    for (Iterator i = elements.iterator(); i.hasNext(); )
327
		List list = new ArrayList();
327
    {
328
		for (Iterator i = allTypes.iterator(); i.hasNext();) {
328
      XSDElementDeclaration elem = (XSDElementDeclaration)i.next();
329
			XSDTypeDefinition td = (XSDTypeDefinition) i.next();
329
      if (elem.getRootContainer() == schema)
330
			if (td instanceof XSDComplexTypeDefinition) {
330
      {
331
				XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) td;
331
        list.add(elem);
332
				if (ct.getRootContainer() == schema) {
332
      }
333
					list.add(ct);
333
    }                
334
				}
334
    return list;
335
			}
335
  }
336
		}
336
  
337
		return list;
337
  protected List getComplexTypes(XSDSchema schema)
338
	}
338
  {
339
339
    List allTypes = schema.getTypeDefinitions();
340
	protected List getSimpleTypes(XSDSchema schema) {
340
    List list = new ArrayList();
341
		List allTypes = schema.getTypeDefinitions();
341
    for (Iterator i = allTypes.iterator(); i.hasNext(); )
342
		List list = new ArrayList();
342
    {
343
		for (Iterator i = allTypes.iterator(); i.hasNext();) {
343
      XSDTypeDefinition td = (XSDTypeDefinition)i.next();
344
			XSDTypeDefinition td = (XSDTypeDefinition) i.next();
344
      if (td instanceof XSDComplexTypeDefinition)
345
			if (td instanceof XSDSimpleTypeDefinition) {
345
      {
346
				XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) td;
346
        XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition)td;
347
				if (st.getRootContainer() == schema) {
347
        if (ct.getRootContainer() == schema)
348
					list.add(st);
348
        {
349
				}
349
          list.add(ct);
350
			}
350
        }
351
		}
351
      }
352
		return list;
352
    }                
353
	}
353
    return list;
354
354
  }
355
	protected List getGroups(XSDSchema schema) {
355
356
		List groups = schema.getModelGroupDefinitions();
356
  protected List getSimpleTypes(XSDSchema schema)
357
		List list = new ArrayList();
357
  {
358
		for (Iterator i = groups.iterator(); i.hasNext();) {
358
    List allTypes = schema.getTypeDefinitions();
359
			XSDModelGroupDefinition group = (XSDModelGroupDefinition) i.next();
359
    List list = new ArrayList();
360
			if (group.getRootContainer() == schema) {
360
    for (Iterator i = allTypes.iterator(); i.hasNext(); )
361
				list.add(group);
361
    {
362
			}
362
      XSDTypeDefinition td = (XSDTypeDefinition)i.next();
363
		}
363
      if (td instanceof XSDSimpleTypeDefinition)
364
		return list;
364
      {
365
	}
365
        XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition)td;
366
366
        if (st.getRootContainer() == schema)
367
	protected List getNotations(XSDSchema schema) {
367
        {
368
		List notations = schema.getNotationDeclarations();
368
          list.add(st);
369
		List list = new ArrayList();
369
        }
370
		for (Iterator i = notations.iterator(); i.hasNext();) {
370
      }
371
			XSDNotationDeclaration notation = (XSDNotationDeclaration) i.next();
371
    }                
372
			if (notation.getRootContainer() == schema) {
372
    return list;
373
				list.add(notation);
373
  }   
374
			}
374
375
		}
375
  protected List getGroups(XSDSchema schema)
376
		return list;
376
  {
377
	}
377
    List groups = schema.getModelGroupDefinitions();
378
    List list = new ArrayList();
379
    for (Iterator i = groups.iterator(); i.hasNext(); )
380
    {
381
      XSDModelGroupDefinition group = (XSDModelGroupDefinition)i.next();
382
      if (group.getRootContainer() == schema)
383
      {
384
        list.add(group);
385
      }
386
    }                
387
    return list;
388
  }
389
  
390
  protected List getNotations(XSDSchema schema)
391
  {
392
    List notations = schema.getNotationDeclarations();
393
    List list = new ArrayList();
394
    for (Iterator i = notations.iterator(); i.hasNext(); )
395
    {
396
      XSDNotationDeclaration notation = (XSDNotationDeclaration)i.next();
397
      if (notation.getRootContainer() == schema)
398
      {
399
        list.add(notation);
400
      }
401
    }                
402
    return list;
403
  }
404
378
405
}
379
}
(-)src/org/eclipse/wst/xsd/ui/internal/util/OpenOnSelectionHelper.java (-8 / +16 lines)
Lines 24-29 Link Here
24
import org.eclipse.ui.part.FileEditorInput;
24
import org.eclipse.ui.part.FileEditorInput;
25
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
25
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
26
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
26
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
27
import org.eclipse.wst.sse.ui.StructuredTextEditor;
27
import org.eclipse.wst.xsd.ui.internal.XSDEditor;
28
import org.eclipse.wst.xsd.ui.internal.XSDEditor;
28
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
29
import org.eclipse.wst.xsd.ui.internal.XSDEditorPlugin;
29
import org.eclipse.wst.xsd.ui.internal.XSDTextEditor;
30
import org.eclipse.wst.xsd.ui.internal.XSDTextEditor;
Lines 46-60 Link Here
46
public class OpenOnSelectionHelper
47
public class OpenOnSelectionHelper
47
{
48
{
48
  
49
  
49
  protected XSDTextEditor textEditor;
50
  protected StructuredTextEditor textEditor;
50
  
51
  protected XSDSchema xsdSchema;
52
51
  /**
53
  /**
52
   * Constructor for OpenOnSelectionHelper.
54
   * @deprecated Constructor for OpenOnSelectionHelper.
53
   */
55
   */
54
  public OpenOnSelectionHelper(XSDTextEditor textEditor)
56
  public OpenOnSelectionHelper(XSDTextEditor textEditor)
55
  {
57
  {
56
    this.textEditor = textEditor;
57
  }
58
  }
59
  
60
  public OpenOnSelectionHelper(StructuredTextEditor textEditor, XSDSchema xsdSchema)
61
  {
62
  	this.textEditor = textEditor;
63
  	this.xsdSchema = xsdSchema;
64
  }
65
  
58
66
59
  boolean lastResult;
67
  boolean lastResult;
60
  
68
  
Lines 94-100 Link Here
94
  
102
  
95
  protected boolean revealObject(final XSDConcreteComponent component)
103
  protected boolean revealObject(final XSDConcreteComponent component)
96
  {
104
  {
97
    if (component.getRootContainer().equals(textEditor.getXSDSchema()))
105
    if (component.getRootContainer().equals(xsdSchema))
98
    {
106
    {
99
      Node element = component.getElement();
107
      Node element = component.getElement();
100
      if (element instanceof IndexedRegion)
108
      if (element instanceof IndexedRegion)
Lines 125-131 Link Here
125
		        {
133
		        {
126
							try
134
							try
127
							{
135
							{
128
							  IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), textEditor.getXSDEditor().getEditorSite().getId());
136
							  // IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), textEditor.getXSDEditor().getEditorSite().getId());
137
								IEditorPart editorPart = workbenchWindow.getActivePage().openEditor(new FileEditorInput(schemaFile), XSDEditorPlugin.getPlugin().PLUGIN_ID);
129
								if (editorPart instanceof XSDEditor)
138
								if (editorPart instanceof XSDEditor)
130
								{
139
								{
131
									((XSDEditor)editorPart).openOnGlobalReference(component);
140
									((XSDEditor)editorPart).openOnGlobalReference(component);
Lines 146-152 Link Here
146
  
155
  
147
  public void openOnGlobalReference(XSDConcreteComponent comp)
156
  public void openOnGlobalReference(XSDConcreteComponent comp)
148
  {
157
  {
149
    XSDSchema schema = textEditor.getXSDSchema();
158
    XSDSchema schema = xsdSchema;
150
    String name = null;
159
    String name = null;
151
    if (comp instanceof XSDNamedComponent)
160
    if (comp instanceof XSDNamedComponent)
152
    {
161
    {
Lines 191-197 Link Here
191
      for (Iterator i = selectedNodes.iterator(); i.hasNext();)
200
      for (Iterator i = selectedNodes.iterator(); i.hasNext();)
192
      {
201
      {
193
        Object obj = i.next();
202
        Object obj = i.next();
194
        XSDSchema xsdSchema = textEditor.getXSDSchema();
195
        if (xsdSchema != null)
203
        if (xsdSchema != null)
196
        {
204
        {
197
          XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node)obj);
205
          XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node)obj);
(-)src/org/eclipse/wst/xsd/ui/internal/StructuredTextViewerConfigurationXSD.java (+44 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *   IBM - Initial API and implementation
10
 *   Jens Lukowski/Innoopract - initial renaming/restructuring
11
 * 
12
 */
13
package org.eclipse.wst.xsd.ui.internal;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
19
import org.eclipse.jface.text.source.ISourceViewer;
20
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
21
import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML;
22
23
/**
24
 * Configuration for editing XSD content type
25
 */
26
public class StructuredTextViewerConfigurationXSD extends StructuredTextViewerConfigurationXML {
27
	public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
28
		if (sourceViewer == null || !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
29
			return null;
30
31
		List allDetectors = new ArrayList(0);
32
		// add XSD Hyperlink detector
33
		allDetectors.add(new XSDHyperlinkDetector());
34
35
		IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
36
		for (int m = 0; m < superDetectors.length; m++) {
37
			IHyperlinkDetector detector = superDetectors[m];
38
			if (!allDetectors.contains(detector)) {
39
				allDetectors.add(detector);
40
			}
41
		}
42
		return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]);
43
	}
44
}
(-)src/org/eclipse/wst/xsd/ui/internal/XSDContentOutlineConfiguration.java (+216 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *   IBM - Initial API and implementation
10
 *   Jens Lukowski/Innoopract - initial renaming/restructuring
11
 * 
12
 */
13
package org.eclipse.wst.xsd.ui.internal;
14
15
import java.util.ArrayList;
16
import java.util.Iterator;
17
import java.util.List;
18
19
import org.eclipse.jface.action.IMenuListener;
20
import org.eclipse.jface.viewers.IContentProvider;
21
import org.eclipse.jface.viewers.ILabelProvider;
22
import org.eclipse.jface.viewers.ISelection;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.TreeViewer;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.KeyAdapter;
28
import org.eclipse.swt.events.KeyEvent;
29
import org.eclipse.swt.events.KeyListener;
30
import org.eclipse.swt.widgets.Tree;
31
import org.eclipse.swt.widgets.TreeItem;
32
import org.eclipse.ui.IEditorPart;
33
import org.eclipse.ui.IWorkbench;
34
import org.eclipse.ui.IWorkbenchPage;
35
import org.eclipse.ui.IWorkbenchWindow;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.wst.sse.ui.views.contentoutline.ContentOutlineConfiguration;
38
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
39
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
40
import org.eclipse.wst.xsd.ui.internal.actions.OpenSchemaAction;
41
import org.eclipse.wst.xsd.ui.internal.provider.XSDAdapterFactoryLabelProvider;
42
import org.eclipse.wst.xsd.ui.internal.provider.XSDContentProvider;
43
import org.eclipse.wst.xsd.ui.internal.provider.XSDModelAdapterFactoryImpl;
44
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter;
45
import org.eclipse.xsd.XSDSchema;
46
import org.eclipse.xsd.XSDSchemaDirective;
47
import org.w3c.dom.Attr;
48
import org.w3c.dom.Element;
49
import org.w3c.dom.Node;
50
51
/**
52
 * Outline configuration for XSD
53
 */
54
public class XSDContentOutlineConfiguration extends ContentOutlineConfiguration {
55
	private XSDContentProvider fContentProvider;
56
	private ILabelProvider fLabelProvider;
57
	private KeyListener[] fKeyListeners = null;
58
	private IMenuListener fMenuListener = null;
59
	private XSDEditor fEditor = null;
60
61
	public IContentProvider getContentProvider(TreeViewer viewer) {
62
		if (fContentProvider == null) {
63
			fContentProvider = new XSDContentProvider(XSDModelAdapterFactoryImpl.getInstance());
64
		}
65
		return fContentProvider;
66
	}
67
68
	public ILabelProvider getLabelProvider(TreeViewer viewer) {
69
		if (fLabelProvider == null) {
70
			fLabelProvider = new XSDAdapterFactoryLabelProvider(XSDModelAdapterFactoryImpl.getInstance());
71
		}
72
		return fLabelProvider;
73
	}
74
75
	public IMenuListener getMenuListener(TreeViewer viewer) {
76
		if (fMenuListener == null) {
77
			// ISSUE: what happens if cannot get XSD Editor? (See
78
			// getXSDEditor comment)
79
			if (getXSDEditor() != null)
80
				fMenuListener = new XSDMenuListener(getXSDEditor().getSelectionManager());
81
		}
82
		return fMenuListener;
83
	}
84
85
	public KeyListener[] getKeyListeners(TreeViewer viewer) {
86
		if (fKeyListeners == null) {
87
			final TreeViewer finalViewer = viewer;
88
			KeyAdapter keyListener = new KeyAdapter() {
89
				public void keyReleased(KeyEvent e) {
90
					if (e.character == SWT.DEL) {
91
						IMenuListener menuListener = getMenuListener(finalViewer);
92
						if (menuListener instanceof XSDMenuListener)
93
							((XSDMenuListener) menuListener).getDeleteAction().run();
94
					}
95
					else if (e.keyCode == SWT.F3) // open editor on any
96
					// include/import/redefine
97
					{
98
						if (e.widget instanceof Tree) {
99
							Tree tree = (Tree) e.widget;
100
							TreeItem[] selection = tree.getSelection();
101
							if (selection.length > 0) {
102
								if (selection[0].getData() instanceof XSDSchemaDirective) {
103
									XSDSchemaDirective comp = (XSDSchemaDirective) selection[0].getData();
104
									OpenSchemaAction openSchema = new OpenSchemaAction(XSDEditorPlugin.getXSDString("_UI_ACTION_OPEN_SCHEMA"), comp);
105
									openSchema.run();
106
								}
107
							}
108
						}
109
					}
110
				}
111
			};
112
			fKeyListeners = new KeyListener[]{keyListener};
113
		}
114
115
		return fKeyListeners;
116
	}
117
118
	public ISelection getSelection(TreeViewer viewer, ISelection selection) {
119
		ISelection sel = selection;
120
121
		if (selection instanceof IStructuredSelection) {
122
			List xsdSelections = new ArrayList();
123
			for (Iterator i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
124
				Object domNode = i.next();
125
				Object xsdNode = getXSDNode(domNode, viewer);
126
				if (xsdNode != null) {
127
					xsdSelections.add(xsdNode);
128
				}
129
			}
130
131
			if (!xsdSelections.isEmpty()) {
132
				sel = new StructuredSelection(xsdSelections);
133
			}
134
		}
135
		return sel;
136
	}
137
138
	/**
139
	 * Determines XSD node based on object (DOM node)
140
	 * 
141
	 * @param object
142
	 * @return
143
	 */
144
	private Object getXSDNode(Object object, TreeViewer viewer) {
145
		// get the element node
146
		Element element = null;
147
		if (object instanceof Node) {
148
			Node node = (Node) object;
149
			if (node != null) {
150
				if (node.getNodeType() == Node.ELEMENT_NODE) {
151
					element = (Element) node;
152
				}
153
				else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
154
					element = ((Attr) node).getOwnerElement();
155
				}
156
			}
157
		}
158
		Object o = element;
159
		if (element != null) {
160
			Object modelObject = getXSDSchema(viewer).getCorrespondingComponent(element);
161
			if (modelObject != null) {
162
				o = modelObject;
163
			}
164
		}
165
		return o;
166
	}
167
168
	/**
169
	 * Gets the xsd schema from treeviewer's input
170
	 * 
171
	 * @param model
172
	 *            (of type Object but really should be IStructuredModel)
173
	 * @return Definition
174
	 */
175
	private XSDSchema getXSDSchema(TreeViewer viewer) {
176
		XSDSchema xsdSchema = null;
177
		Object model = null;
178
		if (viewer != null)
179
			model = viewer.getInput();
180
181
		if (model instanceof IDOMModel) {
182
			IDOMDocument domDoc = ((IDOMModel) model).getDocument();
183
			if (domDoc != null) {
184
				XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class);
185
				/*
186
				 * ISSUE: Didn't want to go through initializing schema if it
187
				 * does not already exist, so just attempted to get existing
188
				 * adapter. If doesn't exist, just don't bother working.
189
				 */
190
				if (modelAdapter != null)
191
					xsdSchema = modelAdapter.getSchema();
192
			}
193
		}
194
		return xsdSchema;
195
	}
196
197
	// ISSUE: There are some cases where outline comes up before editor
198
	private XSDEditor getXSDEditor() {
199
		if (fEditor == null) {
200
			IWorkbench workbench = PlatformUI.getWorkbench();
201
			if (workbench != null) {
202
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
203
				if (window != null) {
204
					IWorkbenchPage page = window.getActivePage();
205
					if (page != null) {
206
						IEditorPart editor = page.getActiveEditor();
207
						if (editor instanceof XSDEditor)
208
							fEditor = (XSDEditor) editor;
209
					}
210
				}
211
			}
212
		}
213
		return fEditor;
214
	}
215
216
}
(-)src/org/eclipse/wst/xsd/ui/internal/XSDHyperlink.java (+87 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *   IBM - Initial API and implementation
10
 *   Jens Lukowski/Innoopract - initial renaming/restructuring
11
 * 
12
 */
13
package org.eclipse.wst.xsd.ui.internal;
14
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.Path;
19
import org.eclipse.jface.text.IRegion;
20
import org.eclipse.jface.text.hyperlink.IHyperlink;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.IWorkbenchPage;
23
import org.eclipse.ui.IWorkbenchWindow;
24
import org.eclipse.ui.PartInitException;
25
import org.eclipse.ui.PlatformUI;
26
import org.eclipse.ui.ide.IDE;
27
import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;
28
import org.eclipse.xsd.XSDConcreteComponent;
29
30
/**
31
 * WSDL Hyperlink that knows how to open links from wsdl files
32
 */
33
public class XSDHyperlink implements IHyperlink {
34
	private IRegion fRegion;
35
	private XSDConcreteComponent fComponent;
36
37
	public XSDHyperlink(IRegion region, XSDConcreteComponent component) {
38
		fRegion = region;
39
		fComponent = component;
40
	}
41
42
	public IRegion getHyperlinkRegion() {
43
		return fRegion;
44
	}
45
46
	public String getTypeLabel() {
47
		return null;
48
	}
49
50
	public String getHyperlinkText() {
51
		return null;
52
	}
53
54
	public void open() {
55
		// if hyperlink points to schema already in editor, select the correct
56
		// node
57
		// if (fComponent.getRootContainer().equals(xsdSchema)) {
58
		// Node element = fComponent.getElement();
59
		// if (element instanceof IndexedRegion) {
60
		// IndexedRegion indexNode = (IndexedRegion) element;
61
		// textEditor.getTextViewer().setRangeIndication(indexNode.getStartOffset(),
62
		// indexNode.getEndOffset() - indexNode.getStartOffset(), true);
63
		// }
64
		// }
65
		// else {
66
		if (fComponent.getSchema() != null) {
67
			String schemaLocation = URIHelper.removePlatformResourceProtocol(fComponent.getSchema().getSchemaLocation());
68
			IPath schemaPath = new Path(schemaLocation);
69
			IFile schemaFile = ResourcesPlugin.getWorkspace().getRoot().getFile(schemaPath);
70
			if (schemaFile != null && schemaFile.exists()) {
71
				IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
72
				if (workbenchWindow != null) {
73
					IWorkbenchPage page = workbenchWindow.getActivePage();
74
					try {
75
						IEditorPart editorPart = IDE.openEditor(page, schemaFile, true);
76
						if (editorPart instanceof XSDEditor) {
77
							((XSDEditor) editorPart).openOnGlobalReference(fComponent);
78
						}
79
					}
80
					catch (PartInitException pie) {
81
						Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie);
82
					}
83
				}
84
			}
85
		}
86
	}
87
}
(-)src/org/eclipse/wst/xsd/ui/internal/XSDHyperlinkDetector.java (+252 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved.   This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *   IBM - Initial API and implementation
10
 *   Jens Lukowski/Innoopract - initial renaming/restructuring
11
 * 
12
 */
13
package org.eclipse.wst.xsd.ui.internal;
14
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.jface.text.IDocument;
19
import org.eclipse.jface.text.IRegion;
20
import org.eclipse.jface.text.ITextViewer;
21
import org.eclipse.jface.text.Region;
22
import org.eclipse.jface.text.hyperlink.IHyperlink;
23
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
24
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
25
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
26
import org.eclipse.wst.sse.core.internal.provisional.StructuredModelManager;
27
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
28
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
29
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter;
30
import org.eclipse.xsd.XSDAttributeDeclaration;
31
import org.eclipse.xsd.XSDAttributeGroupDefinition;
32
import org.eclipse.xsd.XSDConcreteComponent;
33
import org.eclipse.xsd.XSDElementDeclaration;
34
import org.eclipse.xsd.XSDIdentityConstraintDefinition;
35
import org.eclipse.xsd.XSDModelGroupDefinition;
36
import org.eclipse.xsd.XSDSchema;
37
import org.eclipse.xsd.XSDSchemaDirective;
38
import org.eclipse.xsd.XSDSimpleTypeDefinition;
39
import org.eclipse.xsd.XSDTypeDefinition;
40
import org.eclipse.xsd.util.XSDConstants;
41
import org.w3c.dom.Attr;
42
import org.w3c.dom.Node;
43
44
/**
45
 * Detects hyperlinks for XSD files
46
 */
47
public class XSDHyperlinkDetector implements IHyperlinkDetector {
48
	/**
49
	 * Gets the xsd schema from document
50
	 * 
51
	 * @param document
52
	 * @return XSDSchema or null of one does not exist yet for document
53
	 */
54
	private XSDSchema getXSDSchema(IDocument document) {
55
		XSDSchema schema = null;
56
		IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
57
		if (model != null) {
58
			try {
59
				if (model instanceof IDOMModel) {
60
					IDOMDocument domDoc = ((IDOMModel) model).getDocument();
61
					if (domDoc != null) {
62
						XSDModelAdapter modelAdapter = (XSDModelAdapter) domDoc.getExistingAdapter(XSDModelAdapter.class);
63
						/*
64
						 * ISSUE: Didn't want to go through initializing
65
						 * schema if it does not already exist, so just
66
						 * attempted to get existing adapter. If doesn't
67
						 * exist, just don't bother working.
68
						 */
69
						if (modelAdapter != null)
70
							schema = modelAdapter.getSchema();
71
					}
72
				}
73
			}
74
			finally {
75
				model.releaseFromRead();
76
			}
77
		}
78
		return schema;
79
	}
80
81
	/**
82
	 * 
83
	 * @param xsdSchema
84
	 *            cannot be null
85
	 * @param node
86
	 *            cannot be null
87
	 * @return XSDConcreteComponent
88
	 */
89
	private XSDConcreteComponent getXSDComponent(XSDSchema xsdSchema, Node node) {
90
		XSDConcreteComponent objectToReveal = null;
91
92
		XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node) node);
93
		if (xsdComp instanceof XSDElementDeclaration) {
94
			XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp;
95
			if (elementDecl.isElementDeclarationReference()) {
96
				objectToReveal = elementDecl.getResolvedElementDeclaration();
97
			}
98
			else {
99
				XSDConcreteComponent typeDef = null;
100
				if (elementDecl.getAnonymousTypeDefinition() == null) {
101
					typeDef = elementDecl.getTypeDefinition();
102
				}
103
104
				XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation();
105
106
				if (typeDef != null && subGroupAffiliation != null) {
107
					// we have 2 things we can navigate to, if the
108
					// cursor is anywhere on the substitution
109
					// attribute
110
					// then jump to that, otherwise just go to the
111
					// typeDef.
112
					if (node instanceof Attr && ((Attr) node).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
113
						objectToReveal = subGroupAffiliation;
114
					}
115
					else {
116
						// try to reveal the type now. On success,
117
						// then we return true.
118
						// if we fail, set the substitution group
119
						// as
120
						// the object to reveal as a backup plan.
121
						// ISSUE: how to set backup?
122
						// if (revealObject(typeDef)) {
123
						objectToReveal = typeDef;
124
						// }
125
						// else {
126
						// objectToReveal = subGroupAffiliation;
127
						// }
128
					}
129
				}
130
				else {
131
					// one or more of these is null. If the
132
					// typeDef is
133
					// non-null, use it. Otherwise
134
					// try and use the substitution group
135
					objectToReveal = typeDef != null ? typeDef : subGroupAffiliation;
136
				}
137
			}
138
		}
139
		else if (xsdComp instanceof XSDModelGroupDefinition) {
140
			XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp;
141
			if (elementDecl.isModelGroupDefinitionReference()) {
142
				objectToReveal = elementDecl.getResolvedModelGroupDefinition();
143
			}
144
		}
145
		else if (xsdComp instanceof XSDAttributeDeclaration) {
146
			XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp;
147
			if (attrDecl.isAttributeDeclarationReference()) {
148
				objectToReveal = attrDecl.getResolvedAttributeDeclaration();
149
			}
150
			else if (attrDecl.getAnonymousTypeDefinition() == null) {
151
				objectToReveal = attrDecl.getTypeDefinition();
152
			}
153
		}
154
		else if (xsdComp instanceof XSDAttributeGroupDefinition) {
155
			XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp;
156
			if (attrGroupDef.isAttributeGroupDefinitionReference()) {
157
				objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition();
158
			}
159
		}
160
		else if (xsdComp instanceof XSDIdentityConstraintDefinition) {
161
			XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp;
162
			if (idConstraintDef.getReferencedKey() != null) {
163
				objectToReveal = idConstraintDef.getReferencedKey();
164
			}
165
		}
166
		else if (xsdComp instanceof XSDSimpleTypeDefinition) {
167
			XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp;
168
			objectToReveal = typeDef.getItemTypeDefinition();
169
			if (objectToReveal == null) {
170
				// if itemType attribute is not set, then check
171
				// for memberType
172
				List memberTypes = typeDef.getMemberTypeDefinitions();
173
				if (memberTypes != null && memberTypes.size() > 0) {
174
					objectToReveal = (XSDConcreteComponent) memberTypes.get(0);
175
				}
176
			}
177
		}
178
		else if (xsdComp instanceof XSDTypeDefinition) {
179
			XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp;
180
			objectToReveal = typeDef.getBaseType();
181
		}
182
		else if (xsdComp instanceof XSDSchemaDirective) {
183
			XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp;
184
			// String schemaLocation =
185
			// URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation());
186
			// openXSDEditor(schemaLocation);
187
			// return false;
188
			objectToReveal = directive.getResolvedSchema();
189
		}
190
		return objectToReveal;
191
	}
192
193
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
194
		// for now, only capable of creating 1 hyperlink
195
		List hyperlinks = new ArrayList(0);
196
197
		if (region != null && textViewer != null) {
198
			IDocument document = textViewer.getDocument();
199
			Node node = getCurrentNode(document, region.getOffset());
200
			if (node != null) {
201
				XSDSchema xsdSchema = getXSDSchema(textViewer.getDocument());
202
				if (xsdSchema != null) {
203
					XSDConcreteComponent objectToReveal = getXSDComponent(xsdSchema, node);
204
					// now reveal the object if this isn't null
205
					if (objectToReveal != null) {
206
						IRegion nodeRegion = region;
207
						if (node instanceof IndexedRegion) {
208
							IndexedRegion indexed = (IndexedRegion) node;
209
							int start = indexed.getStartOffset();
210
							int end = indexed.getEndOffset();
211
							nodeRegion = new Region(start, end - start);
212
						}
213
						hyperlinks.add(new XSDHyperlink(nodeRegion, objectToReveal));
214
					}
215
				}
216
			}
217
		}
218
219
		if (hyperlinks.size() == 0)
220
			return null;
221
		return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[0]);
222
	}
223
224
	/**
225
	 * Returns the node the cursor is currently on in the document. null if no
226
	 * node is selected
227
	 * 
228
	 * @param offset
229
	 * @return Node either element, doctype, text, or null
230
	 */
231
	private Node getCurrentNode(IDocument document, int offset) {
232
		// get the current node at the offset (returns either: element,
233
		// doctype, text)
234
		IndexedRegion inode = null;
235
		IStructuredModel sModel = null;
236
		try {
237
			sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
238
			inode = sModel.getIndexedRegion(offset);
239
			if (inode == null)
240
				inode = sModel.getIndexedRegion(offset - 1);
241
		}
242
		finally {
243
			if (sModel != null)
244
				sModel.releaseFromRead();
245
		}
246
247
		if (inode instanceof Node) {
248
			return (Node) inode;
249
		}
250
		return null;
251
	}
252
}

Return to bug 112884