예제 #1
0
  /**
   * The <code>PropertySheet</code> implementation of this <code>IPartListener</code> method first
   * sees if the active part is an <code>IContributedContentsView</code> adapter and if so, asks it
   * for its contributing part.
   */
  public void partActivated(IWorkbenchPart part) {
    // Look for a declaratively-contributed adapter - including not yet loaded adapter factories.
    // See bug 86362 [PropertiesView] Can not access AdapterFactory, when plugin is not loaded.
    IContributedContentsView view =
        (IContributedContentsView)
            ViewsPlugin.getAdapter(part, IContributedContentsView.class, true);
    IWorkbenchPart source = null;
    if (view != null) {
      source = view.getContributingPart();
    }
    if (source != null) {
      super.partActivated(source);
    } else {
      super.partActivated(part);
    }

    if (isImportant(part)) {
      currentPart = part;
      // reset the selection (to allow selectionChanged() accept part change for empty selections)
      currentSelection = null;
    }

    // When the view is first opened, pass the selection to the page
    if (bootstrapSelection != null) {
      IPropertySheetPage page = (IPropertySheetPage) getCurrentPage();
      if (page != null) {
        page.selectionChanged(part, bootstrapSelection);
      }
      bootstrapSelection = null;
    }
  }
  /** @return the {@link IDiagramEditor} diagram editor. */
  protected IDiagramEditor getDiagramEditor() {
    IWorkbenchPart part = getPart();
    if (part instanceof DiagramEditorInternal) {
      return (DiagramEditorInternal) part;
    }
    IContributedContentsView contributedView =
        (IContributedContentsView) part.getAdapter(IContributedContentsView.class);
    if (contributedView != null) {
      part = contributedView.getContributingPart();
    }
    if (part instanceof DiagramEditorInternal) {
      return (DiagramEditorInternal) part;
    }

    return null;
  }
  /**
   * Handle the part activated event.
   *
   * @param part the new activated part.
   */
  protected void handlePartActivated(final IWorkbenchPart part) {
    /*
     * The properties view has been activated and the current page is this
     * instance of TabbedPropertySheetPage
     */
    final boolean thisActivated =
        part instanceof PropertySheet && ((PropertySheet) part).getCurrentPage() == this;

    /*
     * When the active part changes and the part does not provide a
     * selection that affects this property sheet page, the PropertySheet
     * does not send us a selectionChanged() event. We need to be informed
     * of these events since we want to send aboutToBeHidden() and
     * aboutToBeShown() when the property sheet is hidden or shown.
     */
    if (!thisActivated
        && !part.equals(contributor)
        && !part.getSite().getId().equals(contributor.getContributorId())) {
      /*
       * Is the part is a IContributedContentsView for the contributor,
       * for example, outline view.
       */
      final IContributedContentsView view =
          (IContributedContentsView) part.getAdapter(IContributedContentsView.class);
      if (view == null
          || view.getContributingPart() != null
              && !view.getContributingPart().equals(contributor)) {
        if (activePropertySheet) {
          if (currentTab != null) {
            currentTab.aboutToBeHidden();
          }
          activePropertySheet = false;
        }
        return;
      }
    }
    if (!activePropertySheet && currentTab != null) {
      currentTab.aboutToBeShown();
      currentTab.refresh();
    }
    activePropertySheet = true;
  }