⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contributionmanager.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @since 3.0     */    protected int indexOf(IContributionItem item) {        return contributions.indexOf(item);    }    /**     * Insert the item at the given index.     *      * @param index The index to be used for insertion     * @param item The item to be inserted     */    public void insert(int index, IContributionItem item) {        if (index > contributions.size()) {			throw new IndexOutOfBoundsException(                    "inserting " + item.getId() + " at " + index); //$NON-NLS-1$ //$NON-NLS-2$		}        if (allowItem(item)) {            contributions.add(index, item);            itemAdded(item);        }    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void insertAfter(String ID, IAction action) {        insertAfter(ID, new ActionContributionItem(action));    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void insertAfter(String ID, IContributionItem item) {        IContributionItem ci = find(ID);        if (ci == null) {			throw new IllegalArgumentException("can't find ID" + ID);//$NON-NLS-1$		}        int ix = contributions.indexOf(ci);        if (ix >= 0) {            // System.out.println("insert after: " + ix);            if (allowItem(item)) {                contributions.add(ix + 1, item);                itemAdded(item);            }        }    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void insertBefore(String ID, IAction action) {        insertBefore(ID, new ActionContributionItem(action));    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void insertBefore(String ID, IContributionItem item) {        IContributionItem ci = find(ID);        if (ci == null) {			throw new IllegalArgumentException("can't find ID " + ID);//$NON-NLS-1$		}        int ix = contributions.indexOf(ci);        if (ix >= 0) {            // System.out.println("insert before: " + ix);            if (allowItem(item)) {                contributions.add(ix, item);                itemAdded(item);            }        }    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public boolean isDirty() {        if (isDirty) {			return true;		}        if (hasDynamicItems()) {            for (Iterator iter = contributions.iterator(); iter.hasNext();) {                IContributionItem item = (IContributionItem) iter.next();                if (item.isDirty()) {					return true;				}            }        }        return false;    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public boolean isEmpty() {        return contributions.isEmpty();    }    /**     * The given item was added to the list of contributions.     * Marks the manager as dirty and updates the number of dynamic items, and the memento.     */    protected void itemAdded(IContributionItem item) {        item.setParent(this);        markDirty();        if (item.isDynamic()) {			dynamicItems++;		}    }    /**     * The given item was removed from the list of contributions.     * Marks the manager as dirty and updates the number of dynamic items.     */    protected void itemRemoved(IContributionItem item) {        item.setParent(null);        markDirty();        if (item.isDynamic()) {			dynamicItems--;		}    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void markDirty() {        setDirty(true);    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void prependToGroup(String groupName, IAction action) {        addToGroup(groupName, new ActionContributionItem(action), false);    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void prependToGroup(String groupName, IContributionItem item) {        addToGroup(groupName, item, false);    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public IContributionItem remove(String ID) {        IContributionItem ci = find(ID);        if (ci == null) {			return null;		}        return remove(ci);    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public IContributionItem remove(IContributionItem item) {        if (contributions.remove(item)) {            itemRemoved(item);            return item;        }        return null;    }    /* (non-Javadoc)     * Method declared on IContributionManager.     */    public void removeAll() {        IContributionItem[] items = getItems();        contributions.clear();        for (int i = 0; i < items.length; i++) {            IContributionItem item = items[i];            itemRemoved(item);        }        dynamicItems = 0;        markDirty();    }    /**     * Replaces the item of the given identifier with another contribution item.     * This can be used, for example, to replace large contribution items with     * placeholders to avoid memory leaks.  If the identifier cannot be found in the     * current list of items, then this does nothing.  If multiple occurrences are     * found, then the replacement items is put in the first position and the other     * positions are removed.     * @param identifier The identifier to look for in the list of contributions;     * should not be <code>null</code>.     * @param replacementItem The contribution item to replace the old item; must     * not be <code>null</code>.  Use {@link org.eclipse.jface.action.ContributionManager#remove(java.lang.String) remove} if that is what you want to do.     * @return <code>true</code> if the given identifier can be; <code>     * @since 3.0     */    public boolean replaceItem(final String identifier,            final IContributionItem replacementItem) {        if (identifier == null) {            return false;        }        final int index = indexOf(identifier);        if (index < 0) {            return false; // couldn't find the item.        }        // Remove the old item.        final IContributionItem oldItem = (IContributionItem) contributions                .get(index);        itemRemoved(oldItem);        // Add the new item.        contributions.set(index, replacementItem);        itemAdded(replacementItem); // throws NPE if (replacementItem == null)        // Go through and remove duplicates.        for (int i = contributions.size() - 1; i > index; i--) {            IContributionItem item = (IContributionItem) contributions.get(i);            if ((item != null) && (identifier.equals(item.getId()))) {                if (Policy.TRACE_TOOLBAR) {                    System.out                            .println("Removing duplicate on replace: " + identifier); //$NON-NLS-1$                }                contributions.remove(i);                itemRemoved(item);            }        }        return true; // success    }    /**     * Sets whether this manager is dirty. When dirty, the list of contributions      * is not accurately reflected in the corresponding widgets.     *     * @param dirty <code>true</code> if this manager is dirty, and <code>false</code>     *   if it is up-to-date     */    protected void setDirty(boolean dirty) {        isDirty = dirty;    }    /**     * Sets the overrides for this contribution manager     *      * @param newOverrides the overrides for the items of this manager     * @since 2.0     */    public void setOverrides(IContributionManagerOverrides newOverrides) {        overrides = newOverrides;    }    /**     * An internal method for setting the order of the contribution items.     *      * @param items the contribution items in the specified order     * @since 3.0     */    protected void internalSetItems(IContributionItem[] items) {        contributions.clear();        for (int i = 0; i < items.length; i++) {            if (allowItem(items[i])) {                contributions.add(items[i]);            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -