private IPerspectiveDescriptor[] load() {
    Preferences store = createSessionScope();
    String[] keys;
    IPerspectiveDescriptor[] result = null;

    IWorkbench workbench = PlatformUI.getWorkbench();
    IPerspectiveRegistry registry = workbench.getPerspectiveRegistry();

    try {
      keys = store.keys();
      result = new IPerspectiveDescriptor[keys.length];
      for (int i = 0; i < keys.length; i++) {
        String perspectiveId = keys[i];

        int pos = store.getInt(perspectiveId, 0);
        if (pos <= perspectiveList.size()) {
          perspectiveList.add(pos, perspectiveId);
        } else {
          perspectiveList.add(perspectiveId);
        }
      }
      for (int i = 0; i < perspectiveList.size(); i++) {
        String id = (String) perspectiveList.get(i);
        result[i] = registry.findPerspectiveWithId(id);
      }

    } catch (BackingStoreException e) {
      e.printStackTrace();
    }
    return result;
  }
  // FIXME see https://bugs.eclipse.org/bugs/show_bug.cgi?id=313771
  private IPerspectiveDescriptor getDescriptorFor(String id) {
    IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry();
    if (perspectiveRegistry instanceof PerspectiveRegistry) {
      return ((PerspectiveRegistry) perspectiveRegistry).findPerspectiveWithId(id, false);
    }

    return perspectiveRegistry.findPerspectiveWithId(id);
  }
Exemplo n.º 3
0
    @Override
    public void widgetSelected(SelectionEvent e) {
      IPerspectiveRegistry perspectiveRegistry = PlatformUI.getWorkbench().getPerspectiveRegistry();
      IWorkbenchPage activePage =
          PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      activePage.setPerspective(
          perspectiveRegistry.findPerspectiveWithId(LiteratureReviewPhasesPerspective.ID));

      LiteratureReviewPhasesView literatureReviewStudiesView =
          (LiteratureReviewPhasesView) ReviewerViewRegister.getView(LiteratureReviewPhasesView.ID);
    }
Exemplo n.º 4
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();
       }
     }
   }
 }
Exemplo n.º 5
0
  public static void switchToLiferayPerspective() {
    // Retrieve the new project open perspective preference setting
    String perspSetting =
        PrefUtil.getAPIPreferenceStore().getString(IDE.Preferences.PROJECT_OPEN_NEW_PERSPECTIVE);

    String promptSetting =
        IDEWorkbenchPlugin.getDefault()
            .getPreferenceStore()
            .getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE);

    // Return if do not switch perspective setting and are not prompting
    if (!(promptSetting.equals(MessageDialogWithToggle.PROMPT))
        && perspSetting.equals(IWorkbenchPreferenceConstants.NO_NEW_PERSPECTIVE)) {
      return;
    }

    // Map perspective id to descriptor.
    IPerspectiveRegistry reg = PlatformUI.getWorkbench().getPerspectiveRegistry();

    IPerspectiveDescriptor finalPersp = reg.findPerspectiveWithId(LiferayPerspectiveFactory.ID);

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

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

      if (page != null) {
        IPerspectiveDescriptor currentPersp = page.getPerspective();

        // don't switch if the current perspective is the Liferay perspective
        if (finalPersp.equals(currentPersp)) {
          return;
        }
      }

      // prompt the user to switch
      if (!confirmPerspectiveSwitch(window, finalPersp)) {
        return;
      }
    }

    // replace active perspective setting otherwise
    replaceCurrentPerspective(finalPersp);
  }
  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;
    }
  }