Exemplo n.º 1
0
  private static void processContentExtensions(
      final CommonViewer commonViewer, boolean activeFilter, boolean activedPerspectiveFilter) {
    final INavigatorContentService contentService = commonViewer.getNavigatorContentService();

    String[] visibleExtensionIds = contentService.getVisibleExtensionIds();

    List<String> visibleIDsForPecpective = new ArrayList<String>();
    List<String> visibleIdsForActiveFilter = new ArrayList<String>();

    if (visibleExtensionIds != null) {
      visibleIdsForActiveFilter.addAll(Arrays.asList(visibleExtensionIds));
    }

    if (activedPerspectiveFilter) {
      String perspectiveId =
          PlatformUI.getWorkbench()
              .getActiveWorkbenchWindow()
              .getActivePage()
              .getPerspective()
              .getId();
      PerspectiveFilterHelper helper = new PerspectiveFilterHelper();
      helper.setTreeViewer(commonViewer);
      helper.setNavigatorContentService(contentService);
      helper.setActionProviderId(PerspectiveFilterActionProvider.ID);
      String[] pvExtensions = helper.getExtensionIdsToActivate(perspectiveId);

      if (pvExtensions != null && pvExtensions.length > 0) {
        visibleIDsForPecpective = Arrays.asList(pvExtensions);
      }
      visibleIdsForActiveFilter.retainAll(visibleIDsForPecpective);
    }

    String[] filteredContents = RepositoryNodeFilterHelper.getFilterByNodeValues();
    List<String> filteredContentsList = new ArrayList<String>();
    if (filteredContents != null) {
      filteredContentsList = Arrays.asList(filteredContents);
    }

    List<String> checkedExtensions = new ArrayList<String>();
    if (activeFilter) {
      for (String id : visibleIdsForActiveFilter) {
        if (!filteredContentsList.contains(id)) {
          checkedExtensions.add(id);
        }
      }
    } else {
      checkedExtensions.addAll(visibleIdsForActiveFilter);
    }
    String[] contentExtensionIdsToActivate =
        (String[]) checkedExtensions.toArray(new String[checkedExtensions.size()]);
    UpdateActiveExtensionsOperation updateExtensions =
        new UpdateActiveExtensionsOperation(commonViewer, contentExtensionIdsToActivate);
    updateExtensions.execute(null, null);
  }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    if (getCommonNavigator() == null || getCommonNavigator().getCommonViewer() == null) {
      return null; // The model explorer is not displayed (The editor is closed?)
    }

    CommonViewer viewer = getCommonNavigator().getCommonViewer();

    String[] newContents = null;

    Object trigger = event.getTrigger();

    if (trigger instanceof Event) {
      // State based on the widget
      Event triggerEvent = (Event) trigger;
      if (triggerEvent.widget instanceof ToolItem) {
        if (((ToolItem) triggerEvent.widget).getSelection()) {
          newContents = new String[] {DIAGRAM_CONTENTS};
        } else {
          newContents = new String[] {UML_MODEL_CONTENTS};
        }
      }
    }

    if (newContents == null) {
      // Revert the current state
      INavigatorContentService navigatorContent = viewer.getNavigatorContentService();

      if (navigatorContent.isActive(DIAGRAM_CONTENTS)) {
        newContents = new String[] {UML_MODEL_CONTENTS};
      } else {
        newContents = new String[] {DIAGRAM_CONTENTS};
      }
    }

    UpdateActiveExtensionsOperation updateExtensions =
        new UpdateActiveExtensionsOperation(viewer, newContents);
    updateExtensions.execute(null, null);

    return null;
  }