Ejemplo n.º 1
0
 public static IWorkbenchPage getActivePage() {
   IWorkbenchWindow workbench = getActiveWorkbenchWindow();
   if (workbench == null) {
     return null;
   }
   return workbench.getActivePage();
 }
  @Override
  public void build() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
    workbenchWindow.addPerspectiveListener(perspectiveAdapter);

    IPerspectiveDescriptor[] descriptors = load();
    for (int i = 0; i < descriptors.length; i++) {
      createPerspectiveButton(descriptors[i]);
    }

    // Button for the perspective dialog
    Composite otherBg = new Composite(background, SWT.NONE);
    otherBg.setLayout(new FormLayout());
    otherButton = new Button(otherBg, SWT.PUSH | SWT.FLAT);
    FormData fdOther = new FormData();
    otherButton.setLayoutData(fdOther);
    fdOther.left = new FormAttachment(0, left.getBounds().width);
    FormData buttonPos = getLayoutSet().getPosition(ILayoutSetConstants.PERSP_BUTTON_POS);
    fdOther.top = buttonPos.top;
    otherButton.setData(RWT.CUSTOM_VARIANT, "perspective"); // $NON-NLS-1$
    otherButton.setText(Messages.get().PerspectiveSwitcherBuilder_Other);
    IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow();
    final IWorkbenchAction perspectiveAction =
        ActionFactory.OPEN_PERSPECTIVE_DIALOG.create(activeWindow);
    otherButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            perspectiveAction.run();
          }
        });
  }
Ejemplo n.º 3
0
  public void run() {

    Page page = null;
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    UDIGEditorInput editorInput =
        (UDIGEditorInput) workbenchWindow.getActivePage().getActiveEditor().getEditorInput();
    if (editorInput instanceof PageEditorInput) {
      page = (Page) ((PageEditorInput) editorInput).getProjectElement();
    }
    if (page == null) {
      throw new RuntimeException(Messages.PrintAction_pageError);
    }

    Dimension pSize = page.getSize();

    float factor = (float) pSize.height / (float) pSize.width;
    float xPlus = 10f;
    float yPlus = xPlus * factor;
    int w = pSize.width + (int) xPlus;
    int h = pSize.height + (int) yPlus;
    page.setSize(new Dimension(w, h));

    // IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    // IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
    // PageEditor pageEditor = (PageEditor) activeEditor;
    // ZoomManager zoomManager = (ZoomManager) pageEditor.getAdapter(ZoomManager.class);
    // double next = zoomManager.getNextZoomLevel();
    // zoomManager.setZoom(next);
  }
  protected void setInitialSelection() {
    // Use the selection, if any
    Object input;
    IWorkbenchPage page = getSite().getPage();
    ISelection selection = null;
    if (page != null) selection = page.getSelection();
    if (selection instanceof ITextSelection) {
      IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
      if (activePage != null) {
        Object part = activePage.getActivePart();
        if (part instanceof IEditorPart) {
          setSelectionFromEditor((IEditorPart) part);
          if (fViewer.getSelection() != null) return;
        }
      }
    }

    // Use saved selection from memento
    if (selection == null || selection.isEmpty()) selection = restoreSelectionState(fMemento);

    if (selection == null || selection.isEmpty()) {
      // Use the input of the page
      input = getSite().getPage().getInput();
      if (!(input instanceof IModelElement)) {
        if (input instanceof IAdaptable)
          input = ((IAdaptable) input).getAdapter(IModelElement.class);
        else return;
      }
      selection = new StructuredSelection(input);
    }
    selectionChanged(null, selection);
  }
Ejemplo n.º 5
0
 protected IWorkbenchPage getActivePage() {
   IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
   if (activeWorkbenchWindow != null) {
     return activeWorkbenchWindow.getActivePage();
   }
   return null;
 }
