Search in sources :

Example 1 with ExportImageAction

use of org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction in project jbosstools-hibernate by jbosstools.

the class DiagramViewer method createActions.

@SuppressWarnings("unchecked")
protected void createActions() {
    // super.createActions();
    // BEGIN: redefine super.createActions
    ActionRegistry registry = getActionRegistry();
    IAction action;
    action = new RefreshAction(this);
    registry.registerAction(action);
    getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REFRESH.getId(), 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 SelectAllAction(this);
    registry.registerAction(action);
    action = new DeleteAction((IWorkbenchPart) this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new SaveAction(this);
    registry.registerAction(action);
    getPropertyActions().add(action.getId());
    registry.registerAction(new PrintDiagramViewerAction(this));
    // END: redefine super.createActions
    getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.PRINT.getId(), getActionRegistry().getAction(ActionFactory.PRINT.getId()));
    getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
    action = new OpenMappingAction(this);
    registry.registerAction(action);
    action = new OpenSourceAction(this);
    registry.registerAction(action);
    action = new ExportImageAction(this);
    registry.registerAction(action);
    action = new AutoLayoutAction(this);
    registry.registerAction(action);
    ToggleConnectionsAction actionToggleConnections = new ToggleConnectionsAction(this);
    registry.registerAction(actionToggleConnections);
    action = new ToggleAssociationAction(this);
    registry.registerAction(action);
    action = new ToggleClassMappingAction(this);
    registry.registerAction(action);
    action = new ToggleForeignKeyConstraintAction(this);
    registry.registerAction(action);
    action = new TogglePropertyMappingAction(this);
    registry.registerAction(action);
    action = new ConnectionRouterFanAction(this);
    registry.registerAction(action);
    getPropertyActions().add(action.getId());
    action = new ConnectionRouterManhattanAction(this);
    registry.registerAction(action);
    getPropertyActions().add(action.getId());
    ToggleShapeExpandStateAction actionToggleShapeExpandState = new ToggleShapeExpandStateAction(this);
    registry.registerAction(actionToggleShapeExpandState);
    getSelectionActions().add(actionToggleShapeExpandState.getId());
    action = new ShapeExpandAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new ShapeCollapseAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    ToggleShapeVisibleStateAction actionToggleShapeVisibleState = new ToggleShapeVisibleStateAction(this);
    registry.registerAction(actionToggleShapeVisibleState);
    getSelectionActions().add(actionToggleShapeVisibleState.getId());
    action = new ShapeHideAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    action = new ShapeShowAction(this);
    registry.registerAction(action);
    getSelectionActions().add(action.getId());
    // action = new CollapseAllAction(this);
    // registry.registerAction(action);
    // action = new ExpandAllAction(this);
    // registry.registerAction(action);
    action = new ZoomInAction(gefRootEditPart.getZoomManager());
    registry.registerAction(action);
    action = new ZoomOutAction(gefRootEditPart.getZoomManager());
    registry.registerAction(action);
    action = new LexicalSortingAction(this, null);
    registry.registerAction(action);
    Action[] act = new Action[4];
    act[0] = (Action) registry.getAction(TogglePropertyMappingAction.ACTION_ID);
    act[1] = (Action) registry.getAction(ToggleClassMappingAction.ACTION_ID);
    act[2] = (Action) registry.getAction(ToggleAssociationAction.ACTION_ID);
    act[3] = (Action) registry.getAction(ToggleForeignKeyConstraintAction.ACTION_ID);
    // act[4] = null;
    // act[5] = (Action)registry.getAction(ConnectionRouterManhattanAction.ACTION_ID);
    // act[6] = (Action)registry.getAction(ConnectionRouterFanAction.ACTION_ID);
    actionToggleConnections.setMenuCreator(new ActionMenu(act));
// act = new Action[2];
// act[0] = (Action)registry.getAction(ShapeExpandAction.ACTION_ID);
// act[1] = (Action)registry.getAction(ShapeCollapseAction.ACTION_ID);
// actionToggleShapeExpandState.setMenuCreator(new ActionMenu(act));
// act = new Action[2];
// act[0] = (Action)registry.getAction(ShapeShowAction.ACTION_ID);
// act[1] = (Action)registry.getAction(ShapeHideAction.ACTION_ID);
// actionToggleShapeVisibleState.setMenuCreator(new ActionMenu(act));
}
Also used : SaveAction(org.eclipse.gef.ui.actions.SaveAction) ToggleAssociationAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleAssociationAction) IAction(org.eclipse.jface.action.IAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) TogglePropertyMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.TogglePropertyMappingAction) ToggleRulerVisibilityAction(org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction) ToggleConnectionsAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleConnectionsAction) ToggleClassMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleClassMappingAction) RedoAction(org.eclipse.gef.ui.actions.RedoAction) RefreshAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.RefreshAction) ShapeCollapseAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeCollapseAction) ShapeShowAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeShowAction) OpenMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenMappingAction) UndoAction(org.eclipse.gef.ui.actions.UndoAction) PrintDiagramViewerAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.PrintDiagramViewerAction) ConnectionRouterFanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterFanAction) ExportImageAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction) ToggleShapeVisibleStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeVisibleStateAction) AutoLayoutAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.AutoLayoutAction) LexicalSortingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.LexicalSortingAction) ToggleGridAction(org.eclipse.gef.ui.actions.ToggleGridAction) OpenSourceAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenSourceAction) SelectAllAction(org.eclipse.gef.ui.actions.SelectAllAction) ToggleShapeExpandStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeExpandStateAction) SaveAction(org.eclipse.gef.ui.actions.SaveAction) Action(org.eclipse.jface.action.Action) DeleteAction(org.eclipse.gef.ui.actions.DeleteAction) ShapeExpandAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeExpandAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) ShapeHideAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeHideAction) ToggleForeignKeyConstraintAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleForeignKeyConstraintAction) ToggleSnapToGeometryAction(org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction) ConnectionRouterManhattanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterManhattanAction) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) ShapeExpandAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeExpandAction) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry) ToggleShapeExpandStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeExpandStateAction) ToggleShapeVisibleStateAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleShapeVisibleStateAction) PrintDiagramViewerAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.PrintDiagramViewerAction) OpenMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenMappingAction) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) RedoAction(org.eclipse.gef.ui.actions.RedoAction) AutoLayoutAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.AutoLayoutAction) ShapeHideAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeHideAction) ShapeShowAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeShowAction) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction) OpenSourceAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.OpenSourceAction) ToggleConnectionsAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleConnectionsAction) IAction(org.eclipse.jface.action.IAction) ToggleAssociationAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleAssociationAction) ExportImageAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction) ToggleForeignKeyConstraintAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleForeignKeyConstraintAction) LexicalSortingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.LexicalSortingAction) ConnectionRouterFanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterFanAction) RefreshAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.RefreshAction) TogglePropertyMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.TogglePropertyMappingAction) SelectAllAction(org.eclipse.gef.ui.actions.SelectAllAction) ConnectionRouterManhattanAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ConnectionRouterManhattanAction) DeleteAction(org.eclipse.gef.ui.actions.DeleteAction) ShapeCollapseAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ShapeCollapseAction) ActionMenu(org.jboss.tools.hibernate.ui.diagram.editors.actions.ActionMenu) ToggleClassMappingAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ToggleClassMappingAction) UndoAction(org.eclipse.gef.ui.actions.UndoAction)

