KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > mapping > presentation > MappingEditor


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2005 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: MappingEditor.java,v 1.7 2005/06/12 13:39:41 emerks Exp $
16  */

17 package org.eclipse.emf.mapping.presentation;
18
19
20 import java.net.URL JavaDoc;
21 import java.text.MessageFormat JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.EventObject JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31
32 import org.eclipse.core.resources.IFile;
33 import org.eclipse.core.resources.IMarker;
34 import org.eclipse.core.resources.ResourcesPlugin;
35 import org.eclipse.core.runtime.CoreException;
36 import org.eclipse.core.runtime.IPath;
37 import org.eclipse.core.runtime.IProgressMonitor;
38 import org.eclipse.core.runtime.Path;
39 import org.eclipse.core.runtime.Platform;
40 import org.eclipse.jface.action.Action;
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.ProgressMonitorDialog;
48 import org.eclipse.jface.viewers.ColumnWeightData;
49 import org.eclipse.jface.viewers.ILabelProvider;
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.SelectionChangedEvent;
55 import org.eclipse.jface.viewers.StructuredSelection;
56 import org.eclipse.jface.viewers.StructuredViewer;
57 import org.eclipse.jface.viewers.TableLayout;
58 import org.eclipse.jface.viewers.TreeViewer;
59 import org.eclipse.jface.viewers.Viewer;
60 import org.eclipse.swt.SWT;
61 import org.eclipse.swt.custom.CTabFolder;
62 import org.eclipse.swt.custom.SashForm;
63 import org.eclipse.swt.custom.TableTree;
64 import org.eclipse.swt.custom.TableTreeItem;
65 import org.eclipse.swt.dnd.DND;
66 import org.eclipse.swt.dnd.DropTargetEvent;
67 import org.eclipse.swt.dnd.Transfer;
68 import org.eclipse.swt.events.ControlAdapter;
69 import org.eclipse.swt.events.ControlEvent;
70 import org.eclipse.swt.events.ControlListener;
71 import org.eclipse.swt.graphics.Image;
72 import org.eclipse.swt.graphics.Point;
73 import org.eclipse.swt.widgets.Composite;
74 import org.eclipse.swt.widgets.Control;
75 import org.eclipse.swt.widgets.Menu;
76 import org.eclipse.swt.widgets.Table;
77 import org.eclipse.swt.widgets.TableColumn;
78 import org.eclipse.swt.widgets.Tree;
79 import org.eclipse.swt.widgets.Widget;
80 import org.eclipse.ui.IActionBars;
81 import org.eclipse.ui.IEditorInput;
82 import org.eclipse.ui.IEditorPart;
83 import org.eclipse.ui.IEditorSite;
84 import org.eclipse.ui.IFileEditorInput;
85 import org.eclipse.ui.IPartListener;
86 import org.eclipse.ui.IWorkbenchPage;
87 import org.eclipse.ui.IWorkbenchPart;
88 import org.eclipse.ui.PartInitException;
89 import org.eclipse.ui.actions.WorkspaceModifyOperation;
90 import org.eclipse.ui.dialogs.SaveAsDialog;
91 import org.eclipse.ui.part.FileEditorInput;
92 import org.eclipse.ui.part.MultiPageEditorPart;
93 import org.eclipse.ui.views.contentoutline.ContentOutline;
94 import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
95 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
96 import org.eclipse.ui.views.properties.IPropertySheetPage;
97 import org.eclipse.ui.views.properties.PropertySheet;
98 import org.eclipse.ui.views.properties.PropertySheetPage;
99
100 import org.eclipse.emf.common.command.BasicCommandStack;
101 import org.eclipse.emf.common.command.Command;
102 import org.eclipse.emf.common.command.CommandStack;
103 import org.eclipse.emf.common.command.CommandStackListener;
104 import org.eclipse.emf.common.command.CommandWrapper;
105 import org.eclipse.emf.common.notify.AdapterFactory;
106 import org.eclipse.emf.common.notify.Notification;
107 import org.eclipse.emf.common.ui.ViewerPane;
108 import org.eclipse.emf.common.ui.viewer.ExtendedTableTreeViewer;
109 import org.eclipse.emf.common.util.TreeIterator;
110 import org.eclipse.emf.common.util.URI;
111 import org.eclipse.emf.ecore.EObject;
112 import org.eclipse.emf.ecore.InternalEObject;
113 import org.eclipse.emf.ecore.impl.ENotificationImpl;
114 import org.eclipse.emf.ecore.resource.Resource;
115 import org.eclipse.emf.edit.command.RemoveCommand;
116 import org.eclipse.emf.edit.domain.EditingDomain;
117 import org.eclipse.emf.edit.domain.IEditingDomainProvider;
118 import org.eclipse.emf.edit.provider.AdapterFactoryTreeIterator;
119 import org.eclipse.emf.edit.provider.DecoratorAdapterFactory;
120 import org.eclipse.emf.edit.provider.IChangeNotifier;
121 import org.eclipse.emf.edit.provider.IDisposable;
122 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
123 import org.eclipse.emf.edit.provider.IItemLabelProvider;
124 import org.eclipse.emf.edit.provider.IItemPropertySource;
125 import org.eclipse.emf.edit.provider.IItemProviderDecorator;
126 import org.eclipse.emf.edit.provider.INotifyChangedListener;
127 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
128 import org.eclipse.emf.edit.provider.ITableItemLabelProvider;
129 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
130 import org.eclipse.emf.edit.provider.ItemProvider;
131 import org.eclipse.emf.edit.provider.ItemProviderDecorator;
132 import org.eclipse.emf.edit.ui.action.DelegatingCommandAction;
133 import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
134 import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTableTreeEditor;
135 import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
136 import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
137 import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
138 import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
139 import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
140 import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
141 import org.eclipse.emf.mapping.MappedObjectState;
142 import org.eclipse.emf.mapping.Mapping;
143 import org.eclipse.emf.mapping.MappingFactory;
144 import org.eclipse.emf.mapping.MappingPackage;
145 import org.eclipse.emf.mapping.MappingPlugin;
146 import org.eclipse.emf.mapping.MappingRoot;
147 import org.eclipse.emf.mapping.action.CreateMappingAction;
148 import org.eclipse.emf.mapping.action.CreateOneSidedMappingAction;
149 import org.eclipse.emf.mapping.action.NameMatchMappingAction;
150 import org.eclipse.emf.mapping.action.RemoveMappingAction;
151 import org.eclipse.emf.mapping.action.TypeMatchMappingAction;
152 import org.eclipse.emf.mapping.command.CreateMappingCommand;
153 import org.eclipse.emf.mapping.command.PersistentCommandStack;
154 import org.eclipse.emf.mapping.command.RemoveMappingCommand;
155 import org.eclipse.emf.mapping.command.RestoreInitialStateCommand;
156 import org.eclipse.emf.mapping.domain.AdapterFactoryMappingDomain;
157 import org.eclipse.emf.mapping.domain.MappingDomain;
158 import org.eclipse.emf.mapping.provider.MappedObjectItemProvider;
159 import org.eclipse.emf.mapping.provider.MappingItemProvider;
160
161
162 /**
163  * This is an example of a model editor.
164  */

