/* (non-Javadoc)
  * @see org.eclipse.ui.ISizeProvider#getSizeFlags(boolean)
  */
 public int getSizeFlags(boolean width) {
   ISizeProvider sizeProvider = (ISizeProvider) Util.getAdapter(part, ISizeProvider.class);
   if (sizeProvider != null) {
     return sizeProvider.getSizeFlags(width);
   }
   return 0;
 }
  protected final ISaveablePart getSaveableView() {
    if (activeView == null) {
      return null;
    }

    return (ISaveablePart) Util.getAdapter(activeView, ISaveablePart.class);
  }
Exemplo n.º 3
0
  /**
   * Implements IPersistableElement. Persist the working set name and working set contents. The
   * contents has to be either IPersistableElements or provide adapters for it to be persistent.
   *
   * @see org.eclipse.ui.IPersistableElement#saveState(IMemento)
   */
  public void saveState(IMemento memento) {
    if (workingSetMemento != null) {
      // just re-save the previous memento if the working set has
      // not been restored
      memento.putMemento(workingSetMemento);
    } else {
      memento.putString(IWorkbenchConstants.TAG_NAME, getName());
      memento.putString(IWorkbenchConstants.TAG_LABEL, getLabel());
      memento.putString(IWorkbenchConstants.TAG_ID, getUniqueId());
      memento.putString(IWorkbenchConstants.TAG_EDIT_PAGE_ID, editPageId);
      Iterator iterator = elements.iterator();
      while (iterator.hasNext()) {
        IAdaptable adaptable = (IAdaptable) iterator.next();
        final IPersistableElement persistable =
            (IPersistableElement) Util.getAdapter(adaptable, IPersistableElement.class);
        if (persistable != null) {
          final IMemento itemMemento = memento.createChild(IWorkbenchConstants.TAG_ITEM);

          itemMemento.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable.getFactoryId());
          SafeRunner.run(
              new SafeRunnable(
                  "Problems occurred while saving persistable item state") { //$NON-NLS-1$

                public void run() throws Exception {
                  persistable.saveState(itemMemento);
                }
              });
        }
      }
    }
  }
Exemplo n.º 4
0
 /* (non-Javadoc)
  * @see org.eclipse.ui.IPluginContribution#getLocalId()
  */
 public String getLocalId() {
   IPluginContribution contribution =
       (IPluginContribution) Util.getAdapter(wizardElement, IPluginContribution.class);
   if (contribution != null) {
     return contribution.getLocalId();
   }
   return wizardElement.getId();
 }
 /*
  * Return the shell described by the supplied uiInfo, or null if no shell is
  * described.
  */
 Shell getShell(IAdaptable uiInfo) {
   if (uiInfo != null) {
     Shell shell = (Shell) Util.getAdapter(uiInfo, Shell.class);
     if (shell != null) {
       return shell;
     }
   }
   return null;
 }
  public final IWorkbenchPart getPart(boolean restore) {
    if (isDisposed()) {
      return null;
    }

    if (part == null && restore) {

      if (state == STATE_CREATION_IN_PROGRESS) {
        IStatus result =
            WorkbenchPlugin.getStatus(
                new PartInitException(
                    NLS.bind(
                        "Warning: Detected recursive attempt by part {0} to create itself (this is probably, but not necessarily, a bug)", //$NON-NLS-1$
                        getId())));
        WorkbenchPlugin.log(result);
        return null;
      }

      try {
        state = STATE_CREATION_IN_PROGRESS;

        IWorkbenchPart newPart = createPart();
        if (newPart != null) {
          part = newPart;
          // Add a dispose listener to the part. This dispose listener does nothing but log an
          // exception
          // if the part's widgets get disposed unexpectedly. The workbench part reference is the
          // only
          // object that should dispose this control, and it will remove the listener before it does
          // so.
          getPane().getControl().addDisposeListener(prematureDisposeListener);
          part.addPropertyListener(propertyChangeListener);
          if (part instanceof IWorkbenchPart3) {
            ((IWorkbenchPart3) part).addPartPropertyListener(partPropertyChangeListener);
          }

          refreshFromPart();
          releaseReferences();

          fireInternalPropertyChange(INTERNAL_PROPERTY_OPENED);

          ISizeProvider sizeProvider = (ISizeProvider) Util.getAdapter(part, ISizeProvider.class);
          if (sizeProvider != null) {
            // If this part has a preferred size, indicate that the preferred size may have changed
            // at this point
            if (sizeProvider.getSizeFlags(true) != 0 || sizeProvider.getSizeFlags(false) != 0) {
              fireInternalPropertyChange(IWorkbenchPartConstants.PROP_PREFERRED_SIZE);
            }
          }
        }
      } finally {
        state = STATE_CREATED;
      }
    }

    return part;
  }
  protected ISaveablePart getSaveablePart(IEvaluationContext context) {
    IWorkbenchPart activePart = InternalHandlerUtil.getActivePart(context);

    if (activePart instanceof ISaveablePart) return (ISaveablePart) activePart;

    ISaveablePart part = (ISaveablePart) Util.getAdapter(activePart, ISaveablePart.class);
    if (part != null) return part;

    return InternalHandlerUtil.getActiveEditor(context);
  }
  /* (non-Javadoc)
   * @see org.eclipse.ui.ISizeProvider#computePreferredSize(boolean, int, int, int)
   */
  public int computePreferredSize(
      boolean width, int availableParallel, int availablePerpendicular, int preferredResult) {

    ISizeProvider sizeProvider = (ISizeProvider) Util.getAdapter(part, ISizeProvider.class);
    if (sizeProvider != null) {
      return sizeProvider.computePreferredSize(
          width, availableParallel, availablePerpendicular, preferredResult);
    }

    return preferredResult;
  }
  protected ISaveablePart getSaveablePart(ExecutionEvent event) {

    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof ISaveablePart) {
      return (ISaveablePart) activePart;
    }

    ISaveablePart part = (ISaveablePart) Util.getAdapter(activePart, ISaveablePart.class);
    if (part != null) return part;

    return HandlerUtil.getActiveEditor(event);
  }