Example 2 with ExportImageAction

use of org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction in project jbosstools-hibernate by jbosstools.

the class ExportImageActionTest method testAction.

public void testAction() {
    final DiagramViewer editor = context.mock(DiagramViewer.class);
    final SaveAsDialog saveDialog = context.mock(SaveAsDialog.class);
    final GraphicalViewer graphicalViewer = context.mock(GraphicalViewer.class);
    final ScalableFreeformRootEditPart scalableFreeformRootEditPart = context.mock(ScalableFreeformRootEditPart.class);
    final IFigure figure = context.mock(IFigure.class);
    final Control control = context.mock(Control.class);
    final Display display = context.mock(Display.class);
    final Rectangle rectangle = new Rectangle(0, 0, 20, 10);
    // $NON-NLS-1$
    final String filePath = PROJECT_NAME + File.separator + "test.jpg";
    final IPath resPath = new Path(filePath);
    context.checking(new Expectations() {

        {
            allowing(editor).getStoreFileName();
            will(returnValue(filePath));
            allowing(saveDialog).setOriginalName(filePath);
            oneOf(saveDialog).open();
            will(returnValue(0));
            oneOf(saveDialog).getResult();
            will(returnValue(resPath));
            allowing(editor).getEditPartViewer();
            will(returnValue(graphicalViewer));
            allowing(graphicalViewer).getRootEditPart();
            will(returnValue(scalableFreeformRootEditPart));
            allowing(scalableFreeformRootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
            will(returnValue(figure));
            allowing(figure).getBounds();
            will(returnValue(rectangle));
        }
    });
    final ExportImageAction exportImageAction = new ExportImageAction(editor);
    exportImageAction.setSaveDialog(saveDialog);
    exportImageAction.setShowErrDialog(false);
    exportImageAction.run();
    // test is the file created
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPath path = workspace.getRoot().getFullPath().append(resPath);
    path = workspace.getRoot().getLocation().append(path);
    File file = path.toFile();
    assertTrue(file.exists() && file.isFile());
    // 
    boolean res = file.delete();
    assertTrue(res);
    // GENERAL TEST:
    // check for all expectations
    context.assertIsSatisfied();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Expectations(org.jmock.Expectations) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ExportImageAction(org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction) DiagramViewer(org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer) Control(org.eclipse.swt.widgets.Control) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) IWorkspace(org.eclipse.core.resources.IWorkspace) File(java.io.File) IFigure(org.eclipse.draw2d.IFigure) Display(org.eclipse.swt.widgets.Display)

Aggregations

ExportImageAction (org.jboss.tools.hibernate.ui.diagram.editors.actions.ExportImageAction)2 File (java.io.File)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IFigure (org.eclipse.draw2d.IFigure)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)1 ActionRegistry (org.eclipse.gef.ui.actions.ActionRegistry)1 DeleteAction (org.eclipse.gef.ui.actions.DeleteAction)1 RedoAction (org.eclipse.gef.ui.actions.RedoAction)1 SaveAction (org.eclipse.gef.ui.actions.SaveAction)1 SelectAllAction (org.eclipse.gef.ui.actions.SelectAllAction)1 ToggleGridAction (org.eclipse.gef.ui.actions.ToggleGridAction)1 ToggleRulerVisibilityAction (org.eclipse.gef.ui.actions.ToggleRulerVisibilityAction)1 ToggleSnapToGeometryAction (org.eclipse.gef.ui.actions.ToggleSnapToGeometryAction)1 UndoAction (org.eclipse.gef.ui.actions.UndoAction)1 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)1 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)1