165 public abstract class MappingEditor
166   extends MultiPageEditorPart
167   implements IEditingDomainProvider, ISelectionProvider, IMenuListener
168 {
169   protected static final String JavaDoc DIVIDER = MappingPlugin.getPlugin().getString("_UI_Mapping_label_separator");
170   protected static final String JavaDoc SEPARATOR = MappingPlugin.getPlugin().getString("_UI_Mapping_label_separator") + " ";
171
172   protected String JavaDoc topLabel = MappingUIPlugin.getPlugin().getString("_UI_Top_label");
173
174   public String JavaDoc getTopLabel()
175   {
176     return topLabel;
177   }
178
179   protected String JavaDoc bottomLabel = MappingUIPlugin.getPlugin().getString("_UI_Bottom_label");
180
181   public String JavaDoc getBottomLabel()
182   {
183     return bottomLabel;
184   }
185
186   protected Image topImage = MappingUIPlugin.getPlugin().getImage("full/cview16/TopLogo");
187
188   public Image getTopImage()
189   {
190     return topImage;
191   }
192
193   protected Image bottomImage = MappingUIPlugin.getPlugin().getImage("full/cview16/BottomLogo");
194
195   public Image getBottomImage()
196   {
197     return bottomImage;
198   }
199
200   protected boolean isNotificationEnabled = true;
201
202   public boolean isNotificationEnabled()
203   {
204     return isNotificationEnabled;
205   }
206
207   public void setNotificationEnabled(boolean isNotificationEnabled)
208   {
209     this.isNotificationEnabled = isNotificationEnabled;
210     if (isNotificationEnabled)
211     {
212       if (leftSelectionViewer != null)
213       {
214         leftSelectionViewer.refresh();
215         rightSelectionViewer.refresh();
216         overviewViewer.refresh();
217       }
218       if (contentOutlineViewer != null)
219       {
220         contentOutlineViewer.refresh();
221       }
222       if (propertySheetPage != null)
223       {
224         propertySheetPage.refresh();
225       }
226     }
227   }
228
229   /**
230    * This keeps track of the file that stores the model.
231    */

232   protected IFileEditorInput modelFile;
233
234   /**
235    * This keeps track of the root object of the model.
236    */

237   protected MappingRoot mappingRoot;
238
239   /**
240    * This keeps track of the editing domain that is used to track all changes to the model.
241    */

242   protected AdapterFactoryMappingDomain mappingDomain;
243
244   /**
245    * This is the content outline page.
246    */

247   protected IContentOutlinePage contentOutlinePage;
248
249   /**
250    * This is a kludge...
251    */

252   protected IStatusLineManager contentOutlineStatusLineManager;
253
254   /**
255    * This is the content outline page's viewer.
256    */

257   protected TreeViewer contentOutlineViewer;
258
259   protected Action contentOutlineFilterAction;
260
261   /**
262    * This is the property sheet page.
263    */

264   protected PropertySheetPage propertySheetPage;
265
266   /**
267    * This is the viewer that shadows the selection in the content outline.
268    * The parent relation must be correctly defined for this to work.
269    */

270   protected SimpleMappedObjectViewer leftSelectionViewer;
271   protected MyDecoratorAdapterFactory leftSelectionFactory;
272   protected SimpleMappedObjectViewer rightSelectionViewer;
273   protected MyDecoratorAdapterFactory rightSelectionFactory;
274   protected ViewerPane overviewViewerPane;
275   protected OverviewViewer overviewViewer;
276   protected OverviewDecoratorAdapterFactory overviewFactory;
277
278   /**
279    * This keeps track of the current viewer pane of the page book.
280    */

281   protected ViewerPane currentViewerPane;
282
283   /**
284    * This keeps track of the active content viewer, which may be either one of the viewers in the pages or the content outline viewer.
285    */

286   protected Viewer currentViewer;
287
288   /**
289    * This keeps track of the content viewer, which had something dropped on it.
290    */

291   protected Viewer dropViewer;
292
293   /**
294    * This listens to which ever viewer is active.
295    */

296   protected ISelectionChangedListener selectionChangedListener;
297
298   /**
299    * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are listening to this editor.
300    */

301   protected Collection JavaDoc selectionChangedListeners = new ArrayList JavaDoc();
302
303   /**
304    * This keeps track of the selection of the editor as a whole.
305    */

306   protected ISelection editorSelection = StructuredSelection.EMPTY;
307
308   /**
309    * This listens for when the outline becomes active
310    */

311   protected IPartListener partListener =
312     new IPartListener()
313     {
314       public void partActivated(IWorkbenchPart p)
315       {
316         if (p instanceof ContentOutline)
317         {
318           if (((ContentOutline)p).getCurrentPage() == contentOutlinePage)
319           {
320             getActionBarContributor().setActiveEditor(MappingEditor.this);
321             setCurrentViewer(contentOutlineViewer);
322           }
323         }
324         else if (p instanceof PropertySheet)
325         {
326           if (((PropertySheet)p).getCurrentPage() == propertySheetPage)
327           {
328             getActionBarContributor().setActiveEditor(MappingEditor.this);
329           }
330         }
331       }
332       public void partBroughtToTop(IWorkbenchPart p)
333       {
334       }
335       public void partClosed(IWorkbenchPart p)
336       {
337       }
338       public void partDeactivated(IWorkbenchPart p)
339       {
340       }
341       public void partOpened(IWorkbenchPart p)
342       {
343       }
344     };
345
346   CommandStackListener commandStackListener =
347     new CommandStackListener()
348     {
349       public void commandStackChanged(final EventObject JavaDoc event)
350       {
351         getContainer().getDisplay().asyncExec
352           (new Runnable JavaDoc()
353            {
354              public void run()
355              {
356                firePropertyChange(IEditorPart.PROP_DIRTY);
357
358                // Try to select the affected objects.
359
//
360
Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand();
361                if (mostRecentCommand != null)
362                {
363                  setSelectionToViewer(mostRecentCommand.getAffectedObjects());
364                }
365        
366                leftSelectionViewer.updateActions();
367                rightSelectionViewer.updateActions();
368        
369                if (propertySheetPage != null)
370                {
371                  propertySheetPage.refresh();
372                }
373              }
374            });
375       }
376     };
377
378   /**
379    * This simply calls super; it is here only so that inner classes can call it.
380    */

381   protected void firePropertyChange(int type)
382   {
383     // VAJ kludge
384
//
385
super.firePropertyChange(type);
386   }
387
388   /**
389    * This creates a model editor.
390    */

391   public MappingEditor()
392   {
393     super();
394   }
395
396   protected abstract AdapterFactoryMappingDomain createMappingDomain();
397
398   /**
399    * This sets the selection into whichever viewer is active.
400    */

401   public void setSelectionToViewer(final Collection JavaDoc collection)
402   {
403     // Make sure it's okay.
404
//
405
if (collection != null && !collection.isEmpty())
406     {
407       // I don't know if we should be run this deferred
408
// because we might have to give the editor a chance to process the viewer update events
409
// and hence to update the views first.
410
//
411
//
412
Runnable JavaDoc runnable =
413        new Runnable JavaDoc()
414         {
415           public void run()
416           {
417             Collection JavaDoc indirectMappedObjects = new ArrayList JavaDoc();
418             Collection JavaDoc mappedInputs = new ArrayList JavaDoc();
419             Collection JavaDoc mappedOutputs = new ArrayList JavaDoc();
420             Collection JavaDoc mappings = new ArrayList JavaDoc();
421             for (Iterator JavaDoc objects = collection.iterator(); objects.hasNext(); )
422             {
423               Object JavaDoc object = objects.next();
424               if (object instanceof Mapping)
425               {
426                 mappings.add(object);
427               }
428               else if (mappingDomain.getMappingRoot().isInputObject(object))
429               {
430                 mappedInputs.add(object);
431                 indirectMappedObjects.add(object);
432               }
433               else if (mappingDomain.getMappingRoot().isOutputObject(object))
434               {
435                 mappedOutputs.add(object);
436                 indirectMappedObjects.add(object);
437               }
438             }
439
440             LOOP: for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
441             {
442               Mapping mapping = (Mapping)i.next();
443
444               indirectMappedObjects.addAll(mapping.getMappedObjects());
445
446               for (Mapping parent = mapping.getNestedIn(); parent != null; parent = parent.getNestedIn())
447               {
448                 if (mappings.contains(parent))
449                 {
450                   continue LOOP;
451                 }
452               }
453               
454               mappedOutputs.addAll(mapping.getOutputs());
455               mappedInputs.addAll(mapping.getInputs());
456             }
457
458             if (!indirectMappedObjects.isEmpty())
459             {
460               overviewViewer.setSelection(new StructuredSelection(indirectMappedObjects.toArray()), true);
461             }
462
463             if (!mappings.isEmpty() && contentOutlineViewer != null)
464             {
465               contentOutlineViewer.setSelection(new StructuredSelection(mappings.toArray()), true);
466             }
467
468             Viewer affectedViewer = dropViewer == null ? currentViewer : dropViewer;
469             dropViewer = null;
470
471             // Try to select the items in the current content viewer of the editor.
472
//
473
if (affectedViewer != null)
474             {
475               if (affectedViewer == leftSelectionViewer)
476               {
477                 Collection JavaDoc topMappedObjects = mappingRoot.isTopToBottom() ? mappedInputs : mappedOutputs;
478                 if (!topMappedObjects.isEmpty())
479                 {
480                   leftSelectionViewer.setSelection(new StructuredSelection(topMappedObjects.toArray()), true);
481                 }
482               }
483               else if (affectedViewer == rightSelectionViewer)
484               {
485                 Collection JavaDoc bottomMappedObjects = !mappingRoot.isTopToBottom() ? mappedInputs : mappedOutputs;
486                 if (!bottomMappedObjects.isEmpty())
487                 {
488                   rightSelectionViewer.setSelection(new StructuredSelection(bottomMappedObjects.toArray()), true);
489                 }
490               }
491               else if (!collection.isEmpty())
492               {
493                 affectedViewer.setSelection(new StructuredSelection(collection.toArray()), true);
494               }
495             }
496           }
497         };
498       runnable.run();
499     }
500     else
501     {
502       dropViewer = null;
503     }
504   }
505
506   /**
507    * This returns the editing domain as required by the {@link IEditingDomainProvider} interface.
508    * This is important for implementing the static methods of
509    * {@link org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain} and for supporting
510    * {@link org.eclipse.emf.edit.ui.action.CommandAction}.
511    */

512   public EditingDomain getEditingDomain()
513   {
514     return mappingDomain;
515   }
516
517   public void setCurrentViewerPane(ViewerPane viewerPane)
518   {
519     if (currentViewerPane != viewerPane)
520     {
521       if (currentViewerPane != null)
522       {
523         currentViewerPane.showFocus(false);
524       }
525       currentViewerPane = viewerPane;
526     }
527     setCurrentViewer(currentViewerPane.getViewer());
528   }
529
530   /**
531    * This makes sure that one content viewer, either for the current page or the outline view, if it has focus,
532    * is the current one.
533    */

534   public void setCurrentViewer(Viewer viewer)
535   {
536     // If it is changing...
537
//
538
if (currentViewer != viewer)
539     {
540       if (selectionChangedListener == null)
541       {
542         // Create the listener on demand.
543
//
544
selectionChangedListener =
545           new ISelectionChangedListener()
546           {
547             // This just notifies those things that are affected by the selection.
548
//
549
public void selectionChanged(SelectionChangedEvent event)
550             {
551               setSelection(event.getSelection());
552             }
553           };
554       }
555
556       // Stop listening to the old one.
557
//
558
if (currentViewer != null)
559       {
560         currentViewer.removeSelectionChangedListener(selectionChangedListener);
561       }
562
563       // Start listening to the new one.
564
//
565
if (viewer != null)
566       {
567         viewer.addSelectionChangedListener(selectionChangedListener);
568       }
569
570       // Remember it.
571
//
572
currentViewer = viewer;
573
574       // Set the editor's selection based on the current viewer's selection.
575
//
576
setSelection(currentViewer.getSelection());
577     }
578   }
579
580   /**
581    * This is the contributor for the mapping editor.
582    */

583   static public class ActionBarContributor extends EditingDomainActionBarContributor
584   {
585     protected DelegatingCommandAction removeMappingAction;
586     protected DelegatingCommandAction createMappingAction;
587     protected DelegatingCommandAction createOneSidedMappingAction;
588     protected DelegatingCommandAction nameMatchMappingAction;
589     protected DelegatingCommandAction typeMatchMappingAction;
590
591     /**
592      * This creates an instance the contributor.
593      */

594     public ActionBarContributor()
595     {
596       removeMappingAction = new DelegatingCommandAction(new RemoveMappingAction());
597       createMappingAction = new DelegatingCommandAction(new CreateMappingAction());
598       createOneSidedMappingAction = new DelegatingCommandAction(new CreateOneSidedMappingAction());
599       nameMatchMappingAction = new DelegatingCommandAction(new NameMatchMappingAction());
600       typeMatchMappingAction = new DelegatingCommandAction(new TypeMatchMappingAction());
601     }
602
603     public void setActiveEditor(IEditorPart part)
604     {
605       super.setActiveEditor(part);
606       removeMappingAction.setActiveWorkbenchPart(part);
607       createMappingAction.setActiveWorkbenchPart(part);
608       createOneSidedMappingAction.setActiveWorkbenchPart(part);
609       nameMatchMappingAction.setActiveWorkbenchPart(part);
610       typeMatchMappingAction.setActiveWorkbenchPart(part);
611     }
612
613 /*
614     public void contributeToMenu(IMenuManager menuManager)
615     {
616       super.contributeToMenu(menuManager);
617     }
618 */

619
620     public void contributeToToolBar(IToolBarManager toolBarManager)
621     {
622       toolBarManager.add(new Separator("mapping-settings"));
623       toolBarManager.add(new Separator("mapping-additions"));
624       toolBarManager.add(new Separator("mapping-global-actions"));
625
626       super.contributeToToolBar(toolBarManager);
627     }
628   }
629
630   /**
631    * This creates a context menu for the viewer and adds a listener as well registering the menu for extension.
632    */

633   protected void createContextMenuFor(final StructuredViewer structuredViewer)
634   {
635     MenuManager contextMenu = new MenuManager("#PopUp");
636     contextMenu.add(new Separator("additions"));
637     contextMenu.setRemoveAllWhenShown(true);
638     contextMenu.addMenuListener(this);
639     Menu menu= contextMenu.createContextMenu(structuredViewer.getControl());
640     structuredViewer.getControl().setMenu(menu);
641     getSite().registerContextMenu(contextMenu, structuredViewer);
642
643     int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
644     Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() };
645     structuredViewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(structuredViewer));
646     structuredViewer.addDropSupport
647       (dndOperations,
648        transfers,
649        new EditingDomainViewerDropAdapter(mappingDomain, structuredViewer)
650        {
651          public void drop(DropTargetEvent event)
652          {
653            dropViewer = structuredViewer;
654            super.drop(event);
655          }
656        });
657   }
658
659   protected class MyDecoratorAdapterFactory extends DecoratorAdapterFactory
660   {
661     protected Collection JavaDoc listeningItemProviderDecorators = new HashSet JavaDoc();
662     protected Action action;
663     protected Action multipleColumnsAction;
664     protected boolean exclude;
665
666     public MyDecoratorAdapterFactory(AdapterFactory adapterFactory, Action action, boolean exclude, Action multipleColumnsAction)
667     {
668       this(adapterFactory, action, exclude);
669       this.multipleColumnsAction = multipleColumnsAction;
670     }
671
672     public MyDecoratorAdapterFactory(AdapterFactory adapterFactory, Action action, boolean exclude)
673     {
674       super(adapterFactory);
675       this.action = action;
676       this.exclude = exclude;
677     }
678
679     public boolean isFactoryForType(Object JavaDoc t)
680     {
681       return super.isFactoryForType(t) || t == ITableItemLabelProvider.class;
682
683     }
684
685     public Object JavaDoc adapt(Object JavaDoc o, Object JavaDoc t)
686     {
687       Object JavaDoc result = super.adapt(o, t == ITableItemLabelProvider.class ? IItemLabelProvider.class : t);
688
689       if (result != null)
690       {
691         MappedObjectState mappedObjectState = mappingDomain.getMappingRoot().getMappedObjectState(o);
692         if (mappedObjectState != null && listeningItemProviderDecorators.add(o))
693         {
694           ((MyItemProviderDecorator) result).setMappedObjectState(mappedObjectState);
695         }
696       }
697
698       return result;
699     }
700
701     protected boolean doMappingRefresh(Object JavaDoc object)
702     {
703       return false;
704     }
705
706     protected void doMappedObjectRefresh(Object JavaDoc object)
707     {
708     }
709
710     public List JavaDoc getPrimaryMappedObjects(Mapping mapping)
711     {
712       return Collections.EMPTY_LIST;
713     }
714   
715     public List JavaDoc getSecondaryMappedObjects(Mapping mapping)
716     {
717       return Collections.EMPTY_LIST;
718     }
719
720     class MyItemProviderDecorator
721       extends
722         ItemProviderDecorator
723       implements
724         IStructuredItemContentProvider,
725         ITreeItemContentProvider,
726         IItemPropertySource,
727         IEditingDomainItemProvider,
728         IItemLabelProvider,
729         ITableItemLabelProvider
730     {
731       protected Collection JavaDoc mappedObjectStates = new ArrayList JavaDoc();
732
733       public MyItemProviderDecorator(AdapterFactory adapterFactory)
734       {
735         super(adapterFactory);
736       }
737
738       public Collection JavaDoc getChildren(Object JavaDoc o)
739       {
740         if (action.isChecked())
741         {
742           Collection JavaDoc result = new ArrayList JavaDoc(super.getChildren(o));
743           LOOP : for (Iterator JavaDoc results = result.iterator(); results.hasNext(); )
744           {
745             Object JavaDoc child = results.next();
746             for (Iterator JavaDoc tree = new AdapterFactoryTreeIterator(getDecoratedAdapterFactory(), child, true); tree.hasNext(); )
747             {
748               Object JavaDoc descendant = tree.next();
749               if (mappingDomain.getMappingRoot().getMappings(descendant).isEmpty() == exclude)
750               {
751                 continue LOOP;
752               }
753             }
754             results.remove();
755           }
756           return result;
757         }
758         else
759         {
760           return super.getChildren(o);
761         }
762       }
763
764       public boolean hasChildren(Object JavaDoc o)
765       {
766         if (action.isChecked())
767         {
768           for (Iterator JavaDoc tree = new AdapterFactoryTreeIterator(getDecoratedAdapterFactory(), o, false); tree.hasNext(); )
769           {
770             Object JavaDoc descendant = tree.next();
771             if (mappingDomain.getMappingRoot().getMappings(descendant).isEmpty() == exclude)
772             {
773               return true;
774             }
775           }
776           return false;
777         }
778         else
779         {
780           return super.hasChildren(o);
781         }
782       }
783
784       public Object JavaDoc getSummaryColumnImage(Object JavaDoc o)
785       {
786         return getOverviewSummaryColumnImage(o);
787       }
788
789       public Object JavaDoc getColumnImage(Object JavaDoc o, int columnIndex)
790       {
791         if (columnIndex == 0)
792         {
793           return super.getImage(o);
794         }
795         else if (multipleColumnsAction == null || !multipleColumnsAction.isEnabled() || !multipleColumnsAction.isChecked())
796         {
797           if (columnIndex == 2)
798           {
799             return getSummaryColumnImage(o);
800           }
801           else
802           {
803             Collection JavaDoc mappedObjects = new ArrayList JavaDoc();
804             Collection JavaDoc mappings = mappingRoot.getMappings(o);
805             for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
806             {
807               Mapping mapping = (Mapping)i.next();
808               for (Iterator JavaDoc j = getSecondaryMappedObjects(mapping).iterator(); j.hasNext(); )
809               {
810                 Object JavaDoc mappedObject = j.next();
811                 if (!mappedObjects.contains(mappedObject))
812                 {
813                   mappedObjects.add(mappedObject);
814                 }
815               }
816             }
817   
818             Object JavaDoc result = null;
819             for (Iterator JavaDoc i = mappedObjects.iterator(); i.hasNext(); )
820             {
821               Object JavaDoc mappedObject = i.next();
822               IItemLabelProvider itemLabelProvider =
823                 (IItemLabelProvider)/* EATM getDecoratedAdapterFactory().*/adapt(mappedObject, IItemLabelProvider.class);
824               Object JavaDoc image = itemLabelProvider.getImage(mappedObject);
825               if (result == null)
826               {
827                 result = image;
828               }
829               else if (!result.equals(image))
830               {
831                 result = MappingPlugin.getPlugin().getImage("full/obj16/MultipleImages");
832                 break;
833               }
834             }
835   
836             return result;
837           }
838         }
839         else
840         {
841           Collection JavaDoc secondaryMappedObjectsCollection = getSecondaryMappedObjects(mappingRoot);
842           if (secondaryMappedObjectsCollection.size() == 1)
843           {
844             secondaryMappedObjectsCollection = mappingDomain.getChildren(secondaryMappedObjectsCollection.iterator().next());
845           }
846           int count = 0;
847           for (Iterator JavaDoc secondaryMappedObjects = secondaryMappedObjectsCollection.iterator(); secondaryMappedObjects.hasNext(); )
848           {
849             Object JavaDoc secondardMappedObject = secondaryMappedObjects.next();
850             if (++count == columnIndex)
851             {
852               Collection JavaDoc mappedObjects = new HashSet JavaDoc();
853               Collection JavaDoc mappings = mappingRoot.getMappings(o);
854               for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
855               {
856                 Mapping mapping = (Mapping)i.next();
857                 mappedObjects.addAll(getSecondaryMappedObjects(mapping));
858               }
859
860               Object JavaDoc result = null;
861               for (Iterator JavaDoc i = mappedObjects.iterator(); i.hasNext(); )
862               {
863                 Object JavaDoc mappedObject = i.next();
864                   //FB
865
for (Object JavaDoc parent = mappedObject; parent instanceof EObject; parent = mappingDomain.getParent(parent))
866                 {
867                   if (parent == secondardMappedObject)
868                   {
869                     IItemLabelProvider itemLabelProvider =
870                       (IItemLabelProvider)/* EATM getDecoratedAdapterFactory().*/ adapt(mappedObject, IItemLabelProvider.class);
871                     Object JavaDoc image = itemLabelProvider.getImage(mappedObject);
872                     if (result == null)
873                     {
874                       result = image;
875                     }
876                     else if (!result.equals(image))
877                     {
878                       result = MappingPlugin.getPlugin().getImage("full/obj16/MultipleImages");
879                     }
880                     break;
881                   }
882                 }
883               }
884
885               return result;
886             }
887           }
888
889           return getSummaryColumnImage(o);
890         }
891       }
892
893       public String JavaDoc getSummaryColumnText(Object JavaDoc o)
894       {
895         return getOverviewSummaryColumnText(o);
896       }
897
898       public String JavaDoc getColumnText(Object JavaDoc o, int columnIndex)
899       {
900         if (columnIndex == 0)
901         {
902           return super.getText(o);
903         }
904         else if (multipleColumnsAction == null || !multipleColumnsAction.isEnabled() || !multipleColumnsAction.isChecked())
905         {
906           if (columnIndex == 2)
907           {
908             return getSummaryColumnText(o);
909           }
910           else
911           {
912             Collection JavaDoc mappedObjects = new ArrayList JavaDoc();
913             Collection JavaDoc mappings = mappingRoot.getMappings(o);
914             for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
915             {
916               Mapping mapping = (Mapping)i.next();
917               for (Iterator JavaDoc j = getSecondaryMappedObjects(mapping).iterator(); j.hasNext(); )
918               {
919                 Object JavaDoc mappedObject = j.next();
920                 if (!mappedObjects.contains(mappedObject))
921                 {
922                   mappedObjects.add(mappedObject);
923                 }
924               }
925             }
926
927             StringBuffer JavaDoc label = new StringBuffer JavaDoc();
928             for (Iterator JavaDoc i = mappedObjects.iterator(); i.hasNext(); )
929             {
930               Object JavaDoc mappedObject = i.next();
931               if (label.length() > 0)
932               {
933                 label.append(SEPARATOR);
934               }
935               IItemLabelProvider itemLabelProvider =
936                 (IItemLabelProvider)/* EATM getDecoratedAdapterFactory().*/adapt(mappedObject, IItemLabelProvider.class);
937               label.append(itemLabelProvider.getText(mappedObject));
938             }
939   
940             return label.toString();
941           }
942         }
943         else
944         {
945           Collection JavaDoc secondaryMappedObjectsCollection = getSecondaryMappedObjects(mappingRoot);
946           if (secondaryMappedObjectsCollection.size() == 1)
947           {
948             secondaryMappedObjectsCollection = mappingDomain.getChildren(secondaryMappedObjectsCollection.iterator().next());
949           }
950           int count = 0;
951           for (Iterator JavaDoc secondaryMappedObjects = secondaryMappedObjectsCollection.iterator(); secondaryMappedObjects.hasNext(); )
952           {
953             Object JavaDoc secondardMappedObject = secondaryMappedObjects.next();
954             if (++count == columnIndex)
955             {
956               Collection JavaDoc mappedObjects = new HashSet JavaDoc();
957               Collection JavaDoc mappings = mappingRoot.getMappings(o);
958               for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
959               {
960                 Mapping mapping = (Mapping)i.next();
961                 mappedObjects.addAll(getSecondaryMappedObjects(mapping));
962               }
963
964               StringBuffer JavaDoc label = new StringBuffer JavaDoc();
965               for (Iterator JavaDoc i = mappedObjects.iterator(); i.hasNext(); )
966               {
967                 Object JavaDoc mappedObject = i.next();
968                   //FB
969
for (Object JavaDoc parent = mappedObject; parent instanceof EObject; parent = mappingDomain.getParent(parent))
970                 {
971                   if (parent == secondardMappedObject)
972                   {
973                     if (label.length() > 0)
974                     {
975                       label.append(SEPARATOR);
976                     }
977                     IItemLabelProvider itemLabelProvider =
978                       (IItemLabelProvider)/* EATM getDecoratedAdapterFactory().*/ adapt(mappedObject, IItemLabelProvider.class);
979                     label.append(itemLabelProvider.getText(mappedObject));
980                     break;
981                   }
982                 }
983               }
984
985               return label.toString();
986             }
987           }
988
989           return getSummaryColumnText(o);
990         }
991       }
992
993       public void fireNotifyChanged(Notification note)
994       {
995         super.fireNotifyChanged(note);
996       }
997
998       public void notifyChanged(Notification note)
999       {
1000        if (mappingDomain.getMappingRoot().isInputObject(note.getNotifier()) ||
1001              mappingDomain.getMappingRoot().isOutputObject(note.getNotifier()))
1002        {
1003          if (note.getFeatureID(null) == Notification.NO_FEATURE_ID - 1)
1004          {
1005            ENotificationImpl newNote = new ENotificationImpl(
1006               (InternalEObject)note.getNotifier(),
1007               Notification.SET,
1008               null,
1009               null,
1010               null,
1011               Notification.NO_INDEX);
1012            super.notifyChanged(newNote);
1013
1014            if (action.isChecked() &&
1015                 (note.getNewValue() instanceof Mapping
1016                 || note.getOldValue() instanceof Mapping))
1017            {
1018              if (!doMappingRefresh(note.getNotifier()))
1019              {
1020                for (Object JavaDoc parent = getParent(note.getNotifier()); parent instanceof EObject; parent = mappingDomain.getParent(parent))
1021                {
1022                  if (mappingDomain.getMappingRoot().getMappings(parent).isEmpty() == exclude)
1023                  {
1024                    ENotificationImpl newNote2 = new ENotificationImpl(
1025                      (InternalEObject)parent,
1026                      Notification.ADD,
1027                      null,
1028                      null,
1029                      null,
1030                      Notification.NO_INDEX);
1031                    super.notifyChanged(newNote2);
1032                    break;
1033                  }
1034                }
1035
1036                if (note.getOldValue() instanceof Mapping)
1037                {
1038                  for (Iterator JavaDoc primaryMappedObjects = getPrimaryMappedObjects((Mapping)note.getOldValue()).iterator();
1039                       primaryMappedObjects.hasNext(); )
1040                  {
1041                    Object JavaDoc primaryMappedObject = primaryMappedObjects.next();
1042                    
1043                     ENotificationImpl newNote2 = new ENotificationImpl(
1044                      (InternalEObject)primaryMappedObject,
1045                      Notification.SET,
1046                      null,
1047                      null,
1048                      null,
1049                      Notification.NO_INDEX);
1050                    super.notifyChanged(newNote2);
1051                  }
1052                }
1053                else if (note.getNewValue() instanceof Mapping)
1054                {
1055                  for (Iterator JavaDoc primaryMappedObjects = getPrimaryMappedObjects((Mapping)note.getNewValue()).iterator();
1056                       primaryMappedObjects.hasNext(); )
1057                  {
1058                    Object JavaDoc primaryMappedObject = primaryMappedObjects.next();
1059                    
1060                     ENotificationImpl newNote2 = new ENotificationImpl(
1061                      (InternalEObject)primaryMappedObject,
1062                      Notification.SET,
1063                      null,
1064                      null,
1065                      null,
1066                      Notification.NO_INDEX);
1067                    super.notifyChanged(newNote2);
1068                  }
1069                }
1070              }
1071            }
1072          }
1073          else if (note.getFeatureID(null) != Notification.NO_FEATURE_ID - 2)
1074          {
1075            Collection JavaDoc additions = new ArrayList JavaDoc();
1076            switch (note.getEventType())
1077            {
1078              case Notification.ADD:
1079              {
1080                additions.add(note.getNewValue());
1081                break;
1082              }
1083              case Notification.ADD_MANY:
1084              {
1085                additions.addAll((Collection JavaDoc)note.getNewValue());
1086                break;
1087              }
1088              case Notification.SET:
1089              {
1090                if (note.getPosition() == Notification.NO_INDEX)
1091                {
1092                  doMappedObjectRefresh(note.getNotifier());
1093                }
1094                else
1095                {
1096                  additions.add(note.getNewValue());
1097                }
1098                break;
1099              }
1100            }
1101
1102            for (Iterator JavaDoc i = additions.iterator(); i.hasNext(); )
1103            {
1104              Object JavaDoc addition = i.next();
1105              for (TreeIterator objects = new AdapterFactoryTreeIterator(mappingDomain.getAdapterFactory(), addition);
1106                   objects.hasNext(); )
1107              {
1108                Object JavaDoc child = objects.next();
1109                adapterFactory.adapt(child, ITreeItemContentProvider.class);
1110              }
1111            }
1112
1113          }
1114        }
1115
1116        super.notifyChanged(note);
1117      }
1118
1119      public void setMappedObjectState(MappedObjectState mappedObjectState)
1120      {
1121        mappedObjectState.addListener(this);
1122        mappedObjectStates.add(mappedObjectState);
1123      }
1124
1125      public void dispose()
1126      {
1127        if (mappedObjectStates != null)
1128        {
1129          for (Iterator JavaDoc i = mappedObjectStates.iterator(); i.hasNext(); )
1130          {
1131            MappedObjectState mappedObjectState = (MappedObjectState)i.next();
1132            mappedObjectState.removeListener(this);
1133          }
1134        }
1135        mappedObjectStates.clear();
1136
1137        super.dispose();
1138      }
1139    }
1140
1141    protected IItemProviderDecorator createItemProviderDecorator(Object JavaDoc object, Object JavaDoc type)
1142    {
1143      MyItemProviderDecorator result = new MyItemProviderDecorator(this);
1144      return result;
1145    }
1146
1147    public void fireNotifyChanged(Notification note)
1148    {
1149      if (isNotificationEnabled())
1150      {
1151        super.fireNotifyChanged(note);
1152      }
1153    }
1154  }
1155
1156  protected class OverviewDecoratorAdapterFactory extends MyDecoratorAdapterFactory
1157  {
1158    INotifyChangedListener notifyChangedListener =
1159      new INotifyChangedListener()
1160      {
1161        public void notifyChanged(Notification note)
1162        {
1163          if (note.getNotifier() instanceof Mapping)
1164          {
1165            Mapping mapping = (Mapping)note.getNotifier();
1166
1167            // The helper part assumes that the summary is likely based on the helper and will change when the helper is set.
1168
//
1169
if (note.getFeature() == MappingPackage.eINSTANCE.getMapping_Inputs() ||
1170                  note.getFeature() == MappingPackage.eINSTANCE.getMapping_Outputs() ||
1171                  getOverviewSummaryColumnLabel() != null && note.getFeature() == MappingPackage.eINSTANCE.getMapping_Helper())
1172            {
1173              for (Iterator JavaDoc mappedObjects = mapping.getMappedObjects().iterator(); mappedObjects.hasNext(); )
1174              {
1175                ENotificationImpl newNote = new ENotificationImpl(
1176                (InternalEObject)mappedObjects.next(),
1177                Notification.SET,
1178                null,
1179                null,
1180                null,
1181                Notification.NO_INDEX);
1182                fireNotifyChanged(newNote);
1183              }
1184            }
1185          }
1186        }
1187      };
1188
1189    public OverviewDecoratorAdapterFactory(AdapterFactory adapterFactory, Action action, boolean exclude, Action multipleColumnsAction)
1190    {
1191      super(adapterFactory, action, exclude, multipleColumnsAction);
1192      ((IChangeNotifier)decoratedAdapterFactory).addListener(notifyChangedListener);
1193    }
1194
1195    public void fireNotifyChanged(Notification note)
1196    {
1197      MappingRoot mappingRoot = mappingDomain.getMappingRoot();
1198      if (note.getNotifier() == mappingRoot &&
1199            (note.getFeature() == MappingPackage.eINSTANCE.getMapping_Outputs()
1200            || note.getFeature() == MappingPackage.eINSTANCE.getMapping_Inputs()))
1201      {
1202        overviewViewer.getControl().setVisible(false);
1203        overviewViewer.preserveState();
1204        overviewViewer.init();
1205        overviewViewer.setInput(new ItemProvider(overviewViewer.getPrimaryMappedObjects(mappingDomain.getMappingRoot())));
1206        overviewViewer.restoreState();
1207        overviewViewer.getControl().setVisible(true);
1208      }
1209      else
1210      {
1211        if (isNotificationEnabled())
1212        {
1213          super.fireNotifyChanged(note);
1214        }
1215      }
1216      if (isNotificationEnabled())
1217      {
1218        overviewViewer.refreshCell();
1219      }
1220    }
1221
1222    public List JavaDoc getPrimaryMappedObjects(Mapping mapping)
1223    {
1224      return overviewViewer.getPrimaryMappedObjects(mapping);
1225    }
1226
1227    public List JavaDoc getSecondaryMappedObjects(Mapping mapping)
1228    {
1229      return overviewViewer.getSecondaryMappedObjects(mapping);
1230    }
1231
1232    protected void doMappedObjectRefresh(Object JavaDoc object)
1233    {
1234      MappingRoot mappingRoot = mappingDomain.getMappingRoot();
1235      Collection JavaDoc mappings = mappingRoot.getMappings(object);
1236      Collection JavaDoc primaryMappedObjects = new HashSet JavaDoc();
1237      for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
1238      {
1239        Mapping mapping = (Mapping)i.next();
1240        primaryMappedObjects.addAll(getPrimaryMappedObjects(mapping));
1241      }
1242      if (!primaryMappedObjects.contains(object))
1243      {
1244        for (Iterator JavaDoc i = primaryMappedObjects.iterator(); i.hasNext(); )
1245        {
1246          Object JavaDoc primaryMappedObject = i.next();
1247          if (isNotificationEnabled())
1248          {
1249            ENotificationImpl newNote = new ENotificationImpl(
1250                (InternalEObject)primaryMappedObject,
1251                Notification.SET,
1252                null,
1253                null,
1254                null,
1255                Notification.NO_INDEX);
1256            super.fireNotifyChanged(newNote);
1257          }
1258        }
1259      }
1260    }
1261  }
1262
1263  class MyViewerPane extends ViewerPane
1264  {
1265    protected MappingDomain domain;
1266    protected boolean isTop;
1267    public MyViewerPane(IWorkbenchPage page, IWorkbenchPart part, MappingDomain domain, boolean isTop)
1268    {
1269      super(page, part);
1270      this.domain = domain;
1271      this.isTop = isTop;
1272    }
1273    public Viewer createViewer(Composite composite)
1274    {
1275      return new SimpleMappedObjectViewer(domain, new Tree(composite, SWT.MULTI), isTop);
1276    }
1277    public void requestActivation()
1278    {
1279      super.requestActivation();
1280      setCurrentViewerPane(this);
1281    }
1282  }
1283
1284  /**
1285   * This is the method used by the framework to install your own controls.
1286   */

