KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > PrimitiveOptionsAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.debug.ui.actions;
12
13
14 import org.eclipse.debug.ui.IDebugModelPresentation;
15 import org.eclipse.debug.ui.IDebugView;
16 import org.eclipse.jdt.debug.core.JDIDebugModel;
17 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
18 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
19 import org.eclipse.jdt.internal.debug.ui.JDIModelPresentation;
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.jface.viewers.Viewer;
25 import org.eclipse.jface.window.Window;
26 import org.eclipse.swt.custom.BusyIndicator;
27 import org.eclipse.swt.widgets.Event;
28 import org.eclipse.ui.IActionDelegate2;
29 import org.eclipse.ui.IViewActionDelegate;
30 import org.eclipse.ui.IViewPart;
31 import org.eclipse.ui.IViewSite;
32
33 /**
34  * Allows setting of primitive display options for java variables
35  */

36 public class PrimitiveOptionsAction implements IViewActionDelegate, IActionDelegate2 {
37     
38     private static String JavaDoc[][] fgPreferenceInfo= new String JavaDoc[][] {
39         {IJDIPreferencesConstants.PREF_SHOW_HEX, JDIModelPresentation.SHOW_HEX_VALUES},
40         {IJDIPreferencesConstants.PREF_SHOW_CHAR, JDIModelPresentation.SHOW_CHAR_VALUES},
41         {IJDIPreferencesConstants.PREF_SHOW_UNSIGNED, JDIModelPresentation.SHOW_UNSIGNED_VALUES},
42     };
43
44     protected IViewPart fView;
45
46     /* (non-Javadoc)
47      * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
48      */

49     public void init(IViewPart view) {
50         fView = view;
51         applyPreferences();
52     }
53     
54     protected void applyPreferences() {
55         IDebugView view = (IDebugView)getView().getAdapter(IDebugView.class);
56         if (view != null) {
57             IDebugModelPresentation presentation = view.getPresentation(JDIDebugModel.getPluginIdentifier());
58             if (presentation != null) {
59                 for (int i = 0; i < fgPreferenceInfo.length; i++) {
60                     applyPreference(fgPreferenceInfo[i][0], fgPreferenceInfo[i][1], presentation);
61                 }
62             }
63         }
64     }
65     
66     protected void applyPreference(String JavaDoc preference, String JavaDoc attribute, IDebugModelPresentation presentation) {
67         boolean on = getBooleanPreferenceValue(getView().getSite().getId(), preference);
68         presentation.setAttribute(attribute, (on ? Boolean.TRUE : Boolean.FALSE));
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.jdt.internal.debug.ui.actions.AbstractDisplayOptionsAction#getDialog()
73      */

74     protected Dialog getDialog() {
75         IViewSite viewSite = getView().getViewSite();
76         return new PrimitiveOptionsDialog(viewSite.getShell(), viewSite.getId());
77     }
78     
79     protected IViewPart getView() {
80         return fView;
81     }
82
83     /* (non-Javadoc)
84      * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
85      */

86     public void runWithEvent(IAction action, Event event) {
87         run(action);
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
92      */

93     public void run(IAction action) {
94         // open dialog
95
int res = getDialog().open();
96         if (res == Window.OK) {
97             final Viewer viewer = getViewer();
98             BusyIndicator.showWhile(viewer.getControl().getDisplay(), new Runnable JavaDoc() {
99                 public void run() {
100                     applyPreferences();
101                     viewer.refresh();
102                     JDIDebugUIPlugin.getDefault().savePluginPreferences();
103                 }
104             });
105         }
106     }
107     
108     protected Viewer getViewer() {
109         IDebugView view = (IDebugView)getView().getAdapter(IDebugView.class);
110         if (view != null) {
111             return view.getViewer();
112         }
113         return null;
114     }
115     
116     /**
117      * Returns the value of this filters preference (on/off) for the given
118      * view.
119      *
120      * @param part
121      * @return boolean
122      */

123     public static boolean getBooleanPreferenceValue(String JavaDoc id, String JavaDoc preference) {
124         String JavaDoc compositeKey = id + "." + preference; //$NON-NLS-1$
125
IPreferenceStore store = JDIDebugUIPlugin.getDefault().getPreferenceStore();
126         boolean value = false;
127         if (store.contains(compositeKey)) {
128             value = store.getBoolean(compositeKey);
129         } else {
130             value = store.getBoolean(preference);
131         }
132         return value;
133     }
134     
135     /* (non-Javadoc)
136      * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
137      */

138     public void init(IAction action) {
139     }
140
141     /* (non-Javadoc)
142      * @see org.eclipse.ui.IActionDelegate2#dispose()
143      */

144     public void dispose() {
145     }
146
147     /* (non-Javadoc)
148      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
149      */

150     public void selectionChanged(IAction action, ISelection selection) {
151     }
152 }
153
Popular Tags