/** Handles workbench exception */
 private void handleWorkbenchException(WorkbenchException e) {
   ErrorDialog.openError(
       getWindow().getShell(),
       WorkbenchMessages.get().ChangeToPerspectiveMenu_errorTitle,
       e.getMessage(),
       e.getStatus());
 }
Ejemplo n.º 2
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;
 }
 private void switchPerspective(final String perspectiveId) {
   IWorkbench workbench = PlatformUI.getWorkbench();
   IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
   try {
     workbench.showPerspective(perspectiveId, window);
   } catch (WorkbenchException e) {
     e.printStackTrace();
   }
 }
 @SuppressWarnings("deprecation")
 public void run(IAction action) {
   try {
     if (window == null) window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
     final IWorkbenchPage page = window.getActivePage();
     page.showView(IPageLayout.ID_RES_NAV);
   } catch (WorkbenchException e) {
     final String message = NLS.bind("Failed to open navigator. \n{0}", e.getMessage());
     MessageDialog.openError(null, "Error", message);
     OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
   }
 }
Ejemplo n.º 5
0
 /** Load all monitors from persistent storage. */
 private void loadMonitors() {
   try {
     FileReader reader = new FileReader(getSaveLocation());
     IMemento memento = XMLMemento.createReadRoot(reader);
     IMemento[] monitorsMemento = memento.getChildren(MONITOR_ID_ATTR);
     for (IMemento monitorMemento : monitorsMemento) {
       loadMonitor(monitorMemento);
     }
   } catch (FileNotFoundException e) {
     LMLMonitorCorePlugin.log(e.getLocalizedMessage());
   } catch (WorkbenchException e) {
     LMLMonitorCorePlugin.log(e.getLocalizedMessage());
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.internal.e4.compatibility.WorkbenchPartReference#initialize
   * (org.eclipse.ui.IWorkbenchPart)
   */
  @Override
  public void initialize(IWorkbenchPart part) throws PartInitException {
    IConfigurationElement element = descriptor.getConfigurationElement();
    editorSite = new EditorSite(getModel(), part, this, element);
    if (element == null) {
      editorSite.setExtensionId(descriptor.getId());
    }
    editorSite.setActionBars(
        createEditorActionBars((WorkbenchPage) getPage(), descriptor, editorSite));
    IEditorPart editor = (IEditorPart) part;
    try {
      editor.init(editorSite, getEditorInput());
    } catch (PartInitException e) {
      if (editor instanceof ErrorEditorPart) {
        editor.init(editorSite, new NullEditorInput(this));
      } else {
        throw e;
      }
    }

    if (editor.getSite() != editorSite || editor.getEditorSite() != editorSite) {
      String id = descriptor == null ? getModel().getElementId() : descriptor.getId();
      throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_siteIncorrect, id));
    }

    if (part instanceof IPersistableEditor) {
      if (editorState != null) {
        ((IPersistableEditor) part).restoreState(editorState);
      } else if (useIPersistableEditor()) {
        String mementoString = getModel().getPersistedState().get(MEMENTO_KEY);
        if (mementoString != null) {
          try {
            IMemento createReadRoot = XMLMemento.createReadRoot(new StringReader(mementoString));
            IMemento editorStateMemento =
                createReadRoot.getChild(IWorkbenchConstants.TAG_EDITOR_STATE);
            if (editorStateMemento != null) {
              ((IPersistableEditor) part).restoreState(editorStateMemento);
            }
          } catch (WorkbenchException e) {
            throw new PartInitException(e.getStatus());
          }
        }
      }
    }

    legacyPart = part;
    addPropertyListeners();
  }