1287  public void createPages()
1288  {
1289    // I assume that the editorInput is a file object.
1290
//
1291
modelFile = (IFileEditorInput)getEditorInput();
1292
1293    // Handle the creation of the model from the modelFile.
1294
//
1295
handleCreation();
1296
1297    // Restore the persistent command stack, if need be.
1298
//
1299
mappingDomain.getCommandStack().execute(RestoreInitialStateCommand.create(mappingDomain));
1300
1301    // Add a listener to set the most recent command's affected objects to be the selection of the viewer with focus.
1302
//
1303
mappingDomain.getCommandStack().addCommandStackListener(commandStackListener);
1304
1305    // Create a page for the selection tree view.
1306
//
1307
{
1308      final SashForm compositePage = new SashForm(getContainer(), SWT.VERTICAL);
1309      final SashForm topSashForm = new SashForm(compositePage, SWT.HORIZONTAL);
1310
1311      ViewerPane leftSelectionViewerPane = new MyViewerPane(getSite().getPage(), MappingEditor.this, mappingDomain, true);
1312      leftSelectionViewerPane.createControl(topSashForm);
1313      leftSelectionViewer = (SimpleMappedObjectViewer)leftSelectionViewerPane.getViewer();
1314
1315      ViewerPane rightSelectionViewerPane = new MyViewerPane(getSite().getPage(), MappingEditor.this, mappingDomain, false);
1316      rightSelectionViewerPane.createControl(topSashForm);
1317      rightSelectionViewer = (SimpleMappedObjectViewer)rightSelectionViewerPane.getViewer();
1318
1319      addSelectionChangedListener
1320        (new ISelectionChangedListener()
1321         {
1322           // This ensures that we handle selections correctly.
1323
//
1324
public void selectionChanged(SelectionChangedEvent event)
1325           {
1326             if (currentViewer == contentOutlineViewer)
1327             {
1328               Collection JavaDoc mappedObjects = getMappedObjects(event.getSelection());
1329               IStructuredSelection selection = new StructuredSelection(mappedObjects.toArray());
1330               leftSelectionViewer.setSelection(selection, true);
1331               rightSelectionViewer.setSelection(selection, true);
1332
1333               Collection JavaDoc indirectMappedObjects = new HashSet JavaDoc();
1334               Collection JavaDoc primaryMappedObjects = new HashSet JavaDoc();
1335               for (Iterator JavaDoc objects = mappedObjects.iterator(); objects.hasNext(); )
1336               {
1337                 Object JavaDoc object = objects.next();
1338                 if (overviewViewer.isSecondaryMappedObject(mappingRoot, object))
1339                 {
1340                   for (Iterator JavaDoc mappings = mappingRoot.getMappings(object).iterator(); mappings.hasNext(); )
1341                   {
1342                     Mapping mapping = (Mapping)mappings.next();
1343                     indirectMappedObjects.addAll(overviewViewer.getPrimaryMappedObjects(mapping));
1344                   }
1345                 }
1346                 else if (overviewViewer.isPrimaryMappedObject(mappingRoot, object))
1347                 {
1348                   primaryMappedObjects.add(object);
1349                 }
1350               }
1351               if (!primaryMappedObjects.isEmpty())
1352               {
1353                 overviewViewer.setSelection(new StructuredSelection(primaryMappedObjects.toArray()), true);
1354               }
1355               else if (!indirectMappedObjects.isEmpty())
1356               {
1357                 overviewViewer.setSelection(new StructuredSelection(indirectMappedObjects.toArray()), true);
1358               }
1359             }
1360             else if (currentViewer == leftSelectionViewer || currentViewer == rightSelectionViewer)
1361             {
1362               Collection JavaDoc mappedObjects = new HashSet JavaDoc();
1363               for (Iterator JavaDoc mappings =
1364                      mappingRoot.getAllMappings(((IStructuredSelection)event.getSelection()).toList()).iterator();
1365                    mappings.hasNext(); )
1366               {
1367                 Mapping mapping = (Mapping)mappings.next();
1368                 mappedObjects.addAll(overviewViewer.getPrimaryMappedObjects(mapping));
1369               }
1370
1371               if (!mappedObjects.isEmpty())
1372               {
1373                 overviewViewer.setSelection(new StructuredSelection(mappedObjects.toArray()), true);
1374               }
1375               else
1376               {
1377                 overviewViewer.setSelection(event.getSelection(), true);
1378               }
1379             }
1380             else if (currentViewer == overviewViewer)
1381             {
1382               IStructuredSelection selection = (IStructuredSelection)event.getSelection();
1383               if (!selection.isEmpty() && contentOutlineViewer != null)
1384               {
1385                 contentOutlineViewer.setSelection(selection, true);
1386               }
1387               Collection JavaDoc mappedObjects = getMappedObjects(selection);
1388               leftSelectionViewer.setSelection(new StructuredSelection(mappedObjects.toArray()));
1389               rightSelectionViewer.setSelection(new StructuredSelection(mappedObjects.toArray()));
1390             }
1391
1392             if (currentViewer == leftSelectionViewer || currentViewer == rightSelectionViewer)
1393             {
1394               Collection JavaDoc mappings =
1395                 mappingRoot.getAllMappings(((IComposedSelection)event.getSelection()).getCombinedSelection().toList());
1396               if (mappings.isEmpty())
1397               {
1398                 mappings =
1399                   mappingRoot.getAllMappings(((IStructuredSelection)event.getSelection()).toList());
1400               }
1401               if (!mappings.isEmpty() && contentOutlineViewer != null)
1402               {
1403                 contentOutlineViewer.setSelection(new StructuredSelection(mappings.toArray()), true);
1404               }
1405             }
1406           }
1407         });
1408
1409      leftSelectionViewer.setOtherViewer(rightSelectionViewer);
1410      rightSelectionViewer.setOtherViewer(leftSelectionViewer);
1411
1412      leftSelectionViewer.makeContributions
1413        (leftSelectionViewerPane.getMenuManager(), leftSelectionViewerPane.getToolBarManager(), getActionBars().getStatusLineManager());
1414      leftSelectionFactory =
1415        new MyDecoratorAdapterFactory(mappingDomain.getAdapterFactory(), leftSelectionViewer.getFilterMappedObjectsAction(), true)
1416        {
1417          protected boolean doMappingRefresh(Object JavaDoc object)
1418          {
1419            if (leftSelectionViewer.getFilterMappedObjectsAction().isChecked())
1420            {
1421              leftSelectionViewer.getFilterMappedObjectsAction().setChecked(false);
1422              leftSelectionViewer.getFilterMappedObjectsAction().run();
1423            }
1424            return true;
1425          }
1426        };
1427      leftSelectionFactory.adapt((Object JavaDoc)mappingRoot, ITreeItemContentProvider.class);
1428      leftSelectionViewer.setAdapterFactory(leftSelectionFactory);
1429      leftSelectionViewer.setContentProvider
1430        (new AdapterFactoryContentProvider(leftSelectionFactory)
1431         {
1432           public void notifyChanged(Notification note)
1433           {
1434             if (note.getNotifier() == mappingRoot &&
1435                   (note.getFeature() == MappingPackage.eINSTANCE.getMapping_Outputs()
1436                   || note.getFeature() == MappingPackage.eINSTANCE.getMapping_Inputs()))
1437             {
1438               leftSelectionViewer.setInput(new ItemProvider(mappingRoot.getTops()));
1439             }
1440             else
1441             {
1442               super.notifyChanged(note);
1443             }
1444           }
1445         });
1446      leftSelectionViewer.setLabelProvider(new MappingDomainLabelProvider(mappingDomain));
1447      leftSelectionViewer.setAutoExpandLevel(2);
1448      leftSelectionViewer.setInput(new ItemProvider(mappingRoot.getTops()));
1449      leftSelectionViewer.setSelection(new StructuredSelection(mappingRoot.getTops().toArray()));
1450      leftSelectionViewerPane.setTitle(getTopLabel(), getTopImage());
1451
1452      rightSelectionViewer.makeContributions
1453        (rightSelectionViewerPane.getMenuManager(), rightSelectionViewerPane.getToolBarManager(), getActionBars().getStatusLineManager());
1454      rightSelectionFactory =
1455        new MyDecoratorAdapterFactory(mappingDomain.getAdapterFactory(), rightSelectionViewer.getFilterMappedObjectsAction(), true)
1456        {
1457          protected boolean doMappingRefresh(Object JavaDoc object)
1458          {
1459            if (rightSelectionViewer.getFilterMappedObjectsAction().isChecked())
1460            {
1461              rightSelectionViewer.getFilterMappedObjectsAction().setChecked(false);
1462              rightSelectionViewer.getFilterMappedObjectsAction().run();
1463            }
1464            return true;
1465          }
1466        };
1467      rightSelectionFactory.adapt((Object JavaDoc)mappingRoot, ITreeItemContentProvider.class);
1468      rightSelectionViewer.setAdapterFactory(rightSelectionFactory);
1469      rightSelectionViewer.setContentProvider
1470        (new AdapterFactoryContentProvider(rightSelectionFactory)
1471         {
1472           public void notifyChanged(Notification note)
1473           {
1474             if (note.getNotifier() == mappingRoot &&
1475                   (note.getFeature() == MappingPackage.eINSTANCE.getMapping_Outputs()
1476                   || note.getFeature() == MappingPackage.eINSTANCE.getMapping_Inputs()))
1477             {
1478               rightSelectionViewer.setInput(new ItemProvider(mappingRoot.getBottoms()));
1479             }
1480             else
1481             {
1482               super.notifyChanged(note);
1483             }
1484           }
1485         });
1486      rightSelectionViewer.setLabelProvider(new MappingDomainLabelProvider(mappingDomain));
1487      rightSelectionViewer.setAutoExpandLevel(2);
1488      rightSelectionViewer.setInput(new ItemProvider(mappingRoot.getBottoms()));
1489      rightSelectionViewer.setSelection(new StructuredSelection(mappingRoot.getBottoms().toArray()));
1490      rightSelectionViewerPane.setTitle(getBottomLabel(), getBottomImage());
1491
1492      overviewViewerPane =
1493        new ViewerPane(getSite().getPage(), MappingEditor.this)
1494        {
1495          public Viewer createViewer(Composite composite)
1496          {
1497            return createOverviewViewer(composite);
1498          }
1499          public void requestActivation()
1500          {
1501            super.requestActivation();
1502            setCurrentViewerPane(this);
1503          }
1504          public void showFocus(boolean inFocus)
1505          {
1506            super.showFocus(inFocus);
1507            if (!inFocus)
1508            {
1509              overviewViewer.dismissCellEditor();
1510            }
1511          }
1512        };
1513      overviewViewerPane.createControl(compositePage);
1514      overviewViewer = (OverviewViewer)overviewViewerPane.getViewer();
1515      overviewViewer.setAutoExpandLevel(2);
1516      overviewViewerPane.setTitle
1517        (MappingUIPlugin.getPlugin().getString("_UI_Overview_label"),
1518           getDefaultCheckedShowTopFirst() ?
1519             MappingUIPlugin.getPlugin().getImage("full/cview16/OverviewLogo") :
1520             MappingUIPlugin.getPlugin().getImage("full/cview16/OverviewLogoFlipped"));
1521
1522      overviewViewer.makeContributions
1523        (overviewViewerPane.getMenuManager(), overviewViewerPane.getToolBarManager(), getActionBars().getStatusLineManager());
1524
1525      overviewFactory = createOverviewDecoratorAdapterFactory();
1526
1527      overviewViewer.setAdapterFactory(overviewFactory);
1528      overviewFactory.adapt((Object JavaDoc)mappingRoot, ITreeItemContentProvider.class);
1529
1530      overviewViewer.setContentProvider
1531        (new AdapterFactoryContentProvider(overviewFactory)
1532         {
1533           public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput)
1534           {
1535             if (newInput != null)
1536             {
1537               for (TreeIterator children = new AdapterFactoryTreeIterator(mappingDomain.getAdapterFactory(), newInput);
1538                    children.hasNext(); )
1539               {
1540                 Object JavaDoc child = children.next();
1541                 adapterFactory.adapt(child, ITreeItemContentProvider.class);
1542               }
1543             }
1544             super.inputChanged(viewer, oldInput, newInput);
1545           }
1546         });
1547      overviewViewer.setLabelProvider(new AdapterFactoryLabelProvider(overviewFactory));
1548      overviewViewer.setInput(new ItemProvider(overviewViewer.getPrimaryMappedObjects(mappingRoot)));
1549
1550      createContextMenuFor(leftSelectionViewer);
1551      createContextMenuFor(rightSelectionViewer);
1552      createContextMenuFor(overviewViewer);
1553
1554      int pageIndex = addPage(compositePage);
1555      setPageText(pageIndex, MappingUIPlugin.getPlugin().getString("_UI_Composition_label"));
1556    }
1557
1558    setActivePage(0);
1559
1560    getContainer().addControlListener
1561      (new ControlAdapter()
1562       {
1563         boolean guard = false;
1564         public void controlResized(ControlEvent event)
1565         {
1566           if (!guard)
1567           {
1568             guard = true;
1569             hideTabs();
1570             guard = false;
1571           }
1572         }
1573       });
1574  }
1575
1576  /**
1577   * If there is just one page in the multi-page editor part, this hides
1578   * the single tab at the bottom.
1579   * <!-- begin-user-doc -->
1580   * <!-- end-user-doc -->
1581   * @generated
1582   */

