KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import java.util.Iterator JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.action.ActionContributionItem;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.action.IMenuCreator;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Menu;
24 import org.eclipse.ui.PlatformUI;
25
26 /**
27  * Drop down action that displays the available detail panes for a selection.
28  *
29  * @since 3.3
30  * @see IDetailPaneContainer
31  */

32 public class AvailableDetailPanesAction extends Action implements IMenuCreator {
33     
34     private Menu fMenu;
35     private Set JavaDoc fAvailableIDs;
36     private IDetailPaneContainer fDetailPaneContainer;
37     
38     /**
39      * Each entry in the menu will be of this type. It represents one possible detail pane
40      * that the user can select. If the user selects it, the display is changed to use that
41      * detail pane and the preferred detail pane map in the pane manager is updated.
42      *
43      * @see DetailPaneManager
44      * @since 3.3
45      */

46     private class SetDetailPaneAction extends Action {
47         
48         private String JavaDoc fPaneID;
49         private Set JavaDoc fPossiblePaneIDs;
50         
51         public SetDetailPaneAction(String JavaDoc name, String JavaDoc paneID, Set JavaDoc possiblePaneIDs){
52             super(name,AS_RADIO_BUTTON);
53             fPaneID = paneID;
54             fPossiblePaneIDs = possiblePaneIDs;
55         }
56         
57         public void run() {
58             // Don't change panes unless the user is selecting a different pane than the one currently displayed
59
if (isChecked() && !fDetailPaneContainer.getCurrentPaneID().equals(fPaneID)){
60                 DetailPaneManager.getDefault().setPreferredDetailPane(fPossiblePaneIDs, fPaneID);
61                 fDetailPaneContainer.refreshDetailPaneContents();
62             }
63         }
64             
65     }
66     
67     public AvailableDetailPanesAction(IDetailPaneContainer detailPaneContainer) {
68         fDetailPaneContainer = detailPaneContainer;
69         setText(DetailMessages.AvailableDetailPanesAction_0);
70         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.VARIABLES_SELECT_DETAIL_PANE);
71         
72         setEnabled(false);
73         setMenuCreator(this);
74         init();
75     }
76     
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.action.IAction#run()
79      */

80     public void run() {
81     }
82     
83     /* (non-Javadoc)
84      * @see org.eclipse.jface.action.IMenuCreator#dispose()
85      */

86     public void dispose() {
87         if (fMenu != null) {
88             fMenu.dispose();
89         }
90         fAvailableIDs.clear();
91     }
92     
93     /* (non-Javadoc)
94      * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
95      */

96     public Menu getMenu(Control parent) {
97         return null;
98     }
99     
100     protected void addActionToMenu(Menu parent, IAction action) {
101         ActionContributionItem item= new ActionContributionItem(action);
102         item.fill(parent, -1);
103     }
104     
105     /* (non-Javadoc)
106      * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
107      */

108     public Menu getMenu(Menu parent) {
109         if (fMenu != null) {
110             fMenu.dispose();
111         }
112         
113         fMenu= new Menu(parent);
114         
115         Iterator JavaDoc iter = fAvailableIDs.iterator();
116         int i = 0;
117         while (iter.hasNext()) {
118             String JavaDoc currentID = (String JavaDoc) iter.next();
119             
120             StringBuffer JavaDoc name = new StringBuffer JavaDoc();
121             //add the numerical accelerator
122
i++;
123             if (i < 9) {
124                 name.append('&');
125                 name.append(i);
126                 name.append(' ');
127             }
128             
129             String JavaDoc typeName = DetailPaneManager.getDefault().getNameFromID(currentID);
130             if (typeName != null && typeName.length() > 0){
131                 name.append(typeName);
132             } else {
133                 name.append(currentID);
134             }
135                     
136             IAction action = new SetDetailPaneAction(name.toString(),currentID,fAvailableIDs);
137             
138             if (currentID.equals(fDetailPaneContainer.getCurrentPaneID())){
139                 action.setChecked(true);
140             }
141             
142             addActionToMenu(fMenu, action);
143         }
144         
145         return fMenu;
146     }
147     
148     /* (non-Javadoc)
149      * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
150      */

151     public void init() {
152         fAvailableIDs = DetailPaneManager.getDefault().getAvailablePaneIDs(fDetailPaneContainer.getCurrentSelection());
153         if (fAvailableIDs.size() > 1){
154             setEnabled(true);
155         }
156     }
157 }
158
Popular Tags