KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > menus > UIElement


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.ui.menus;
13
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.ui.IWorkbench;
16 import org.eclipse.ui.IWorkbenchPartSite;
17 import org.eclipse.ui.IWorkbenchWindow;
18 import org.eclipse.ui.services.IServiceLocator;
19
20 /**
21  * Allow a command or application to provide feedback to a user through updating
22  * a MenuItem or ToolItem. Initially used to update properties for UI elements
23  * created by the CommandContributionItem.
24  * <p>
25  * This class may be extended by clients.
26  * </p>
27  *
28  * @since 3.3
29  */

30 public abstract class UIElement {
31
32     private IServiceLocator serviceLocator;
33
34     /**
35      * Construct a new instance of this class keyed off of the provided service
36      * locator.
37      *
38      * @param serviceLocator
39      * the locator. May not be <code>null</code>.
40      */

41     protected UIElement(IServiceLocator serviceLocator)
42             throws IllegalArgumentException JavaDoc {
43         if (serviceLocator == null)
44             throw new IllegalArgumentException JavaDoc();
45         this.serviceLocator = serviceLocator;
46     }
47
48     /**
49      * Update the label on this UI element.
50      *
51      * @param text
52      * The new label to display.
53      */

54     public abstract void setText(String JavaDoc text);
55
56     /**
57      * Update the tooltip on this UI element. Tooltips are currently only valid
58      * for toolbar contributions.
59      *
60      * @param text
61      * The new tooltip to display.
62      */

63     public abstract void setTooltip(String JavaDoc text);
64
65     /**
66      * Update the icon on this UI element.
67      *
68      * @param desc
69      * The descriptor for the new icon to display.
70      */

71     public abstract void setIcon(ImageDescriptor desc);
72
73     /**
74      * Update the disabled icon on this UI element.
75      *
76      * @param desc
77      * The descriptor for the new icon to display.
78      */

79     public abstract void setDisabledIcon(ImageDescriptor desc);
80
81     /**
82      * Update the hover icon on this UI element.
83      *
84      * @param desc
85      * The descriptor for the new icon to display.
86      */

87     public abstract void setHoverIcon(ImageDescriptor desc);
88
89     /**
90      * Update the checked state on this UI element. For example, if this was a
91      * toggle or radio button.
92      *
93      * @param checked
94      * true to set toggle on
95      */

96     public abstract void setChecked(boolean checked);
97
98     /**
99      * Get the service locator scope in which this UI element resides. May not
100      * be <code>null</code>.
101      *
102      * <p>
103      * The locator may be used to obtain services that are scoped in the same
104      * way as the {@link UIElement}. Such services include but are not limited
105      * to {@link IWorkbench}, {@link IWorkbenchWindow}, and
106      * {@link IWorkbenchPartSite}. While this method may not return
107      * <code>null</code> requests for any of these particular services may
108      * return <code>null</code>.
109      * </p>
110      *
111      * @return the service locator for this element
112      * @see IServiceLocator#getService(Class)
113      */

114     public final IServiceLocator getServiceLocator() {
115         return serviceLocator;
116     }
117
118     /**
119      * Set the menu contribution id to use. This is only applicable to menu
120      * contributions that support a drop-down style menu. The default
121      * implementation does nothing.
122      * <p>
123      * Example: element.setDropdownId("org.eclipse.ui.navigate.back.my.menu");
124      * </p>
125      *
126      * @param id
127      * used to populate the dropdown menu. Must not be
128      * <code>null</code>.
129      */

130     public void setDropDownId(String JavaDoc id) {
131         // This does nothing.
132
}
133 }
134
Popular Tags