1583  protected void hideTabs()
1584  {
1585    if (getPageCount() <= 1)
1586    {
1587      setPageText(0, "");
1588      if (getContainer() instanceof CTabFolder)
1589      {
1590        ((CTabFolder)getContainer()).setTabHeight(1);
1591        Point point = getContainer().getSize();
1592        getContainer().setSize(point.x, point.y + 6);
1593      }
1594    }
1595  }
1596
1597  public String JavaDoc getURIFromFile(IFile file)
1598  {
1599    return URI.createPlatformResourceURI(file.getFullPath().toString()).toString();
1600  }
1601
1602  /**
1603   * This creates the model based on the {@link #modelFile}.
1604   */

1605  protected void handleCreation()
1606  {
1607    // Get the OS compatible name of the model file.
1608
//
1609
// String fileName = modelFile.getFile().getLocation().toOSString();
1610

1611    try
1612    {
1613      // Load the resource through the editing domain.
1614
// This will create a context and associate it with the resource set.
1615
//
1616
Resource resource = mappingDomain.loadResource(getURIFromFile(modelFile.getFile()));
1617   
1618      // The one object in the resource's extent should be the root object.
1619
//
1620
if (resource.getContents().isEmpty())
1621      {
1622        handleMissingModelFile();
1623      }
1624      else
1625      {
1626        Object JavaDoc rootObject = resource.getContents().get(0);
1627  
1628        if (rootObject instanceof MappingRoot)
1629        {
1630          setMappingRoot((MappingRoot)rootObject);
1631        }
1632        else
1633        {
1634          handleMissingModelFile();
1635        }
1636      }
1637    }
1638    catch (Exception JavaDoc exception)
1639    {
1640      handleCreationException(exception);
1641    }
1642  }
1643
1644  protected abstract void handleMissingModelFile();
1645
1646  protected void handleCreationException(Exception JavaDoc exception)
1647  {
1648    exception.printStackTrace();
1649    setMappingRoot(MappingFactory.eINSTANCE.createMappingRoot());
1650  }
1651
1652  protected void setMappingRoot(MappingRoot mappingRoot)
1653  {
1654    this.mappingRoot = mappingRoot;
1655    this.mappingRoot.setDomain(mappingDomain);
1656
1657    // This case happens when the IDE is brought up with the editor already open
1658
//
1659
if (contentOutlineViewer != null && contentOutlineViewer.getInput() == null)
1660    {
1661      // Select the root object in the view.
1662
//
1663
contentOutlineViewer.setInput(new ItemProvider(Collections.singleton(mappingRoot)));
1664      ArrayList JavaDoc selection = new ArrayList JavaDoc();
1665      selection.add(mappingRoot);
1666      contentOutlineViewer.setSelection(new StructuredSelection(selection), true);
1667    }
1668  }
1669
1670  /**
1671   * This is how the framework determines which interfaces we implement.
1672   */

