KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > sdo > presentation > SDOEditor


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: SDOEditor.java,v 1.13 2005/06/08 06:21:18 nickb Exp $
16  */

17 package org.eclipse.emf.ecore.sdo.presentation;
18
19
20 import java.io.IOException JavaDoc;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.EventObject JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.eclipse.core.resources.IFile;
30 import org.eclipse.core.resources.IMarker;
31 import org.eclipse.core.resources.IResource;
32 import org.eclipse.core.resources.IResourceChangeEvent;
33 import org.eclipse.core.resources.IResourceChangeListener;
34 import org.eclipse.core.resources.IResourceDelta;
35 import org.eclipse.core.resources.IResourceDeltaVisitor;
36 import org.eclipse.core.resources.ResourcesPlugin;
37 import org.eclipse.core.runtime.CoreException;
38 import org.eclipse.core.runtime.IPath;
39 import org.eclipse.core.runtime.IProgressMonitor;
40 import org.eclipse.core.runtime.NullProgressMonitor;
41 import org.eclipse.jface.action.IMenuListener;
42 import org.eclipse.jface.action.IMenuManager;
43 import org.eclipse.jface.action.IStatusLineManager;
44 import org.eclipse.jface.action.IToolBarManager;
45 import org.eclipse.jface.action.MenuManager;
46 import org.eclipse.jface.action.Separator;
47 import org.eclipse.jface.dialogs.MessageDialog;
48 import org.eclipse.jface.dialogs.ProgressMonitorDialog;
49 import org.eclipse.jface.viewers.ColumnWeightData;
50 import org.eclipse.jface.viewers.ISelection;
51 import org.eclipse.jface.viewers.ISelectionChangedListener;
52 import org.eclipse.jface.viewers.ISelectionProvider;
53 import org.eclipse.jface.viewers.IStructuredSelection;
54 import org.eclipse.jface.viewers.ListViewer;
55 import org.eclipse.jface.viewers.SelectionChangedEvent;
56 import org.eclipse.jface.viewers.StructuredSelection;
57 import org.eclipse.jface.viewers.StructuredViewer;
58 import org.eclipse.jface.viewers.TableLayout;
59 import org.eclipse.jface.viewers.TableViewer;
60 import org.eclipse.jface.viewers.TreeViewer;
61 import org.eclipse.jface.viewers.Viewer;
62 import org.eclipse.swt.SWT;
63 import org.eclipse.swt.custom.CTabFolder;
64 import org.eclipse.swt.dnd.DND;
65 import org.eclipse.swt.dnd.Transfer;
66 import org.eclipse.swt.events.ControlAdapter;
67 import org.eclipse.swt.events.ControlEvent;
68 import org.eclipse.swt.graphics.Point;
69 import org.eclipse.swt.layout.FillLayout;
70 import org.eclipse.swt.widgets.Composite;
71 import org.eclipse.swt.widgets.Control;
72 import org.eclipse.swt.widgets.Menu;
73 import org.eclipse.swt.widgets.Table;
74 import org.eclipse.swt.widgets.TableColumn;
75 import org.eclipse.swt.widgets.Tree;
76 import org.eclipse.swt.widgets.TreeColumn;
77 import org.eclipse.ui.IActionBars;
78 import org.eclipse.ui.IEditorInput;
79 import org.eclipse.ui.IEditorPart;
80 import org.eclipse.ui.IEditorSite;
81 import org.eclipse.ui.IFileEditorInput;
82 import org.eclipse.ui.IPartListener;
83 import org.eclipse.ui.IWorkbenchPart;
84 import org.eclipse.ui.PartInitException;
85 import org.eclipse.ui.actions.WorkspaceModifyOperation;
86 import org.eclipse.ui.dialogs.SaveAsDialog;
87 import org.eclipse.ui.ide.IGotoMarker;
88 import org.eclipse.ui.part.FileEditorInput;
89 import org.eclipse.ui.part.MultiPageEditorPart;
90 import org.eclipse.ui.views.contentoutline.ContentOutline;
91 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
92 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
93 import org.eclipse.ui.views.properties.IPropertySheetPage;
94 import org.eclipse.ui.views.properties.PropertySheet;
95 import org.eclipse.ui.views.properties.PropertySheetPage;
96
97 import org.eclipse.emf.common.command.BasicCommandStack;
98 import org.eclipse.emf.common.command.Command;
99 import org.eclipse.emf.common.command.CommandStack;
100 import org.eclipse.emf.common.command.CommandStackListener;
101 import org.eclipse.emf.common.notify.Adapter;
102 import org.eclipse.emf.common.notify.AdapterFactory;
103 import org.eclipse.emf.common.ui.ViewerPane;
104 import org.eclipse.emf.common.ui.viewer.IViewerProvider;
105 import org.eclipse.emf.common.util.URI;
106 import org.eclipse.emf.ecore.EObject;
107 import org.eclipse.emf.ecore.EValidator;
108 import org.eclipse.emf.ecore.change.provider.ChangeItemProviderAdapterFactory;
109 import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
110 import org.eclipse.emf.ecore.resource.Resource;
111 import org.eclipse.emf.ecore.resource.ResourceSet;
112 import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
113 import org.eclipse.emf.edit.domain.EditingDomain;
114 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
115 import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator;
116 import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
117 import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
118 import org.eclipse.emf.edit.provider.resource.ResourceSetItemProvider;
119 import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
120 import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor;
121 import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
122 import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
123 import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
124 import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
125 import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
126
127 import org.eclipse.emf.ecore.sdo.EChangeSummary;
128 import org.eclipse.emf.ecore.sdo.EDataGraph;
129 import org.eclipse.emf.ecore.sdo.EDataObject;
130 import org.eclipse.emf.ecore.sdo.provider.SDOItemProviderAdapterFactory;
131
132 //import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
133

134
135 /**
136  * This is an example of a SDO model editor.
137  * <!-- begin-user-doc -->
138  * <!-- end-user-doc -->
139  * @generated
140  */