Ejemplo n.º 7
0
 void switchPerspective() {
   IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
   if (store.getBoolean(PreferenceInitializer.ATTR_SWITCH_PERSPECTIVE)) {
     IWorkbench workbench = PlatformUI.getWorkbench();
     IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
     IPerspectiveRegistry perspectiveRegistry = workbench.getPerspectiveRegistry();
     String perspectiveId = store.getString(PreferenceInitializer.ATTR_PERSPECTIVE_ID);
     if (perspectiveId != null
         && perspectiveId.length() > 0
         && perspectiveRegistry.findPerspectiveWithId(perspectiveId) != null) {
       try {
         workbench.showPerspective(perspectiveId, window);
       } catch (WorkbenchException e) {
         e.printStackTrace();
       }
     }
   }
 }
  public void run(final IAction action) {
    if (this.selecteMethod != null) {
      InteractionModelBuilder interactionModelBuilder = new InteractionModelBuilder();
      InteractionModel interactionModel =
          interactionModelBuilder.buildInteractionModel(this.selecteMethod);

      try {
        IWorkbenchWindow dw =
            ModelGoonActivator.getDefault().getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage page = dw.getActivePage();

        String fileName =
            this.selecteMethod.getDeclaringType().getElementName()
                + "#"
                + this.selecteMethod.getElementName();
        IWorkspace workspace = ResourcesPlugin.getWorkspace();

        IFile file =
            this.selecteMethod
                .getCompilationUnit()
                .getResource()
                .getProject()
                .getFile(fileName + ".mgs");
        // file.setHidden(true);
        // if (!file.exists()) {
        // file.create(new ByteArrayInputStream(new byte[] {}), false,
        // null);
        // }

        if (page != null) {
          SequenceDiagramEditor editor = (SequenceDiagramEditor) IDE.openEditor(page, file, true);
          editor.setModel(interactionModel);
        }
      } catch (WorkbenchException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 9
0
  public static void deSerialize() {
    IPath path = URLWaypointPlugin.getDefault().getStateLocation().append(URL_FILE);
    File mementoFile = path.toFile();

    if (mementoFile.exists()) {
      try {
        FileInputStream input = new FileInputStream(mementoFile);
        BufferedReader reader =
            new BufferedReader(new InputStreamReader(input, "utf-8")); // $NON-NLS-1$
        IMemento memento = XMLMemento.createReadRoot(reader);
        restoreStateFromMemento(memento);
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
      } catch (WorkbenchException e) {
        e.printStackTrace();
      }
    }
  }
  boolean openPerspective(
      final String perspId,
      final IAdaptable input,
      final IWorkbench workbench,
      final IPreferenceStore store,
      final ILog logger) {
    try {
      // Verify the requested perspective ID
      IPerspectiveRegistry reg = workbench.getPerspectiveRegistry();
      IPerspectiveDescriptor perspective = reg.findPerspectiveWithId(perspId);
      if (perspective == null) {
        logger.log(statusFactory.error("Unable to open perspective: " + perspId));
        return false;
      }

      // Get "Open Behavior" preference.
      String pref = store.getString(IWorkbenchPreferenceConstants.OPEN_NEW_PERSPECTIVE);

      // Implement open behavior.
      if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_WINDOW)) {
        workbench.openWorkbenchWindow(perspId, input);
      } else if (pref.equals(IWorkbenchPreferenceConstants.OPEN_PERSPECTIVE_REPLACE)) {
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        IWorkbenchPage activePage = window.getActivePage();
        if (activePage != null) {
          activePage.setPerspective(perspective);
        } else {
          window.openPage(perspId, input);
        }
      }

      Shell shell = workbench.getActiveWorkbenchWindow().getShell();
      shell.setMinimized(false);
      shell.forceActive();
      logger.log(statusFactory.info("Opened perspective: " + perspId));
      return true;
    } catch (WorkbenchException e) {
      logger.log(statusFactory.error("Error opening perspective: " + e.getMessage(), e));
      return false;
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.IEditorReference#getEditorInput()
   */
  public IEditorInput getEditorInput() throws PartInitException {
    IEditorPart editor = getEditor(false);
    if (editor != null) {
      return editor.getEditorInput();
    }

    if (input == null) {
      String memento = getModel().getPersistedState().get(MEMENTO_KEY);
      if (memento == null) {
        input = new NullEditorInput();
      } else {
        try {
          XMLMemento createReadRoot = XMLMemento.createReadRoot(new StringReader(memento));
          input = restoreInput(createReadRoot);
        } catch (WorkbenchException e) {
          throw new PartInitException(e.getStatus());
        }
      }
    }
    return input;
  }