1673  public Object JavaDoc getAdapter(Class JavaDoc key)
1674  {
1675    if (key.equals(IContentOutlinePage.class))
1676    {
1677      return getContentOutlinePage();
1678    }
1679    else if (key.equals(IPropertySheetPage.class))
1680    {
1681      return getPropertySheetPage();
1682    }
1683    else
1684    {
1685      return super.getAdapter(key);
1686    }
1687  }
1688
1689  /**
1690   * This accesses a cached version of the content outliner.
1691   */

1692  public IContentOutlinePage getContentOutlinePage()
1693  {
1694    if (contentOutlinePage == null)
1695    {
1696      // The content outline is just a tree.
1697
//
1698
class MyContentOutlinePage extends ContentOutlinePage
1699      {
1700        public void createControl(Composite parent)
1701        {
1702          contentOutlineFilterAction =
1703            new Action
1704              (MappingUIPlugin.getPlugin().getString("_UI_FilterMappedObjects_menu_item"),
1705               MappingUIPlugin.getPlugin().getImageDescriptor("full/elcl16/OutlineFilter"))
1706            {
1707              public void run()
1708              {
1709                contentOutlineViewer.getControl().setVisible(false);
1710                Object JavaDoc [] expandedElements = contentOutlineViewer.getExpandedElements();
1711                Collection JavaDoc selectedObjects = new HashSet JavaDoc();
1712                for (Iterator JavaDoc i = ((IStructuredSelection)contentOutlineViewer.getSelection()).iterator(); i.hasNext(); )
1713                {
1714                  Object JavaDoc selectedObject = i.next();
1715                  selectedObjects.add(selectedObject);
1716                  selectedObjects.add
1717                    (selectedObject instanceof MappedObjectItemProvider ?
1718                      ((MappedObjectItemProvider)selectedObject).getMapping() :
1719                      selectedObject);
1720                }
1721
1722                Object JavaDoc input = contentOutlineViewer.getInput();
1723                contentOutlineViewer.setInput(input);
1724
1725                contentOutlineViewer.setExpandedElements(expandedElements);
1726                contentOutlineViewer.setSelection(new StructuredSelection(selectedObjects.toArray()), true);
1727                contentOutlineViewer.getControl().setVisible(true);
1728              }
1729              public void setChecked(boolean checked)
1730              {
1731                super.setChecked(checked);
1732                setToolTipText
1733                  (MappingUIPlugin.getPlugin().getString
1734                    (checked ? "_UI_OutlineFilter_checked_description" : "_UI_OutlineFilter_unchecked_description"));
1735              }
1736            };
1737          contentOutlineFilterAction.setChecked(true);
1738          contentOutlineFilterAction.setHoverImageDescriptor
1739            (MappingUIPlugin.getPlugin().getImageDescriptor("full/clcl16/OutlineFilter"));
1740          contentOutlineFilterAction.setDisabledImageDescriptor
1741            (MappingUIPlugin.getPlugin().getImageDescriptor("full/dlcl16/OutlineFilter"));
1742
1743          super.createControl(parent);
1744          contentOutlineViewer = getTreeViewer();
1745          contentOutlineViewer.addSelectionChangedListener(this);
1746          contentOutlineViewer.setAutoExpandLevel(2);
1747
1748          // Set up the tree viewer.
1749
//
1750
contentOutlineViewer.setContentProvider
1751            (new AdapterFactoryContentProvider(mappingDomain.getAdapterFactory())
1752             {
1753               public Object JavaDoc [] getChildren(Object JavaDoc object)
1754               {
1755                 return
1756                   contentOutlineFilterAction.isChecked() ?
1757                     ((Mapping)object).getNested().toArray() :
1758                     super.getChildren(object);
1759               }
1760
1761               public boolean hasChildren(Object JavaDoc object)
1762               {
1763                 return
1764                   contentOutlineFilterAction.isChecked() ?
1765                     object instanceof Mapping && !((Mapping)object).getNested().isEmpty() :
1766                     object instanceof Mapping;
1767               }
1768             });
1769          contentOutlineViewer.setLabelProvider(new MappingDomainLabelProvider(mappingDomain));
1770          if (mappingRoot != null)
1771          {
1772            contentOutlineViewer.setInput(new ItemProvider(Collections.singleton(mappingRoot)));
1773          }
1774
1775          // Make sure our popups work.
1776
//
1777
createContextMenuFor(contentOutlineViewer);
1778
1779          if (mappingRoot != null)
1780          {
1781            // Select the root object in the view.
1782
//
1783
ArrayList JavaDoc selection = new ArrayList JavaDoc();
1784            selection.add(mappingRoot);
1785            contentOutlineViewer.setSelection(new StructuredSelection(selection), true);
1786          }
1787        }
1788
1789        public void setActionBars(IActionBars actionBars)
1790        {
1791          super.setActionBars(actionBars);
1792
1793          contentOutlineStatusLineManager = actionBars.getStatusLineManager();
1794          actionBars.getToolBarManager().add(contentOutlineFilterAction);
1795          actionBars.getMenuManager().add(contentOutlineFilterAction);
1796          getActionBarContributor().shareGlobalActions(this, actionBars);
1797        }
1798      }
1799
1800      contentOutlinePage = new MyContentOutlinePage();
1801    }
1802
1803    return contentOutlinePage;
1804  }
1805
1806  /**
1807   * This accesses a cached version of the property sheet.
1808   */

1809  public IPropertySheetPage getPropertySheetPage()
1810  {
1811    if (propertySheetPage == null)
1812    {
1813      propertySheetPage =
1814        new PropertySheetPage()
1815        {
1816          public void setActionBars(IActionBars actionBars)
1817          {
1818            super.setActionBars(actionBars);
1819            getActionBarContributor().shareGlobalActions(this, actionBars);
1820          }
1821        };
1822      propertySheetPage.setPropertySourceProvider(new AdapterFactoryContentProvider(mappingDomain.getAdapterFactory()));
1823    }
1824
1825    return propertySheetPage;
1826  }
1827
1828  /**
1829   * This is for implementing {@link IEditorPart} and simply tests the command stack.
1830   */

1831  public boolean isDirty()
1832  {
1833    return ((BasicCommandStack)mappingDomain.getCommandStack()).isSaveNeeded();
1834  }
1835
1836  /**
1837   * This is for implementing {@link IEditorPart} and simply saves the model file.
1838   */

1839  public void doSave(IProgressMonitor progressMonitor)
1840  {
1841    doSaveHelper(modelFile.getFile());
1842  }
1843
1844  protected void doSaveHelper(final IFile file)
1845  {
1846    // Do the work within an operation because this is a long running activity that modifies the workbench.
1847
//
1848
WorkspaceModifyOperation operation =
1849      new WorkspaceModifyOperation()
1850      {
1851        // This is the method that gets invoked when the operation runs.
1852
//
1853
protected void execute(IProgressMonitor monitor) throws CoreException
1854        {
1855          try
1856          {
1857            if (mappingDomain.getCommandStack() instanceof PersistentCommandStack)
1858            {
1859              mappingRoot.setCommandStack(((PersistentCommandStack)mappingDomain.getCommandStack()).getEncoding());
1860            }
1861
1862            // Save the resource to the file system.
1863
//
1864
Resource r = mappingRoot.eResource();
1865            r.save(Collections.EMPTY_MAP);
1866            
1867
1868            // Update the workbench's knowledge of the file's contents.
1869
//
1870
file.refreshLocal(1, monitor);
1871
1872            if (!mappingRoot.isOutputReadOnly())
1873            {
1874              HashSet JavaDoc mappedObjectResources = new HashSet JavaDoc();
1875              for (Iterator JavaDoc outputs = mappingRoot.getOutputs().iterator(); outputs.hasNext(); )
1876              {
1877                EObject output = (EObject)outputs.next();
1878                Resource mappedObjectResource = output.eResource();
1879                if (mappedObjectResource != null)
1880                {
1881                  if (mappedObjectResources.add(mappedObjectResource))
1882                  {
1883                    mappedObjectResource.save(Collections.EMPTY_MAP);
1884                    URL JavaDoc resolvedURL = Platform.resolve(new URL JavaDoc(mappedObjectResource.getURI().toString()));
1885                    IFile mappedObjectFile =
1886                      ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(resolvedURL.getFile()));
1887                    if (mappedObjectFile != null)
1888                    {
1889                      mappedObjectFile.refreshLocal(1, monitor);
1890                    }
1891                  }
1892                }
1893              }
1894            }
1895          }
1896          catch (Exception JavaDoc exception)
1897          {
1898            exception.printStackTrace();
1899          }
1900        }
1901      };
1902
1903    try
1904    {
1905      // This runs the operation, and shows progress.
1906
// (It appears to be a bad thing to fork this onto another thread.)
1907
//
1908
new ProgressMonitorDialog(getSite().getShell()).run(false, false, operation);
1909
1910      // Refresh the necessary state.
1911
//
1912
((BasicCommandStack)mappingDomain.getCommandStack()).saveIsDone();
1913      firePropertyChange(IEditorPart.PROP_DIRTY);
1914    }
1915    catch (Exception JavaDoc exception)
1916    {
1917      // Something went wrong that shouldn't.
1918
//
1919
System.err.println(MappingPlugin.getPlugin().getString("_EXC_SaveFailed"));
1920      exception.printStackTrace();
1921    }
1922  }
1923
1924  /**
1925   * This always returns false because it is not currently supported.
1926   */

