KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > actions > ContributionItemFactory


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 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 package org.eclipse.ui.actions;
12
13 import org.eclipse.jface.action.IContributionItem;
14 import org.eclipse.ui.IWorkbenchWindow;
15 import org.eclipse.ui.internal.ChangeToPerspectiveMenu;
16 import org.eclipse.ui.internal.PinEditorAction;
17 import org.eclipse.ui.internal.ReopenEditorMenu;
18 import org.eclipse.ui.internal.ShowInMenu;
19 import org.eclipse.ui.internal.ShowViewMenu;
20 import org.eclipse.ui.internal.SwitchToWindowMenu;
21 import org.eclipse.ui.internal.actions.HelpSearchContributionItem;
22 import org.eclipse.ui.internal.actions.PinEditorContributionItem;
23
24 /**
25  * Access to standard contribution items provided by the workbench.
26  * <p>
27  * Most of the functionality of this class is provided by
28  * static methods and fields.
29  * Example usage:
30  * <pre>
31  * MenuManager menu = ...;
32  * IContributionItem reEdit
33  * = ContributionItemFactory.REOPEN_EDITORS.create(window);
34  * menu.add(reEdit);
35  * </pre>
36  * </p>
37  * <p>
38  * Clients may declare subclasses that provide additional application-specific
39  * contribution item factories.
40  * </p>
41  *
42  * @since 3.0
43  */

