KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > FilterDropDownMenuCreator


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.launchConfigurations;
12
13 import org.eclipse.debug.internal.ui.DebugUIPlugin;
14 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
15 import org.eclipse.debug.internal.ui.SWTFactory;
16 import org.eclipse.jface.action.Action;
17 import org.eclipse.jface.action.ActionContributionItem;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.action.IMenuCreator;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Menu;
24 import org.eclipse.swt.widgets.MenuItem;
25
26 /**
27  * Creates the drop down menu for the filtering button in the launch configuration dialog
28  * @since 3.2
29  */

30 public class FilterDropDownMenuCreator implements IMenuCreator {
31
32     /**
33      * Provides wrapper action for filtering actions on the launch configuration dialog
34      * @since 3.2
35      */

36     class FilterAction extends Action {
37         
38         /** The preference store. */
39         private IPreferenceStore fStore = null;
40
41         /** The preference key for the value in the store. */
42         private String JavaDoc fKey = null;
43         
44         /**
45          * Constructor for check style menu items
46          * @param store the pref store
47          * @param name the name of the action
48          * @param key the pref key it is tied to
49          */

50         public FilterAction(Menu menu, IPreferenceStore store, String JavaDoc name, String JavaDoc key) {
51             super(name, IAction.AS_CHECK_BOX);
52             fStore = store;
53             fKey = key;
54             setChecked(fStore.getBoolean(fKey));
55             fillIntoMenu(menu, this);
56         }
57         
58         /**
59          * Constructor for flyout menu style actions
60          * @param menu the parent menu
61          * @param name the text of the action
62          * @param creator the menu creator for this action
63          */

64         public FilterAction(Menu menu, String JavaDoc name, IMenuCreator creator) {
65             super(name, IAction.AS_DROP_DOWN_MENU);
66             setMenuCreator(creator);
67             fillIntoMenu(menu, this);
68         }
69         
70         /**
71          * fills the new action into the specified menu
72          * @param menu the parent menu
73          * @param action the new aciton to fill in to the parent
74          */

75         private void fillIntoMenu(Menu menu, IAction action) {
76             ActionContributionItem item = new ActionContributionItem(action);
77             item.fill(menu, -1);
78         }
79         
80         /* (non-Javadoc)
81          * @see org.eclipse.jface.action.Action#run()
82          */

83         public void run() {
84             if(fStore != null) {
85                 fStore.setValue(fKey, isChecked());
86             }
87         }
88     }
89     
90     /**
91      * the menu created via this class
92      */

93     private Menu fCreatedMenu = null;
94
95     /**
96      * gets the DebugUIPlugin preference store
97      * @return the pref store
98      */

99     private IPreferenceStore getDebugPrefStore() {
100         return DebugUIPlugin.getDefault().getPreferenceStore();
101     }
102     
103     /* (non-Javadoc)
104      * @see org.eclipse.jface.action.IMenuCreator#dispose()
105      */

106     public void dispose() {
107         fCreatedMenu = null;
108     }
109
110     /* (non-Javadoc)
111      * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
112      */

113     public Menu getMenu(Control parent) {
114         if(fCreatedMenu != null) {
115             fCreatedMenu.dispose();
116         }
117         //create the menu & items
118
fCreatedMenu = new Menu(parent);
119         new FilterAction(fCreatedMenu, getDebugPrefStore(), LaunchConfigurationsMessages.FilterDropDownMenuCreator_0, IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED);
120         new FilterAction(fCreatedMenu, getDebugPrefStore(), LaunchConfigurationsMessages.FilterDropDownMenuCreator_1, IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED);
121         new FilterAction(fCreatedMenu, getDebugPrefStore(), LaunchConfigurationsMessages.FilterDropDownMenuCreator_2, IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES);
122         new FilterAction(fCreatedMenu, getDebugPrefStore(), LaunchConfigurationsMessages.FilterDropDownMenuCreator_4, IInternalDebugUIConstants.PREF_FILTER_WORKING_SETS);
123         
124         //add separator
125
new MenuItem(fCreatedMenu, SWT.SEPARATOR);
126     
127         //add pref action
128
IAction action = new Action(LaunchConfigurationsMessages.FilterDropDownMenuCreator_3) {
129             public void run() {
130                 SWTFactory.showPreferencePage("org.eclipse.debug.ui.LaunchConfigurations"); //$NON-NLS-1$
131
}
132         };
133         new ActionContributionItem(action).fill(fCreatedMenu, -1);
134         return fCreatedMenu;
135     }
136     
137     /* (non-Javadoc)
138      * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
139      */

140     public Menu getMenu(Menu parent) {
141         return fCreatedMenu;
142     }
143 }
144
Popular Tags