1927  public boolean isSaveAsAllowed()
1928  {
1929    return true;
1930  }
1931
1932  /**
1933   * This also changes the model.
1934   */

1935  public void doSaveAs()
1936  {
1937    SaveAsDialog saveAsDialog= new SaveAsDialog(getSite().getShell());
1938    saveAsDialog.open();
1939    IPath path= saveAsDialog.getResult();
1940    if (path != null)
1941    {
1942      IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
1943      if (file != null)
1944      {
1945        mappingRoot.eResource().setURI(URI.createURI(getURIFromFile(file)));
1946        modelFile = new FileEditorInput(file);
1947        setInput(modelFile);
1948        setPartName(file.getName());
1949        doSaveHelper(file);
1950      }
1951    }
1952  }
1953
1954  public void gotoMarker(IMarker marker)
1955  {
1956  }
1957
1958  public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException
1959  {
1960    if (editorInput instanceof IFileEditorInput)
1961    {
1962      setSite(site);
1963      setInput(editorInput);
1964      site.setSelectionProvider(this);
1965
1966      site.getPage().addPartListener(partListener);
1967
1968      setPartName(((IFileEditorInput)editorInput).getFile().getName());
1969
1970      // Create the mapping domain with a special command stack.
1971
//
1972
mappingDomain = createMappingDomain();
1973
1974      editorSelection = new StructuredSelection();
1975    }
1976    else
1977    {
1978      throw new PartInitException(MappingUIPlugin.getPlugin().getString("_EXC_InvalidEditorInput"));
1979    }
1980  }
1981
1982  public void setFocus()
1983  {
1984    // Doing this just makes focus go to the default control, not the control that last has focus.
1985
//
1986
// super.setFocus();
1987

1988    if (currentViewerPane != null)
1989    {
1990      currentViewerPane.setFocus();
1991    }
1992    else
1993    {
1994      getControl(getActivePage()).setFocus();
1995    }
1996  }
1997
1998  /**
1999   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
2000   */

2001  public void addSelectionChangedListener(ISelectionChangedListener listener)
2002  {
2003    selectionChangedListeners.add(listener);
2004  }
2005
2006  /**
2007   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}.
2008   */

2009  public void removeSelectionChangedListener(ISelectionChangedListener listener)
2010  {
2011    selectionChangedListeners.remove(listener);
2012  }
2013
2014  /**
2015   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to return this editor's overall selection.
2016   */

2017  public ISelection getSelection()
2018  {
2019    return editorSelection;
2020  }
2021
2022  /**
2023   * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to set this editor's overall selection.
2024   * Calling this result will notify the listeners.
2025   */

2026  public void setSelection(ISelection selection)
2027  {
2028    editorSelection = selection;
2029    for (Iterator JavaDoc listeners = selectionChangedListeners.iterator(); listeners.hasNext(); )
2030    {
2031      ISelectionChangedListener listener = (ISelectionChangedListener)listeners.next();
2032      listener.selectionChanged(new SelectionChangedEvent(this, selection));
2033    }
2034    setStatusLineManager(selection);
2035  }
2036
2037  protected static final String JavaDoc SELECTED_MAPPING_PREFIX =
2038    MappingUIPlugin.getPlugin().getString("_UI_SelectedMapping_statusline_prefix") + " ";
2039
2040  protected static final String JavaDoc SELECTED_MAPPED_OBJECT_PREFIX =
2041    MappingUIPlugin.getPlugin().getString("_UI_SelectedMappedObject_statusline_prefix") + " ";
2042
2043  public void setStatusLineManager(ISelection selection)
2044  {
2045    IStatusLineManager statusLineManager = getActionBars().getStatusLineManager();
2046    if (currentViewer == contentOutlineViewer)
2047    {
2048      statusLineManager = contentOutlineStatusLineManager;
2049    }
2050
2051    if (selection instanceof IComposedSelection)
2052    {
2053      Collection JavaDoc objects = ((IComposedSelection)selection).getCombinedSelection().toList();
2054      String JavaDoc text = MappingItemProvider.getText(mappingDomain.getMappingRoot(), mappingDomain.getAdapterFactory(), objects, "/");
2055      statusLineManager.setMessage(SELECTED_MAPPING_PREFIX + text);
2056    }
2057    else if (selection instanceof IStructuredSelection)
2058    {
2059      Collection JavaDoc collection = ((IStructuredSelection)selection).toList();
2060      switch (collection.size())
2061      {
2062        case 0:
2063        {
2064          statusLineManager.setMessage
2065            (MappingUIPlugin.getPlugin().getString("_UI_Selected_statusline_prefix", "0"));
2066          break;
2067        }
2068        case 1:
2069        {
2070          Object JavaDoc object = collection.iterator().next();
2071          if (object instanceof Mapping)
2072          {
2073            String JavaDoc text =
2074              MappingItemProvider.getText
2075                (mappingDomain.getMappingRoot(), mappingDomain.getAdapterFactory(), ((Mapping)object).getMappedObjects(), "/");
2076            statusLineManager.setMessage(SELECTED_MAPPING_PREFIX + text);
2077          }
2078          else
2079          {
2080            if (object instanceof MappedObjectItemProvider)
2081            {
2082              object = ((MappedObjectItemProvider)object).getMappedObject();
2083            }
2084
2085            String JavaDoc text =
2086              MappingItemProvider.getText
2087                (mappingDomain.getMappingRoot(), mappingDomain.getAdapterFactory(), Collections.singleton(object), "/");
2088            statusLineManager.setMessage(SELECTED_MAPPED_OBJECT_PREFIX + text);
2089          }
2090          break;
2091        }
2092        default:
2093        {
2094          statusLineManager.setMessage
2095            (MappingUIPlugin.getPlugin().getString("_UI_Selected_statusline_prefix", String.valueOf(collection.size())));
2096          break;
2097        }
2098      }
2099    }
2100    else
2101    {
2102      statusLineManager.setMessage("");
2103    }
2104  }
2105
2106  /**
2107   * This implements {@link org.eclipse.jface.action.IMenuListener} to help fill the context menu.
2108   */

2109  public void menuAboutToShow(IMenuManager menuManager)
2110  {
2111    ((IMenuListener)getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager);
2112  }
2113
2114  /**
2115   * This turns the selection into the set of RefObjects involved in the mapping.
2116   */

2117  public Collection JavaDoc getMappedObjects(ISelection selection)
2118  {
2119    Collection JavaDoc result = new ArrayList JavaDoc();
2120    if (selection instanceof IComposedSelection)
2121    {
2122      ISelection [] selections = ((IComposedSelection)selection).getSelections();
2123      for (int i = 0; i < selections.length; ++i)
2124      {
2125        result.addAll(getMappedObjects(selections[i]));
2126      }
2127    }
2128    else if (selection instanceof IStructuredSelection)
2129    {
2130      for (Iterator JavaDoc selectedElements = ((IStructuredSelection)selection).iterator(); selectedElements.hasNext(); )
2131      {
2132        Object JavaDoc selectedElement = selectedElements.next();
2133
2134        if (selectedElement instanceof MappedObjectItemProvider)
2135        {
2136          selectedElement = ((MappedObjectItemProvider)selectedElement).getMappedObject();
2137        }
2138
2139        // If the object is an input or output object, then use it.
2140
//
2141
if (mappingDomain.getMappingRoot().isInputObject(selectedElement) ||
2142              mappingDomain.getMappingRoot().isOutputObject(selectedElement))
2143        {
2144          result.add(selectedElement);
2145        }
2146        else
2147        {
2148          // Process the children recursively.
2149
//
2150
Object JavaDoc [] selectedElementChildren = mappingDomain.getChildren(selectedElement).toArray();
2151          for (int i = 0; i < selectedElementChildren.length; ++i)
2152          {
2153            Object JavaDoc selectedElementChild = selectedElementChildren[i];
2154            if (!(selectedElementChild instanceof Mapping))
2155            {
2156              result.addAll(getMappedObjects(new StructuredSelection(selectedElementChild)));
2157            }
2158          }
2159        }
2160      }
2161    }
2162
2163    return result;
2164  }
2165
2166  /**
2167   * This turns the selection into the set of mappings, but only if all the objects are mappings.
2168   */