Exemplo n.º 10
0
 /**
  * Verifies if the given element matches one of the selection requirements. Element must at least
  * pass the type test, and optionally wildcard name match.
  */
 private boolean verifyElement(IAdaptable element) {
   if (classes.isEmpty()) {
     return true;
   }
   for (int i = 0; i < classes.size(); i++) {
     SelectionClass sc = (SelectionClass) classes.get(i);
     if (verifyClass(element, sc.className) == false) {
       continue;
     }
     if (sc.nameFilter == null) {
       return true;
     }
     IWorkbenchAdapter de = (IWorkbenchAdapter) Util.getAdapter(element, IWorkbenchAdapter.class);
     if ((de != null) && verifyNameMatch(de.getLabel(element), sc.nameFilter)) {
       return true;
     }
   }
   return false;
 }
  /**
   * Register a contributor.
   *
   * @param contributor the contributor
   * @param targetType the target type
   */
  public void registerContributor(IObjectContributor contributor, String targetType) {
    List contributorList = (List) contributors.get(targetType);
    if (contributorList == null) {
      contributorList = new ArrayList(5);
      contributors.put(targetType, contributorList);
    }
    contributorList.add(contributor);
    flushLookup();

    IConfigurationElement element =
        (IConfigurationElement) Util.getAdapter(contributor, IConfigurationElement.class);

    // hook the object listener
    if (element != null) {
      ContributorRecord contributorRecord = new ContributorRecord(contributor, targetType);
      contributorRecordSet.add(contributorRecord);
      PlatformUI.getWorkbench()
          .getExtensionTracker()
          .registerObject(
              element.getDeclaringExtension(), contributorRecord, IExtensionTracker.REF_WEAK);
    }
  }
Exemplo n.º 12
0
 /**
  * Returns the <code>IShowInTargetList</code> for the given source part, or <code>null</code> if
  * it does not provide one.
  *
  * @param sourcePart the source part
  * @return the <code>IShowInTargetList</code> or <code>null</code>
  */
 private IShowInTargetList getShowInTargetList(IWorkbenchPart sourcePart) {
   return (IShowInTargetList) Util.getAdapter(sourcePart, IShowInTargetList.class);
 }
Exemplo n.º 13
0
 /**
  * Returns the <code>IShowInSource</code> provided by the source part, or <code>null</code> if it
  * does not provide one.
  *
  * @param sourcePart the source part
  * @return an <code>IShowInSource</code> or <code>null</code>
  */
 private IShowInSource getShowInSource(IWorkbenchPart sourcePart) {
   return (IShowInSource) Util.getAdapter(sourcePart, IShowInSource.class);
 }