44 public abstract class ContributionItemFactory {
45
46     /**
47      * Id of contribution items created by this factory.
48      */

49     private final String JavaDoc contributionItemId;
50
51     /**
52      * Creates a new workbench contribution item factory with the given id.
53      *
54      * @param contributionItemId the id of contribution items created by this factory
55      */

56     protected ContributionItemFactory(String JavaDoc contributionItemId) {
57         this.contributionItemId = contributionItemId;
58     }
59
60     /**
61      * Creates a new standard contribution item for the given workbench window.
62      * <p>
63      * A typical contribution item automatically registers listeners against the
64      * workbench window so that it can keep its enablement state up to date.
65      * Ordinarily, the window's references to these listeners will be dropped
66      * automatically when the window closes. However, if the client needs to get
67      * rid of a contribution item while the window is still open, the client must
68      * call IContributionItem#dispose to give the item an
69      * opportunity to deregister its listeners and to perform any other cleanup.
70      * </p>
71      *
72      * @param window the workbench window
73      * @return the workbench contribution item
74      */

75     public abstract IContributionItem create(IWorkbenchWindow window);
76
77     /**
78      * Returns the id of this contribution item factory.
79      *
80      * @return the id of contribution items created by this factory
81      */

82     public String JavaDoc getId() {
83         return contributionItemId;
84     }
85
86     /**
87      * Workbench action (id "pinEditor"): Toggle whether the editor is pinned.
88      * This action maintains its enablement state.
89      */

90     public static final ContributionItemFactory PIN_EDITOR = new ContributionItemFactory(
91             "pinEditor") { //$NON-NLS-1$
92
/* (non-javadoc) method declared on ContributionItemFactory */
93         public IContributionItem create(IWorkbenchWindow window) {
94             if (window == null) {
95                 throw new IllegalArgumentException JavaDoc();
96             }
97             PinEditorAction action = new PinEditorAction(window);
98             action.setId(getId());
99             return new PinEditorContributionItem(action, window);
100         }
101     };
102
103     /**
104      * Workbench contribution item (id "openWindows"): A list of windows
105      * currently open in the workbench. Selecting one of the items makes the
106      * corresponding window the active window.
107      * This action dynamically maintains the list of windows.
108      */

109     public static final ContributionItemFactory OPEN_WINDOWS = new ContributionItemFactory(
110             "openWindows") { //$NON-NLS-1$
111
/* (non-javadoc) method declared on ContributionItemFactory */
112         public IContributionItem create(IWorkbenchWindow window) {
113             if (window == null) {
114                 throw new IllegalArgumentException JavaDoc();
115             }
116             return new SwitchToWindowMenu(window, getId(), true);
117         }
118     };
119
120     /**
121      * Workbench contribution item (id "viewsShortlist"): A list of views
122      * available to be opened in the window, arranged as a shortlist of
123      * promising views and an "Other" subitem. Selecting
124      * one of the items opens the corresponding view in the active window.
125      * This action dynamically maintains the view shortlist.
126      */

127     public static final ContributionItemFactory VIEWS_SHORTLIST = new ContributionItemFactory(
128             "viewsShortlist") { //$NON-NLS-1$
129
/* (non-javadoc) method declared on ContributionItemFactory */
130         public IContributionItem create(IWorkbenchWindow window) {
131             if (window == null) {
132                 throw new IllegalArgumentException JavaDoc();
133             }
134             return new ShowViewMenu(window, getId());
135         }
136     };
137
138     /**
139      * Workbench contribution item (id "viewsShowIn"): A list of views
140      * available to be opened in the window, arranged as a list of
141      * alternate views to show the same item currently selected. Selecting
142      * one of the items opens the corresponding view in the active window.
143      * This action dynamically maintains the view list.
144      */

145     public static final ContributionItemFactory VIEWS_SHOW_IN = new ContributionItemFactory(
146             "viewsShowIn") { //$NON-NLS-1$
147
/* (non-javadoc) method declared on ContributionItemFactory */
148         public IContributionItem create(IWorkbenchWindow window) {
149             if (window == null) {
150                 throw new IllegalArgumentException JavaDoc();
151             }
152             return new ShowInMenu(window, getId());
153         }
154     };
155
156     /**
157      * Workbench contribution item (id "reopenEditors"): A list of recent
158      * editors (with inputs) available to be reopened in the window. Selecting
159      * one of the items reopens the corresponding editor on its input in the
160      * active window. This action dynamically maintains the list of editors.
161      */

162     public static final ContributionItemFactory REOPEN_EDITORS = new ContributionItemFactory(
163             "reopenEditors") { //$NON-NLS-1$
164
/* (non-javadoc) method declared on ContributionItemFactory */
165         public IContributionItem create(IWorkbenchWindow window) {
166             if (window == null) {
167                 throw new IllegalArgumentException JavaDoc();
168             }
169             return new ReopenEditorMenu(window, getId(), true);
170         }
171     };
172
173     /**
174      * Workbench contribution item (id "perspectivesShortlist"): A list of
175      * perspectives available to be opened, arranged as a shortlist of
176      * promising perspectives and an "Other" subitem. Selecting
177      * one of the items makes the corresponding perspective active. Should a
178      * new perspective need to be opened, a workbench user preference controls
179      * whether the prespective is opened in the active window or a new window.
180      * This action dynamically maintains the perspectives shortlist.
181      */

182     public static final ContributionItemFactory PERSPECTIVES_SHORTLIST = new ContributionItemFactory(
183             "perspectivesShortlist") { //$NON-NLS-1$
184
/* (non-javadoc) method declared on ContributionItemFactory */
185         public IContributionItem create(IWorkbenchWindow window) {
186             if (window == null) {
187                 throw new IllegalArgumentException JavaDoc();
188             }
189             return new ChangeToPerspectiveMenu(window, getId());
190         }
191     };
192     
193     /**
194      * Workbench contribution item (id "newWizardShortlist"): A list of
195      * new item wizards available to be opened, arranged as a shortlist of
196      * promising new item wizards and an "Other" subitem. Selecting
197      * one of the items invokes the corresponding new item wizard.
198      * This action dynamically maintains the new item wizard shortlist.
199      * @since 3.1
200      */

201     public static final ContributionItemFactory NEW_WIZARD_SHORTLIST = new ContributionItemFactory(
202             "newWizardShortlist") { //$NON-NLS-1$
203
/* (non-javadoc) method declared on ContributionItemFactory */
204         public IContributionItem create(IWorkbenchWindow window) {
205             if (window == null) {
206                 throw new IllegalArgumentException JavaDoc();
207             }
208             return new BaseNewWizardMenu(window, getId());
209         }
210     };
211     
212     /**
213      * Workbench contribution item (id "helpSearch"): An editable field
214      * for entering help search queries.
215      * @since 3.1
216      */

217     public static final ContributionItemFactory HELP_SEARCH = new ContributionItemFactory(
218             "helpSearch") {//$NON-NLS-1$
219
public IContributionItem create(IWorkbenchWindow window) {
220             if (window == null) {
221                 throw new IllegalArgumentException JavaDoc();
222             }
223             return new HelpSearchContributionItem(window, getId());
224         }
225     };
226
227     
228 }
229
Popular Tags