Ejemplo n.º 6
0
  private void hideMenuCheck() {
    try {
      URL pluginUrl = Platform.getBundle(GrassUiPlugin.PLUGIN_ID).getResource("/");
      String pluginPath = FileLocator.toFileURL(pluginUrl).getPath();
      File pluginFile = new File(pluginPath);
      File installFolder = pluginFile.getParentFile().getParentFile().getParentFile();

      File grassFolderFile = new File(installFolder, "grass");
      if (Platform.getOS().equals(Platform.OS_WIN32)) {
        if (!grassFolderFile.exists() || !grassFolderFile.isDirectory()) {
          IWorkbenchWindow[] wwindows = PlatformUI.getWorkbench().getWorkbenchWindows();
          String actionSetID = "eu.hydrologis.jgrass.ui.grassactionset";

          for (IWorkbenchWindow iWorkbenchWindow : wwindows) {
            IWorkbenchPage activePage = iWorkbenchWindow.getActivePage();
            if (activePage != null) {
              activePage.hideActionSet(actionSetID);
              MenuManager mbManager = ((ApplicationWindow) iWorkbenchWindow).getMenuBarManager();
              for (int i = 0; i < mbManager.getItems().length; i++) {
                IContributionItem item = mbManager.getItems()[i];
                if (item.getId().equals(actionSetID)) {
                  item.setVisible(false);
                }
              }
            }
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 7
0
  @Override
  public void run(IAction action) {

    try {
      IWorkbenchWindow windoow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      RefactoringWizard wizard = new RefactoringWizard();

      ITextSelection textSelection = getITextSelection();

      int startLine = textSelection.getStartLine() + 1;
      int endLine = textSelection.getEndLine() + 1;
      InOneMethodVisitor iomv = new InOneMethodVisitor(getICompilationUnit(), startLine, endLine);
      if (iomv.isInOne()) {
        wizard.init(windoow.getWorkbench(), getICompilationUnit(), getITextSelection());
        WizardDialog dialog = new WizardDialog(shell, wizard);
        dialog.open();
      } else {
        throw new Exception("Selected Code Block Illegal!");
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      alert(e);
      e.printStackTrace();
    }
  }
Ejemplo n.º 8
0
  public void run() {
    NewPHPClassWizard wizard = new NewPHPClassWizard();
    wizard.init(window.getWorkbench(), getSelection());

    WizardDialog wizardDialog = new WizardDialog(window.getShell(), wizard);
    wizardDialog.open();
  }
 /**
  * Looks up the current evaluation context for the given window. Tries all workbench windows if
  * the active window does not have a context
  *
  * @param window the window to look in
  * @param otherwindows a listing of all other windows to try if the given window does not have a
  *     context
  * @return the evaluation context or <code>null</code>
  */
 IJavaScriptStackFrame getEvaluationContext(IWorkbenchWindow window, List otherwindows) {
   IWorkbenchPage activePage = window.getActivePage();
   IJavaScriptStackFrame frame = null;
   if (activePage != null) {
     frame = getContext(activePage);
   }
   if (frame == null) {
     IWorkbenchPage[] pages = window.getPages();
     for (int i = 0; i < pages.length; i++) {
       if (activePage != pages[i]) {
         frame = getContext(pages[i]);
         if (frame != null) {
           return frame;
         }
       }
     }
     otherwindows.add(window);
     IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
     for (int i = 0; i < windows.length; i++) {
       if (!otherwindows.contains(windows[i])) {
         frame = getEvaluationContext(windows[i], otherwindows);
         if (frame != null) {
           return frame;
         }
       }
     }
     return null;
   }
   return frame;
 }
  private GradleProject getContext() {
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win == null ? null : win.getActivePage();

    if (page != null) {
      ISelection selection = page.getSelection();
      if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        if (!ss.isEmpty()) {
          Object obj = ss.getFirstElement();
          if (obj instanceof IResource) {
            IResource rsrc = (IResource) obj;
            IProject prj = rsrc.getProject();
            if (prj != null) {
              return GradleCore.create(prj);
            }
          }
        }
      }
      IEditorPart part = page.getActiveEditor();
      if (part != null) {
        IEditorInput input = part.getEditorInput();
        IResource rsrc = (IResource) input.getAdapter(IResource.class);
        if (rsrc != null) {
          IProject prj = rsrc.getProject();
          if (prj != null) {
            return GradleCore.create(prj);
          }
        }
      }
    }
    return null;
  }
Ejemplo n.º 11
0
 public static IWorkbenchPage getActivePage() {
   IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow();
   if (activeWorkbenchWindow != null) {
     return activeWorkbenchWindow.getActivePage();
   }
   return null;
 }
 @Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
   if (activeWorkbenchWindow != null) {
     WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
     if (page != null) {
       Map parameters = event.getParameters();
       String value =
           (String) parameters.get(IWorkbenchCommandConstants.WINDOW_CLOSE_PERSPECTIVE_PARM_ID);
       if (value == null) {
         page.closePerspective(page.getPerspective(), true, true);
       } else {
         IPerspectiveDescriptor perspective =
             activeWorkbenchWindow
                 .getWorkbench()
                 .getPerspectiveRegistry()
                 .findPerspectiveWithId(value);
         if (perspective != null) {
           page.closePerspective(perspective, true, true);
         }
       }
     }
   }
   return null;
 }
  private void open(IFile file) {
    IWorkbenchWindow dw = FMUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = dw.getActivePage();
    if (page != null) {
      IContentType contentType = null;
      try {
        IContentDescription description = file.getContentDescription();
        if (description != null) {
          contentType = description.getContentType();
        }
        IEditorDescriptor desc = null;
        if (contentType != null) {
          desc =
              PlatformUI.getWorkbench()
                  .getEditorRegistry()
                  .getDefaultEditor(file.getName(), contentType);
        } else {
          desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
        }

        if (desc != null) {
          page.openEditor(new FileEditorInput(file), desc.getId());
        }
      } catch (CoreException e) {
        FMUIPlugin.getDefault().logError(e);
      }
    }
  }
Ejemplo n.º 14
0
  public static void open(final IValue value) {
    if (value == null) {
      return;
    }
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();

    if (win == null && wb.getWorkbenchWindowCount() != 0) {
      win = wb.getWorkbenchWindows()[0];
    }

    if (win != null) {
      final IWorkbenchPage page = win.getActivePage();

      if (page != null) {
        Display.getDefault()
            .asyncExec(
                new Runnable() {
                  public void run() {
                    try {
                      page.openEditor(new ValueEditorInput(value, true, 2), Editor.EditorId);
                    } catch (PartInitException e) {
                      PDBUIPlugin.getDefault().logException("failed to open tree editor", e);
                    }
                  }
                });
      }
    }
  }
  /**
   * Attempts to return the default shell. If it cannot return the default shell, it returns the
   * shell of the first workbench window that has shell.
   *
   * @return The shell
   * @since 1.2
   */
  public static Shell getDefaultShell() {
    Shell shell = null;

    try {
      shell = Display.getDefault().getActiveShell();
    } catch (Exception e) {
      // ignore
    }

    try {
      if (shell == null) {
        if (!PlatformUI.isWorkbenchRunning()) {
          return new Shell();
        }
        IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (activeWindow != null) {
          shell = activeWindow.getShell();
        }
      }
    } catch (Exception e) {
      // ignore
    }

    if (shell == null) {
      if (!PlatformUI.isWorkbenchRunning()) {
        return new Shell();
      }
      IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
      for (int i = 0; shell == null && i < windows.length; i++) {
        shell = windows[i].getShell();
      }
    }

    return shell;
  }
Ejemplo n.º 16
0
 public static @Nullable ISelection getActiveSelection(@Nullable IWorkbenchSite site) {
   try {
     if (site == null) {
       return null;
     }
     IWorkbenchWindow workbenchWindow = site.getWorkbenchWindow();
     if (workbenchWindow == null) {
       return null;
     }
     IWorkbenchPage activePage = workbenchWindow.getActivePage();
     if (activePage == null) {
       return null;
     }
     IEditorPart activeEditor = activePage.getActiveEditor();
     if (activeEditor == null) {
       return null;
     }
     IEditorSite editorSite = activeEditor.getEditorSite();
     if (editorSite == null) {
       return null;
     }
     ISelectionProvider selectionProvider = editorSite.getSelectionProvider();
     if (selectionProvider == null) {
       return null;
     }
     return selectionProvider.getSelection();
   } catch (Exception e) {
     return null;
   }
 }
Ejemplo n.º 17
0
  public static IWorkbench getMockWorkbench(String file) {

    IWorkbench workbench = mock(IWorkbench.class);
    IWorkbenchWindow window = mock(IWorkbenchWindow.class);
    IWorkbenchPage page = mock(IWorkbenchPage.class);

    ITextEditor editor = mock(ITextEditor.class);

    IDocumentProvider docProvider = mock(IDocumentProvider.class);
    IDocument doc = mock(IDocument.class);

    IPath ipath = mock(IPath.class);
    File afile = mock(File.class);
    IFile inputFile = mock(IFile.class);

    IFileEditorInput editorInput = mock(IFileEditorInput.class);

    when(workbench.getWorkbenchWindows()).thenReturn(new IWorkbenchWindow[] {window});
    when(window.getActivePage()).thenReturn(page);
    when(page.getActiveEditor()).thenReturn(editor);

    when(editor.getEditorInput()).thenReturn(editorInput);
    when(editor.getDocumentProvider()).thenReturn(docProvider);

    when(editorInput.getFile()).thenReturn(inputFile);
    when(docProvider.getDocument(any())).thenReturn(doc);

    when(inputFile.getLocation()).thenReturn(ipath);
    when(inputFile.getName()).thenReturn(file);

    when(ipath.toFile()).thenReturn(afile);
    when(afile.length()).thenReturn(33l);

    return workbench;
  }
Ejemplo n.º 18
0
 /**
  * Display gmon results in the GProf View. NOTE: this method has to be called from within the UI
  * thread.
  *
  * @param decoder
  * @param id Secondary id, usually path to gmon file.
  */
 public static GmonView displayGprofView(GmonDecoder decoder, String id) {
   GmonView gmonview = null;
   try {
     IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     IWorkbenchPage page = window.getActivePage();
     if (id != null) {
       id = id.replace('.', '_');
       id = id.replace(':', '_');
     }
     gmonview = (GmonView) page.showView(ID, id, IWorkbenchPage.VIEW_ACTIVATE);
     if (decoder.getHistogramDecoder().getProfRate() == 0) {
       gmonview.switchSampleTime.setToolTipText(
           "Unable to display time, because profiling rate is null"); //$NON-NLS-1$
       gmonview.switchSampleTime.setEnabled(false);
     }
     gmonview.setInput(decoder);
     GmonView.setHistTitle(decoder, gmonview.label);
     if (!decoder.getHistogramDecoder().hasValues()) {
       gmonview.action1.setChecked(true);
       gmonview.action2.setChecked(false);
       gmonview.action1.run();
     }
   } catch (CoreException e) {
     Status status =
         new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
     Activator.getDefault().getLog().log(status);
   }
   return gmonview;
 }
 public int open() {
   try {
     ensureConsistency();
   } catch (InvocationTargetException e) {
     ExceptionHandler.handle(
         e,
         JavaUIMessages.TypeSelectionDialog_error3Title,
         JavaUIMessages.TypeSelectionDialog_error3Message);
     return CANCEL;
   } catch (InterruptedException e) {
     // cancelled by user
     return CANCEL;
   }
   if (fInitialFilter == null) {
     IWorkbenchWindow window = JavaScriptPlugin.getActiveWorkbenchWindow();
     if (window != null) {
       ISelection selection = window.getSelectionService().getSelection();
       if (selection instanceof ITextSelection) {
         String text = ((ITextSelection) selection).getText();
         if (text != null) {
           text = text.trim();
           if (text.length() > 0
               && JavaScriptConventions.validateJavaScriptTypeName(
                       text, JavaScriptCore.VERSION_1_3, JavaScriptCore.VERSION_1_3)
                   .isOK()) {
             fInitialFilter = text;
             fSelectionMode = FULL_SELECTION;
           }
         }
       }
     }
   }
   return super.open();
 }
Ejemplo n.º 20
0
 public static Shell getActiveWorkbenchShell() {
   IWorkbenchWindow window = getActiveWorkbenchWindow();
   if (window != null) {
     return window.getShell();
   }
   return null;
 }
Ejemplo n.º 21
0
 /**
  * Create a new instance of <code>LockToolBarAction</code>
  *
  * @param window the workbench window this action applies to
  */
 public LockToolBarAction(IWorkbenchWindow window) {
   super(WorkbenchMessages.LockToolBarAction_text);
   if (window == null) {
     throw new IllegalArgumentException();
   }
   this.workbenchWindow = window;
   setActionDefinitionId("org.eclipse.ui.window.lockToolBar"); // $NON-NLS-1$
   // @issue missing action id
   setToolTipText(WorkbenchMessages.LockToolBarAction_toolTip);
   setEnabled(true);
   // queue the update for the checked state since this action is created
   // before the coolbar
   window
       .getWorkbench()
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               if (workbenchWindow instanceof WorkbenchWindow) {
                 setChecked(((WorkbenchWindow) workbenchWindow).isCoolBarLocked());
               }
             }
           });
   window
       .getWorkbench()
       .getHelpSystem()
       .setHelp(this, IWorkbenchHelpContextIds.LOCK_TOOLBAR_ACTION);
 }
  /**
   * Find Open Editor for the currently selected ModelExtensionDefinition
   *
   * @param selectedMedFile the mxd file to check
   * @return the currently open editor or <code>null</code> if none open
   */
  private static IEditorPart getOpenEditor(IFile selectedMedFile) {
    final IWorkbenchWindow window = Activator.getDefault().getCurrentWorkbenchWindow();

    if (window != null) {
      final IWorkbenchPage page = window.getActivePage();

      if (page != null) {
        // look through the open editors and see if there is one available for this model file.
        IEditorReference[] editors = page.getEditorReferences();

        for (int i = 0; i < editors.length; ++i) {
          IEditorPart editor = editors[i].getEditor(false);

          if (editor != null) {
            IEditorInput input = editor.getEditorInput();

            if (input instanceof IFileEditorInput) {
              if ((selectedMedFile != null)
                  && selectedMedFile.equals(((IFileEditorInput) input).getFile())) {
                return editor;
              }
            }
          }
        }
      }
    }

    return null;
  }
 /**
  * Since these actions are re-created each time the run/debug as menu is filled, the enablement of
  * this action is static.
  */
 private void updateEnablement() {
   IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
   boolean enabled = false;
   if (wb != null) {
     IWorkbenchPage page = wb.getActivePage();
     if (page != null) {
       ISelection selection = page.getSelection();
       if (selection instanceof IStructuredSelection) {
         IStructuredSelection structuredSelection = (IStructuredSelection) selection;
         try {
           // check enablement logic, if any
           Expression expression = fShortcut.getShortcutEnablementExpression();
           if (expression == null) {
             enabled = !structuredSelection.isEmpty();
           } else {
             List list = structuredSelection.toList();
             IEvaluationContext context = new EvaluationContext(null, list);
             context.addVariable("selection", list); // $NON-NLS-1$
             enabled = fShortcut.evalEnablementExpression(context, expression);
           }
         } catch (CoreException e) {
         }
       } else {
         IEditorPart editor = page.getActiveEditor();
         if (editor != null) {
           enabled = true;
         }
       }
     }
   }
   setEnabled(enabled);
 }
  /**
   * Returns a VDB editor given a vdb resource if editor is open
   *
   * @param vdb the vdb
   * @return the vdb editor
   */
  public static VdbEditor getVdbEditorForFile(IResource vdb) {
    if (vdb != null && vdb.exists()) {
      IWorkbenchWindow window = UiPlugin.getDefault().getCurrentWorkbenchWindow();

      if (window != null) {
        final IWorkbenchPage page = window.getActivePage();

        if (page != null) {
          // look through the open editors and see if there is one available for this model file.
          IEditorReference[] editors = page.getEditorReferences();
          for (int i = 0; i < editors.length; ++i) {

            IEditorPart editor = editors[i].getEditor(false);
            if (editor != null) {
              IEditorInput input = editor.getEditorInput();
              if (input instanceof IFileEditorInput) {
                if (vdb.equals(((IFileEditorInput) input).getFile())
                    || vdb.getFullPath()
                        .equals(((IFileEditorInput) input).getFile().getFullPath())) {
                  // found it;
                  if (ModelUtil.isVdbArchiveFile(vdb)) {
                    return (VdbEditor) editor;
                  }
                  break;
                }
              }
            }
          }
        }
      }
    }

    return null;
  }
  /**
   * @param ji
   * @param job
   */
  private void execute(JobInfo ji, Job job) {

    Object prop = job.getProperty(IProgressConstants.ACTION_PROPERTY);
    if (prop instanceof IAction && ((IAction) prop).isEnabled()) {
      IAction action = (IAction) prop;
      action.run();
      removeTopElement(ji);
    }

    prop = job.getProperty(IProgressConstants2.COMMAND_PROPERTY);
    if (prop instanceof ParameterizedCommand) {
      ParameterizedCommand command = (ParameterizedCommand) prop;
      IWorkbenchWindow window = getWindow();
      IHandlerService service = (IHandlerService) window.getService(IHandlerService.class);
      Exception exception = null;
      try {
        service.executeCommand(command, null);
        removeTopElement(ji);
      } catch (ExecutionException e) {
        exception = e;
      } catch (NotDefinedException e) {
        exception = e;
      } catch (NotEnabledException e) {
        exception = e;
      } catch (NotHandledException e) {
        exception = e;
      }

      if (exception != null) {
        Status status =
            new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, exception.getMessage(), exception);
        StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
      }
    }
  }
