Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbblajer2006-11-16 18:31:55 +0000
committerbblajer2006-11-16 18:31:55 +0000
commite02f6466572d7c6efbd624e3840cedf5394d5330 (patch)
treef952aace1fed7ad061394546c245e09184be80d5 /plugins/org.eclipse.gmf.runtime.lite/src/org
parent7ed9d9c8e4c9f9b38ef532b85e81a57956cf1578 (diff)
downloadorg.eclipse.gmf-tooling-e02f6466572d7c6efbd624e3840cedf5394d5330.tar.gz
org.eclipse.gmf-tooling-e02f6466572d7c6efbd624e3840cedf5394d5330.tar.xz
org.eclipse.gmf-tooling-e02f6466572d7c6efbd624e3840cedf5394d5330.zip
Refactoring to use as much common code as possible for diagram editors and viewers (for #163214);
Manifest.mf specifies J2SE1.5 as required execution environment.
Diffstat (limited to 'plugins/org.eclipse.gmf.runtime.lite/src/org')
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramContentOutlinePage.java235
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramDisplayer.java398
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditor.java577
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditorInput.java64
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramViewPart.java332
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramManager.java28
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramOutlineHost.java33
-rw-r--r--plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/UpdatableActionGroup.java37
8 files changed, 1290 insertions, 414 deletions
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramContentOutlinePage.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramContentOutlinePage.java
new file mode 100644
index 000000000..218fd838d
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramContentOutlinePage.java
@@ -0,0 +1,235 @@
+/**
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.parts;
+
+import org.eclipse.draw2d.LightweightSystem;
+import org.eclipse.draw2d.Viewport;
+import org.eclipse.draw2d.parts.ScrollableThumbnail;
+import org.eclipse.draw2d.parts.Thumbnail;
+import org.eclipse.gef.KeyHandler;
+import org.eclipse.gef.KeyStroke;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.editparts.FreeformGraphicalRootEditPart;
+import org.eclipse.gef.editparts.RootTreeEditPart;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.GEFActionConstants;
+import org.eclipse.gef.ui.parts.ContentOutlinePage;
+import org.eclipse.gef.ui.parts.TreeViewer;
+import org.eclipse.gmf.internal.runtime.lite.Activator;
+import org.eclipse.gmf.runtime.lite.edit.parts.tree.DiagramTreeEditPartFactory;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+/**
+ * The diagram outline.
+ */
+public class DiagramContentOutlinePage extends Page implements IContentOutlinePage {
+ public static final int ID_OVERVIEW = 0;
+ public static final int ID_OUTLINE = 1;
+
+ private final int myDefaultMode;
+ private ContentOutlinePage myOutlinePage;
+ private Canvas myOverview;
+ private PageBook myPageBook;
+ private IAction myShowOutlineAction;
+ private IAction myShowOverviewAction;
+ private Thumbnail myThumbnail;
+ private TreeViewer myTreeViewer;
+ private DisposeListener myDisposeListener;
+ private final IDiagramOutlineHost myHost;
+
+ public DiagramContentOutlinePage(IDiagramOutlineHost host, int defaultMode) {
+ myHost = host;
+ myDefaultMode = defaultMode;
+ }
+
+ @Override
+ public void init(IPageSite pageSite) {
+ super.init(pageSite);
+ ActionRegistry registry = myHost.getActionRegistry();
+ IActionBars bars = pageSite.getActionBars();
+ String id = ActionFactory.UNDO.getId();
+ bars.setGlobalActionHandler(id, registry.getAction(id));
+ id = ActionFactory.REDO.getId();
+ bars.setGlobalActionHandler(id, registry.getAction(id));
+ id = ActionFactory.DELETE.getId();
+ bars.setGlobalActionHandler(id, registry.getAction(id));
+ bars.updateActionBars();
+
+ // Toolbar refresh to solve linux defect RATLC525198
+ bars.getToolBarManager().markDirty();
+ }
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ if (myOutlinePage != null) {
+ myOutlinePage.addSelectionChangedListener(listener);
+ }
+ }
+
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ if (myOutlinePage != null) {
+ myOutlinePage.removeSelectionChangedListener(listener);
+ }
+ }
+
+ public ISelection getSelection() {
+ if (myOutlinePage != null) {
+ return myOutlinePage.getSelection();
+ }
+ return StructuredSelection.EMPTY;
+ }
+
+ public void setSelection(ISelection selection) {
+ if (myOutlinePage != null) {
+ myOutlinePage.setSelection(selection);
+ }
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ myPageBook = new PageBook(parent, SWT.NONE);
+ myTreeViewer = new TreeViewer();
+ myTreeViewer.setRootEditPart(new RootTreeEditPart());
+ myTreeViewer.setEditDomain(myHost.getEditDomain());
+ myTreeViewer.setEditPartFactory(new DiagramTreeEditPartFactory(myHost.getGraphicalViewer()));
+ configureTreeViewer(myTreeViewer);
+ myOutlinePage = new ContentOutlinePage(myTreeViewer);
+ myOutlinePage.createControl(myPageBook);
+ myTreeViewer.setContents(myHost.getGraphicalViewer().getContents().getModel());
+ hookOutlineViewer(myTreeViewer);
+ configureOutlinePage();
+ showPage(myDefaultMode);
+ }
+
+ protected void hookOutlineViewer(TreeViewer viewer) {
+ myHost.getSelectionSynchronizer().addViewer(viewer);
+ }
+
+ protected void unhookOutlineViewer(TreeViewer viewer) {
+ myHost.getSelectionSynchronizer().removeViewer(viewer);
+ }
+
+ protected void configureOutlinePage() {
+ IToolBarManager tbm = this.getSite().getActionBars().getToolBarManager();
+ myShowOutlineAction = new Action() {
+ public void run() {
+ showPage(ID_OUTLINE);
+ }
+ };
+ myShowOutlineAction.setImageDescriptor(Activator.getImageDescriptor("icons/outline.gif")); //$NON-NLS-1$
+ myShowOutlineAction.setToolTipText("Show Outline");
+ tbm.add(myShowOutlineAction);
+ myShowOverviewAction = new Action() {
+ public void run() {
+ showPage(ID_OVERVIEW);
+ }
+ };
+ myShowOverviewAction.setImageDescriptor(Activator.getImageDescriptor("icons/overview.gif")); //$NON-NLS-1$
+ myShowOverviewAction.setToolTipText("Show Overview");
+ tbm.add(myShowOverviewAction);
+ }
+
+ protected void configureTreeViewer(TreeViewer treeViewer) {
+ KeyHandler keyHandler = new KeyHandler();
+ keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
+ myHost.getActionRegistry().getAction(ActionFactory.DELETE.getId()));
+ keyHandler.put(KeyStroke.getPressed(SWT.F2, 0), myHost.getActionRegistry()
+ .getAction(GEFActionConstants.DIRECT_EDIT));
+ treeViewer.setKeyHandler(keyHandler);
+ }
+
+ protected void showPage(int pageId) {
+ switch (pageId) {
+ case ID_OUTLINE:
+ myShowOutlineAction.setChecked(true);
+ myShowOverviewAction.setChecked(false);
+ myPageBook.showPage(myOutlinePage.getControl());
+ if (myThumbnail != null) {
+ myThumbnail.setVisible(false);
+ }
+ break;
+ case ID_OVERVIEW:
+ myShowOutlineAction.setChecked(false);
+ myShowOverviewAction.setChecked(true);
+ if (myOverview == null || myOverview.isDisposed()) {
+ initializeOverview();
+ }
+ myPageBook.showPage(myOverview);
+ if (myThumbnail != null) {
+ myThumbnail.setVisible(true);
+ }
+ }
+ }
+
+ protected void initializeOverview() {
+ myOverview = new Canvas(myPageBook, SWT.NONE);
+ LightweightSystem lws = new LightweightSystem(myOverview);
+ FreeformGraphicalRootEditPart root = (FreeformGraphicalRootEditPart) myHost.getGraphicalViewer().getRootEditPart();
+ myThumbnail = new ScrollableThumbnail((Viewport) root.getFigure());
+ myThumbnail.setSource(root.getLayer(LayerConstants.SCALABLE_LAYERS));
+ lws.setContents(myThumbnail);
+ myDisposeListener = new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ if (myThumbnail != null) {
+ myThumbnail.deactivate();
+ myThumbnail = null;
+ }
+ }
+ };
+ myHost.getGraphicalControl().addDisposeListener(myDisposeListener);
+ }
+
+ @Override
+ public Control getControl() {
+ return myPageBook;
+ }
+
+ @Override
+ public void setFocus() {
+ if (myOutlinePage != null) {
+ myOutlinePage.setFocus();
+ }
+ }
+
+ @Override
+ public void dispose() {
+ if (myOutlinePage != null) {
+ myOutlinePage.dispose();
+ }
+ unhookOutlineViewer(myTreeViewer);
+ if (myThumbnail != null) {
+ myThumbnail.deactivate();
+ myThumbnail = null;
+ }
+ if (myDisposeListener != null) {
+ myHost.getGraphicalControl().removeDisposeListener(myDisposeListener);
+ }
+ myOverview = null;
+ super.dispose();
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramDisplayer.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramDisplayer.java
new file mode 100644
index 000000000..2aea87809
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramDisplayer.java
@@ -0,0 +1,398 @@
+/**
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.parts;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.EventObject;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditDomain;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.commands.CommandStackListener;
+import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
+import org.eclipse.gef.editparts.ScalableRootEditPart;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.SelectionAction;
+import org.eclipse.gef.ui.actions.StackAction;
+import org.eclipse.gef.ui.actions.WorkbenchPartAction;
+import org.eclipse.gef.ui.palette.FlyoutPaletteComposite;
+import org.eclipse.gef.ui.palette.PaletteViewerProvider;
+import org.eclipse.gef.ui.palette.FlyoutPaletteComposite.FlyoutPreferences;
+import org.eclipse.gef.ui.parts.GraphicalEditor;
+import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
+import org.eclipse.gef.ui.parts.SelectionSynchronizer;
+import org.eclipse.gef.ui.views.palette.PaletteViewerPage;
+import org.eclipse.gmf.internal.runtime.lite.Activator;
+import org.eclipse.gmf.runtime.lite.properties.PropertySourceProvider;
+import org.eclipse.gmf.runtime.lite.properties.UndoablePropertySheetEntry;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.views.properties.PropertySheetPage;
+
+/**
+ * @author bblajer
+ */
+public class DiagramDisplayer implements IDiagramOutlineHost {
+ private TransactionalEditingDomain editingDomain;
+ private PaletteRoot paletteRoot;
+ private PropertySheetPage undoablePropertySheetPage;
+ private GraphicalViewer graphicalViewer;
+ private ActionRegistry actionRegistry;
+ private UpdatableActionGroup stackActions = new UpdatableActionGroup();
+ private EditDomain myEditDomain;
+ private IDiagramManager myDiagramManager;
+ private FlyoutPaletteComposite mySplitter;
+ private PaletteViewerProvider myPaletteViewerProvider;
+ private PaletteViewerPage myPalettePage;
+ private SelectionSynchronizer synchronizer;
+ private Control myTopLevelControl;
+
+ private CommandStackListener commandStackListener = new CommandStackListener() {
+ public void commandStackChanged(EventObject event) {
+ stackActions.update();
+ }
+ };
+
+ private UpdatableActionGroup editPartActions = new UpdatableActionGroup();
+
+ private ISelectionListener selectionListener = new ISelectionListener() {
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ editPartActions.update();
+ }
+ };
+
+ private UpdatableActionGroup propertyActions = new UpdatableActionGroup();
+
+ private IPropertyListener propertyListener = new IPropertyListener() {
+ public void propertyChanged(Object source, int propId) {
+ propertyActions.update();
+ }
+ };
+
+ /**
+ * Constructs a new instance of the diagram displayer.
+ */
+ public DiagramDisplayer(IDiagramManager diagramManager, EditDomain gefEditDomain, TransactionalEditingDomain emfEditingDomain) {
+ myDiagramManager = diagramManager;
+ assert gefEditDomain != null;
+ assert emfEditingDomain != null;
+ setEditDomain(gefEditDomain);
+ editingDomain = emfEditingDomain;
+
+ getCommandStack().addCommandStackListener(commandStackListener);
+ myDiagramManager.getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);
+ myDiagramManager.getSite().getPart().addPropertyListener(propertyListener);
+ }
+
+ public void dispose() {
+ // remove CommandStackListener
+ getCommandStack().removeCommandStackListener(commandStackListener);
+
+ // remove selection listener
+ myDiagramManager.getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(selectionListener);
+
+ getEditDomain().setActiveTool(null);
+
+ // dispose the ActionRegistry (will dispose all actions)
+ getActionRegistry().dispose();
+ }
+
+ protected ZoomManager getZoomManager() {
+ return getZoomManager(getGraphicalViewer());
+ }
+
+ private ZoomManager getZoomManager(GraphicalViewer viewer) {
+ // get zoom manager from root edit part
+ RootEditPart rootEditPart = viewer.getRootEditPart();
+ ZoomManager zoomManager = null;
+ if (rootEditPart instanceof ScalableFreeformRootEditPart) {
+ zoomManager = ((ScalableFreeformRootEditPart) rootEditPart).getZoomManager();
+ } else if (rootEditPart instanceof ScalableRootEditPart) {
+ zoomManager = ((ScalableRootEditPart) rootEditPart).getZoomManager();
+ }
+ return zoomManager;
+ }
+
+ protected PaletteRoot getPaletteRoot() {
+ if (paletteRoot == null) {
+ paletteRoot = new PaletteRoot();
+ myDiagramManager.configurePalette(paletteRoot);
+ }
+ return paletteRoot;
+ }
+
+ public CommandStack getCommandStack() {
+ return myEditDomain.getCommandStack();
+ }
+
+ protected PropertySheetPage getPropertySheetPage() {
+ if (undoablePropertySheetPage == null) {
+ undoablePropertySheetPage = new PropertySheetPage();
+ UndoablePropertySheetEntry rootEntry = new UndoablePropertySheetEntry(getCommandStack());
+ rootEntry.setPropertySourceProvider(new PropertySourceProvider(myDiagramManager.getDomainAdapterFactory()));
+ undoablePropertySheetPage.setRootEntry(rootEntry);
+ }
+
+ return undoablePropertySheetPage;
+ }
+
+ /**
+ * Adds an action to this editor's <code>ActionRegistry</code>. (This is
+ * a helper method.)
+ *
+ * @param action
+ * the action to add.
+ */
+ protected void addAction(IAction action) {
+ getActionRegistry().registerAction(action);
+ }
+
+ /**
+ * Adds an editor action to this editor.
+ *
+ * <p>
+ * Editor actions are actions that depend and work on the editor.
+ *
+ * @param action
+ * the editor action
+ */
+ protected void addEditorAction(WorkbenchPartAction action) {
+ getActionRegistry().registerAction(action);
+ propertyActions.addAction(action);
+ }
+
+ /**
+ * Adds an <code>EditPart</code> action to this editor.
+ *
+ * <p>
+ * <code>EditPart</code> actions are actions that depend and work on the
+ * selected <code>EditPart</code>s.
+ *
+ * @param action
+ * the <code>EditPart</code> action
+ */
+ protected void addEditPartAction(SelectionAction action) {
+ getActionRegistry().registerAction(action);
+ editPartActions.addAction(action);
+ }
+
+ /**
+ * Adds an <code>CommandStack</code> action to this editor.
+ *
+ * <p>
+ * <code>CommandStack</code> actions are actions that depend and work on
+ * the <code>CommandStack</code>.
+ *
+ * @param action
+ * the <code>CommandStack</code> action
+ */
+ protected void addStackAction(StackAction action) {
+ getActionRegistry().registerAction(action);
+ stackActions.addAction(action);
+ }
+
+ public ActionRegistry getActionRegistry() {
+ if (actionRegistry == null)
+ actionRegistry = new ActionRegistry();
+ return actionRegistry;
+ }
+
+ public TransactionalEditingDomain getEditingDomain() {
+ return editingDomain;
+ }
+
+ public void createViewer(Composite parent) {
+ if (myDiagramManager.isFlyoutPalette()) {
+ mySplitter = new FlyoutPaletteComposite(parent, SWT.NONE, myDiagramManager.getSite().getPage(), getPaletteViewerProvider(), getPalettePreferences());
+ createGraphicalViewer(mySplitter);
+ myTopLevelControl = mySplitter;
+ } else {
+ SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
+ createGraphicalViewer(sashForm);
+ getPaletteViewerProvider().createPaletteViewer(sashForm);
+ sashForm.setWeights(new int[] {85, 15}); //TODO: allow customization and persistence
+ myTopLevelControl = sashForm;
+ }
+ }
+
+ /**
+ * Creates the GraphicalViewer on the specified <code>Composite</code>.
+ * @param parent the parent composite
+ */
+ protected void createGraphicalViewer(Composite parent) {
+ GraphicalViewer viewer = new ScrollingGraphicalViewer();
+ viewer.createControl(parent);
+ setGraphicalViewer(viewer);
+ myDiagramManager.configureGraphicalViewer();
+ hookGraphicalViewer();
+ initializeGraphicalViewer();
+ }
+
+ /**
+ * Sets the graphicalViewer for this diagram displayer.
+ * @param viewer the graphical viewer
+ */
+ protected void setGraphicalViewer(GraphicalViewer viewer) {
+ myEditDomain.addViewer(viewer);
+ graphicalViewer = viewer;
+ if (mySplitter != null) {
+ mySplitter.setGraphicalControl(graphicalViewer.getControl());
+ }
+ }
+
+ public GraphicalViewer getGraphicalViewer() {
+ return graphicalViewer;
+ }
+
+ /**
+ * Hooks the GraphicalViewer to the rest of the Editor. By default, the viewer
+ * is added to the SelectionSynchronizer, which can be used to keep 2 or more
+ * EditPartViewers in sync. The viewer is also registered as the ISelectionProvider
+ * for the Editor's PartSite.
+ */
+ protected void hookGraphicalViewer() {
+ getSelectionSynchronizer().addViewer(getGraphicalViewer());
+ myDiagramManager.getSite().setSelectionProvider(getGraphicalViewer());
+ }
+
+ /**
+ * @see GraphicalEditor#initializeGraphicalViewer()
+ */
+ protected void initializeGraphicalViewer() {
+ if (mySplitter != null) {
+ mySplitter.hookDropTargetListener(getGraphicalViewer());
+ }
+ myDiagramManager.initializeGraphicalViewer();
+ }
+
+ /**
+ * Returns the selection syncronizer object. The synchronizer can be used to sync the
+ * selection of 2 or more EditPartViewers.
+ * @return the syncrhonizer
+ */
+ public final SelectionSynchronizer getSelectionSynchronizer() {
+ if (synchronizer == null)
+ synchronizer = new SelectionSynchronizer();
+ return synchronizer;
+ }
+
+ public void setFocus() {
+ getGraphicalViewer().getControl().setFocus();
+ }
+
+ private PaletteViewerProvider getPaletteViewerProvider() {
+ if (myPaletteViewerProvider == null)
+ myPaletteViewerProvider = createPaletteViewerProvider();
+ return myPaletteViewerProvider;
+ }
+
+ /**
+ * Creates a PaletteViewerProvider that will be used to create palettes for the view
+ * and the flyout.
+ *
+ * @return the palette provider
+ */
+ protected PaletteViewerProvider createPaletteViewerProvider() {
+ return new PaletteViewerProvider(myEditDomain);
+ }
+
+ protected void setEditDomain(EditDomain ed) {
+ myEditDomain = ed;
+ myEditDomain.setPaletteRoot(getPaletteRoot());
+ }
+
+ public EditDomain getEditDomain() {
+ return myEditDomain;
+ }
+
+ public Control getTopLevelControl() {
+ return myTopLevelControl;
+ }
+
+ public Control getGraphicalControl() {
+ return getGraphicalViewer().getControl();
+ }
+
+ /**
+ * Returns a FlyoutPreferences object that stores the flyout
+ * settings in the lite runtime plugin.
+ * @return the FlyoutPreferences object used to save the flyout palette's preferences
+ */
+ private FlyoutPreferences getPalettePreferences() {
+ return FlyoutPaletteComposite
+ .createFlyoutPreferences(Activator.getDefault().getPluginPreferences());
+ }
+
+ public PaletteViewerPage getPalettePage() {
+ if (myPalettePage == null) {
+ myPalettePage = new CustomPalettePage(getPaletteViewerProvider());
+ }
+ return myPalettePage;
+ }
+
+ private class CustomPalettePage extends PaletteViewerPage {
+ public CustomPalettePage(PaletteViewerProvider provider) {
+ super(provider);
+ }
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ if (mySplitter != null)
+ mySplitter.setExternalViewer(viewer);
+ }
+ public void dispose() {
+ if (mySplitter != null)
+ mySplitter.setExternalViewer(null);
+ super.dispose();
+ }
+ }
+
+ public void save(IProgressMonitor progressMonitor) throws CoreException {
+ if (progressMonitor == null) {
+ progressMonitor = new NullProgressMonitor();
+ }
+ progressMonitor.beginTask("Saving", getEditingDomain().getResourceSet().getResources().size());
+ try {
+ for(Iterator it = getEditingDomain().getResourceSet().getResources().iterator(); it.hasNext(); ) {
+ Resource next = (Resource)it.next();
+ if (next.isLoaded() && (next.isModified() || !next.isTrackingModification())) {
+ next.save(Collections.EMPTY_MAP);
+ }
+ progressMonitor.worked(1);
+ }
+ } catch (IOException e) {
+ IStatus status = new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), 0, "Error writing file.", e);
+ throw new CoreException(status);
+ } finally {
+ progressMonitor.done();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditor.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditor.java
index 564f39504..2904657c4 100644
--- a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditor.java
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditor.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2006 Borland Software Corp.
+ * Copyright (c) 2006 Borland Software Corporation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,22 +11,14 @@
*/
package org.eclipse.gmf.runtime.lite.parts;
-import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.EventObject;
import java.util.Iterator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.draw2d.LightweightSystem;
-import org.eclipse.draw2d.Viewport;
-import org.eclipse.draw2d.parts.ScrollableThumbnail;
-import org.eclipse.draw2d.parts.Thumbnail;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
@@ -37,295 +29,163 @@ import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
import org.eclipse.gef.DefaultEditDomain;
+import org.eclipse.gef.EditDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.GraphicalViewer;
-import org.eclipse.gef.KeyHandler;
-import org.eclipse.gef.KeyStroke;
-import org.eclipse.gef.LayerConstants;
-import org.eclipse.gef.RootEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.commands.CommandStackListener;
-import org.eclipse.gef.editparts.FreeformGraphicalRootEditPart;
-import org.eclipse.gef.editparts.RootTreeEditPart;
-import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
-import org.eclipse.gef.editparts.ScalableRootEditPart;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.ui.actions.ActionRegistry;
-import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.gef.ui.actions.StackAction;
-import org.eclipse.gef.ui.actions.UpdateAction;
import org.eclipse.gef.ui.actions.WorkbenchPartAction;
-import org.eclipse.gef.ui.parts.ContentOutlinePage;
-import org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette;
-import org.eclipse.gef.ui.parts.TreeViewer;
-import org.eclipse.gmf.internal.runtime.lite.Activator;
-import org.eclipse.gmf.runtime.lite.edit.parts.tree.DiagramTreeEditPartFactory;
-import org.eclipse.gmf.runtime.lite.properties.PropertySourceProvider;
-import org.eclipse.gmf.runtime.lite.properties.UndoablePropertySheetEntry;
+import org.eclipse.gef.ui.views.palette.PalettePage;
import org.eclipse.gmf.runtime.lite.services.DefaultDiagramLayouter;
import org.eclipse.gmf.runtime.lite.services.IDiagramLayouter;
-import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.actions.ActionFactory;
-import org.eclipse.ui.part.IPageSite;
-import org.eclipse.ui.part.Page;
-import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.ui.views.properties.PropertySheetPage;
/**
- * Common functionality of all diagram editors generated with the lite generator.
+ * This class serves as the base class for the generated diagram editors.
+ * @author bblajer
*/
-public abstract class DiagramEditor extends GraphicalEditorWithFlyoutPalette {
- protected static final int ID_OVERVIEW = 0;
- protected static final int ID_OUTLINE = 1;
-
- protected class DiagramContentOutlinePage extends Page implements IContentOutlinePage {
- private ContentOutlinePage myOutlinePage;
- private Canvas myOverview;
- private PageBook myPageBook;
- private IAction myShowOutlineAction;
- private IAction myShowOverviewAction;
- private Thumbnail myThumbnail;
- private TreeViewer myTreeViewer;
- private DisposeListener myDisposeListener;
+public abstract class DiagramEditor extends EditorPart implements IDiagramManager {
+ private DiagramDisplayer myDiagramDisplayer;
+ private boolean myIsDirty = false;
- @Override
- public void init(IPageSite pageSite) {
- super.init(pageSite);
- ActionRegistry registry = getActionRegistry();
- IActionBars bars = pageSite.getActionBars();
- String id = ActionFactory.UNDO.getId();
- bars.setGlobalActionHandler(id, registry.getAction(id));
- id = ActionFactory.REDO.getId();
- bars.setGlobalActionHandler(id, registry.getAction(id));
- id = ActionFactory.DELETE.getId();
- bars.setGlobalActionHandler(id, registry.getAction(id));
- bars.updateActionBars();
-
- // Toolbar refresh to solve linux defect RATLC525198
- bars.getToolBarManager().markDirty();
- }
-
- public void addSelectionChangedListener(ISelectionChangedListener listener) {
- if (myOutlinePage != null) {
- myOutlinePage.addSelectionChangedListener(listener);
- }
- }
-
- public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- if (myOutlinePage != null) {
- myOutlinePage.removeSelectionChangedListener(listener);
- }
+ private CommandStackListener commandStackListener = new CommandStackListener() {
+ public void commandStackChanged(EventObject event) {
+ setDirty(((CommandStack) event.getSource()).isDirty());
}
+ };
- public ISelection getSelection() {
- if (myOutlinePage != null) {
- return myOutlinePage.getSelection();
- }
- return StructuredSelection.EMPTY;
- }
+ protected void save(IProgressMonitor monitor) throws CoreException {
+ myDiagramDisplayer.save(monitor);
+ }
- public void setSelection(ISelection selection) {
- if (myOutlinePage != null) {
- myOutlinePage.setSelection(selection);
- }
- }
+ protected final TransactionalEditingDomain getEditingDomain() {
+ return myDiagramDisplayer.getEditingDomain();
+ }
- @Override
- public void createControl(Composite parent) {
- myPageBook = new PageBook(parent, SWT.NONE);
- myTreeViewer = new TreeViewer();
- myTreeViewer.setRootEditPart(new RootTreeEditPart());
- myTreeViewer.setEditDomain(getEditDomain());
- myTreeViewer.setEditPartFactory(new DiagramTreeEditPartFactory(getGraphicalViewer()));
- configureTreeViewer(myTreeViewer);
- myOutlinePage = new ContentOutlinePage(myTreeViewer);
- myOutlinePage.createControl(myPageBook);
- myTreeViewer.setContents(getGraphicalViewer().getContents().getModel());
- hookOutlineViewer(myTreeViewer);
- configureOutlinePage();
- showPage(getDefaultOutlineViewMode());
- }
+ protected final EditDomain getEditDomain() {
+ return myDiagramDisplayer.getEditDomain();
+ }
- protected void hookOutlineViewer(TreeViewer viewer) {
- getSelectionSynchronizer().addViewer(viewer);
- }
+ protected final CommandStack getCommandStack() {
+ return getEditDomain().getCommandStack();
+ }
- protected void unhookOutlineViewer(TreeViewer viewer) {
- getSelectionSynchronizer().removeViewer(viewer);
- }
+ protected final ZoomManager getZoomManager() {
+ return myDiagramDisplayer.getZoomManager();
+ }
- protected void configureOutlinePage() {
- IToolBarManager tbm = this.getSite().getActionBars().getToolBarManager();
- myShowOutlineAction = new Action() {
- public void run() {
- showPage(ID_OUTLINE);
- }
- };
- myShowOutlineAction.setImageDescriptor(Activator.getImageDescriptor("icons/outline.gif")); //$NON-NLS-1$
- myShowOutlineAction.setToolTipText("Show Outline");
- tbm.add(myShowOutlineAction);
- myShowOverviewAction = new Action() {
- public void run() {
- showPage(ID_OVERVIEW);
- }
- };
- myShowOverviewAction.setImageDescriptor(Activator.getImageDescriptor("icons/overview.gif")); //$NON-NLS-1$
- myShowOverviewAction.setToolTipText("Show Overview");
- tbm.add(myShowOverviewAction);
- }
+ protected final ActionRegistry getActionRegistry() {
+ return myDiagramDisplayer.getActionRegistry();
+ }
- protected void configureTreeViewer(TreeViewer treeViewer) {
- KeyHandler keyHandler = new KeyHandler();
- keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
- getActionRegistry().getAction(ActionFactory.DELETE.getId()));
- keyHandler.put(KeyStroke.getPressed(SWT.F2, 0), getActionRegistry()
- .getAction(GEFActionConstants.DIRECT_EDIT));
- treeViewer.setKeyHandler(keyHandler);
- }
+ protected final GraphicalViewer getGraphicalViewer() {
+ return myDiagramDisplayer.getGraphicalViewer();
+ }
- protected void showPage(int pageId) {
- switch (pageId) {
- case ID_OUTLINE:
- myShowOutlineAction.setChecked(true);
- myShowOverviewAction.setChecked(false);
- myPageBook.showPage(myOutlinePage.getControl());
- if (myThumbnail != null) {
- myThumbnail.setVisible(false);
- }
- break;
- case ID_OVERVIEW:
- myShowOutlineAction.setChecked(false);
- myShowOverviewAction.setChecked(true);
- if (myOverview == null || myOverview.isDisposed()) {
- initializeOverview();
- }
- myPageBook.showPage(myOverview);
- if (myThumbnail != null) {
- myThumbnail.setVisible(true);
- }
- }
- }
+ protected IPropertySheetPage getPropertySheetPage() {
+ return myDiagramDisplayer.getPropertySheetPage();
+ }
- protected void initializeOverview() {
- myOverview = new Canvas(myPageBook, SWT.NONE);
- LightweightSystem lws = new LightweightSystem(myOverview);
- FreeformGraphicalRootEditPart root = (FreeformGraphicalRootEditPart) getGraphicalViewer().getRootEditPart();
- myThumbnail = new ScrollableThumbnail((Viewport) root.getFigure());
- myThumbnail.setSource(root.getLayer(LayerConstants.SCALABLE_LAYERS));
- lws.setContents(myThumbnail);
- myDisposeListener = new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- if (myThumbnail != null) {
- myThumbnail.deactivate();
- myThumbnail = null;
- }
- }
- };
- getGraphicalControl().addDisposeListener(myDisposeListener);
- }
+ protected IContentOutlinePage getOutlinePage() {
+ return new DiagramContentOutlinePage(myDiagramDisplayer, getDefaultOutlineViewMode());
+ }
- @Override
- public Control getControl() {
- return myPageBook;
- }
+ protected IDiagramLayouter getDiagramLayouter() {
+ return new DefaultDiagramLayouter();
+ }
- @Override
- public void setFocus() {
- if (myOutlinePage != null) {
- myOutlinePage.setFocus();
- }
- }
+ /**
+ * Returns the initial display mode for the outline page to be shown. Possible values are <code>DiagramContentOutlinePage.ID_OUTLINE</code> and
+ * <code>DiagramContentOutlinePage.ID_OVERVIEW</code>.
+ * By default, the outline page starts in the overview mode. Subclasses may reimplement.
+ */
+ protected int getDefaultOutlineViewMode() {
+ return DiagramContentOutlinePage.ID_OVERVIEW;
+ }
- @Override
- public void dispose() {
- if (myOutlinePage != null) {
- myOutlinePage.dispose();
- }
- unhookOutlineViewer(myTreeViewer);
- if (myThumbnail != null) {
- myThumbnail.deactivate();
- myThumbnail = null;
- }
- if (myDisposeListener != null) {
- getGraphicalControl().removeDisposeListener(myDisposeListener);
- }
- myOverview = null;
- super.dispose();
- }
+ @Override
+ public boolean isSaveAsAllowed() {
+ // TODO: should be allowed.
+ return false;
}
- private static class UpdatableActionGroup {
- public void addAction(UpdateAction action) {
- assert action != null;
- myActions.add(action);
- }
+ @Override
+ public void doSaveAs() {
+ // TODO: Implement.
+ }
- public void removeAction(UpdateAction action) {
- myActions.remove(action);
+ @Override
+ public void init(IEditorSite site, IEditorInput input) throws PartInitException {
+ setSite(site);
+ TransactionalEditingDomain editingDomain = getEditingDomain(input);
+ if (editingDomain == null) {
+ editingDomain = createEditingDomain();
}
+ myDiagramDisplayer = new DiagramDisplayer(this, createEditDomain(), editingDomain);
+ getCommandStack().addCommandStackListener(commandStackListener);
+ setInput(input);
+ }
- public void update() {
- for (Iterator it = myActions.iterator(); it.hasNext();) {
- UpdateAction next = (UpdateAction) it.next();
- next.update();
- }
+ @Override
+ public void dispose() {
+ if (myDiagramDisplayer != null) {
+ getCommandStack().removeCommandStackListener(commandStackListener);
+ myDiagramDisplayer.dispose();
+ myDiagramDisplayer = null;
}
-
- private ArrayList myActions = new ArrayList();
+ super.dispose();
}
- private TransactionalEditingDomain editingDomain;
-
- private boolean isDirty = false;
-
- private PaletteRoot paletteRoot;
-
- private PropertySheetPage undoablePropertySheetPage;
-
- private UpdatableActionGroup stackActions = new UpdatableActionGroup();
-
- private CommandStackListener commandStackListener = new CommandStackListener() {
- public void commandStackChanged(EventObject event) {
- stackActions.update();
- setDirty(((CommandStack) event.getSource()).isDirty());
+ @Override
+ public Object getAdapter(Class type) {
+ if (type == IPropertySheetPage.class) {
+ return getPropertySheetPage();
+ } else if (type == IContentOutlinePage.class) {
+ return getOutlinePage();
+ } else if (type == ZoomManager.class) {
+ return getZoomManager();
+ } else if (type == IDiagramLayouter.class) {
+ return getDiagramLayouter();
+ } else if (type == PalettePage.class) {
+ return myDiagramDisplayer.getPalettePage();
+ } else if (type == GraphicalViewer.class) {
+ return getGraphicalViewer();
+ } else if (type == CommandStack.class) {
+ return getCommandStack();
+ } else if (type == ActionRegistry.class) {
+ return getActionRegistry();
+ } else if (type == EditPart.class && getGraphicalViewer() != null) {
+ return getGraphicalViewer().getRootEditPart();
+ } else if (type == IFigure.class && getGraphicalViewer() != null) {
+ return ((GraphicalEditPart)getGraphicalViewer().getRootEditPart()).getFigure();
}
- };
-
- private UpdatableActionGroup editPartActions = new UpdatableActionGroup();
+ return super.getAdapter(type);
+ }
- private ISelectionListener selectionListener = new ISelectionListener() {
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- editPartActions.update();
+ private void setDirty(boolean isDirty) {
+ if (isDirty != myIsDirty) {
+ myIsDirty = isDirty;
+ firePropertyChange(PROP_DIRTY);
}
- };
-
- private UpdatableActionGroup editorActions = new UpdatableActionGroup();
+ }
- protected void firePropertyChange(int propertyId) {
- super.firePropertyChange(propertyId);
- editorActions.update();
+ @Override
+ public boolean isDirty() {
+ return myIsDirty;
}
/**
@@ -336,7 +196,7 @@ public abstract class DiagramEditor extends GraphicalEditorWithFlyoutPalette {
* the action to add.
*/
protected void addAction(IAction action) {
- getActionRegistry().registerAction(action);
+ myDiagramDisplayer.addAction(action);
}
/**
@@ -349,8 +209,7 @@ public abstract class DiagramEditor extends GraphicalEditorWithFlyoutPalette {
* the editor action
*/
protected void addEditorAction(WorkbenchPartAction action) {
- getActionRegistry().registerAction(action);
- editorActions.addAction(action);
+ myDiagramDisplayer.addEditorAction(action);
}
/**
@@ -364,8 +223,7 @@ public abstract class DiagramEditor extends GraphicalEditorWithFlyoutPalette {
* the <code>EditPart</code> action
*/
protected void addEditPartAction(SelectionAction action) {
- getActionRegistry().registerAction(action);
- editPartActions.addAction(action);
+ myDiagramDisplayer.addEditPartAction(action);
}
/**
@@ -379,12 +237,51 @@ public abstract class DiagramEditor extends GraphicalEditorWithFlyoutPalette {
* the <code>CommandStack</code> action
*/
protected void addStackAction(StackAction action) {
- getActionRegistry().registerAction(action);
- stackActions.addAction(action);
+ myDiagramDisplayer.addStackAction(action);
}
- public void init(IEditorSite site, IEditorInput input) throws PartInitException {
- setSite(site);
+ @Override
+ public void createPartControl(Composite parent) {
+ myDiagramDisplayer.createViewer(parent);
+ createActions();
+ }
+
+ @Override
+ public void setFocus() {
+ myDiagramDisplayer.setFocus();
+ }
+
+ /**
+ * Returns the editing domain instance to be used for the specified input. If this method returns <code>null</code>,
+ * a {@link #createEditDomain() default instance} will be created and used.
+ * By default, return <code>null</code>. Subclasses may reimplement.
+ */
+ protected TransactionalEditingDomain getEditingDomain(IEditorInput editorInput) {
+ return null;
+ }
+
+ /**
+ * Returns the editing domain instance to be used for the diagram if none may be {@link #getEditingDomain(IEditorInput) inferred} from the input.
+ * Subclasses may extend or reimplement.
+ */
+ protected TransactionalEditingDomain createEditingDomain() {
+ TransactionalEditingDomain editingDomain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
+ editingDomain.getResourceSet().eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(editingDomain));
+ editingDomain.getResourceSet().eAdapters().add(new ForceTrackingModificationAdapter());
+ return editingDomain;
+ }
+
+ public void configureGraphicalViewer() {
+ getGraphicalViewer().getControl().setBackground(ColorConstants.listBackground);
+ }
+
+ public abstract void configurePalette(PaletteRoot paletteRoot);
+
+ /**
+ * Creates edit domain that will be used for the editor.
+ * Subclasses may extend.
+ */
+ protected EditDomain createEditDomain() {
DefaultEditDomain domain = new DefaultEditDomain(this);
domain.setCommandStack(new CommandStack(){
@Override
@@ -421,164 +318,16 @@ public abstract class DiagramEditor extends GraphicalEditorWithFlyoutPalette {
return true;
}
});
- setEditDomain(domain);
-
- // add CommandStackListener
- getCommandStack().addCommandStackListener(getStackActionsListener());
-
- // add selection change listener
- getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(getSelectionListener());
- setInput(input);
- }
-
- public void dispose() {
- // remove CommandStackListener
- getCommandStack().removeCommandStackListener(getStackActionsListener());
-
- // remove selection listener
- getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(getSelectionListener());
-
- // dispose the ActionRegistry (will dispose all actions)
- getActionRegistry().dispose();
- }
-
- protected void save(IProgressMonitor progressMonitor) throws CoreException {
- if (progressMonitor == null) {
- progressMonitor = new NullProgressMonitor();
- }
- progressMonitor.beginTask("Saving", getEditingDomain().getResourceSet().getResources().size());
- try {
- for(Iterator it = getEditingDomain().getResourceSet().getResources().iterator(); it.hasNext(); ) {
- Resource next = (Resource)it.next();
- if (next.isLoaded() && (next.isModified() || !next.isTrackingModification())) {
- next.save(Collections.EMPTY_MAP);
- }
- progressMonitor.worked(1);
- }
- } catch (IOException e) {
- IStatus status = new Status(IStatus.ERROR, Activator.getDefault().getBundle().getSymbolicName(), 0, "Error writing file.", e);
- throw new CoreException(status);
- } finally {
- progressMonitor.done();
- }
- }
-
- public boolean isSaveAsAllowed() {
- // TODO: should be allowed.
- return false;
- }
-
- public void doSaveAs() {
- // TODO: Implement.
- }
-
- public Object getAdapter(Class type) {
- if (type == IPropertySheetPage.class) {
- return getPropertySheetPage();
- } else if (type == IContentOutlinePage.class) {
- return getOutlinePage();
- } else if (type == ZoomManager.class) {
- return getZoomManager();
- } else if (type == IDiagramLayouter.class) {
- return getDiagramLayouter();
- }
- return super.getAdapter(type);
- }
-
- protected IDiagramLayouter getDiagramLayouter() {
- return new DefaultDiagramLayouter();
- }
-
- protected ZoomManager getZoomManager() {
- return getZoomManager(getGraphicalViewer());
- }
-
- private ZoomManager getZoomManager(GraphicalViewer viewer) {
- // get zoom manager from root edit part
- RootEditPart rootEditPart = viewer.getRootEditPart();
- ZoomManager zoomManager = null;
- if (rootEditPart instanceof ScalableFreeformRootEditPart) {
- zoomManager = ((ScalableFreeformRootEditPart) rootEditPart).getZoomManager();
- } else if (rootEditPart instanceof ScalableRootEditPart) {
- zoomManager = ((ScalableRootEditPart) rootEditPart).getZoomManager();
- }
- return zoomManager;
- }
-
- protected PaletteRoot getPaletteRoot() {
- if (paletteRoot == null) {
- paletteRoot = new PaletteRoot();
- configurePalette(paletteRoot);
- }
- return paletteRoot;
- }
-
- protected abstract void configurePalette(PaletteRoot paletteRoot);
-
- protected CommandStackListener getStackActionsListener() {
- return commandStackListener;
- }
-
- protected IContentOutlinePage getOutlinePage() {
- return new DiagramContentOutlinePage();
+ return domain;
}
- /**
- * Returns the initial display mode for the outline page to be shown. Possible values are <code>ID_OUTLINE</code> and <code>ID_OVERVIEW</code>.
- * By default, the outline page starts in the overview mode. Subclasses may reimplement.
- */
- protected int getDefaultOutlineViewMode() {
- return ID_OVERVIEW;
- }
+ public abstract void initializeGraphicalViewer();
+ public abstract AdapterFactory getDomainAdapterFactory();
- protected PropertySheetPage getPropertySheetPage() {
- if (undoablePropertySheetPage == null) {
- undoablePropertySheetPage = new PropertySheetPage();
- UndoablePropertySheetEntry rootEntry = new UndoablePropertySheetEntry(getCommandStack());
- rootEntry.setPropertySourceProvider(new PropertySourceProvider(getDomainAdapterFactory()));
- undoablePropertySheetPage.setRootEntry(rootEntry);
- }
+ public abstract boolean isFlyoutPalette();
- return undoablePropertySheetPage;
- }
-
- private ISelectionListener getSelectionListener() {
- return selectionListener;
- }
-
- public boolean isDirty() {
- return isDirty;
- }
-
- private void setDirty(boolean dirty) {
- if (isDirty != dirty) {
- isDirty = dirty;
- firePropertyChange(IEditorPart.PROP_DIRTY);
- }
- }
-
- protected TransactionalEditingDomain getEditingDomain() {
- if (editingDomain == null) {
- editingDomain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
- //editingDomain.setAdapterFactory(getDomainAdapterFactory());
- editingDomain.getResourceSet().eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(editingDomain));
- editingDomain.getResourceSet().eAdapters().add(new ForceTrackingModificationAdapter());
- }
- return editingDomain;
- }
-
- protected abstract AdapterFactory getDomainAdapterFactory();
-
- public void setFocus() {
- getGraphicalViewer().getControl().setFocus();
- }
-
- public final void createPartControl(Composite parent) {
- super.createPartControl(parent);
- // initialize actions
- createActions();
- }
+ protected abstract void createActions();
private static class ForceTrackingModificationAdapter extends AdapterImpl {
@Override
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditorInput.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditorInput.java
new file mode 100644
index 000000000..db096a91c
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramEditorInput.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.parts;
+
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * A simple implementation of an {@link org.eclipse.ui.IEditorInput} that may be used to open a diagram with the editing domain
+ * specified by the diagram instance.
+ */
+public class DiagramEditorInput extends PlatformObject implements IEditorInput {
+ private final Diagram myDiagram;
+
+ public DiagramEditorInput(Diagram diagram) {
+ assert diagram != null;
+ myDiagram = diagram;
+ }
+
+ public Diagram getDiagram() {
+ return myDiagram;
+ }
+
+ public boolean exists() {
+ return myDiagram.eResource() != null;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return myDiagram.getName();
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ return getName();
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (adapter == URI.class) {
+ return EcoreUtil.getURI(myDiagram);
+ }
+ return super.getAdapter(adapter);
+ }
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramViewPart.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramViewPart.java
new file mode 100644
index 000000000..b2cd45f14
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/DiagramViewPart.java
@@ -0,0 +1,332 @@
+/**
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.parts;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
+import org.eclipse.gef.EditDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.actions.SelectionAction;
+import org.eclipse.gef.ui.actions.StackAction;
+import org.eclipse.gef.ui.actions.WorkbenchPartAction;
+import org.eclipse.gef.ui.views.palette.PalettePage;
+import org.eclipse.gmf.internal.runtime.lite.Activator;
+import org.eclipse.gmf.runtime.lite.services.DefaultDiagramLayouter;
+import org.eclipse.gmf.runtime.lite.services.IDiagramLayouter;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+
+/**
+ * This class serves as the base class for the generated diagram view parts.
+ * @author bblajer
+ */
+public abstract class DiagramViewPart extends ViewPart implements IDiagramManager {
+ private DiagramDisplayer myDiagramDisplayer;
+ private PageBook myBook;
+ private Control myUninitializedControl;
+
+ @Override
+ public void init(IViewSite site) throws PartInitException {
+ super.init(site);
+ }
+
+ @Override
+ public void dispose() {
+ if (myDiagramDisplayer != null) {
+ myDiagramDisplayer.dispose();
+ }
+ myDiagramDisplayer = null;
+ super.dispose();
+ }
+
+ @Override
+ public void createPartControl(Composite parent) {
+ myBook = new PageBook(parent, SWT.NONE);
+ myUninitializedControl = createUninitializedControl(myBook);
+ myBook.showPage(myUninitializedControl);
+ }
+
+ @Override
+ public void setFocus() {
+ if (myDiagramDisplayer != null) {
+ myDiagramDisplayer.setFocus();
+ return;
+ }
+ myBook.setFocus();
+ }
+
+ /**
+ * Returns the editing domain to be used for the new diagram if no editing domain was specified in {@link #showDiagram(TransactionalEditingDomain, URI)}.
+ * Subclasses may reimplement or extend.
+ */
+ protected TransactionalEditingDomain createEditingDomain() {
+ TransactionalEditingDomain editingDomain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
+ editingDomain.getResourceSet().eAdapters().add(new AdapterFactoryEditingDomain.EditingDomainProvider(editingDomain));
+ return editingDomain;
+ }
+
+ /**
+ * Shows the given diagram in the viewer.
+ * @param editingDomain the editing domain that should be used for loading the diagram or <code>null</code> if the viewer should create {@link #createEditingDomain() a default instance}.
+ * @param diagramURI the URI to load the diagram from.
+ */
+ public final void showDiagram(TransactionalEditingDomain editingDomain, URI diagramURI) {
+ DiagramDisplayer oldDiagramDisplayer = myDiagramDisplayer;
+ if (diagramURI == null) {
+ if (oldDiagramDisplayer == null) {
+ return;
+ }
+ myBook.showPage(myUninitializedControl);
+ } else {
+ if (editingDomain == null) {
+ editingDomain = createEditingDomain();
+ }
+ myDiagramDisplayer = new DiagramDisplayer(this, createEditDomain(), editingDomain);
+ myDiagramDisplayer.createViewer(myBook);
+ try {
+ setInput(diagramURI);
+ myBook.showPage(myDiagramDisplayer.getTopLevelControl());
+ } catch (CoreException e) {
+ Activator.getDefault().getLog().log(e.getStatus());
+ ErrorDialog.openError(getSite().getShell(), "Error", "Failed to open diagram", e.getStatus());
+ if (myDiagramDisplayer.getTopLevelControl() != null && !myDiagramDisplayer.getTopLevelControl().isDisposed()) {
+ myDiagramDisplayer.getTopLevelControl().dispose();
+ myDiagramDisplayer.dispose();
+ //prevent navigation from the old diagram.
+ oldDiagramDisplayer = null;
+ }
+ }
+ }
+ if (oldDiagramDisplayer != null) {
+ oldDiagramDisplayer.getTopLevelControl().dispose();
+ oldDiagramDisplayer.dispose();
+ }
+ }
+
+ public void configureGraphicalViewer() {
+ getGraphicalViewer().getControl().setBackground(ColorConstants.listBackground);
+ }
+
+ public abstract void configurePalette(PaletteRoot paletteRoot);
+
+ /**
+ * Sets the input for the diagram. Implementors should load the contents from the given URI and initialize the diagram.
+ * @throws CoreException if the diagram with the specified URI cannot be loaded for any reason.
+ */
+ protected abstract void setInput(URI diagramURI) throws CoreException;
+
+ /**
+ * Creates edit domain that will be used for this viewer. This method is called once for each diagram being displayed in the editor.
+ * Subclasses may extend.
+ */
+ protected EditDomain createEditDomain() {
+ EditDomain domain = new EditDomain();
+ domain.setCommandStack(new CommandStack() {
+ @Override
+ public void execute(Command command) {
+ super.execute(command);
+ save();
+ }
+ @Override
+ public void undo() {
+ super.undo();
+ save();
+ }
+ @Override
+ public void redo() {
+ super.redo();
+ save();
+ }
+ private void save() {
+ try {
+ myDiagramDisplayer.save(null);
+ } catch (CoreException e) {
+ Activator.getDefault().getLog().log(e.getStatus());
+ }
+ }
+ });
+ return domain;
+ }
+
+ protected final TransactionalEditingDomain getEditingDomain() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return myDiagramDisplayer.getEditingDomain();
+ }
+
+ protected final EditDomain getEditDomain() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return myDiagramDisplayer.getEditDomain();
+ }
+
+ protected final CommandStack getCommandStack() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return getEditDomain().getCommandStack();
+ }
+
+ protected final ZoomManager getZoomManager() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return myDiagramDisplayer.getZoomManager();
+ }
+
+ protected final ActionRegistry getActionRegistry() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return myDiagramDisplayer.getActionRegistry();
+ }
+
+ protected final GraphicalViewer getGraphicalViewer() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return myDiagramDisplayer.getGraphicalViewer();
+ }
+
+ protected IPropertySheetPage getPropertySheetPage() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return myDiagramDisplayer.getPropertySheetPage();
+ }
+
+ protected IDiagramLayouter getDiagramLayouter() {
+ if (myDiagramDisplayer == null) {
+ return null;
+ }
+ return new DefaultDiagramLayouter();
+ }
+
+ @Override
+ public Object getAdapter(Class type) {
+ if (type == IPropertySheetPage.class) {
+ return getPropertySheetPage();
+ } else if (type == IContentOutlinePage.class) {
+// return getOutlinePage();
+ return null;
+ } else if (type == ZoomManager.class) {
+ return getZoomManager();
+ } else if (type == IDiagramLayouter.class) {
+ return getDiagramLayouter();
+ } else if (type == PalettePage.class) {
+ return myDiagramDisplayer.getPalettePage();
+ } else if (type == GraphicalViewer.class) {
+ return getGraphicalViewer();
+ } else if (type == CommandStack.class) {
+ return getCommandStack();
+ } else if (type == ActionRegistry.class) {
+ return getActionRegistry();
+ } else if (type == EditPart.class && getGraphicalViewer() != null) {
+ return getGraphicalViewer().getRootEditPart();
+ } else if (type == IFigure.class && getGraphicalViewer() != null) {
+ return ((GraphicalEditPart)getGraphicalViewer().getRootEditPart()).getFigure();
+ }
+ return super.getAdapter(type);
+ }
+
+ /**
+ * Adds an action to this editor's <code>ActionRegistry</code>.
+ *
+ * @param action
+ * the action to add.
+ */
+ protected void addAction(IAction action) {
+ myDiagramDisplayer.addAction(action);
+ }
+
+ /**
+ * Adds an editor action to this editor.
+ *
+ * <p>
+ * Editor actions are actions that depend and work on the editor.
+ *
+ * @param action
+ * the editor action
+ */
+ protected void addEditorAction(WorkbenchPartAction action) {
+ myDiagramDisplayer.addEditorAction(action);
+ }
+
+ /**
+ * Adds an <code>EditPart</code> action to this editor.
+ *
+ * <p>
+ * <code>EditPart</code> actions are actions that depend and work on the
+ * selected <code>EditPart</code>s.
+ *
+ * @param action
+ * the <code>EditPart</code> action
+ */
+ protected void addEditPartAction(SelectionAction action) {
+ myDiagramDisplayer.addEditPartAction(action);
+ }
+
+ /**
+ * Adds an <code>CommandStack</code> action to this editor.
+ *
+ * <p>
+ * <code>CommandStack</code> actions are actions that depend and work on
+ * the <code>CommandStack</code>.
+ *
+ * @param action
+ * the <code>CommandStack</code> action
+ */
+ protected void addStackAction(StackAction action) {
+ myDiagramDisplayer.addStackAction(action);
+ }
+
+ /**
+ * Returns the control this viewer displays when no input has been set.
+ * Subclasses may reimplement.
+ */
+ protected Control createUninitializedControl(Composite parent) {
+ Label result = new Label(parent, SWT.NONE);
+ result.setText("There is no diagram to display or the diagram failed to load");
+ return result;
+ }
+
+ public abstract AdapterFactory getDomainAdapterFactory();
+
+ public abstract void initializeGraphicalViewer();
+
+ public abstract boolean isFlyoutPalette();
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramManager.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramManager.java
new file mode 100644
index 000000000..065a0dc08
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramManager.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.parts;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.ui.IWorkbenchPartSite;
+
+/**
+ * @author bblajer
+ */
+interface IDiagramManager {
+ public IWorkbenchPartSite getSite();
+ public void configurePalette(PaletteRoot paletteRoot);
+ public AdapterFactory getDomainAdapterFactory();
+ public boolean isFlyoutPalette();
+ public void configureGraphicalViewer();
+ public void initializeGraphicalViewer();
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramOutlineHost.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramOutlineHost.java
new file mode 100644
index 000000000..8a96d1288
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/IDiagramOutlineHost.java
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.parts;
+
+import org.eclipse.gef.EditDomain;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.ui.actions.ActionRegistry;
+import org.eclipse.gef.ui.parts.SelectionSynchronizer;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * Host for the diagram outline. This interface is not intended to be implemented by clients.
+ */
+public interface IDiagramOutlineHost {
+ public ActionRegistry getActionRegistry();
+
+ public EditDomain getEditDomain();
+
+ public EditPartViewer getGraphicalViewer();
+
+ public SelectionSynchronizer getSelectionSynchronizer();
+
+ public Control getGraphicalControl();
+}
diff --git a/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/UpdatableActionGroup.java b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/UpdatableActionGroup.java
new file mode 100644
index 000000000..4d22e826c
--- /dev/null
+++ b/plugins/org.eclipse.gmf.runtime.lite/src/org/eclipse/gmf/runtime/lite/parts/UpdatableActionGroup.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2006 Borland Software Corporation
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * bblajer - initial API and implementation
+ */
+package org.eclipse.gmf.runtime.lite.parts;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.gef.ui.actions.UpdateAction;
+
+class UpdatableActionGroup {
+ public void addAction(UpdateAction action) {
+ assert action != null;
+ myActions.add(action);
+ }
+
+ public void removeAction(UpdateAction action) {
+ myActions.remove(action);
+ }
+
+ public void update() {
+ for (Iterator<UpdateAction> it = myActions.iterator(); it.hasNext();) {
+ UpdateAction next = it.next();
+ next.update();
+ }
+ }
+
+ private ArrayList<UpdateAction> myActions = new ArrayList<UpdateAction>();
+} \ No newline at end of file

Back to the top