KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > navigator > CommonActionProvider


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.navigator;
12
13 import org.eclipse.ui.IActionBars;
14 import org.eclipse.ui.IMemento;
15 import org.eclipse.ui.actions.ActionGroup;
16
17 /**
18  * <p>
19  * Provides actions from extensions for menu and
20  * {@link org.eclipse.ui.IActionBars} contributions.
21  * </p>
22  * <p>
23  * This abstract class should be extended by clients of the
24  * <b>org.eclipse.ui.navigator.navigatorContent</b> extension point for
25  * top-level and nested <b>actionProvider </b> elements.
26  * </p>
27  * <p>
28  * {@link CommonActionProvider}s may be declared as top-level elements in the
29  * extension point (e.g. an <b>actionProvider</b> element at the root of the
30  * extension point). Alternatively, <b>actionProvider</b> elements may be
31  * nested under a <b>navigatorContent</b> element, in which case they are
32  * considered to be "associated" with that content extension. For more
33  * information, see the <b>org.eclipse.ui.navigator.navigatorContent</b>
34  * extension point.
35  * </p>
36  * <p>
37  * Each action provider will have the opportunity to contribute to the context
38  * menu when a user right clicks and also contribute to the {@link IActionBars}
39  * each time the selection changes. Clients should re-configure the
40  * {@link IActionBars} each time that {@link #fillActionBars(IActionBars)} is
41  * called (which is once per selection changes). {@link #updateActionBars()}
42  * will never be called from the {@link NavigatorActionService}. This behavior
43  * is required since each selection could determine a different set of
44  * retargetable actions. For instance, the "Delete" operation for a custom model
45  * element is likely to be different than for a resource.
46  * </p>
47  * <p>
48  * Therefore, each extension will have an opportunity to contribute to the
49  * IActionBars based on the <b>possibleChildren</b> expression of the enclosing
50  * <b>navigatorContent</b> extension or the <b>enablement</b> expression of
51  * the <b>actionProvider</b> (for both top-level <b>actionProvider</b>s and
52  * nested <b>actionProvider</b>s which only support a subset of the enclosing
53  * content extensions <b>possibleChildren</b> expression).
54  * <p>
55  * Clients may extend this class.
56  * </p>
57  *
58  * @since 3.2
59  */

60 public abstract class CommonActionProvider extends ActionGroup implements
61         IMementoAware {
62
63     private ICommonActionExtensionSite actionSite;
64
65     /**
66      * <p>
67      * Initialize the current ICommonActionProvider with the supplied
68      * information.
69      * </p>
70      * <p>
71      * init() is guaranteed to be called before any other method of the
72      * ActionGroup super class.
73      *
74      * @param aSite
75      * The configuration information for the instantiated Common
76      * Action Provider.
77      */

78     public void init(ICommonActionExtensionSite aSite) {
79         actionSite = aSite;
80     }
81
82     /**
83      * <p>
84      * Restore the previous state of any actions using the flags in aMemento.
85      * This method allows the state of any actions that persist from session to
86      * session to be restored.
87      * </p>
88      *
89      * <p>
90      * The default behavior is to do nothing.
91      * </p>
92      *
93      * @param aMemento
94      * A memento that was given to the view part to restore its
95      * state.
96      */

97     public void restoreState(IMemento aMemento) {
98     }
99
100     /**
101      * <p>
102      * Save flags in aMemento to remember the state of any actions that persist
103      * from session to session.
104      * </p>
105      * <p>
106      * Extensions should qualify any keys stored in the memento with their
107      * plugin id
108      * </p>
109      *
110      * <p>
111      * The default behavior is to do nothing.
112      * </p>
113      *
114      * @param aMemento
115      * A memento that was given to the view part to save its state.
116      */

117     public void saveState(IMemento aMemento) {
118     }
119
120     /**
121      *
122      * @return The cached reference to the action site. Will only be non-null if
123      * the subclass calls super.init() first.
124      */

125     protected final ICommonActionExtensionSite getActionSite() {
126         return actionSite;
127     }
128
129 }
130
Popular Tags