141 public class SDOEditor
142   extends MultiPageEditorPart
143   implements IEditingDomainProvider, ISelectionProvider, IMenuListener, IViewerProvider, IGotoMarker
144 {
145   /**
146    * This keeps track of the editing domain that is used to track all changes to the model.
147    * <!-- begin-user-doc -->
148    * <!-- end-user-doc -->
149    * @generated
150    */

151   protected AdapterFactoryEditingDomain editingDomain;
152
153   /**
154    * This is the one adapter factory used for providing views of the model.
155    * <!-- begin-user-doc -->
156    * <!-- end-user-doc -->
157    * @generated
158    */

159   protected ComposedAdapterFactory adapterFactory;
160
161   /**
162    * This is the content outline page.
163    * <!-- begin-user-doc -->
164    * <!-- end-user-doc -->
165    * @generated
166    */

167   protected IContentOutlinePage contentOutlinePage;
168
169   /**
170    * This is a kludge...
171    * <!-- begin-user-doc -->
172    * <!-- end-user-doc -->
173    * @generated
174    */

175   protected IStatusLineManager contentOutlineStatusLineManager;
176
177   /**
178    * This is the content outline page's viewer.
179    * <!-- begin-user-doc -->
180    * <!-- end-user-doc -->
181    * @generated
182    */

183   protected TreeViewer contentOutlineViewer;
184
185   /**
186    * This is the property sheet page.
187    * <!-- begin-user-doc -->
188    * <!-- end-user-doc -->
189    * @generated
190    */

191   protected PropertySheetPage propertySheetPage;
192
193   /**
194    * This is the viewer that shadows the selection in the content outline.
195    * The parent relation must be correctly defined for this to work.
196    * <!-- begin-user-doc -->
197    * <!-- end-user-doc -->
198    * @generated
199    */

200   protected TreeViewer selectionViewer;
201
202   /**
203    * This inverts the roll of parent and child in the content provider and show parents as a tree.
204    * <!-- begin-user-doc -->
205    * <!-- end-user-doc -->
206    * @generated
207    */

208   protected TreeViewer parentViewer;
209
210   /**
211    * This shows how a tree view works.
212    * <!-- begin-user-doc -->
213    * <!-- end-user-doc -->
214    * @generated
215    */

216   protected TreeViewer treeViewer;
217
218   /**
219    * This shows how a list view works.
220    * A list viewer doesn't support icons.
221    * <!-- begin-user-doc -->
222    * <!-- end-user-doc -->
223    * @generated
224    */

225   protected ListViewer listViewer;
226
227   /**
228    * This shows how a table view works.
229    * A table can be used as a list with icons.
230    * <!-- begin-user-doc -->
231    * <!-- end-user-doc -->
232    * @generated
233    */

234   protected TableViewer tableViewer;
235
236   /**
237    * This shows how a tree view with columns works.
238    * <!-- begin-user-doc -->
239    * <!-- end-user-doc -->
240    * @generated
241    */

242   protected TreeViewer treeViewerWithColumns;
243
244   /**
245    * This keeps track of the active viewer pane, in the book.
246    * <!-- begin-user-doc -->
247    * <!-- end-user-doc -->
248    * @generated
249    */

250   protected ViewerPane currentViewerPane;
251
252   /**
253    * This keeps track of the active content viewer, which may be either one of the viewers in the pages or the content outline viewer.
254    * <!-- begin-user-doc -->
255    * <!-- end-user-doc -->
256    * @generated
257    */

258   protected Viewer currentViewer;
259
260   /**
261    * This listens to which ever viewer is active.
262    * <!-- begin-user-doc -->
263    * <!-- end-user-doc -->
264    * @generated
265    */

266   protected ISelectionChangedListener selectionChangedListener;
267
268   /**
269    * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are listening to this editor.
270    * <!-- begin-user-doc -->
271    * <!-- end-user-doc -->
272    * @generated
273    */

274   protected Collection JavaDoc selectionChangedListeners = new ArrayList JavaDoc();
275
276   /**
277    * This keeps track of the selection of the editor as a whole.
278    * <!-- begin-user-doc -->
279    * <!-- end-user-doc -->
280    * @generated
281    */

282   protected ISelection editorSelection= StructuredSelection.EMPTY;
283
284   /**
285    * This listens for when the outline becomes active
286    * <!-- begin-user-doc -->
287    * <!-- end-user-doc -->
288    * @generated
289    */

290   protected IPartListener partListener =
291     new IPartListener()
292     {
293       public void partActivated(IWorkbenchPart p)
294       {
295         if (p instanceof ContentOutline)
296         {
297           if (((ContentOutline)p).getCurrentPage() == contentOutlinePage)
298           {
299             getActionBarContributor().setActiveEditor(SDOEditor.this);
300
301             setCurrentViewer(contentOutlineViewer);
302           }
303         }
304         else if (p instanceof PropertySheet)
305         {
306           if (((PropertySheet)p).getCurrentPage() == propertySheetPage)
307           {
308             getActionBarContributor().setActiveEditor(SDOEditor.this);
309             handleActivate();
310           }
311         }
312         else if (p == SDOEditor.this)
313         {
314           handleActivate();
315         }
316       }
317       public void partBroughtToTop(IWorkbenchPart p)
318       {
319       }
320       public void partClosed(IWorkbenchPart p)
321       {
322       }
323       public void partDeactivated(IWorkbenchPart p)
324       {
325       }
326       public void partOpened(IWorkbenchPart p)
327       {
328       }
329     };
330
331   /**
332    * Resources that have been removed since last activation.
333    * @generated
334    */

335   Collection JavaDoc removedResources = new ArrayList JavaDoc();
336
337   /**
338    * Resources that have been changed since last activation.
339    * @generated
340    */

341   Collection JavaDoc changedResources = new ArrayList JavaDoc();
342
343   /**
344    * Resources that have been saved.
345    * @generated
346    */

347   Collection JavaDoc savedResources = new ArrayList JavaDoc();
348
349   /**
350    * This listens for workspace changes.
351    * <!-- begin-user-doc -->
352    * <!-- end-user-doc -->
353    * @generated
354    */

355   protected IResourceChangeListener resourceChangeListener =
356     new IResourceChangeListener()
357     {
358       public void resourceChanged(IResourceChangeEvent event)
359       {
360         // Only listening to these.
361
// if (event.getType() == IResourceDelta.POST_CHANGE)
362
{
363           IResourceDelta delta = event.getDelta();
364           try
365           {
366             class ResourceDeltaVisitor implements IResourceDeltaVisitor
367             {
368               protected ResourceSet resourceSet = editingDomain.getResourceSet();
369               protected Collection JavaDoc changedResources = new ArrayList JavaDoc();
370               protected Collection JavaDoc removedResources = new ArrayList JavaDoc();
371
372               public boolean visit(IResourceDelta delta)
373               {
374                 if (delta.getFlags() != IResourceDelta.MARKERS &&
375                       delta.getResource().getType() == IResource.FILE)
376                 {
377                   if ((delta.getKind() & (IResourceDelta.CHANGED | IResourceDelta.REMOVED)) != 0)
378                   {
379                     Resource resource = resourceSet.getResource(URI.createURI(delta.getFullPath().toString()), false);
380                     if (resource != null)
381                     {
382                       if ((delta.getKind() & IResourceDelta.REMOVED) != 0)
383                       {
384                         removedResources.add(resource);
385                       }
386                       else
387                       {
388                         changedResources.add(resource);
389                       }
390                     }
391                   }
392                 }
393
394                 return true;
395               }
396
397               public Collection JavaDoc getChangedResources()
398               {
399                 return changedResources;
400               }
401
402               public Collection JavaDoc getRemovedResources()
403               {
404                 return removedResources;
405               }
406             }
407
408             ResourceDeltaVisitor visitor = new ResourceDeltaVisitor();
409             delta.accept(visitor);
410
411             if (!visitor.getRemovedResources().isEmpty())
412             {
413               removedResources.addAll(visitor.getRemovedResources());
414               if (!isDirty())
415               {
416                 getSite().getShell().getDisplay().asyncExec
417                   (new Runnable JavaDoc()
418                    {
419                      public void run()
420                      {
421                        getSite().getPage().closeEditor(SDOEditor.this, false);
422                        SDOEditor.this.dispose();
423                      }
424                    });
425               }
426             }
427
428             if (!visitor.getChangedResources().isEmpty())
429             {
430               changedResources.addAll(visitor.getChangedResources());
431             }
432           }
433           catch (CoreException exception)
434           {
435             SDOEditorPlugin.INSTANCE.log(exception);
436           }
437         }
438       }
439     };
440
441
442   /**
443    * Handles activation of the editor or it's associated views.
444    * @generated
445    */

446   protected void handleActivate()
447   {
448     // Recompute the read only state.
449
//
450
if (editingDomain.getResourceToReadOnlyMap() != null)
451     {
452       editingDomain.getResourceToReadOnlyMap().clear();
453
454       // Refresh any actions that may become enabled or disabled.
455
//
456
setSelection(getSelection());
457     }
458
459     if (!removedResources.isEmpty())
460     {
461       if (handleDirtyConflict())
462       {
463         getSite().getPage().closeEditor(SDOEditor.this, false);
464         SDOEditor.this.dispose();
465       }
466       else
467       {
468         removedResources.clear();
469         changedResources.clear();
470         savedResources.clear();
471       }
472     }
473     else if (!changedResources.isEmpty())
474     {
475       changedResources.removeAll(savedResources);
476       handleChangedResources();
477       changedResources.clear();
478       savedResources.clear();
479     }
480   }
481
482
483   /**
484    * Handles what to do with changed resources on activation.
485    * @generated
486    */

487   protected void handleChangedResources()
488   {
489     if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict()))
490     {
491       editingDomain.getCommandStack().flush();
492
493       for (Iterator JavaDoc i = changedResources.iterator(); i.hasNext(); )
494       {
495         Resource resource = (Resource)i.next();
496         if (resource.isLoaded())
497         {
498           resource.unload();
499           try
500           {
501             resource.load(Collections.EMPTY_MAP);
502           }
503           catch (IOException JavaDoc exception)
504           {
505             SDOEditorPlugin.INSTANCE.log(exception);
506           }
507         }
508       }
509     }
510   }
511
512   /**
513    * Shows a dialog that asks if conflicting changes should be discarded.
514    * @generated
515    */