Ejemplo n.º 26
0
 @Nullable
 public static ISelectionProvider getSelectionProvider(IServiceLocator serviceLocator) {
   ISelectionProvider selectionProvider = serviceLocator.getService(ISelectionProvider.class);
   if (selectionProvider != null) {
     return selectionProvider;
   }
   IWorkbenchPartSite partSite = getWorkbenchPartSite(serviceLocator);
   if (partSite == null) {
     IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
     if (activePart == null) {
       IWorkbenchWindow activeWindow = DBeaverUI.getActiveWorkbenchWindow();
       if (activeWindow != null) {
         activePart = activeWindow.getActivePage().getActivePart();
       }
     }
     if (activePart != null) {
       partSite = activePart.getSite();
     }
   }
   if (partSite != null) {
     return partSite.getSelectionProvider();
   } else {
     return null;
   }
 }
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
    IWorkbenchPage page = window.getActivePage();
    View view = (View) page.findView(View.ID);
    view.getViewer().refresh();

    // open dialog to get path
    FileDialog filedlg = new FileDialog(window.getShell(), SWT.SAVE);
    filedlg.setText("Create Sequence Diagram File");
    filedlg.setFilterPath("SystemRoot");
    filedlg.setFilterExtensions(new String[] {"di"});
    String selected = filedlg.open();

    // create & initial the sequence diagram
    MyCreater myCreater = new MyCreater();
    myCreater.init(window.getWorkbench(), new StructuredSelection()); // fixed bug
    IFile iFile = myCreater.create(selected);

    // create the model
    SequenceDiagram sdDiagram = new SequenceDiagram();
    sdDiagram.setiFile(iFile);
    sdDiagram.setFilePath(
        new Path(selected).removeFileExtension().addFileExtension("uml").toOSString());
    ModelManager.getInstance().AddModel(sdDiagram);

    // open the editor
    myCreater.open(iFile);

    // refresh the model viewer
    view.getViewer().refresh();

    return null;
  }
