001: /*******************************************************************************
002: * Copyright (c) 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: ******************************************************************************/package org.eclipse.ui.menus;
011:
012: import org.eclipse.jface.resource.ImageDescriptor;
013: import org.eclipse.ui.IWorkbench;
014: import org.eclipse.ui.IWorkbenchPartSite;
015: import org.eclipse.ui.IWorkbenchWindow;
016: import org.eclipse.ui.services.IServiceLocator;
017:
018: /**
019: * Allow a command or application to provide feedback to a user through updating
020: * a MenuItem or ToolItem. Initially used to update properties for UI elements
021: * created by the CommandContributionItem.
022: * <p>
023: * This class may be extended by clients.
024: * </p>
025: *
026: * @since 3.3
027: */
028: public abstract class UIElement {
029:
030: private IServiceLocator serviceLocator;
031:
032: /**
033: * Construct a new instance of this class keyed off of the provided service
034: * locator.
035: *
036: * @param serviceLocator
037: * the locator. May not be <code>null</code>.
038: */
039: protected UIElement(IServiceLocator serviceLocator)
040: throws IllegalArgumentException {
041: if (serviceLocator == null)
042: throw new IllegalArgumentException();
043: this .serviceLocator = serviceLocator;
044: }
045:
046: /**
047: * Update the label on this UI element.
048: *
049: * @param text
050: * The new label to display.
051: */
052: public abstract void setText(String text);
053:
054: /**
055: * Update the tooltip on this UI element. Tooltips are currently only valid
056: * for toolbar contributions.
057: *
058: * @param text
059: * The new tooltip to display.
060: */
061: public abstract void setTooltip(String text);
062:
063: /**
064: * Update the icon on this UI element.
065: *
066: * @param desc
067: * The descriptor for the new icon to display.
068: */
069: public abstract void setIcon(ImageDescriptor desc);
070:
071: /**
072: * Update the disabled icon on this UI element.
073: *
074: * @param desc
075: * The descriptor for the new icon to display.
076: */
077: public abstract void setDisabledIcon(ImageDescriptor desc);
078:
079: /**
080: * Update the hover icon on this UI element.
081: *
082: * @param desc
083: * The descriptor for the new icon to display.
084: */
085: public abstract void setHoverIcon(ImageDescriptor desc);
086:
087: /**
088: * Update the checked state on this UI element. For example, if this was a
089: * toggle or radio button.
090: *
091: * @param checked
092: * true to set toggle on
093: */
094: public abstract void setChecked(boolean checked);
095:
096: /**
097: * Get the service locator scope in which this UI element resides. May not
098: * be <code>null</code>.
099: *
100: * <p>
101: * The locator may be used to obtain services that are scoped in the same
102: * way as the {@link UIElement}. Such services include but are not limited
103: * to {@link IWorkbench}, {@link IWorkbenchWindow}, and
104: * {@link IWorkbenchPartSite}. While this method may not return
105: * <code>null</code> requests for any of these particular services may
106: * return <code>null</code>.
107: * </p>
108: *
109: * @return the service locator for this element
110: * @see IServiceLocator#getService(Class)
111: */
112: public final IServiceLocator getServiceLocator() {
113: return serviceLocator;
114: }
115:
116: /**
117: * Set the menu contribution id to use. This is only applicable to menu
118: * contributions that support a drop-down style menu. The default
119: * implementation does nothing.
120: * <p>
121: * Example: element.setDropdownId("org.eclipse.ui.navigate.back.my.menu");
122: * </p>
123: *
124: * @param id
125: * used to populate the dropdown menu. Must not be
126: * <code>null</code>.
127: */
128: public void setDropDownId(String id) {
129: // This does nothing.
130: }
131: }
|