516   protected boolean handleDirtyConflict()
517   {
518     return
519       MessageDialog.openQuestion
520         (getSite().getShell(),
521          getString("_UI_FileConflict_label"),
522          getString("_WARN_FileConflict"));
523   }
524
525   /**
526    * This creates a model editor.
527    * <!-- begin-user-doc -->
528    * <!-- end-user-doc -->
529    * @generated NOT
530    */

531   public SDOEditor()
532   {
533     super();
534
535     // Create an adapter factory that yields item providers.
536
//
537
List JavaDoc factories = new ArrayList JavaDoc();
538     factories.add
539       (new ResourceItemProviderAdapterFactory()
540        {
541          public Adapter createResourceSetAdapter()
542          {
543            return
544              new ResourceSetItemProvider(this)
545              {
546                public Collection JavaDoc getChildren(Object JavaDoc object)
547                {
548                  Collection JavaDoc result = new ArrayList JavaDoc(super.getChildren(object));
549                  for (Iterator JavaDoc i = result.iterator(); i.hasNext(); )
550                  {
551                    Resource resource = (Resource)i.next();
552                    if (resource.getContents().size() == 1)
553                    {
554                      Object JavaDoc content = resource.getContents().get(0);
555                      if (content instanceof EChangeSummary || content instanceof EDataObject)
556                      {
557                        i.remove();
558                      }
559                    }
560                  }
561                  return result;
562                }
563              };
564          }
565        });
566     factories.add(new SDOItemProviderAdapterFactory());
567     factories.add(new ChangeItemProviderAdapterFactory());
568     factories.add(new EcoreItemProviderAdapterFactory());
569     // factories.add(new ReflectiveItemProviderAdapterFactory());
570

571     adapterFactory = new ComposedAdapterFactory(factories);
572
573     // Create the command stack that will notify this editor as commands are executed.
574
//
575
BasicCommandStack commandStack = new BasicCommandStack();
576
577     // Add a listener to set the most recent command's affected objects to be the selection of the viewer with focus.
578
//
579
commandStack.addCommandStackListener
580       (new CommandStackListener()
581        {
582          public void commandStackChanged(final EventObject JavaDoc event)
583          {
584            getContainer().getDisplay().asyncExec
585              (new Runnable JavaDoc()
586               {
587                 public void run()
588                 {
589                   firePropertyChange(IEditorPart.PROP_DIRTY);
590
591                   // Try to select the affected objects.
592
//
593
Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand();
594                   if (mostRecentCommand != null)
595                   {
596                     setSelectionToViewer(mostRecentCommand.getAffectedObjects());
597                   }
598                   if (propertySheetPage != null)
599                   {
600                     propertySheetPage.refresh();
601                   }
602                 }
603               });
604          }
605        });
606
607     // Create the editing domain with a special command stack.
608
//
609
editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap JavaDoc());
610   }
611
612   /**
613    * This is here for the listener to be able to call it.
614    * <!-- begin-user-doc -->
615    * <!-- end-user-doc -->
616    * @generated
617    */

