@Override
  protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();

    GraphicalViewer viewer = getGraphicalViewer();
    viewer.setEditPartFactory(new TadpoleEditPartFactory());

    // zoom menu
    zoomContribution(viewer);

    // layout action
    createDiagramAction(viewer);

    // context menu
    ContextMenuProvider provider = new TadpoleERDContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(provider);

    // key handler
    configureKeyHandler();

    // grid and geometry
    configureGeometry();
    configureGrid();
  }
  protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer viewer = getGraphicalViewer();
    viewer.setEditPartFactory(createEditPartFactory());

    ScalableRootEditPart rootEditPart = new ScalableRootEditPart();
    viewer.setRootEditPart(rootEditPart);

    // ZoomManagerの取得
    ZoomManager manager = rootEditPart.getZoomManager();

    // ズームレベルの設定
    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 ZoomInAction(manager));
    // 縮小アクションの作成と登録
    getActionRegistry().registerAction(new ZoomOutAction(manager));

    getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer()));

    // コンテクストメニューの作成
    String menuId = this.getClass().getName() + ".EditorContext";

    MenuManager menuMgr = new MenuManager(menuId, menuId);
    openPropertyAction = new OpenPropertyViewAction(viewer);
    openOutlineAction = new OpenOutlineViewAction(viewer);
    saveAsImageAction = new SaveAsImageAction(viewer);
    copyAsImageAction = new CopyAsImageAction(viewer);
    createDiagramAction(viewer);

    getSite().registerContextMenu(menuId, menuMgr, viewer);

    PrintAction printAction = new PrintAction(this);
    printAction.setImageDescriptor(UMLPlugin.getImageDescriptor("icons/print.gif"));
    getActionRegistry().registerAction(printAction);

    final DeleteAction deleteAction = new DeleteAction((IWorkbenchPart) this);
    deleteAction.setSelectionProvider(getGraphicalViewer());
    getActionRegistry().registerAction(deleteAction);
    viewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            deleteAction.update();
          }
        });

    // Actions
    //		IAction showRulers = new ToggleRulerVisibilityAction(getGraphicalViewer());
    //		getActionRegistry().registerAction(showRulers);
    //
    //		IAction snapAction = new ToggleSnapToGeometryAction(getGraphicalViewer());
    //		getActionRegistry().registerAction(snapAction);
    //
    //		IAction showGrid = new ToggleGridAction(getGraphicalViewer());
    //		getActionRegistry().registerAction(showGrid);

    menuMgr.add(new Separator("edit"));
    menuMgr.add(getActionRegistry().getAction(ActionFactory.DELETE.getId()));
    menuMgr.add(getActionRegistry().getAction(ActionFactory.UNDO.getId()));
    menuMgr.add(getActionRegistry().getAction(ActionFactory.REDO.getId()));
    //		menuMgr.add(getActionRegistry().getAction(ActionFactory.COPY.getId()));
    //		menuMgr.add(getActionRegistry().getAction(ActionFactory.PASTE.getId()));
    menuMgr.add(new Separator("zoom"));
    menuMgr.add(getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
    menuMgr.add(getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
    fillDiagramPopupMenu(menuMgr);
    menuMgr.add(new Separator("print"));
    menuMgr.add(saveAsImageAction);
    menuMgr.add(copyAsImageAction);
    menuMgr.add(printAction);
    menuMgr.add(new Separator("views"));
    menuMgr.add(openPropertyAction);
    menuMgr.add(openOutlineAction);
    menuMgr.add(new Separator("generate"));
    menuMgr.add(new Separator("additions"));
    viewer.setContextMenu(menuMgr);
    viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer).setParent(getCommonKeyHandler()));
  }
Exemple #3
0
  // Private constructor means you can't open an OPIShell without adding
  // it to the cache.
  private OPIShell(Display display, IPath path, MacrosInput macrosInput) throws Exception {
    this.path = path;
    this.macrosInput = macrosInput;
    icon =
        OPIBuilderPlugin.imageDescriptorFromPlugin(
                OPIBuilderPlugin.PLUGIN_ID, "icons/OPIRunner.png")
            .createImage(display);

    shell = new Shell(display);
    shell.setImage(icon);
    displayModel = new DisplayModel(path);
    displayModel.setOpiRuntime(this);
    actionRegistry = new ActionRegistry();

    viewer = new GraphicalViewerImpl();
    viewer.createControl(shell);
    viewer.setEditPartFactory(new WidgetEditPartFactory(ExecutionMode.RUN_MODE));
    viewer.setRootEditPart(
        new ScalableFreeformRootEditPart() {
          @Override
          public DragTracker getDragTracker(Request req) {
            return new DragEditPartsTracker(this);
          }

          @Override
          public boolean isSelectable() {
            return false;
          }
        });

    EditDomain editDomain =
        new EditDomain() {
          @Override
          public void loadDefaultTool() {
            setActiveTool(new RuntimePatchedSelectionTool());
          }
        };
    editDomain.addViewer(viewer);

    displayModel = createDisplayModel();
    setTitle();

    shell.setLayout(new FillLayout());
    shell.addShellListener(
        new ShellListener() {
          private boolean firstRun = true;

          public void shellIconified(ShellEvent e) {}

          public void shellDeiconified(ShellEvent e) {}

          public void shellDeactivated(ShellEvent e) {}

          public void shellClosed(ShellEvent e) {
            // Remove this shell from the cache.
            openShells.remove(OPIShell.this);
            sendUpdateCommand();
          }

          public void shellActivated(ShellEvent e) {
            if (firstRun) {
              // Resize the shell after it's open, so we can take into account different window
              // borders.
              // Do this only the first time it's activated.
              resizeToContents();
              shell.setFocus();
              firstRun = false;
            }
          }
        });
    shell.addDisposeListener(
        new DisposeListener() {

          @Override
          public void widgetDisposed(DisposeEvent e) {
            if (!icon.isDisposed()) icon.dispose();
          }
        });
    /*
     * Don't open the Shell here, as it causes SWT to think the window is on top when it really isn't.
     * Wait until the window is open, then call shell.setFocus() in the activated listener.
     *
     * Make some attempt at sizing the shell, sometimes a shell is not given focus and the shellActivated
     * listener callback doesn't resize the window. It's better to have something a little too large as the
     * default. Related to Eclipse bug 96700.
     */
    shell.setSize(
        displayModel.getSize().width + WINDOW_BORDER_X,
        displayModel.getSize().height + WINDOW_BORDER_Y);
    shell.setVisible(true);
  }