Ejemplo n.º 28
0
  /* (non-Javadoc)
   * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
   */
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    // clear console
    Console.getInstance().clear();

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
      Activator.getDefault().testsStarted();

      // get the selections in the Project explorer
      IStructuredSelection selection =
          (IStructuredSelection)
              window.getSelectionService().getSelection("org.eclipse.ui.navigator.ProjectExplorer");
      final Object[] selectedElements = selection.toArray();

      BusyIndicator.showWhile(
          null,
          new Runnable() {
            @Override
            public void run() {
              // go through each open selected project
              for (int index = 0; index < selectedElements.length; index++) {
                Object element = selectedElements[index];
                log.debug("Calling runTestsObject on " + selectedElements[index]);
                runTestsObject(element);
              }
            }
          });
    }
    return null;
  }
 private static void openXmlEditor(final IFileStore fileStore, int line, int column, String name) {
   assert fileStore != null;
   IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   if (window != null) {
     IWorkbenchPage page = window.getActivePage();
     if (page != null) {
       try {
         if (!fileStore.getName().endsWith(".pom")) { // .pom means stuff from local repository?
           IEditorPart part = IDE.openEditorOnFileStore(page, fileStore);
           reveal(selectEditorPage(part), line, column);
         } else {
           // we need special EditorInput for stuff from repository
           name = name + ".pom"; // $NON-NLS-1$
           File file = new File(fileStore.toURI());
           try {
             IEditorInput input =
                 new MavenPathStorageEditorInput(
                     name, name, file.getAbsolutePath(), readStream(new FileInputStream(file)));
             IEditorPart part = OpenPomAction.openEditor(input, name);
             reveal(selectEditorPage(part), line, column);
           } catch (IOException e) {
             log.error("failed opening editor", e);
           }
         }
       } catch (PartInitException e) {
         MessageDialog.openInformation(
             Display.getDefault().getActiveShell(), //
             Messages.PomHyperlinkDetector_error_title,
             NLS.bind(Messages.PomHyperlinkDetector_error_message, fileStore, e.toString()));
       }
     }
   }
 }
 protected Shell getShell() {
   IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
   if (window != null) {
     return window.getShell();
   }
   return null;
 }