618   protected void firePropertyChange(int action)
619   {
620     super.firePropertyChange(action);
621   }
622
623   /**
624    * This sets the selection into whichever viewer is active.
625    * <!-- begin-user-doc -->
626    * <!-- end-user-doc -->
627    * @generated
628    */

629   public void setSelectionToViewer(Collection JavaDoc collection)
630   {
631     final Collection JavaDoc theSelection = collection;
632     // Make sure it's okay.
633
//
634
if (theSelection != null && !theSelection.isEmpty())
635     {
636       // I don't know if this should be run this deferred
637
// because we might have to give the editor a chance to process the viewer update events
638
// and hence to update the views first.
639
//
640
//
641
Runnable JavaDoc runnable =
642         new Runnable JavaDoc()
643         {
644           public void run()
645           {
646             // Try to select the items in the current content viewer of the editor.
647
//
648
if (currentViewer != null)
649             {
650               currentViewer.setSelection(new StructuredSelection(theSelection.toArray()), true);
651             }
652           }
653         };
654       runnable.run();
655     }
656   }
657
658   /**
659    * This returns the editing domain as required by the {@link IEditingDomainProvider} interface.
660    * This is important for implementing the static methods of {@link AdapterFactoryEditingDomain}
661    * and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}.
662    * <!-- begin-user-doc -->
663    * <!-- end-user-doc -->
664    * @generated
665    */

666   public EditingDomain getEditingDomain()
667   {
668     return editingDomain;
669   }
670
671   /**
672    * <!-- begin-user-doc -->
673    * <!-- end-user-doc -->
674    * @generated
675    */

676   public class ReverseAdapterFactoryContentProvider extends AdapterFactoryContentProvider
677   {
678     public ReverseAdapterFactoryContentProvider(AdapterFactory adapterFactory)
679     {
680       super(adapterFactory);
681     }
682
683     public Object JavaDoc [] getElements(Object JavaDoc object)
684     {
685       Object JavaDoc parent = super.getParent(object);
686       return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray();
687     }
688
689     public Object JavaDoc [] getChildren(Object JavaDoc object)
690     {
691       Object JavaDoc parent = super.getParent(object);
692       return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray();
693     }
694
695     public boolean hasChildren(Object JavaDoc object)
696     {
697       Object JavaDoc parent = super.getParent(object);
698       return parent != null;
699     }
700
701     public Object JavaDoc getParent(Object JavaDoc object)
702     {
703       return null;
704     }
705   }
706
707   /**
708    * <!-- begin-user-doc -->
709    * <!-- end-user-doc -->
710    * @generated
711    */

712   public void setCurrentViewerPane(ViewerPane viewerPane)
713   {
714     if (currentViewerPane != viewerPane)
715     {
716       if (currentViewerPane != null)
717       {
718         currentViewerPane.showFocus(false);
719       }
720       currentViewerPane = viewerPane;
721     }
722     setCurrentViewer(currentViewerPane.getViewer());
723   }
724
725   /**
726    * This makes sure that one content viewer, either for the current page or the outline view, if it has focus,
727    * is the current one.
728    * <!-- begin-user-doc -->
729    * <!-- end-user-doc -->
730    * @generated
731    */

732   public void setCurrentViewer(Viewer viewer)
733   {
734     // If it is changing...
735
//
736
if (currentViewer != viewer)
737     {
738       if (selectionChangedListener == null)
739       {
740         // Create the listener on demand.
741
//
742
selectionChangedListener =
743           new ISelectionChangedListener()
744           {
745             // This just notifies those things that are affected by the section.
746
//
747
public void selectionChanged(SelectionChangedEvent selectionChangedEvent)
748             {
749               setSelection(selectionChangedEvent.getSelection());
750             }
751           };
752       }
753
754       // Stop listening to the old one.
755
//
756
if (currentViewer != null)
757       {
758         currentViewer.removeSelectionChangedListener(selectionChangedListener);
759       }
760
761       // Start listening to the new one.
762
//
763
if (viewer != null)
764       {
765         viewer.addSelectionChangedListener(selectionChangedListener);
766       }
767
768       // Remember it.
769
//
770
currentViewer = viewer;
771
772       // Set the editors selection based on the current viewer's selection.
773
//
774
setSelection(currentViewer == null ? StructuredSelection.EMPTY : currentViewer.getSelection());
775     }
776   }
777
778   /**
779    * This returns the viewer as required by the {@link IViewerProvider} interface.
780    * <!-- begin-user-doc -->
781    * <!-- end-user-doc -->
782    * @generated
783    */

784   public Viewer getViewer()
785   {
786     return currentViewer;
787   }
788
789   /**
790    * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
791    * <!-- begin-user-doc -->
792    * <!-- end-user-doc -->
793    * @generated
794    */

795   protected void createContextMenuFor(StructuredViewer viewer)
796   {
797     MenuManager contextMenu = new MenuManager("#PopUp");
798     contextMenu.add(new Separator("additions"));
799     contextMenu.setRemoveAllWhenShown(true);
800     contextMenu.addMenuListener(this);
801     Menu menu= contextMenu.createContextMenu(viewer.getControl());
802     viewer.getControl().setMenu(menu);
803     getSite().registerContextMenu(contextMenu, viewer);
804
805     int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
806     Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
807     viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
808     viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer));
809   }
810
811   /**
812    * This is the method called to load a resource into the editing domain's resource set based on the editor's input.
813    * <!-- begin-user-doc -->
814    * <!-- end-user-doc -->
815    * @generated NOT
816    */

