diff --git a/de.bmotionstudio.gef.editor/plugin.xml b/de.bmotionstudio.gef.editor/plugin.xml index fcf68ecbf61c2d30b9dcdfc7e75b308106cc13bb..d44d7914a1c714edf19f32656e68d01aecb97ec6 100644 --- a/de.bmotionstudio.gef.editor/plugin.xml +++ b/de.bmotionstudio.gef.editor/plugin.xml @@ -157,6 +157,21 @@ id="de.bmotionstudio.command.startVisualizationFromFile" name="Start Visualization from File"> </command> + <command + description="SnapToGeometry" + id="org.eclipse.gef.toggle_snapto_geometry" + name="SnapToGeometry"> + </command> + <command + description="ToggleGridVisibility" + id="org.eclipse.gef.toggle_grid_visibility" + name="ToggleGridVisibility"> + </command> + <command + description="ToggleRulerVisibility" + id="org.eclipse.gef.toggle_ruler_visibility" + name="ToggleRulerVisibility"> + </command> </extension> <extension point="org.eclipse.ui.handlers"> diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioContributor.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioContributor.java index 1dd07823ec3f1f653a8fe069e524f5559fa4c4dc..7f9a821a914c6438744cdbbbad44fc4c8ede40b3 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioContributor.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioContributor.java @@ -6,60 +6,58 @@ package de.bmotionstudio.gef.editor; -import org.eclipse.gef.ui.actions.ActionBarContributor; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.ui.part.EditorActionBarContributor; -public class BMotionStudioContributor extends ActionBarContributor { +public class BMotionStudioContributor extends EditorActionBarContributor { - @Override - protected void buildActions() { - // IWorkbenchWindow iww = getPage().getWorkbenchWindow(); - // - // addRetargetAction(new UndoRetargetAction()); - // addRetargetAction(new RedoRetargetAction()); - // - // addRetargetAction(new DeleteRetargetAction()); - // - // addRetargetAction((RetargetAction) ActionFactory.COPY.create(iww)); - // addRetargetAction((RetargetAction) ActionFactory.PASTE.create(iww)); - // - // addRetargetAction(new ZoomInRetargetAction()); - // addRetargetAction(new ZoomOutRetargetAction()); - // - // addRetargetAction(new RetargetAction( - // GEFActionConstants.TOGGLE_RULER_VISIBILITY, "Ruler", - // IAction.AS_CHECK_BOX)); - // - // addRetargetAction(new RetargetAction( - // GEFActionConstants.TOGGLE_GRID_VISIBILITY, "Grid", - // IAction.AS_CHECK_BOX)); - // - // addRetargetAction(new RetargetAction( - // GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY, "Snap to Geometry", - // IAction.AS_CHECK_BOX)); - } + // @Override + // protected void buildActions() { + // // IWorkbenchWindow iww = getPage().getWorkbenchWindow(); + // + // addRetargetAction(new UndoRetargetAction()); + // addRetargetAction(new RedoRetargetAction()); + // // + // // addRetargetAction(new DeleteRetargetAction()); + // // + // // addRetargetAction((RetargetAction) ActionFactory.COPY.create(iww)); + // // addRetargetAction((RetargetAction) ActionFactory.PASTE.create(iww)); + // // + // // addRetargetAction(new ZoomInRetargetAction()); + // // addRetargetAction(new ZoomOutRetargetAction()); + // // + // // addRetargetAction(new RetargetAction( + // // GEFActionConstants.TOGGLE_RULER_VISIBILITY, "Ruler", + // // IAction.AS_CHECK_BOX)); + // // + // // addRetargetAction(new RetargetAction( + // // GEFActionConstants.TOGGLE_GRID_VISIBILITY, "Grid", + // // IAction.AS_CHECK_BOX)); + // // + // // addRetargetAction(new RetargetAction( + // // GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY, "Snap to Geometry", + // // IAction.AS_CHECK_BOX)); + // } @Override public void contributeToToolBar(IToolBarManager toolBarManager) { -// toolBarManager.add(getAction(ActionFactory.DELETE.getId())); -// toolBarManager.add(getAction(ActionFactory.COPY.getId())); -// toolBarManager.add(getAction(ActionFactory.PASTE.getId())); -// toolBarManager.add(new Separator()); -// toolBarManager.add(getAction(GEFActionConstants.ZOOM_IN)); -// toolBarManager.add(getAction(GEFActionConstants.ZOOM_OUT)); -// toolBarManager.add(new ZoomComboContributionItem(getPage())); - } - - @Override - protected void declareGlobalActionKeys() { + // toolBarManager.add(getAction(ActionFactory.DELETE.getId())); + // toolBarManager.add(getActionRegistry().getAction( + // ActionFactory.COPY.getId())); + // toolBarManager.add(getActionRegistry().getAction( + // ActionFactory.PASTE.getId())); + // toolBarManager.add(new Separator()); + // toolBarManager.add(getAction(GEFActionConstants.ZOOM_IN)); + // toolBarManager.add(getAction(GEFActionConstants.ZOOM_OUT)); + // toolBarManager.add(new ZoomComboContributionItem(getPage())); } @Override public void contributeToMenu(IMenuManager menuManager) { - super.contributeToMenu(menuManager); - + // super.contributeToMenu(menuManager); + // // IContributionItem bMenu = menuManager // .find("de.bmotionstudio.gef.editor.menu"); // if (bMenu != null) { @@ -76,11 +74,12 @@ public class BMotionStudioContributor extends ActionBarContributor { // .insertAfter( // "de.bmotionstudio.gef.editor.command.openBMotionStudioWebsite", // viewMenu); - + // // } } + // @Override // public void setActiveEditor(IEditorPart editor) { // if (editor instanceof BMotionStudioEditor) { // super.setActiveEditor(((BMotionStudioEditor) editor).getEditPage()); diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java index ee9c49c0bc16acc589f5283d1fb9c9709048a3c4..04eaa635bb02e46bec611da71fd2260bb85bd09f 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/BMotionStudioEditor.java @@ -15,7 +15,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; -import java.util.EventObject; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -30,9 +29,6 @@ import org.eclipse.core.runtime.preferences.IPreferenceFilter; import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.runtime.preferences.PreferenceFilterEntry; -import org.eclipse.gef.EditDomain; -import org.eclipse.gef.commands.CommandStack; -import org.eclipse.gef.commands.CommandStackListener; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -64,12 +60,11 @@ import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.model.VisualizationView; import de.prob.logging.Logger; -public class BMotionStudioEditor extends EditorPart implements IPartListener2 { +public class BMotionStudioEditor extends EditorPart implements + IPartListener2 { private Simulation simulation; - private EditDomain editDomain; - private Composite container; private IFile file; @@ -115,7 +110,6 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { // Yes --> just switch to this perspective if (perspective != null) { - System.out.println("Swtich perspective"); switchPerspective(perspective.getId()); } else { // No --> create a new one @@ -242,7 +236,7 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { @Override public void dispose() { - getCommandStack().removeCommandStackListener(getCommandStackListener()); + // getCommandStack().removeCommandStackListener(getCommandStackListener()); IWorkbenchPage activePage = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); if (activePage != null) @@ -284,8 +278,6 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { BMotionEditorPlugin.setAliases(xstream); Object obj = xstream.fromXML(inputStream); - editDomain = new EditDomain(); - importPerspective(file.getProject().getFile( getPerspectiveFileName())); openPerspective(site.getPage()); @@ -301,8 +293,7 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { "New Visualization View", visualization); String secId = UUID.randomUUID().toString(); - createVisualizationViewPart(secId, editDomain, - visualizationView); + createVisualizationViewPart(secId, visualizationView); simulation.getVisualizationViews() .put(secId, visualizationView); @@ -328,7 +319,7 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { if (viewReference != null) { } else { // If not, create a new one - createVisualizationViewPart(secId, editDomain, visView); + createVisualizationViewPart(secId, visView); } } @@ -360,12 +351,12 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { setSite(site); setInput(input); - getCommandStack().addCommandStackListener(getCommandStackListener()); + // getCommandStack().addCommandStackListener(getCommandStackListener()); } private VisualizationViewPart createVisualizationViewPart(String secId, - EditDomain editDomain, VisualizationView visualizationView) + VisualizationView visualizationView) throws PartInitException { IWorkbenchWindow window = PlatformUI.getWorkbench() .getActiveWorkbenchWindow(); @@ -417,7 +408,7 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { IFile file = ((IFileEditorInput) getEditorInput()).getFile(); file.setContents(new ByteArrayInputStream(out.toByteArray()), true, false, monitor); - getCommandStack().markSaveLocation(); + // getCommandStack().markSaveLocation(); } catch (CoreException ce) { ce.printStackTrace(); } catch (IOException ioe) { @@ -476,8 +467,7 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { simulation.getVisualizationViews().put(secId, visualizationView); - createVisualizationViewPart(secId, editDomain, - visualizationView); + createVisualizationViewPart(secId, visualizationView); setDirty(true); @@ -506,23 +496,24 @@ public class BMotionStudioEditor extends EditorPart implements IPartListener2 { this.simulation = simulation; } - private CommandStackListener commandStackListener = new CommandStackListener() { - public void commandStackChanged(EventObject event) { - setDirty(getCommandStack().isDirty()); - } - }; + // private CommandStackListener commandStackListener = new + // CommandStackListener() { + // public void commandStackChanged(EventObject event) { + // setDirty(getCommandStack().isDirty()); + // } + // }; - protected CommandStackListener getCommandStackListener() { - return commandStackListener; - } + // protected CommandStackListener getCommandStackListener() { + // return commandStackListener; + // } - public CommandStack getCommandStack() { - return getEditDomain().getCommandStack(); - } + // public CommandStack getCommandStack() { + // return getEditDomain().getCommandStack(); + // } - protected EditDomain getEditDomain() { - return editDomain; - } + // protected EditDomain getEditDomain() { + // return editDomain; + // } @Override public void partActivated(IWorkbenchPartReference partRef) { diff --git a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java index 879e9b45851041f3dd22bbabc131930c8438ba37..573434a867efacd60a3542594aee7d2098694550 100644 --- a/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java +++ b/de.bmotionstudio.gef.editor/src/de/bmotionstudio/gef/editor/VisualizationViewPart.java @@ -1,25 +1,50 @@ package de.bmotionstudio.gef.editor; +import java.util.ArrayList; +import java.util.EventObject; +import java.util.Iterator; +import java.util.List; + import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.PositionConstants; import org.eclipse.gef.EditDomain; import org.eclipse.gef.GraphicalViewer; +import org.eclipse.gef.MouseWheelHandler; +import org.eclipse.gef.MouseWheelZoomHandler; import org.eclipse.gef.SnapToGeometry; import org.eclipse.gef.SnapToGrid; import org.eclipse.gef.commands.CommandStack; +import org.eclipse.gef.commands.CommandStackListener; import org.eclipse.gef.editparts.ScalableRootEditPart; +import org.eclipse.gef.editparts.ZoomManager; import org.eclipse.gef.rulers.RulerProvider; import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.gef.ui.actions.GEFActionConstants; +import org.eclipse.gef.ui.actions.RedoAction; +import org.eclipse.gef.ui.actions.SelectAllAction; +import org.eclipse.gef.ui.actions.ToggleGridAction; +import org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction; +import org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction; +import org.eclipse.gef.ui.actions.UndoAction; +import org.eclipse.gef.ui.actions.UpdateAction; +import org.eclipse.gef.ui.actions.ZoomInAction; +import org.eclipse.gef.ui.actions.ZoomOutAction; import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; import org.eclipse.gef.ui.parts.SelectionSynchronizer; import org.eclipse.gef.ui.rulers.RulerComposite; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IActionBars; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.part.IPage; +import org.eclipse.ui.part.IPageSite; import org.eclipse.ui.part.MessagePage; import org.eclipse.ui.part.Page; import org.eclipse.ui.part.PageBook; @@ -27,6 +52,8 @@ import org.eclipse.ui.part.PageBookView; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import org.eclipse.ui.views.properties.IPropertySheetPage; +import de.bmotionstudio.gef.editor.action.CopyAction; +import de.bmotionstudio.gef.editor.action.PasteAction; import de.bmotionstudio.gef.editor.internal.BControlTransferDropTargetListener; import de.bmotionstudio.gef.editor.model.BMotionRuler; import de.bmotionstudio.gef.editor.model.BMotionRulerProvider; @@ -35,7 +62,8 @@ import de.bmotionstudio.gef.editor.model.Visualization; import de.bmotionstudio.gef.editor.model.VisualizationView; import de.bmotionstudio.gef.editor.part.BMSEditPartFactory; -public class VisualizationViewPart extends PageBookView { +public class VisualizationViewPart extends PageBookView implements + CommandStackListener { public static String ID = "de.bmotionstudio.gef.editor.VisualizationView"; @@ -49,21 +77,33 @@ public class VisualizationViewPart extends PageBookView { private Composite container; + private BMotionStudioEditor editor; + private BMotionSelectionSynchronizer selectionSynchronizer; + private List<String> selectionActions = new ArrayList<String>(); + private List<String> stackActions = new ArrayList<String>(); + private List<String> propertyActions = new ArrayList<String>(); + @Override public Object getAdapter(@SuppressWarnings("rawtypes") Class type) { // // Adapter for zoom manager - // if (type == ZoomManager.class) - // return ((ScalableRootEditPart) getGraphicalViewer() - // .getRootEditPart()).getZoomManager(); + if (type == ZoomManager.class) + return ((ScalableRootEditPart) getGraphicalViewer() + .getRootEditPart()).getZoomManager(); // Adapter for content outline page if (type == IContentOutlinePage.class) { return new BMotionOutlinePage(this); } + if (type == ActionRegistry.class) + return getActionRegistry(); + + if (type == CommandStack.class) + return getCommandStack(); + // Adapter for property page if (type == IPropertySheetPage.class) { BMotionPropertyPage page = new BMotionPropertyPage( @@ -92,12 +132,6 @@ public class VisualizationViewPart extends PageBookView { super.setFocus(); } - protected ActionRegistry getActionRegistry() { - if (actionRegistry == null) - actionRegistry = new ActionRegistry(); - return actionRegistry; - } - public Visualization getVisualization() { return this.visualizationView.getVisualization(); } @@ -125,20 +159,46 @@ public class VisualizationViewPart extends PageBookView { @Override protected PageRec doCreatePage(IWorkbenchPart part) { + if (part instanceof BMotionStudioEditor) { - BMotionStudioEditor editor = (BMotionStudioEditor) part; + + editor = (BMotionStudioEditor) part; Simulation simulation = editor.getSimulation(); - this.editDomain = editor.getEditDomain(); + + if (simulation == null) + return null; + + this.editDomain = new EditDomain(); + getCommandStack().addCommandStackListener(this); + this.visualizationView = simulation.getVisualizationViews().get( getViewSite().getSecondaryId()); - if (this.editDomain == null || this.visualizationView == null) + if (visualizationView == null) return null; + + createActions(); + page = new VisualizationViewPage(); initPage(page); page.createControl(getPageBook()); + return new PageRec(part, page); + } + return null; + + } + + /** + * Lazily creates and returns the action registry. + * + * @return the action registry + */ + protected ActionRegistry getActionRegistry() { + if (actionRegistry == null) + actionRegistry = new ActionRegistry(); + return actionRegistry; } @Override @@ -167,11 +227,9 @@ public class VisualizationViewPart extends PageBookView { } protected CommandStack getCommandStack() { - return getEditDomain().getCommandStack(); - } - - public void setEditDomain(EditDomain editDomain) { - this.editDomain = editDomain; + if (getEditDomain() != null) + return getEditDomain().getCommandStack(); + return null; } public VisualizationView getVisualizationView() { @@ -182,14 +240,158 @@ public class VisualizationViewPart extends PageBookView { this.visualizationView = visualizationView; } + private void createActions() { + + ActionRegistry registry = getActionRegistry(); + IAction action; + + action = new UndoAction(this); + registry.registerAction(action); + getStackActions().add(action.getId()); + + action = new RedoAction(this); + registry.registerAction(action); + getStackActions().add(action.getId()); + + action = new CopyAction(this); + registry.registerAction(action); + getSelectionActions().add(action.getId()); + + action = new PasteAction(this); + registry.registerAction(action); + getSelectionActions().add(action.getId()); + + action = new SelectAllAction(this); + registry.registerAction(action); + + } + private class VisualizationViewPage extends Page { private RulerComposite container; private GraphicalViewer graphicalViewer; - public GraphicalViewer getGraphicalViewer() { - return graphicalViewer; + private ScalableRootEditPart rootEditPart; + + @Override + public void init(IPageSite site) { + super.init(site); + } + + private void createActions() { + + ZoomManager manager = rootEditPart.getZoomManager(); + getActionRegistry().registerAction(new ZoomInAction(manager)); + getActionRegistry().registerAction(new ZoomOutAction(manager)); + + double[] zoomLevels = new double[] { 0.25, 0.5, 0.75, 1.0, 1.5, + 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 }; + manager.setZoomLevels(zoomLevels); + ArrayList<String> zoomContributions = new ArrayList<String>(); + zoomContributions.add(ZoomManager.FIT_ALL); + zoomContributions.add(ZoomManager.FIT_HEIGHT); + zoomContributions.add(ZoomManager.FIT_WIDTH); + manager.setZoomLevelContributions(zoomContributions); + + getActionRegistry().registerAction( + new ToggleRulerVisibilityAction(getGraphicalViewer()) { + @Override + public void run() { + super.run(); + setChecked(!isChecked()); + editor.setDirty(true); + } + }); + getActionRegistry().registerAction( + new ToggleSnapToGeometryAction(getGraphicalViewer()) { + @Override + public void run() { + super.run(); + setChecked(!isChecked()); + editor.setDirty(true); + } + }); + getActionRegistry().registerAction( + new ToggleGridAction(getGraphicalViewer()) { + @Override + public void run() { + super.run(); + setChecked(!isChecked()); + editor.setDirty(true); + } + }); + + } + + private void buildActions() { + + IActionBars bars = getSite().getActionBars(); + ActionRegistry ar = getActionRegistry(); + + bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), + ar.getAction(ActionFactory.UNDO.getId())); + bars.setGlobalActionHandler(ActionFactory.REDO.getId(), + ar.getAction(ActionFactory.REDO.getId())); + + bars.setGlobalActionHandler(ActionFactory.COPY.getId(), + ar.getAction(ActionFactory.COPY.getId())); + bars.setGlobalActionHandler(ActionFactory.PASTE.getId(), + ar.getAction(ActionFactory.PASTE.getId())); + + bars.updateActionBars(); + + } + + private void createMenu(final IPageSite pageSite) { + + pageSite.getActionBars() + .getToolBarManager() + .add(getActionRegistry().getAction( + ActionFactory.UNDO.getId())); + pageSite.getActionBars() + .getToolBarManager() + .add(getActionRegistry().getAction( + ActionFactory.REDO.getId())); + pageSite.getActionBars() + .getToolBarManager() + .add(getActionRegistry().getAction( + ActionFactory.COPY.getId())); + pageSite.getActionBars() + .getToolBarManager() + .add(getActionRegistry().getAction( + ActionFactory.PASTE.getId())); + + pageSite.getActionBars().getToolBarManager().add(new Separator()); + + pageSite.getActionBars() + .getToolBarManager() + .add(getActionRegistry().getAction( + GEFActionConstants.ZOOM_IN)); + pageSite.getActionBars() + .getToolBarManager() + .add(getActionRegistry().getAction( + GEFActionConstants.ZOOM_OUT)); + + pageSite.getActionBars() + .getMenuManager() + .add(getActionRegistry().getAction( + GEFActionConstants.TOGGLE_GRID_VISIBILITY)); + pageSite.getActionBars() + .getMenuManager() + .add(getActionRegistry().getAction( + GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY)); + pageSite.getActionBars() + .getMenuManager() + .add(getActionRegistry().getAction( + GEFActionConstants.TOGGLE_RULER_VISIBILITY)); + + pageSite.getActionBars().updateActionBars(); + + // TODO Reimplement me! + // pageSite.getActionBars().getToolBarManager() + // .add(new ZoomComboContributionItem(pageSite.getPage())); + } @Override @@ -200,6 +402,10 @@ public class VisualizationViewPart extends PageBookView { configureGraphicalViewer(); initGraphicalViewer(); hookGraphicalViewer(); + loadProperties(); + buildActions(); + createActions(); + createMenu(getSite()); setPartName(getVisualizationView().getName()); } @@ -209,7 +415,8 @@ public class VisualizationViewPart extends PageBookView { } public void configureGraphicalViewer() { - ScalableRootEditPart rootEditPart = new ScalableRootEditPart(); + + rootEditPart = new ScalableRootEditPart(); rootEditPart.setViewer(graphicalViewer); graphicalViewer.setRootEditPart(rootEditPart); graphicalViewer.setEditPartFactory(new BMSEditPartFactory()); @@ -221,12 +428,22 @@ public class VisualizationViewPart extends PageBookView { .addDropTargetListener(new BControlTransferDropTargetListener( graphicalViewer, getVisualization())); graphicalViewer.getControl().setBackground(ColorConstants.white); - loadProperties(); + + graphicalViewer + .addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + updateActions(selectionActions); + } + }); + } + + public GraphicalViewer getGraphicalViewer() { + return graphicalViewer; } public void initGraphicalViewer() { graphicalViewer.setContents(getVisualization()); - loadProperties(); } @Override @@ -267,8 +484,59 @@ public class VisualizationViewPart extends PageBookView { getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, getVisualization().isGridEnabled()); + getGraphicalViewer().setProperty( + MouseWheelHandler.KeyGenerator.getKey(SWT.NONE), + MouseWheelZoomHandler.SINGLETON); + } } + @Override + public void dispose() { + if (getCommandStack() != null) + getCommandStack().removeCommandStackListener(this); + if (getActionRegistry() != null) + getActionRegistry().dispose(); + super.dispose(); + } + + @Override + public void commandStackChanged(EventObject event) { + updateActions(stackActions); + editor.setDirty(getCommandStack().isDirty()); + } + + /** + * A convenience method for updating a set of actions defined by the given + * List of action IDs. The actions are found by looking up the ID in the + * {@link #getActionRegistry() action registry}. If the corresponding action + * is an {@link UpdateAction}, it will have its <code>update()</code> method + * called. + * + * @param actionIds + * the list of IDs to update + */ + protected void updateActions(List<String> actionIds) { + ActionRegistry registry = getActionRegistry(); + Iterator<String> iter = actionIds.iterator(); + while (iter.hasNext()) { + IAction action = registry.getAction(iter.next()); + if (action instanceof UpdateAction) + ((UpdateAction) action).update(); + } + } + + protected List<String> getStackActions() { + return stackActions; + } + + protected List<String> getPropertyActions() { + return propertyActions; + } + + protected List<String> getSelectionActions() { + return selectionActions; + } + }