2169  public Collection JavaDoc getMappings(ISelection selection)
2170  {
2171    Collection JavaDoc result = new ArrayList JavaDoc();
2172    if (selection instanceof IStructuredSelection)
2173    {
2174      for (Iterator JavaDoc selectedElements = ((IStructuredSelection)selection).iterator(); selectedElements.hasNext(); )
2175      {
2176        Object JavaDoc selectedElement = selectedElements.next();
2177
2178        if (selectedElement instanceof Mapping)
2179        {
2180          result.add(selectedElement);
2181        }
2182        else if (selectedElement instanceof MappedObjectItemProvider)
2183        {
2184          result.add(((MappedObjectItemProvider)selectedElement).getMapping());
2185        }
2186        else
2187        {
2188          return Collections.EMPTY_LIST;
2189        }
2190      }
2191    }
2192
2193    return result;
2194  }
2195
2196  public AdapterFactoryMappingDomain getMappingDomain()
2197  {
2198    return mappingDomain;
2199  }
2200
2201  public Viewer getCurrentViewer()
2202  {
2203    return currentViewer;
2204  }
2205
2206  public void dispose()
2207  {
2208    getSite().getPage().removePartListener(partListener);
2209    if (mappingDomain != null)
2210    {
2211      AdapterFactory adapterFactory = mappingDomain.getAdapterFactory();
2212      if (adapterFactory instanceof IDisposable)
2213      {
2214        ((IDisposable)adapterFactory).dispose();
2215      }
2216      mappingDomain.getCommandStack().removeCommandStackListener(commandStackListener);
2217    }
2218
2219    if (propertySheetPage != null)
2220    {
2221      propertySheetPage.dispose();
2222    }
2223
2224    if (contentOutlinePage != null)
2225    {
2226      contentOutlinePage.dispose();
2227    }
2228
2229    if (leftSelectionFactory != null)
2230    {
2231      leftSelectionFactory.dispose();
2232      rightSelectionFactory.dispose();
2233      overviewFactory.dispose();
2234    }
2235
2236    getActionBarContributor().setActiveEditor(null);
2237
2238    if (mappingRoot != null)
2239    {
2240      mappingRoot.dispose();
2241    }
2242
2243    super.dispose();
2244  }
2245
2246  public EditingDomainActionBarContributor getActionBarContributor()
2247  {
2248    return (EditingDomainActionBarContributor)getEditorSite().getActionBarContributor();
2249  }
2250
2251  public IActionBars getActionBars()
2252  {
2253    return getActionBarContributor().getActionBars();
2254  }
2255
2256  protected String JavaDoc overviewSummaryColumnLabel;
2257  public String JavaDoc getOverviewSummaryColumnLabel()
2258  {
2259    return overviewSummaryColumnLabel;
2260  }
2261
2262  public Object JavaDoc getOverviewSummaryColumnImage(Object JavaDoc o)
2263  {
2264    return null;
2265  }
2266
2267  public String JavaDoc getOverviewSummaryColumnText(Object JavaDoc o)
2268  {
2269    return "";
2270  }
2271
2272  public boolean hasLaunchedOverviewSummaryColumnEditor(Object JavaDoc object)
2273  {
2274    return false;
2275  }
2276
2277  public void createLaunchedOverviewSummaryColumnEditor(Composite parent, Object JavaDoc object)
2278  {
2279  }
2280
2281  public boolean getDefaultCheckedShowTopFirst()
2282  {
2283    return !mappingDomain.getMappingRoot().isTopToBottom();
2284  }
2285
2286  public boolean getDefaultShowMultipleColumns()
2287  {
2288    return false;
2289  }
2290
2291  public boolean getDefaultFilterUnmappedObjects()
2292  {
2293    return true;
2294  }
2295
2296  protected OverviewViewer createOverviewViewer(Composite composite)
2297  {
2298    return new OverviewViewer(this, composite);
2299  }
2300
2301  protected OverviewDecoratorAdapterFactory createOverviewDecoratorAdapterFactory()
2302  {
2303    return
2304      new OverviewDecoratorAdapterFactory
2305        (mappingDomain.getAdapterFactory(),
2306         overviewViewer.getFilterUnmappedObjectsAction(),
2307         false,
2308         overviewViewer.getMultipleColumnsAction());
2309  }
2310
2311  public static class OverviewViewer extends ExtendedTableTreeViewer
2312  {
2313    protected SimpleMappedObjectViewer otherViewer;
2314    protected MappingEditor mappingEditor;
2315    protected AdapterFactoryMappingDomain mappingDomain;
2316    protected AdapterFactory adapterFactory;
2317    protected Action filterUnmappedObjects;
2318    protected Action multipleColumns;
2319    protected Action showTopFirst;
2320    protected TableTree tableTree;
2321    protected Table table;
2322    protected AdapterFactoryTableTreeEditor tableTreeEditor;
2323
2324
2325    ControlListener controlListener = new DelayedColumnFitter();
2326
2327    public OverviewViewer(MappingEditor editor, Composite composite)
2328    {
2329      super(composite);
2330      this.mappingEditor = editor;
2331      this.mappingDomain = editor.getMappingDomain();
2332
2333      tableTree = getTableTree();
2334      table = tableTree.getTable();
2335      table.getVerticalBar().setVisible(true);
2336      table.setHeaderVisible(true);
2337      table.setLinesVisible(true);
2338
2339      // This is a big festering hack to make the images the right size from the start.
2340
//
2341
org.eclipse.swt.widgets.TableItem item = new org.eclipse.swt.widgets.TableItem(table, SWT.NULL);
2342      item.setImage(1, ExtendedImageRegistry.getInstance().getImage(MappingPlugin.getPlugin().getImage("full/obj16/MultipleImages")));
2343      TableTreeItem itemx = new TableTreeItem(tableTree, SWT.NULL, 0);
2344      itemx.setImage(1, ExtendedImageRegistry.getInstance().getImage(MappingPlugin.getPlugin().getImage("full/obj16/MultipleImages")));
2345      itemx.dispose();
2346      item.dispose();
2347
2348      table.addControlListener(controlListener);
2349
2350      tableTreeEditor =
2351        new AdapterFactoryTableTreeEditor(tableTree, mappingDomain.getAdapterFactory())
2352        {
2353          TreeViewer dropDownTreeViewer;
2354          Collection JavaDoc dropDownRoots;
2355          Collection JavaDoc mappedObjects;
2356          Mapping mapping;
2357          HashMap JavaDoc filteredChildren;
2358
2359          public boolean hasDropDownEditor(Object JavaDoc object, int column)
2360          {
2361            if (column == 0 || column == this.table.getColumnCount() - 1 && mappingEditor.getOverviewSummaryColumnLabel() != null)
2362            {
2363              return false;
2364            }
2365
2366            MappingRoot mappingRoot = mappingDomain.getMappingRoot();
2367
2368            dropDownTreeViewer = null;
2369            dropDownRoots = new ArrayList JavaDoc();
2370            mappedObjects = new ArrayList JavaDoc();
2371            mapping = null;
2372            filteredChildren = new HashMap JavaDoc();
2373
2374            if (multipleColumns == null || multipleColumns.isEnabled() && !multipleColumns.isChecked())
2375            {
2376              Collection JavaDoc mappings = mappingRoot.getMappings(object);
2377              for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
2378              {
2379                if (mapping != null)
2380                {
2381                  return false;
2382                }
2383                mapping = (Mapping)i.next();
2384                for (Iterator JavaDoc j = getSecondaryMappedObjects(mapping).iterator(); j.hasNext(); )
2385                {
2386                  Object JavaDoc mappedObject = j.next();
2387                  if (!mappedObjects.contains(mappedObject))
2388                  {
2389                    mappedObjects.add(mappedObject);
2390                  }
2391                }
2392              }
2393              dropDownRoots.addAll(getSecondaryMappedObjects(mappingRoot));
2394            }
2395            else
2396            {
2397              Collection JavaDoc secondaryMappedObjectsCollection = getSecondaryMappedObjects(mappingRoot);
2398              if (secondaryMappedObjectsCollection.size() == 1)
2399              {
2400                secondaryMappedObjectsCollection = mappingDomain.getChildren(secondaryMappedObjectsCollection.iterator().next());
2401              }
2402              int count = 0;
2403              for (Iterator JavaDoc secondaryMappedObjects = secondaryMappedObjectsCollection.iterator(); secondaryMappedObjects.hasNext(); )
2404              {
2405                Object JavaDoc secondaryMappedObject = secondaryMappedObjects.next();
2406                if (++count == column)
2407                {
2408                  dropDownRoots.add(secondaryMappedObject);
2409                  mappedObjects = new HashSet JavaDoc();
2410                  Collection JavaDoc mappings = mappingRoot.getMappings(object);
2411                  for (Iterator JavaDoc i = mappings.iterator(); i.hasNext(); )
2412                  {
2413                    if (mapping != null)
2414                    {
2415                      return false;
2416                    }
2417                    mapping = (Mapping)i.next();
2418                    mappedObjects.addAll(getSecondaryMappedObjects(mapping));
2419                  }
2420                  break;
2421                }
2422              }
2423            }
2424
2425            if (mapping == mappingRoot)
2426            {
2427              return false;
2428            }
2429
2430            Collection JavaDoc dropDownTree = new ArrayList JavaDoc();
2431            Collection JavaDoc primaryMappedObjects = mapping != null ? (Collection JavaDoc)getPrimaryMappedObjects(mapping) : Collections.singleton(object);
2432            for (Iterator JavaDoc i = dropDownRoots.iterator(); i.hasNext(); )
2433            {
2434              Object JavaDoc o = i.next();
2435              if (filter(dropDownTree, mapping, primaryMappedObjects, o))
2436              {
2437                dropDownTree.add(o);
2438              }
2439            }
2440
2441            if (dropDownTree.isEmpty())
2442            {
2443              return false;
2444            }
2445
2446            dropDownRoots = dropDownTree;
2447
2448            return true;
2449          }
2450
2451          protected boolean filter(Collection JavaDoc dropDownTree, Mapping mapping, Collection JavaDoc primaryMappedObjects, Object JavaDoc candidate)
2452          {
2453            Collection JavaDoc children = new ArrayList JavaDoc();
2454            for (Iterator JavaDoc i = mappingDomain.getChildren(candidate).iterator(); i.hasNext(); )
2455            {
2456              Object JavaDoc child = i.next();
2457              if (filter(dropDownTree, mapping, primaryMappedObjects, child))
2458              {
2459                children.add(child);
2460              }
2461            }
2462
2463            filteredChildren.put(candidate, children);
2464            return !children.isEmpty() || canCreateMapping(primaryMappedObjects, candidate);
2465          }
2466
2467          protected boolean canCreateMapping(Collection JavaDoc primaryObjects, Object JavaDoc secondaryObject)
2468          {
2469            if (!showTopFirst.isChecked() != mappingDomain.getMappingRoot().isTopToBottom())
2470            {
2471              return mappingDomain.getMappingRoot().canCreateMapping(Collections.singleton(secondaryObject), primaryObjects, mapping);
2472            }
2473            else
2474            {
2475              return mappingDomain.getMappingRoot().canCreateMapping(primaryObjects, Collections.singleton(secondaryObject), mapping);
2476            }
2477          }
2478
2479          public Control createDropDownEditor(Composite parent, Object JavaDoc object, int column)
2480          {
2481            dropDownTreeViewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.FLAT));
2482            dropDownTreeViewer.setAutoExpandLevel(2);
2483            dropDownTreeViewer.setContentProvider
2484              (new AdapterFactoryContentProvider(this.adapterFactory)
2485               {
2486                 public boolean hasChildren(Object JavaDoc o)
2487                 {
2488                   Collection JavaDoc children = (Collection JavaDoc)filteredChildren.get(o);
2489                   return children != null && !children.isEmpty();
2490                 }
2491                 public Object JavaDoc [] getChildren(Object JavaDoc o)
2492                 {
2493                   Collection JavaDoc children = (Collection JavaDoc)filteredChildren.get(o);
2494                   return (children != null ? children : Collections.EMPTY_LIST).toArray();
2495                 }
2496               });
2497            dropDownTreeViewer.setLabelProvider(new AdapterFactoryLabelProvider(this.adapterFactory));
2498            dropDownTreeViewer.setInput(new ItemProvider(dropDownRoots));
2499
2500            if (!mappedObjects.isEmpty())
2501            {
2502              dropDownTreeViewer.setSelection(new StructuredSelection(mappedObjects.toArray()), true);
2503            }
2504
2505            return dropDownTreeViewer.getControl();
2506          }
2507
2508          public boolean hasLaunchedEditor(Object JavaDoc object, int column)
2509          {
2510            return
2511              mappingEditor.getOverviewSummaryColumnLabel() != null &&
2512              column == this.table.getColumnCount() - 1 &&
2513              mappingEditor.hasLaunchedOverviewSummaryColumnEditor(object);
2514          }
2515
2516          public void createLaunchedEditor(Composite parent, Object JavaDoc object, int column)
2517          {
2518            mappingEditor.createLaunchedOverviewSummaryColumnEditor(parent, object);
2519          }
2520
2521          public void apply()
2522          {
2523            if (dropDownTreeViewer == null)
2524            {
2525              return;
2526            }
2527
2528            final Collection JavaDoc selection = new ArrayList JavaDoc(((IStructuredSelection)dropDownTreeViewer.getSelection()).toList());
2529            if (mapping == null)
2530            {
2531              if (!selection.isEmpty())
2532              {
2533                selection.add(currentTableTreeItem.getData());
2534                Command command = CreateMappingCommand.create(mappingDomain, selection);
2535                mappingDomain.getCommandStack().execute(command);
2536              }
2537            }
2538            else if (!selection.isEmpty())
2539            {
2540              boolean flip = !showTopFirst.isChecked() != mappingDomain.getMappingRoot().isTopToBottom();
2541              final Collection JavaDoc inputs = flip ? selection : mapping.getInputs();
2542              final Collection JavaDoc outputs = flip ? mapping.getOutputs() : selection;
2543              if (!inputs.containsAll(mapping.getInputs()) || !mapping.getInputs().containsAll(inputs) ||
2544                    !outputs.containsAll(mapping.getOutputs()) || !mapping.getOutputs().containsAll(outputs))
2545              {
2546                Command command =
2547                  new CommandWrapper
2548                    ((mappingDomain.getMappingEnablementFlags() & MappingDomain.ENABLE_UNMAPPED_PARENTS) == 0 ?
2549                      RemoveCommand.create(mappingDomain, Collections.singleton(mapping)) :
2550                      RemoveMappingCommand.create(mappingDomain, Collections.singleton(mapping)))
2551                  {
2552                    protected Command createCommand;
2553
2554                    protected boolean prepare()
2555                    {
2556                      boolean result = super.prepare() && mappingDomain.getMappingRoot().canCreateMapping(inputs, outputs, mapping);
2557                      return result;
2558                    }
2559                    public void execute()
2560                    {
2561                      super.execute();
2562                      createCommand = CreateMappingCommand.create(mappingDomain, inputs, outputs);
2563                      createCommand.execute();
2564                    }
2565
2566                    public void undo()
2567                    {
2568                      createCommand.undo();
2569                      super.undo();
2570                    }
2571                    public void redo()
2572                    {
2573                      super.redo();
2574                      createCommand.redo();
2575                    }
2576
2577                    public Collection JavaDoc getResult()
2578                    {
2579                      return createCommand.getResult();
2580                    }
2581
2582                    public Collection JavaDoc getAffectedObjects()
2583                    {
2584                      return createCommand.getAffectedObjects();
2585                    }
2586
2587                    public void dispose()
2588                    {
2589                      super.dispose();
2590                      if (createCommand != null)
2591                      {
2592                        createCommand.dispose();
2593                      }
2594                    }
2595                  };
2596                mappingDomain.getCommandStack().execute(command);
2597              }
2598            }
2599
2600            super.apply();
2601
2602            dropDownTreeViewer = null;
2603          }
2604        };
2605    }
2606
2607    public void cancelEditing()
2608    {
2609      super.cancelEditing();
2610      tableTreeEditor.dismiss();
2611    }
2612
2613    public boolean isPrimaryMappedObject(MappingRoot mappingRoot, Object JavaDoc object)
2614    {
2615      return
2616        !showTopFirst.isChecked() == mappingRoot.isTopToBottom() ?
2617          mappingRoot.isInputObject(object) :
2618          mappingRoot.isOutputObject(object);
2619    }
2620
2621    public boolean isSecondaryMappedObject(MappingRoot mappingRoot, Object JavaDoc object)
2622    {
2623      return
2624        !showTopFirst.isChecked() != mappingRoot.isTopToBottom() ?
2625          mappingRoot.isInputObject(object) :
2626          mappingRoot.isOutputObject(object);
2627    }
2628
2629    public List JavaDoc getPrimaryMappedObjects(Mapping mapping)
2630    {
2631      return
2632        !showTopFirst.isChecked() == mappingDomain.getMappingRoot().isTopToBottom() ?
2633          mapping.getInputs() :
2634          mapping.getOutputs();
2635    }
2636
2637    public List JavaDoc getSecondaryMappedObjects(Mapping mapping)
2638    {
2639      return
2640        !showTopFirst.isChecked() != mappingDomain.getMappingRoot().isTopToBottom() ?
2641          mapping.getInputs() :
2642          mapping.getOutputs();
2643    }
2644
2645    protected Collection JavaDoc expandedObjects = new HashSet JavaDoc();
2646    protected Collection JavaDoc selectedObjects = new HashSet JavaDoc();
2647
2648    public void preserveState()
2649    {
2650      Collection JavaDoc oldExpandedObjects = expandedObjects;
2651      expandedObjects = new HashSet JavaDoc(Arrays.asList(getExpandedElements()));
2652      oldExpandedObjects.removeAll(expandedObjects);
2653      for (Iterator JavaDoc i = oldExpandedObjects.iterator(); i.hasNext(); )
2654      {
2655        Object JavaDoc oldExpandedObject = i.next();
2656        Widget item = findItem(oldExpandedObject);
2657        if (item == null)
2658        {
2659          expandedObjects.add(oldExpandedObject);
2660        }
2661      }
2662
2663      Collection JavaDoc oldSelectedObjects = selectedObjects;
2664      selectedObjects = new HashSet JavaDoc();
2665      MappingRoot mappingRoot = mappingDomain.getMappingRoot();
2666      for (Iterator JavaDoc i = ((IStructuredSelection)super.getSelection()).iterator(); i.hasNext(); )
2667      {
2668        Object JavaDoc selectedObject = i.next();
2669        selectedObjects.add(selectedObject);
2670        for (Iterator JavaDoc mappings = mappingRoot.getMappings(selectedObject).iterator(); mappings.hasNext(); )
2671        {
2672          Mapping mapping = (Mapping)mappings.next();
2673          selectedObjects.addAll(mapping.getInputs().contains(selectedObject) ? mapping.getOutputs() : mapping.getInputs());
2674        }
2675      }
2676      if (selectedObjects.isEmpty())
2677      {
2678        selectedObjects = oldSelectedObjects;
2679      }
2680    }
2681
2682    public void restoreState()
2683    {
2684      setExpandedElements(expandedObjects.toArray());
2685      this.setSelection(new StructuredSelection(selectedObjects.toArray()), true);
2686    }
2687
2688    public void init()
2689    {
2690      tableTree.removeAll();
2691
2692      TableColumn [] columns = table.getColumns();
2693      for (int i = 0; i < columns.length; ++i)
2694      {
2695        columns[i].dispose();
2696      }
2697
2698      TableLayout layout = new TableLayout();
2699      table.setLayout(layout);
2700      // oldWidth = table.getClientArea().width;
2701

2702      TableColumn objectColumn = new TableColumn(table, SWT.NONE);
2703      objectColumn.addControlListener(controlListener);
2704      layout.addColumnData(new ColumnWeightData(2, true));
2705      objectColumn.setText(!showTopFirst.isChecked() ? mappingEditor.getTopLabel() : mappingEditor.getBottomLabel());
2706      objectColumn.setResizable(true);
2707
2708      if (multipleColumns != null)
2709      {
2710        Collection JavaDoc secondaryMappedObjects = getSecondaryMappedObjects(mappingDomain.getMappingRoot());
2711        multipleColumns.setEnabled
2712          (secondaryMappedObjects.size() > 1 ||
2713            secondaryMappedObjects.size() == 1 && mappingDomain.getChildren(secondaryMappedObjects.iterator().next()).size() > 1);
2714        if (!multipleColumns.isEnabled())
2715        {
2716          multipleColumns.setChecked(false);
2717        }
2718      }
2719    
2720      String JavaDoc summaryColumnLabel = mappingEditor.getOverviewSummaryColumnLabel();
2721
2722      if (multipleColumns == null || !multipleColumns.isChecked())
2723      {
2724        TableColumn otherColumn = new TableColumn(table, SWT.NONE);
2725        otherColumn.addControlListener(controlListener);
2726        layout.addColumnData(new ColumnWeightData(2, true));
2727        otherColumn.setText(showTopFirst.isChecked() ? mappingEditor.getTopLabel() : mappingEditor.getBottomLabel());
2728        otherColumn.setResizable(true);
2729        if (summaryColumnLabel != null)
2730        {
2731          TableColumn summaryColumn = new TableColumn(table, SWT.NONE);
2732          summaryColumn.addControlListener(controlListener);
2733          layout.addColumnData(new ColumnWeightData(2, true));
2734          summaryColumn.setText(summaryColumnLabel);
2735          summaryColumn.setResizable(true);
2736          setColumnProperties(new String JavaDoc [] {"a", "b", "c"});
2737        }
2738        else
2739        {
2740          setColumnProperties(new String JavaDoc [] {"a", "b"});
2741        }
2742      }
2743      else
2744      {
2745        Collection JavaDoc properties = new ArrayList JavaDoc();
2746        Collection JavaDoc secondaryMappedObjectsCollection = getSecondaryMappedObjects(mappingDomain.getMappingRoot());
2747        if (secondaryMappedObjectsCollection.size() == 1)
2748        {
2749          secondaryMappedObjectsCollection = mappingDomain.getChildren(secondaryMappedObjectsCollection.iterator().next());
2750        }
2751        for (Iterator JavaDoc secondaryMappedObjects = secondaryMappedObjectsCollection.iterator(); secondaryMappedObjects.hasNext(); )
2752        {
2753          Object JavaDoc mappedObject = secondaryMappedObjects.next();
2754
2755          TableColumn mappedObjectColumn = new TableColumn(table, SWT.NONE);
2756          mappedObjectColumn.addControlListener(controlListener);
2757          layout.addColumnData(new ColumnWeightData(2, true));
2758
2759          String JavaDoc text = ((ILabelProvider)getLabelProvider()).getText(mappedObject);
2760
2761          mappedObjectColumn.setText(text);
2762          mappedObjectColumn.setResizable(true);
2763
2764          properties.add(text);
2765        }
2766
2767        if (summaryColumnLabel != null)
2768        {
2769          properties.add("summaryColumnLabel");
2770          TableColumn summaryColumn = new TableColumn(table, SWT.NONE);
2771          summaryColumn.addControlListener(controlListener);
2772          layout.addColumnData(new ColumnWeightData(2, true));
2773          summaryColumn.setText(summaryColumnLabel);
2774          summaryColumn.setResizable(true);
2775        }
2776        setColumnProperties((String JavaDoc [])properties.toArray(new String JavaDoc [properties.size()]));
2777        setColumnProperties((String JavaDoc [])properties.toArray(new String JavaDoc [properties.size()]));
2778      }
2779
2780      table.layout();
2781    }
2782
2783    public void setAdapterFactory(AdapterFactory adapterFactory)
2784    {
2785      this.adapterFactory = adapterFactory;
2786    }
2787
2788    void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager)
2789    {
2790      showTopFirst =
2791        new Action
2792          ("",
2793           MappingUIPlugin.getPlugin().getImageDescriptor("full/elcl16/ExchangeSourceAndTarget"))
2794        {
2795          public void run()
2796          {
2797            getControl().setVisible(false);
2798            dismissCellEditor();
2799            preserveState();
2800            init();
2801            setInput(new ItemProvider(getPrimaryMappedObjects(mappingDomain.getMappingRoot())));
2802            restoreState();
2803            getControl().setVisible(true);
2804          }
2805
2806          public void setChecked(boolean checked)
2807          {
2808            super.setChecked(checked);
2809            setToolTipText
2810              (MessageFormat.format
2811                (MappingUIPlugin.getPlugin().getString("_UI_ShowTopFirst_description"),
2812                  new String JavaDoc [] { checked ? mappingEditor.getTopLabel() : mappingEditor.getBottomLabel() }));
2813
2814            setText
2815              (MessageFormat.format
2816                 (MappingUIPlugin.getPlugin().getString("_UI_ShowTopFirst_menu_item"),
2817                  new String JavaDoc [] { checked ? mappingEditor.getTopLabel() : mappingEditor.getBottomLabel() }));
2818
2819            mappingEditor.overviewViewerPane.setTitle
2820              (MappingUIPlugin.getPlugin().getString("_UI_Overview_label"),
2821                 !checked ?
2822                   MappingUIPlugin.getPlugin().getImage("full/cview16/OverviewLogo") :
2823                   MappingUIPlugin.getPlugin().getImage("full/cview16/OverviewLogoFlipped"));
2824          }
2825        };
2826      showTopFirst.setChecked(!mappingEditor.getDefaultCheckedShowTopFirst());
2827      showTopFirst.setHoverImageDescriptor(MappingUIPlugin.getPlugin().getImageDescriptor("full/clcl16/ExchangeSourceAndTarget"));
2828      showTopFirst.setDisabledImageDescriptor(MappingUIPlugin.getPlugin().getImageDescriptor("full/dlcl16/ExchangeSourceAndTarget"));
2829      toolBarManager.add(showTopFirst);
2830      menuManager.add(showTopFirst);
2831
2832      multipleColumns =
2833        new Action
2834          (MappingUIPlugin.getPlugin().getString("_UI_ShowMultipleColumns_menu_item"),
2835           MappingUIPlugin.getPlugin().getImageDescriptor("full/elcl16/ShowMultipleTopsOrBottoms"))
2836        {
2837          public void run()
2838          {
2839            getControl().setVisible(false);
2840            preserveState();
2841            dismissCellEditor();
2842            init();
2843            setInput(getInput());
2844            restoreState();
2845            getControl().setVisible(true);
2846          }
2847          public void setChecked(boolean checked)
2848          {
2849            super.setChecked(checked);
2850            setToolTipText
2851              (MappingUIPlugin.getPlugin().getString
2852                (checked ?
2853                   "_UI_ShowMultipleColumns_checked_description" :
2854                   "_UI_ShowMultipleColumns_unchecked_description"));
2855          }
2856        };
2857      multipleColumns.setChecked(mappingEditor.getDefaultShowMultipleColumns());
2858      Collection JavaDoc secondaryMappedObjects = getSecondaryMappedObjects(mappingDomain.getMappingRoot());
2859      multipleColumns.setEnabled
2860        (secondaryMappedObjects.size() > 1 ||
2861          secondaryMappedObjects.size() == 1 && mappingDomain.getChildren(secondaryMappedObjects.iterator().next()).size() > 1);
2862      multipleColumns.setHoverImageDescriptor(MappingUIPlugin.getPlugin().getImageDescriptor("full/clcl16/ShowMultipleTopsOrBottoms"));
2863      multipleColumns.setDisabledImageDescriptor(MappingUIPlugin.getPlugin().getImageDescriptor("full/dlcl16/ShowMultipleTopsOrBottoms"));
2864      toolBarManager.add(multipleColumns);
2865      menuManager.add(multipleColumns);
2866
2867      filterUnmappedObjects =
2868        new Action
2869          (MappingUIPlugin.getPlugin().getString("_UI_FilterUnmappedObjects_menu_item"),
2870           MappingUIPlugin.getPlugin().getImageDescriptor("full/elcl16/ShowOnlyMappedObjects"))
2871        {
2872          public void run()
2873          {
2874            preserveState();
2875            dismissCellEditor();
2876            setInput(getInput());
2877            restoreState();
2878          }
2879          public void setChecked(boolean checked)
2880          {
2881            super.setChecked(checked);
2882            setToolTipText
2883              (MappingUIPlugin.getPlugin().getString
2884                (checked ?
2885                   "_UI_FilterUnmappedObjects_checked_description" :
2886                   "_UI_FilterUnmappedObjects_unchecked_description"));
2887          }
2888        };
2889      filterUnmappedObjects.setChecked(mappingEditor.getDefaultFilterUnmappedObjects());
2890      filterUnmappedObjects.setHoverImageDescriptor(MappingUIPlugin.getPlugin().getImageDescriptor("full/clcl16/ShowOnlyMappedObjects"));
2891      filterUnmappedObjects.setDisabledImageDescriptor(MappingUIPlugin.getPlugin().getImageDescriptor("full/dlcl16/ShowOnlyMappedObjects"));
2892      toolBarManager.add(filterUnmappedObjects);
2893      menuManager.add(filterUnmappedObjects);
2894
2895      toolBarManager.update(true);
2896      menuManager.update(true);
2897
2898      init();
2899    }
2900
2901    public Action getFilterUnmappedObjectsAction()
2902    {
2903      return filterUnmappedObjects;
2904    }
2905
2906    public Action getMultipleColumnsAction()
2907    {
2908      return multipleColumns;
2909    }
2910
2911    public Action getShowTopFirstAction()
2912    {
2913      return showTopFirst;
2914    }
2915
2916    public ISelection getSelection()
2917    {
2918      IStructuredSelection theSelection = (IStructuredSelection)super.getSelection();
2919      List JavaDoc result = new ArrayList JavaDoc();
2920      for (Iterator JavaDoc objects = theSelection.iterator(); objects.hasNext(); )
2921      {
2922        Object JavaDoc object = objects.next();
2923        result.addAll(mappingDomain.getMappingRoot().getMappings(object));
2924      }
2925
2926      return result.isEmpty() ? theSelection : new StructuredSelection(result.toArray());
2927    }
2928
2929    public void dismissCellEditor()
2930    {
2931      tableTreeEditor.dismiss();
2932    }
2933
2934    public void refreshCell()
2935    {
2936      if (tableTreeEditor.getEditor() != null)
2937      {
2938        tableTreeEditor.getEditor().redraw();
2939      }
2940    }
2941
2942    /**
2943     * This override ensures the objects which aren't in the view don't cause a failure.
2944     */