817   public void createModel()
818   {
819     // I assume that the input is a file object.
820
//
821
IFileEditorInput modelFile = (IFileEditorInput)getEditorInput();
822
823     try
824     {
825       // Load the resource through the editing domain.
826
//
827
Resource resource =
828         editingDomain.loadResource
829           (URI.createPlatformResourceURI(modelFile.getFile().getFullPath().toString()).toString());
830
831       EDataGraph eDataGraph = (EDataGraph)resource.getContents().get(0);
832       eDataGraph.setResourceSet(editingDomain.getResourceSet());
833       eDataGraph.getChangeSummary(); // demand create the change summary if necessary
834
}
835     catch (Exception JavaDoc exception)
836     {
837       SDOEditorPlugin.INSTANCE.log(exception);
838     }
839   }
840
841   /**
842    * This is the method used by the framework to install your own controls.
843    * <!-- begin-user-doc -->
844    * <!-- end-user-doc -->
845    * @generated
846    */

847   public void createPages()
848   {
849     // Creates the model from the editor input
850
//
851
createModel();
852
853     // Create a page for the selection tree view.
854
//
855
{
856       ViewerPane viewerPane =
857         new ViewerPane(getSite().getPage(), SDOEditor.this)
858         {
859           public Viewer createViewer(Composite composite)
860           {
861             Tree tree = new Tree(composite, SWT.MULTI);
862             TreeViewer newTreeViewer = new TreeViewer(tree);
863             return newTreeViewer;
864           }
865           public void requestActivation()
866           {
867             super.requestActivation();
868             setCurrentViewerPane(this);
869           }
870         };
871       viewerPane.createControl(getContainer());
872
873       selectionViewer = (TreeViewer)viewerPane.getViewer();
874       selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
875
876       selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
877       selectionViewer.setInput(editingDomain.getResourceSet());
878       viewerPane.setTitle(editingDomain.getResourceSet());
879
880       new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
881
882       createContextMenuFor(selectionViewer);
883       int pageIndex = addPage(viewerPane.getControl());
884       setPageText(pageIndex, getString("_UI_SelectionPage_label"));
885     }
886
887     // Create a page for the parent tree view.
888
//
889
{
890       ViewerPane viewerPane =
891         new ViewerPane(getSite().getPage(), SDOEditor.this)
892         {
893           public Viewer createViewer(Composite composite)
894           {
895             Tree tree = new Tree(composite, SWT.MULTI);
896             TreeViewer newTreeViewer = new TreeViewer(tree);
897             return newTreeViewer;
898           }
899           public void requestActivation()
900           {
901             super.requestActivation();
902             setCurrentViewerPane(this);
903           }
904         };
905       viewerPane.createControl(getContainer());
906
907       parentViewer = (TreeViewer)viewerPane.getViewer();
908       parentViewer.setAutoExpandLevel(30);
909       parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
910       parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
911
912       createContextMenuFor(parentViewer);
913       int pageIndex = addPage(viewerPane.getControl());
914       setPageText(pageIndex, getString("_UI_ParentPage_label"));
915     }
916
917     // This is the page for the list viewer
918
//
919
{
920       ViewerPane viewerPane =
921         new ViewerPane(getSite().getPage(), SDOEditor.this)
922         {
923           public Viewer createViewer(Composite composite)
924           {
925             return new ListViewer(composite);
926           }
927           public void requestActivation()
928           {
929             super.requestActivation();
930             setCurrentViewerPane(this);
931           }
932         };
933       viewerPane.createControl(getContainer());
934       listViewer = (ListViewer)viewerPane.getViewer();
935       listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
936       listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
937
938       createContextMenuFor(listViewer);
939       int pageIndex = addPage(viewerPane.getControl());
940       setPageText(pageIndex, getString("_UI_ListPage_label"));
941     }
942
943     // This is the page for the tree viewer
944
//
945
{
946       ViewerPane viewerPane =
947         new ViewerPane(getSite().getPage(), SDOEditor.this)
948         {
949           public Viewer createViewer(Composite composite)
950           {
951             return new TreeViewer(composite);
952           }
953           public void requestActivation()
954           {
955             super.requestActivation();
956             setCurrentViewerPane(this);
957           }
958         };
959       viewerPane.createControl(getContainer());
960       treeViewer = (TreeViewer)viewerPane.getViewer();
961       treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
962       treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
963
964       new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory);
965
966       createContextMenuFor(treeViewer);
967       int pageIndex = addPage(viewerPane.getControl());
968       setPageText(pageIndex, getString("_UI_TreePage_label"));
969     }
970
971     // This is the page for the table viewer.
972
//
973
{
974       ViewerPane viewerPane =
975         new ViewerPane(getSite().getPage(), SDOEditor.this)
976         {
977           public Viewer createViewer(Composite composite)
978           {
979             return new TableViewer(composite);
980           }
981           public void requestActivation()
982           {
983             super.requestActivation();
984             setCurrentViewerPane(this);
985           }
986         };
987       viewerPane.createControl(getContainer());
988       tableViewer = (TableViewer)viewerPane.getViewer();
989
990       Table table = tableViewer.getTable();
991       TableLayout layout = new TableLayout();
992       table.setLayout(layout);
993       table.setHeaderVisible(true);
994       table.setLinesVisible(true);
995
996       TableColumn objectColumn = new TableColumn(table, SWT.NONE);
997       layout.addColumnData(new ColumnWeightData(3, 100, true));
998       objectColumn.setText(getString("_UI_ObjectColumn_label"));
999       objectColumn.setResizable(true);
1000
1001      TableColumn selfColumn = new TableColumn(table, SWT.NONE);
1002      layout.addColumnData(new ColumnWeightData(2, 100, true));
1003      selfColumn.setText(getString("_UI_SelfColumn_label"));
1004      selfColumn.setResizable(true);
1005
1006      tableViewer.setColumnProperties(new String JavaDoc [] {"a", "b"});
1007      tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
1008      tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
1009
1010      createContextMenuFor(tableViewer);
1011      int pageIndex = addPage(viewerPane.getControl());
1012      setPageText(pageIndex, getString("_UI_TablePage_label"));
1013    }
1014
1015    // This is the page for the table tree viewer.
1016
//
1017
{
1018      ViewerPane viewerPane =
1019        new ViewerPane(getSite().getPage(), SDOEditor.this)
1020        {
1021          public Viewer createViewer(Composite composite)
1022          {
1023            return new TreeViewer(composite);
1024          }
1025          public void requestActivation()
1026          {
1027            super.requestActivation();
1028            setCurrentViewerPane(this);
1029          }
1030        };
1031      viewerPane.createControl(getContainer());
1032
1033      treeViewerWithColumns = (TreeViewer)viewerPane.getViewer();
1034
1035      Tree tree = treeViewerWithColumns.getTree();
1036      tree.setLayoutData(new FillLayout());
1037      tree.setHeaderVisible(true);
1038      tree.setLinesVisible(true);
1039
1040      TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
1041      objectColumn.setText(getString("_UI_ObjectColumn_label"));
1042      objectColumn.setResizable(true);
1043      objectColumn.setWidth(250);
1044
1045      TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE);
1046      selfColumn.setText(getString("_UI_SelfColumn_label"));
1047      selfColumn.setResizable(true);
1048      selfColumn.setWidth(200);
1049
1050      treeViewerWithColumns.setColumnProperties(new String JavaDoc [] {"a", "b"});
1051      treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
1052      treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
1053
1054      createContextMenuFor(treeViewerWithColumns);
1055      int pageIndex = addPage(viewerPane.getControl());
1056      setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label"));
1057    }
1058
1059    setActivePage(0);
1060
1061    getContainer().addControlListener
1062      (new ControlAdapter()
1063       {
1064        boolean guard = false;
1065        public void controlResized(ControlEvent event)
1066        {
1067          if (!guard)
1068          {
1069            guard = true;
1070            hideTabs();
1071            guard = false;
1072          }
1073        }
1074       });
1075  }
1076
1077  /**
1078   * If there is just one page in the multi-page editor part, this hides
1079   * the single tab at the bottom.
1080   * <!-- begin-user-doc -->
1081   * <!-- end-user-doc -->
1082   * @generated
1083   */

