Exemplo n.º 1
0
 /**
  * This method is called when 'Finish' button is pressed in the wizard. We will create an
  * operation and run it using wizard as execution context.
  */
 public boolean performFinish() {
   final String fileName = page.getProjectName();
   IRunnableWithProgress op =
       new IRunnableWithProgress() {
         public void run(IProgressMonitor monitor) throws InvocationTargetException {
           try {
             doFinish(fileName, monitor);
           } catch (CoreException e) {
             throw new InvocationTargetException(e);
           } finally {
             monitor.done();
           }
         }
       };
   try {
     getContainer().run(true, false, op);
     workbench.showPerspective(
         "edu.rosehulman.soar.perspective.SoarPerspectiveFactory",
         workbench.getWorkbenchWindows()[0]);
   } catch (InterruptedException e) {
     return false;
   } catch (InvocationTargetException e) {
     Throwable realException = e.getTargetException();
     MessageDialog.openError(getShell(), "Error", realException.getMessage());
     return false;
   } catch (WorkbenchException e) {
     MessageDialog.openError(getShell(), "Error", e.getMessage());
     return false;
   }
   return true;
 }
Exemplo n.º 2
0
 /**
  * Runs task in Eclipse progress dialog. NOTE: this call can't be canceled if it will block in IO
  */
 public static void runInProgressDialog(final DBRRunnableWithProgress runnable)
     throws InvocationTargetException {
   try {
     IRunnableContext runnableContext;
     IWorkbench workbench = PlatformUI.getWorkbench();
     IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
     if (workbenchWindow != null) {
       runnableContext =
           new ProgressMonitorDialog(workbench.getActiveWorkbenchWindow().getShell());
     } else {
       runnableContext = workbench.getProgressService();
     }
     runnableContext.run(
         true,
         true,
         new IRunnableWithProgress() {
           @Override
           public void run(IProgressMonitor monitor)
               throws InvocationTargetException, InterruptedException {
             runnable.run(RuntimeUtils.makeMonitor(monitor));
           }
         });
   } catch (InterruptedException e) {
     // do nothing
   }
 }
  /* (non-Javadoc)
   * @see PerspectiveMenu#run(IPerspectiveDescriptor)
   */
  protected void run(IPerspectiveDescriptor desc) {
    //        IPreferenceStore store = PrefUtil.getInternalPreferenceStore();
    //        int mode = store.getInt(IPreferenceConstants.OPEN_PERSP_MODE);
    int mode = IPreferenceConstants.OPM_ACTIVE_PAGE;
    IWorkbenchPage page = getWindow().getActivePage();
    IPerspectiveDescriptor persp = null;
    if (page != null) {
      persp = page.getPerspective();
    }

    // Only open a new window if user preference is set and the window
    // has an active perspective.
    if (IPreferenceConstants.OPM_NEW_WINDOW == mode && persp != null) {
      try {
        IWorkbench workbench = getWindow().getWorkbench();
        IAdaptable input = ((Workbench) workbench).getDefaultPageInput();
        workbench.openWorkbenchWindow(desc.getId(), input);
      } catch (WorkbenchException e) {
        handleWorkbenchException(e);
      }
    } else {
      if (page != null) {
        page.setPerspective(desc);
      } else {
        try {
          IWorkbench workbench = getWindow().getWorkbench();
          IAdaptable input = ((Workbench) workbench).getDefaultPageInput();
          getWindow().openPage(desc.getId(), input);
        } catch (WorkbenchException e) {
          handleWorkbenchException(e);
        }
      }
    }
  }
Exemplo n.º 4
0
 /** Called when the action is executed. */
 public void run(IAction action) {
   wizard = new P5ExportWizard();
   IWorkbench wb = PlatformUI.getWorkbench();
   wizard.init(wb, null);
   Shell shell = wb.getActiveWorkbenchWindow().getShell();
   WizardDialog wd = new WizardDialog(shell, wizard);
   wd.open();
   // System.err.println("WIZARD="+wizard);
 }
Exemplo n.º 5
0
 @NotNull
 public static IWorkbenchWindow getActiveWorkbenchWindow() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
   if (window != null) {
     return window;
   }
   IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
   if (windows.length > 0) {
     return windows[0];
   }
   throw new IllegalStateException("No workbench window");
 }
Exemplo n.º 6
0
  private IEditorInput getEditorInput() throws IOException {
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow[] wws = wb.getWorkbenchWindows();
    if (wws.length != 1) throw new IOException("Failed to find workbench window");
    IWorkbenchWindow ww = wws[0];

    IWorkbenchPage[] wps = ww.getPages();
    if (wws.length != 1) throw new IOException("Failed to find workbench page");
    IWorkbenchPage wp = wps[0];

    IEditorPart ep = wp.getActiveEditor();
    if (ep == null) throw new IOException("Failed to find active editor");
    return ep.getEditorInput();
  }
Exemplo n.º 7
0
 public static DBRRunnableContext getDefaultRunnableContext() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   if (workbench != null && workbench.getActiveWorkbenchWindow() != null) {
     return new RunnableContextDelegate(workbench.getActiveWorkbenchWindow());
   } else {
     return new DBRRunnableContext() {
       @Override
       public void run(boolean fork, boolean cancelable, DBRRunnableWithProgress runnable)
           throws InvocationTargetException, InterruptedException {
         runnable.run(VoidProgressMonitor.INSTANCE);
       }
     };
   }
 }
Exemplo n.º 8
0
 @Nullable
 public static Shell getActiveShell() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   return workbench == null ? null : getShell(workbench.getActiveWorkbenchWindow());
 }