2945    protected void setSelectionToWidget(List JavaDoc list, boolean reveal)
2946    {
2947      List JavaDoc filteredSelection = new ArrayList JavaDoc();
2948      if (list != null)
2949      {
2950        filteredSelection.addAll(list);
2951        for (Iterator JavaDoc i = filteredSelection.iterator(); i.hasNext(); )
2952        {
2953          Object JavaDoc selectedObject = i.next();
2954          if (findItem(selectedObject) == null && internalExpand(selectedObject, false) == null)
2955          {
2956            i.remove();
2957          }
2958        }
2959      }
2960
2961      super.setSelectionToWidget(filteredSelection, reveal);
2962    }
2963  }
2964}
2965
2966class DelayedColumnFitter extends ControlAdapter
2967{
2968  protected Table table;
2969  protected DelayedLayout delayedLayout;
2970  protected int columnResizeTime;
2971  protected int oldWidth;
2972  protected boolean inLayout;
2973
2974  public void controlResized(ControlEvent event)
2975  {
2976    if (event.getSource() instanceof Table)
2977    {
2978      table = (Table)event.getSource();
2979      if (delayedLayout == null)
2980      {
2981        delayedLayout = new DelayedLayout(event.time);
2982      }
2983    }
2984    else
2985    {
2986      if (!inLayout)
2987      {
2988        columnResizeTime = event.time;
2989      }
2990    }
2991  }
2992
2993  protected class DelayedLayout implements Runnable JavaDoc
2994  {
2995    protected TableLayout layout;
2996    protected int newWidth;
2997    protected boolean ignore;
2998
2999    public DelayedLayout(int time)
3000    {
3001      newWidth = table.getClientArea().width;
3002      if (oldWidth != newWidth && oldWidth != 0)
3003      {
3004        layout = new TableLayout();
3005        TableColumn [] tableColumns = table.getColumns();
3006        for (int i = 0; i < tableColumns.length; ++i)
3007        {
3008          layout.addColumnData(new ColumnWeightData(tableColumns[i].getWidth(), true));
3009        }
3010
3011        if (columnResizeTime != 0 && time - columnResizeTime < 500)
3012        {
3013          ignore = true;
3014        }
3015      }
3016      else
3017      {
3018        ignore = true;
3019      }
3020
3021      oldWidth = newWidth;
3022      columnResizeTime = 0;
3023
3024      table.getDisplay().asyncExec(this);
3025    }
3026
3027    public void run()
3028    {
3029      delayedLayout = null;
3030      if (!table.isDisposed() && !ignore)
3031      {
3032        columnResizeTime = 0;
3033        table.setLayout(layout);
3034        inLayout = true;
3035        table.layout();
3036        inLayout = false;
3037/*
3038        if (delayedLayout != null)
3039        {
3040          System.out.println("Layout causes a layout!!!!!");
3041        }
3042*/

3043      }
3044    }
3045  }
3046}
3047
3048
Popular Tags