1084  protected void hideTabs()
1085  {
1086    if (getPageCount() <= 1)
1087    {
1088      setPageText(0, "");
1089      if (getContainer() instanceof CTabFolder)
1090      {
1091        ((CTabFolder)getContainer()).setTabHeight(1);
1092        Point point = getContainer().getSize();
1093        getContainer().setSize(point.x, point.y + 6);
1094      }
1095    }
1096  }
1097
1098  /**
1099   * This is used to track the active viewer.
1100   * <!-- begin-user-doc -->
1101   * <!-- end-user-doc -->
1102   * @generated
1103   */

1104  protected void pageChange(int pageIndex)
1105  {
1106    super.pageChange(pageIndex);
1107
1108    // This is a temporary workaround... EATM
1109
//
1110
Control control = getControl(pageIndex);
1111    if (control != null)
1112    {
1113      control.setVisible(true);
1114      control.setFocus();
1115    }
1116
1117    if (contentOutlinePage != null)
1118    {
1119      handleContentOutlineSelection(contentOutlinePage.getSelection());
1120    }
1121  }
1122
1123  /**
1124   * This is how the framework determines which interfaces we implement.
1125   * <!-- begin-user-doc -->
1126   * <!-- end-user-doc -->
1127   * @generated
1128   */

1129  public Object JavaDoc getAdapter(Class JavaDoc key)
1130  {
1131    if (key.equals(IContentOutlinePage.class))
1132    {
1133      return getContentOutlinePage();
1134    }
1135    else if (key.equals(IPropertySheetPage.class))
1136    {
1137      return getPropertySheetPage();
1138    }
1139    else if (key.equals(IGotoMarker.class))
1140    {
1141      return this;
1142    }
1143    else
1144    {
1145      return super.getAdapter(key);
1146    }
1147  }
1148
1149  /**
1150   * This accesses a cached version of the content outliner.
1151   * <!-- begin-user-doc -->
1152   * <!-- end-user-doc -->
1153   * @generated
1154   */

1155  public IContentOutlinePage getContentOutlinePage()
1156  {
1157    if (contentOutlinePage == null)
1158    {
1159      // The content outline is just a tree.
1160
//
1161
class MyContentOutlinePage extends ContentOutlinePage
1162      {
1163        public void createControl(Composite parent)
1164        {
1165          super.createControl(parent);
1166          contentOutlineViewer = getTreeViewer();
1167          contentOutlineViewer.addSelectionChangedListener(this);
1168
1169          // Set up the tree viewer.
1170
//
1171
contentOutlineViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
1172          contentOutlineViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
1173          contentOutlineViewer.setInput(editingDomain.getResourceSet());
1174
1175          // Make sure our popups work.
1176
//
1177
createContextMenuFor(contentOutlineViewer);
1178
1179          if (!editingDomain.getResourceSet().getResources().isEmpty())
1180          {
1181            // Select the root object in the view.
1182
//
1183
ArrayList JavaDoc selection = new ArrayList JavaDoc();
1184            selection.add(editingDomain.getResourceSet().getResources().get(0));
1185            contentOutlineViewer.setSelection(new StructuredSelection(selection), true);
1186          }
1187        }
1188
1189        public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager)
1190        {
1191          super.makeContributions(menuManager, toolBarManager, statusLineManager);
1192          contentOutlineStatusLineManager = statusLineManager;
1193        }
1194
1195        public void setActionBars(IActionBars actionBars)
1196        {
1197          super.setActionBars(actionBars);
1198          getActionBarContributor().shareGlobalActions(this, actionBars);
1199        }
1200      }
1201
1202      contentOutlinePage = new MyContentOutlinePage();
1203
1204      // Listen to selection so that we can handle it is a special way.
1205
//
1206
contentOutlinePage.addSelectionChangedListener
1207        (new ISelectionChangedListener()
1208         {
1209           // This ensures that we handle selections correctly.
1210
//
1211
public void selectionChanged(SelectionChangedEvent event)
1212           {
1213             handleContentOutlineSelection(event.getSelection());
1214           }
1215         });
1216    }
1217
1218    return contentOutlinePage;
1219  }
1220
1221  /**
1222   * This accesses a cached version of the property sheet.
1223   * <!-- begin-user-doc -->
1224   * <!-- end-user-doc -->
1225   * @generated
1226   */

