KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > variables > details > AbstractDetailPane


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 package org.eclipse.debug.internal.ui.views.variables.details;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.debug.ui.IDetailPane;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.ui.IViewSite;
22 import org.eclipse.ui.IWorkbenchPartSite;
23 import org.eclipse.ui.texteditor.IUpdate;
24
25 /**
26  * Abstract class that holds common methods used by implementors of IDetailPane.
27  *
28  * @see DefaultDetailPane
29  * @since 3.3
30  */

31 public abstract class AbstractDetailPane implements IDetailPane {
32
33     /**
34      * The <code>IWorkbenchPartSite</code> that the details area (and the
35      * variables view) belongs to.
36      */

37     private IWorkbenchPartSite fWorkbenchPartSite;
38     
39     /**
40      * Map of actions. Keys are strings, values
41      * are <code>IAction</code>.
42      */

43     private Map JavaDoc fActionMap = new HashMap JavaDoc();
44     
45     /**
46      * Collection to track actions that should be updated when selection occurs.
47      */

48     private List JavaDoc fSelectionActions = new ArrayList JavaDoc();
49     
50     /* (non-Javadoc)
51      * @see org.eclipse.debug.ui.IDetailPane#init(org.eclipse.ui.IWorkbenchPartSite)
52      */

53     public void init(IWorkbenchPartSite workbench) {
54         fWorkbenchPartSite = workbench;
55
56     }
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.debug.ui.IDetailPane#dispose()
60      */

61     public void dispose() {
62         fActionMap.clear();
63         fSelectionActions.clear();
64     }
65
66     /**
67      * Adds an action to the Map storing actions. Removes it if action is null.
68      *
69      * @param actionID The ID of the action, used as the key in the Map
70      * @param action The action associated with the ID
71      */

72     protected void setAction(String JavaDoc actionID, IAction action) {
73         if (action == null) {
74             fActionMap.remove(actionID);
75         } else {
76             fActionMap.put(actionID, action);
77         }
78     }
79     
80     /**
81      * Adds the given action to the global action handler for the ViewSite.
82      * A call to <code>updateActionBars()</code> must be called after changes
83      * to propagate changes through the workbench.
84      *
85      * @param actionID The ID of the action
86      * @param action The action to be set globally
87      */

88     protected void setGlobalAction(String JavaDoc actionID, IAction action){
89         getViewSite().getActionBars().setGlobalActionHandler(actionID, action);
90     }
91     
92     /**
93      * Adds the given action to the list of actions that will be updated when
94      * <code>updateSelectionDependentActions()</code> is called. If the string
95      * is null it will not be added to the list.
96      *
97      * @param actionID The ID of the action which should be updated
98      */

99     protected void setSelectionDependantAction(String JavaDoc actionID){
100         if (actionID != null) fSelectionActions.add(actionID);
101     }
102     
103     /**
104      * Gets the action out of the map, casts it to an <code>IAction</code>
105      *
106      * @param actionID The ID of the action to find
107      * @return The action associated with the ID or null if none is found.
108      */

109     protected IAction getAction(String JavaDoc actionID) {
110         return (IAction) fActionMap.get(actionID);
111     }
112     
113     /**
114      * Calls the update method of the action with the given action ID.
115      * The action must exist in the action map and must be an instance of
116      * </code>IUpdate</code>
117      *
118      * @param actionId The ID of the action to update
119      */

120     protected void updateAction(String JavaDoc actionId) {
121         IAction action= getAction(actionId);
122         if (action instanceof IUpdate) {
123             ((IUpdate) action).update();
124         }
125     }
126     
127     /**
128      * Iterates through the list of selection dependent actions and
129      * updates them. Use <code>setSelectionDependentAction(String actionID)</code>
130      * to add an action to the list. The action must have been added to the known
131      * actions map by calling <code>setAction(String actionID, IAction action)</code>
132      * before it can be updated by this method.
133      */

134     protected void updateSelectionDependentActions() {
135         Iterator JavaDoc iterator= fSelectionActions.iterator();
136         while (iterator.hasNext()) {
137             updateAction((String JavaDoc)iterator.next());
138         }
139     }
140     
141     /**
142      * Gets the view site for this view. May be null if this detail pane
143      * is not part of a view.
144      *
145      * @return The site for this view or <code>null</code>
146      */

147     protected IViewSite getViewSite(){
148         if (fWorkbenchPartSite == null){
149             return null;
150         } else {
151             return (IViewSite) fWorkbenchPartSite.getPart().getSite();
152         }
153     }
154
155     /**
156      * Gets the workbench part site for this view. May be null if this detail pane
157      * is not part of a view.
158      *
159      * @return The workbench part site or <code>null</code>
160      */

161     protected IWorkbenchPartSite getWorkbenchPartSite() {
162         return fWorkbenchPartSite;
163     }
164     
165     /**
166      * Returns whether this detail pane is being displayed in a view with a workbench part site.
167      *
168      * @return whether this detail pane is being displayed in a view with a workbench part site.
169      */

170     protected boolean isInView(){
171         return fWorkbenchPartSite != null;
172     }
173
174 }
175
Popular Tags