KickJava   Java API By Example, From Geeks To Geeks.

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


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.jdt.internal.debug.ui.DebugUIMessages;
15 import org.eclipse.jdt.internal.debug.ui.IJDIPreferencesConstants;
16 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds;
17 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
18 import org.eclipse.jface.dialogs.Dialog;
19 import org.eclipse.jface.preference.IPreferenceStore;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Control;
24 import org.eclipse.swt.widgets.Shell;
25 import org.eclipse.ui.PlatformUI;
26
27 /**
28  * Dialog to alter primitive display options for a specific view
29  */

30 public class PrimitiveOptionsDialog extends Dialog {
31
32     private Button fHexButton;
33     private Button fCharButton;
34     private Button fUnsignedButton;
35     // preference prefix
36
private String JavaDoc fPrefix;
37     
38     public PrimitiveOptionsDialog(Shell parentShell, String JavaDoc prefix) {
39         super(parentShell);
40         fPrefix = prefix;
41     }
42     
43     /* (non-Javadoc)
44      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
45      */

46     protected Control createDialogArea(Composite parent) {
47         PlatformUI.getWorkbench().getHelpSystem().setHelp(
48             parent,
49             IJavaDebugHelpContextIds.PRIMITIVE_DISPLAY_OPTIONS_DIALOG);
50         
51         getShell().setText(ActionMessages.PrimitiveOptionsDialog_Primitive_Type_Display_Options_1); //$NON-NLS-1$
52
Composite composite = (Composite)super.createDialogArea(parent);
53         
54         // Create the 3 primitive display checkboxes
55
fHexButton = new Button(composite, SWT.CHECK);
56         fHexButton.setText(DebugUIMessages.JavaDebugPreferencePage_Display__hexadecimal_values__byte__short__char__int__long__3); //$NON-NLS-1$
57
fHexButton.setSelection(getBooleanPreferenceValue(fPrefix, IJDIPreferencesConstants.PREF_SHOW_HEX));
58         fCharButton = new Button(composite, SWT.CHECK);
59         fCharButton.setText(DebugUIMessages.JavaDebugPreferencePage_Display_ASCII__character_values__byte__short__int__long__4); //$NON-NLS-1$
60
fCharButton.setSelection(getBooleanPreferenceValue(fPrefix, IJDIPreferencesConstants.PREF_SHOW_CHAR));
61         fUnsignedButton = new Button(composite, SWT.CHECK);
62         fUnsignedButton.setText(DebugUIMessages.JavaDebugPreferencePage_Display__unsigned_values__byte__5); //$NON-NLS-1$
63
fUnsignedButton.setSelection(getBooleanPreferenceValue(fPrefix, IJDIPreferencesConstants.PREF_SHOW_UNSIGNED));
64         applyDialogFont(composite);
65         return composite;
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
70      */

71     protected void okPressed() {
72         IPreferenceStore store = JDIDebugUIPlugin.getDefault().getPreferenceStore();
73         store.setValue(fPrefix + "." + IJDIPreferencesConstants.PREF_SHOW_HEX, fHexButton.getSelection()); //$NON-NLS-1$
74
store.setValue(fPrefix + "." + IJDIPreferencesConstants.PREF_SHOW_CHAR, fCharButton.getSelection()); //$NON-NLS-1$
75
store.setValue(fPrefix + "." + IJDIPreferencesConstants.PREF_SHOW_UNSIGNED, fUnsignedButton.getSelection()); //$NON-NLS-1$
76
super.okPressed();
77     }
78     
79     /**
80      * Returns the value of this filters preference (on/off) for the given
81      * view.
82      *
83      * @param part
84      * @return boolean
85      */

86     public static boolean getBooleanPreferenceValue(String JavaDoc id, String JavaDoc preference) {
87         String JavaDoc compositeKey = id + "." + preference; //$NON-NLS-1$
88
IPreferenceStore store = JDIDebugUIPlugin.getDefault().getPreferenceStore();
89         boolean value = false;
90         if (store.contains(compositeKey)) {
91             value = store.getBoolean(compositeKey);
92         } else {
93             value = store.getBoolean(preference);
94         }
95         return value;
96     }
97 }
98
Popular Tags