1227  public IPropertySheetPage getPropertySheetPage()
1228  {
1229    if (propertySheetPage == null)
1230    {
1231      propertySheetPage =
1232        new PropertySheetPage()
1233        {
1234          public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager)
1235          {
1236            super.makeContributions(menuManager, toolBarManager, statusLineManager);
1237          }
1238
1239          public void setActionBars(IActionBars actionBars)
1240          {
1241            super.setActionBars(actionBars);
1242            getActionBarContributor().shareGlobalActions(this, actionBars);
1243          }
1244        };
1245      propertySheetPage.setPropertySourceProvider(new AdapterFactoryContentProvider(adapterFactory));
1246    }
1247
1248    return propertySheetPage;
1249  }
1250
1251  /**
1252   * This deals with how we want selection in the outliner to affect the other views.
1253   * <!-- begin-user-doc -->
1254   * <!-- end-user-doc -->
1255   * @generated
1256   */

1257  public void handleContentOutlineSelection(ISelection selection)
1258  {
1259    if (currentViewerPane != null && !selection.isEmpty() && selection instanceof IStructuredSelection)
1260    {
1261      Iterator JavaDoc selectedElements = ((IStructuredSelection)selection).iterator();
1262      if (selectedElements.hasNext())
1263      {
1264        // Get the first selected element.
1265
//
1266
Object JavaDoc selectedElement = selectedElements.next();
1267
1268        // If it's the selection viewer, then we want it to select the same selection as this selection.
1269
//
1270
if (currentViewerPane.getViewer() == selectionViewer)
1271        {
1272          ArrayList JavaDoc selectionList = new ArrayList JavaDoc();
1273          selectionList.add(selectedElement);
1274          while (selectedElements.hasNext())
1275          {
1276            selectionList.add(selectedElements.next());
1277          }
1278
1279          // Set the selection to the widget.
1280
//
1281
selectionViewer.setSelection(new StructuredSelection(selectionList));
1282        }
1283        else
1284        {
1285          // Set the input to the widget.
1286
//
1287
if (currentViewerPane.getViewer().getInput() != selectedElement)
1288          {
1289            currentViewerPane.getViewer().setInput(selectedElement);
1290            currentViewerPane.setTitle(selectedElement);
1291          }
1292        }
1293      }
1294    }
1295  }
1296
1297  /**
1298   * This is for implementing {@link IEditorPart} and simply tests the command stack.
1299   * <!-- begin-user-doc -->
1300   * <!-- end-user-doc -->
1301   * @generated
1302   */

1303  public boolean isDirty()
1304  {
1305    return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded();
1306  }
1307
1308  /**
1309   * This is for implementing {@link IEditorPart} and simply saves the model file.
1310   * <!-- begin-user-doc -->
1311   * <!-- end-user-doc -->
1312   * @generated
1313   */

1314  public void doSave(IProgressMonitor progressMonitor)
1315  {
1316    // Do the work within an operation because this is a long running activity that modifies the workbench.
1317
//
1318
WorkspaceModifyOperation operation =
1319      new WorkspaceModifyOperation()
1320      {
1321        // This is the method that gets invoked when the operation runs.
1322
//
1323
public void execute(IProgressMonitor monitor)
1324        {
1325          try
1326          {
1327            // Save the resource to the file system.
1328
//
1329
Resource savedResource = (Resource)editingDomain.getResourceSet().getResources().get(0);
1330            savedResources.add(savedResource);
1331            savedResource.save(Collections.EMPTY_MAP);
1332          }
1333          catch (Exception JavaDoc exception)
1334          {
1335            SDOEditorPlugin.INSTANCE.log(exception);
1336          }
1337        }
1338      };
1339
1340    try
1341    {
1342      // This runs the options, and shows progress.
1343
//
1344
new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation);
1345
1346      // Refresh the necessary state.
1347
//
1348
((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone();
1349      firePropertyChange(IEditorPart.PROP_DIRTY);
1350    }
1351    catch (Exception JavaDoc exception)
1352    {
1353      // Something went wrong that shouldn't.
1354
//
1355
SDOEditorPlugin.INSTANCE.log(exception);
1356    }
1357  }
1358
1359  /**
1360   * This always returns true because it is not currently supported.
1361   * <!-- begin-user-doc -->
1362   * <!-- end-user-doc -->
1363   * @generated
1364   */

1365  public boolean isSaveAsAllowed()
1366  {
1367    return true;
1368  }
1369
1370  /**
1371   * This also changes the editor's input.
1372   * <!-- begin-user-doc -->
1373   * <!-- end-user-doc -->
1374   * @generated
1375   */

1376  public void doSaveAs()
1377  {
1378    SaveAsDialog saveAsDialog= new SaveAsDialog(getSite().getShell());
1379    saveAsDialog.open();
1380    IPath path= saveAsDialog.getResult();
1381    if (path != null)
1382    {
1383      IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
1384      if (file != null)
1385      {
1386        doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString()), new FileEditorInput(file));
1387      }
1388    }
1389  }
1390  
1391  /**
1392   * <!-- begin-user-doc -->
1393   * <!-- end-user-doc -->
1394   * @generated
1395   */

1396  protected void doSaveAs(URI uri, IEditorInput editorInput)
1397  {
1398    ((Resource)editingDomain.getResourceSet().getResources().get(0)).setURI(uri);
1399    setInput(editorInput);
1400    setPartName(editorInput.getName());
1401    IProgressMonitor progressMonitor =
1402      getActionBars().getStatusLineManager() != null ?
1403        getActionBars().getStatusLineManager().getProgressMonitor() :
1404        new NullProgressMonitor();
1405    doSave(progressMonitor);
1406  }
1407
1408  /**
1409   * <!-- begin-user-doc -->
1410   * <!-- end-user-doc -->
1411   * @generated
1412   */

1413  public void gotoMarker(IMarker marker)
1414  {
1415    try
1416    {
1417      if (marker.getType().equals(EValidator.MARKER))
1418      {
1419        String JavaDoc uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null);
1420        if (uriAttribute != null)
1421        {
1422          URI uri = URI.createURI(uriAttribute);
1423          EObject eObject = editingDomain.getResourceSet().getEObject(uri, true);
1424          if (eObject != null)
1425          {
1426            setSelectionToViewer(Collections.singleton(editingDomain.getWrapper(eObject)));
1427          }
1428        }
1429      }
1430    }
1431    catch (CoreException exception)
1432    {
1433      SDOEditorPlugin.INSTANCE.log(exception);
1434    }
1435  }
1436
1437  /**
1438   * This is called during startup.
1439   * <!-- begin-user-doc -->
1440   * <!-- end-user-doc -->
1441   * @generated
1442   */

