Exemple #1
0
 private void setTitle() {
   if (displayModel.getName() != null && displayModel.getName().trim().length() > 0) {
     shell.setText(displayModel.getName());
   } else { // If the name doesn't exist, use the OPI path
     shell.setText(path.toString());
   }
 }
Exemple #2
0
 private DisplayModel createDisplayModel() throws Exception {
   displayModel = new DisplayModel(path);
   XMLUtil.fillDisplayModelFromInputStream(ResourceUtil.pathToInputStream(path), displayModel);
   if (macrosInput != null) {
     macrosInput = macrosInput.getCopy();
     macrosInput.getMacrosMap().putAll(displayModel.getMacrosInput().getMacrosMap());
     displayModel.setPropertyValue(AbstractContainerModel.PROP_MACROS, macrosInput);
   }
   viewer.setContents(displayModel);
   displayModel.setViewer(viewer);
   displayModel.setOpiRuntime(this);
   return displayModel;
 }
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);
  }
Exemple #4
0
 @Override
 public IEditorInput getOPIInput() {
   IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(displayModel.getOpiFilePath());
   return new FileEditorInput(file);
 }
Exemple #5
0
 private void resizeToContents() {
   int frameX = shell.getSize().x - shell.getClientArea().width;
   int frameY = shell.getSize().y - shell.getClientArea().height;
   shell.setSize(displayModel.getSize().width + frameX, displayModel.getSize().height + frameY);
 }