KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.action.IContributionItem;
15 import org.eclipse.ui.services.IServiceLocator;
16
17 /**
18  * ContributionFactories are used by the IMenuService to populate
19  * ContributionManagers. In {@link #createContributionItems(IServiceLocator, IContributionRoot)}
20  * you fill in the additions List with {@link IContributionItem} to be inserted at this
21  * factory's location. For example:
22  * <p>
23  *
24  * <pre>
25  * AbstractContributionFactory contributions = new AbstractContributionFactory(
26  * &quot;menu:org.eclipse.ui.tests.api.MenuTestHarness?after=additions&quot;) {
27  * public void createContributionItems(IMenuService menuService, List additions) {
28  * CommandContributionItem item = new CommandContributionItem(
29  * &quot;org.eclipse.ui.tests.menus.helloWorld&quot;,
30  * &quot;org.eclipse.ui.tests.commands.enabledHelloWorld&quot;, null, null,
31  * &quot;Say Hello&quot;, null);
32  * additions.add(item);
33  * item = new CommandContributionItem(
34  * &quot;org.eclipse.ui.tests.menus.refresh&quot;,
35  * &quot;org.eclipse.ui.tests.commands.refreshView&quot;, null, null,
36  * &quot;Refresh&quot;, null);
37  * menuService.registerVisibleWhen(item, new MyActiveContextExpression(
38  * &quot;org.eclipse.ui.tests.myview.context&quot;));
39  * additions.add(item);
40  * }
41  *
42  * public void releaseContributionItems(IMenuService menuService, List items) {
43  * // we have nothing to do
44  * }
45  * };
46  * IMenuService service = (IMenuService) PlatformUI.getWorkbench().getService(
47  * IMenuService.class);
48  * service.addContributionFactory(contributions);
49  * </pre>
50  *
51  * </p>
52  * <p>
53  * Only the abstract methods may be implemented.
54  * </p>
55  *
56  * @since 3.3
57  * @see org.eclipse.ui.menus.IMenuService
58  * @see org.eclipse.jface.action.MenuManager
59  * @see org.eclipse.jface.action.ToolBarManager
60  */

61 public abstract class AbstractContributionFactory {
62     private String JavaDoc location = null;
63     private String JavaDoc namespace;
64
65     /**
66      * The contribution factories must be instantiated with their location,
67      * which which specifies the contributions insertion location.
68      *
69      * @param location
70      * the addition location in Menu API URI format. It must not be
71      * <code>null</code>.
72      * @param namespace
73      * the namespace for this contribution. May be <code>null</code>.
74      * @see #getNamespace()
75      */

76     public AbstractContributionFactory(String JavaDoc location, String JavaDoc namespace) {
77         this.location = location;
78         this.namespace = namespace;
79     }
80
81     /**
82      * Return the location as a String.
83      *
84      * @return the location - never <code>null</code>.
85      */

86     public String JavaDoc getLocation() {
87         return location;
88     }
89
90     /**
91      * This factory should create the IContributionItems that it wants to
92      * contribute, and add them to the additions list. The menu service will
93      * call this method at the appropriate time. It should always return new
94      * instances of its contributions in the additions list.
95      * <p>
96      * This method is not meant to be called by clients. It will be called by
97      * the menu service at the appropriate time.
98      * </p>
99      *
100      * @param serviceLocator
101      * a service locator that may be used in the construction of
102      * items created by this factory
103      * @param additions
104      * A {@link IContributionRoot} supplied by the framework. It will
105      * never be <code>null</code>.
106      * @see org.eclipse.ui.menus.CommandContributionItem
107      * @see org.eclipse.jface.action.MenuManager
108      */

109     public abstract void createContributionItems(IServiceLocator serviceLocator,
110             IContributionRoot additions);
111
112     /**
113      * Return the namespace for this cache. This corresponds to the plug-in that
114      * is contributing this factory.
115      *
116      * @return the namespace the namespace of this factory
117      */

118     public String JavaDoc getNamespace() {
119         return namespace;
120     }
121 }
122
Popular Tags