1443  public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException
1444  {
1445    setSite(site);
1446    setInput(editorInput);
1447    setPartName(editorInput.getName());
1448    site.setSelectionProvider(this);
1449    site.getPage().addPartListener(partListener);
1450    ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
1451  }
1452
1453  /**
1454   * <!-- begin-user-doc -->
1455   * <!-- end-user-doc -->
1456   * @generated
1457   */

1458  public void setFocus()
1459  {
1460    getControl(getActivePage()).setFocus();
1461  }
1462
1463  /**
1464   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
1465   * <!-- begin-user-doc -->
1466   * <!-- end-user-doc -->
1467   * @generated
1468   */

1469  public void addSelectionChangedListener(ISelectionChangedListener listener)
1470  {
1471    selectionChangedListeners.add(listener);
1472  }
1473
1474  /**
1475   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
1476   * <!-- begin-user-doc -->
1477   * <!-- end-user-doc -->
1478   * @generated
1479   */

1480  public void removeSelectionChangedListener(ISelectionChangedListener listener)
1481  {
1482    selectionChangedListeners.remove(listener);
1483  }
1484
1485  /**
1486   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to return this editor's overall selection.
1487   * <!-- begin-user-doc -->
1488   * <!-- end-user-doc -->
1489   * @generated
1490   */

1491  public ISelection getSelection()
1492  {
1493    return editorSelection;
1494  }
1495
1496  /**
1497   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to set this editor's overall selection.
1498   * Calling this result will notify the listeners.
1499   * <!-- begin-user-doc -->
1500   * <!-- end-user-doc -->
1501   * @generated
1502   */

1503  public void setSelection(ISelection selection)
1504  {
1505    editorSelection = selection;
1506
1507    for (Iterator JavaDoc listeners = selectionChangedListeners.iterator(); listeners.hasNext(); )
1508    {
1509      ISelectionChangedListener listener = (ISelectionChangedListener)listeners.next();
1510      listener.selectionChanged(new SelectionChangedEvent(this, selection));
1511    }
1512    setStatusLineManager(selection);
1513  }
1514
1515  /**
1516   * <!-- begin-user-doc -->
1517   * <!-- end-user-doc -->
1518   * @generated
1519   */

1520  public void setStatusLineManager(ISelection selection)
1521  {
1522    IStatusLineManager statusLineManager = currentViewer != null && currentViewer == contentOutlineViewer ?
1523      contentOutlineStatusLineManager : getActionBars().getStatusLineManager();
1524  
1525    if (statusLineManager != null)
1526    {
1527      if (selection instanceof IStructuredSelection)
1528      {
1529        Collection JavaDoc collection = ((IStructuredSelection)selection).toList();
1530        switch (collection.size())
1531        {
1532          case 0:
1533          {
1534            statusLineManager.setMessage(getString("_UI_NoObjectSelected"));
1535            break;
1536          }
1537          case 1:
1538          {
1539            String JavaDoc text = new AdapterFactoryItemDelegator(adapterFactory).getText(collection.iterator().next());
1540            statusLineManager.setMessage(getString("_UI_SingleObjectSelected", text));
1541            break;
1542          }
1543          default:
1544          {
1545            statusLineManager.setMessage(getString("_UI_MultiObjectSelected", Integer.toString(collection.size())));
1546            break;
1547          }
1548        }
1549      }
1550      else
1551      {
1552        statusLineManager.setMessage("");
1553      }
1554    }
1555  }
1556
1557  /**
1558   * This looks up a string in the plugin's plugin.properties file.
1559   * <!-- begin-user-doc -->
1560   * <!-- end-user-doc -->
1561   * @generated
1562   */

1563  private static String JavaDoc getString(String JavaDoc key)
1564  {
1565    return SDOEditorPlugin.INSTANCE.getString(key);
1566  }
1567
1568  /**
1569   * This looks up a string in plugin.properties, making a substitution.
1570   * <!-- begin-user-doc -->
1571   * <!-- end-user-doc -->
1572   * @generated
1573   */

1574  private static String JavaDoc getString(String JavaDoc key, Object JavaDoc s1)
1575  {
1576    return SDOEditorPlugin.INSTANCE.getString(key, new Object JavaDoc [] { s1 });
1577  }
1578
1579  /**
1580   * This implements {@link org.eclipse.jface.action.IMenuListener} to help fill the context menus with contributions from the Edit menu.
1581   * <!-- begin-user-doc -->
1582   * <!-- end-user-doc -->
1583   * @generated
1584   */

1585  public void menuAboutToShow(IMenuManager menuManager)
1586  {
1587    ((IMenuListener)getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager);
1588  }
1589
1590  /**
1591   * <!-- begin-user-doc -->
1592   * <!-- end-user-doc -->
1593   * @generated
1594   */

1595  public EditingDomainActionBarContributor getActionBarContributor()
1596  {
1597    return (EditingDomainActionBarContributor)getEditorSite().getActionBarContributor();
1598  }
1599
1600  /**
1601   * <!-- begin-user-doc -->
1602   * <!-- end-user-doc -->
1603   * @generated
1604   */

1605  public IActionBars getActionBars()
1606  {
1607    return getActionBarContributor().getActionBars();
1608  }
1609
1610  /**
1611   * <!-- begin-user-doc -->
1612   * <!-- end-user-doc -->
1613   * @generated
1614   */

1615  public AdapterFactory getAdapterFactory()
1616  {
1617    return adapterFactory;
1618  }
1619
1620  /**
1621   * <!-- begin-user-doc -->
1622   * <!-- end-user-doc -->
1623   * @generated
1624   */

1625  public void dispose()
1626  {
1627    ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener);
1628
1629    getSite().getPage().removePartListener(partListener);
1630
1631    adapterFactory.dispose();
1632
1633    if (getActionBarContributor().getActiveEditor() == this)
1634    {
1635      getActionBarContributor().setActiveEditor(null);
1636    }
1637
1638    if (propertySheetPage != null)
1639    {
1640      propertySheetPage.dispose();
1641    }
1642
1643    if (contentOutlinePage != null)
1644    {
1645      contentOutlinePage.dispose();
1646    }
1647
1648    super.dispose();
1649  }
1650
1651}
1652
Popular Tags