private static String getPartId(IWorkbenchPartReference ref) { if (ref == null) { return "null part"; //$NON-NLS-1$ } return Util.safeString(ref.getPartName()) + " - " //$NON-NLS-1$ + Util.safeString(ref.getId()); }
/** * Sets or clears the title tool tip text of this part. Clients should call this method instead of * overriding <code>getTitleToolTip</code> * * @param toolTip the new tool tip text, or <code>null</code> to clear */ protected void setTitleToolTip(String toolTip) { toolTip = Util.safeString(toolTip); // Do not send changes if they are the same if (Util.equals(this.toolTip, toolTip)) { return; } this.toolTip = toolTip; firePropertyChange(IWorkbenchPart.PROP_TITLE); }
private static String getPartId(IWorkbenchPart part) { if (part == null) { return "null part"; //$NON-NLS-1$ } return Util.safeString(part.getTitle()) + " - " //$NON-NLS-1$ + Util.safeString(part.getSite().getId()); }
/** * Sets or clears the title of this part. Clients should call this method instead of overriding * getTitle. * * <p>This may change a title that was previously set using setPartName or setContentDescription. * * @deprecated new code should use setPartName and setContentDescription * @param title the title, or <code>null</code> to clear */ protected void setTitle(String title) { title = Util.safeString(title); // Do not send changes if they are the same if (Util.equals(this.title, title)) { return; } this.title = title; firePropertyChange(IWorkbenchPart.PROP_TITLE); }
public final boolean equals(final Object object) { if (object instanceof SelectionEnabler) { final SelectionEnabler that = (SelectionEnabler) object; return Util.equals(this.classes, that.classes) && Util.equals(this.enablementExpression, that.enablementExpression) && Util.equals(this.mode, that.mode); } return false; }
/** * Computes the hash code for this object based on the id. * * @return The hash code for this object. */ public final int hashCode() { if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode = HASH_INITIAL * HASH_FACTOR + Util.hashCode(classes); hashCode = hashCode * HASH_FACTOR + Util.hashCode(enablementExpression); hashCode = hashCode * HASH_FACTOR + Util.hashCode(mode); if (hashCode == HASH_CODE_NOT_COMPUTED) { hashCode++; } } return hashCode; }
/** * Tests the receiver and the object for equality * * @param object object to compare the receiver to * @return true=the object equals the receiver, the name is the same. false otherwise */ public boolean equals(Object object) { if (this == object) { return true; } if (object instanceof WorkingSet) { WorkingSet workingSet = (WorkingSet) object; return Util.equals(workingSet.getName(), getName()) && Util.equals(workingSet.getElementsArray(), getElementsArray()) && Util.equals(workingSet.getId(), getId()); } return false; }
void internalSetPartName(String partName) { partName = Util.safeString(partName); Assert.isNotNull(partName); // Do not send changes if they are the same if (Util.equals(this.partName, partName)) { return; } this.partName = partName; firePropertyChange(IWorkbenchPartConstants.PROP_PART_NAME); }
public String getTitle() { String label = Util.safeString(getModel().getLocalizedLabel()); if (label.length() == 0) { if (input == null) { if (descriptor != null) { return descriptor.getLabel(); } } else { return Util.safeString(input.getName()); } } return label; }
@Override public int hashCode() { if (hashCode == HASH_INITIAL) { hashCode = hashCode * HASH_FACTOR + Util.hashCode(categoryActivityBindings); hashCode = hashCode * HASH_FACTOR + Util.hashCode(defined); hashCode = hashCode * HASH_FACTOR + Util.hashCode(id); hashCode = hashCode * HASH_FACTOR + Util.hashCode(name); if (hashCode == HASH_INITIAL) { hashCode++; } } return hashCode; }
/** * Log an event fired from the workbench page * * @param page * @param eventId */ public static final void logPagePropertyChanged( IWorkbenchPage page, String changeId, Object oldValue, Object newValue) { if (isEnabled(PAGE_PROPERTY_EVENTS)) { System.out.println( PAGE_PROPERTY_EVENTS + " page " //$NON-NLS-1$ + Util.safeString(page.getLabel()) + ", " + changeId + " = " + Util.safeString(newValue.toString()) + "( old value = " + newValue.toString() + " )"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } }
protected final ISaveablePart getSaveableView() { if (activeView == null) { return null; } return (ISaveablePart) Util.getAdapter(activeView, ISaveablePart.class); }
protected void setImageDescriptor(ImageDescriptor descriptor) { if (Util.equals(imageDescriptor, descriptor)) { return; } Image oldImage = image; ImageDescriptor oldDescriptor = imageDescriptor; image = null; imageDescriptor = descriptor; // Don't queue events triggered by image changes. We'll dispose the image // immediately after firing the event, so we need to fire it right away. immediateFirePropertyChange(IWorkbenchPartConstants.PROP_TITLE); if (queueEvents) { // If there's a PROP_TITLE event queued, remove it from the queue because // we've just fired it. queuedEvents.clear(IWorkbenchPartConstants.PROP_TITLE); } // If we had allocated the old image, deallocate it now (AFTER we fire the property change // -- listeners may need to clean up references to the old image) if (oldImage != null) { JFaceResources.getResources().destroy(oldDescriptor); } }
/** * 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); } }); } } } }
/* (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 void setToolTip(String newToolTip) { if (Util.equals(tooltip, newToolTip)) { return; } tooltip = newToolTip; firePropertyChange(IWorkbenchPartConstants.PROP_TITLE); }
protected void setContentDescription(String newContentDescription) { if (Util.equals(contentDescription, newContentDescription)) { return; } contentDescription = newContentDescription; firePropertyChange(IWorkbenchPartConstants.PROP_CONTENT_DESCRIPTION); }
protected void setPartName(String newPartName) { if (Util.equals(partName, newPartName)) { return; } partName = newPartName; firePropertyChange(IWorkbenchPartConstants.PROP_PART_NAME); }
protected void setTitle(String newTitle) { if (Util.equals(title, newTitle)) { return; } title = newTitle; firePropertyChange(IWorkbenchPartConstants.PROP_TITLE); }
boolean setCategoryActivityBindings(Set categoryActivityBindings) { categoryActivityBindings = Util.safeCopy(categoryActivityBindings, ICategoryActivityBinding.class); if (!Util.equals(categoryActivityBindings, this.categoryActivityBindings)) { this.categoryActivityBindings = categoryActivityBindings; this.categoryActivityBindingsAsArray = (ICategoryActivityBinding[]) this.categoryActivityBindings.toArray( new ICategoryActivityBinding[this.categoryActivityBindings.size()]); hashCode = HASH_INITIAL; string = null; return true; } return false; }
/* (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(); }
public final String getId() { if (part != null) { IWorkbenchPartSite site = part.getSite(); if (site != null) { return site.getId(); } } return Util.safeString(id); }
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; }
/* * 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; }
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); }
boolean setName(String name) { if (!Util.equals(name, this.name)) { this.name = name; hashCode = HASH_INITIAL; string = null; return true; } return false; }
public boolean setDescription(String description) { if (!Util.equals(description, this.description)) { this.description = description; hashCode = HASH_INITIAL; string = null; return true; } return false; }
void internalSetContentDescription(String description) { Assert.isNotNull(description); // Do not send changes if they are the same if (Util.equals(contentDescription, description)) { return; } this.contentDescription = description; firePropertyChange(IWorkbenchPartConstants.PROP_CONTENT_DESCRIPTION); }
/* (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; }
/** * Gets the part name directly from the associated workbench part, or the empty string if none. * * @return */ protected final String getRawPartName() { String result = ""; // $NON-NLS-1$ if (part instanceof IWorkbenchPart2) { IWorkbenchPart2 part2 = (IWorkbenchPart2) part; result = Util.safeString(part2.getPartName()); } return result; }