KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > renderings > TableRenderingPreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2005, 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
12 package org.eclipse.debug.internal.ui.views.memory.renderings;
13
14 import org.eclipse.debug.internal.ui.DebugUIMessages;
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.SWTFactory;
17 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.jface.preference.FieldEditor;
20 import org.eclipse.jface.preference.IPreferenceStore;
21 import org.eclipse.jface.preference.IntegerFieldEditor;
22 import org.eclipse.jface.preference.PreferencePage;
23 import org.eclipse.jface.util.IPropertyChangeListener;
24 import org.eclipse.jface.util.PropertyChangeEvent;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.events.SelectionListener;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Group;
34 import org.eclipse.ui.PlatformUI;
35
36 public class TableRenderingPreferencePage extends PreferencePage implements
37     IPropertyChangeListener, SelectionListener{
38
39     private Button fAuto;
40     private Button fManual;
41     private IntegerFieldEditor fPreBufferSize;
42     private IntegerFieldEditor fPostBufferSize;
43     private IntegerFieldEditor fPageSize;
44     private Group fGroup;
45     private Composite fComposite;
46     
47     
48     public TableRenderingPreferencePage(String JavaDoc title) {
49         super(title);
50     }
51
52     protected Control createContents(Composite parent) {
53
54         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IDebugUIConstants.PLUGIN_ID + ".table_renderings_preference_page_context"); //$NON-NLS-1$
55

56         fComposite = new Composite(parent, SWT.NONE);
57         fComposite.setLayout(new GridLayout());
58         GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
59         fComposite.setLayoutData(data);
60
61         GridData hspanData = new GridData(SWT.FILL, SWT.FILL, true, false);
62         hspanData.horizontalSpan = 2;
63         
64         SWTFactory.createWrapLabel(fComposite, DebugUIMessages.TableRenderingPreferencePage_10, 2, 300);
65         
66         fAuto = new Button(fComposite, SWT.RADIO);
67         fAuto.setText(DebugUIMessages.TableRenderingPreferencePage_0);
68         fAuto.setLayoutData(hspanData);
69         
70         fGroup = new Group(fComposite, SWT.NONE);
71         fGroup.setText(DebugUIMessages.TableRenderingPreferencePage_5);
72         GridData groupData = new GridData(SWT.FILL, SWT.FILL, true, false);
73         groupData.horizontalSpan = 2;
74         fGroup.setLayoutData(groupData);
75         fPreBufferSize = new IntegerFieldEditor(IDebugPreferenceConstants.PREF_TABLE_RENDERING_PRE_BUFFER_SIZE, DebugUIMessages.TableRenderingPreferencePage_6, fGroup);
76         fPreBufferSize.setPreferenceStore(getPreferenceStore());
77         fPreBufferSize.load();
78         fPostBufferSize = new IntegerFieldEditor(IDebugPreferenceConstants.PREF_TABLE_RENDERING_POST_BUFFER_SIZE, DebugUIMessages.TableRenderingPreferencePage_7, fGroup);
79         fPostBufferSize.setPreferenceStore(getPreferenceStore());
80         fPostBufferSize.load();
81         
82         fManual = new Button(fComposite, SWT.RADIO);
83         fManual.setText(DebugUIMessages.TableRenderingPreferencePage_8);
84         fManual.setLayoutData(hspanData);
85         
86         fPageSize = new IntegerFieldEditor(IDebugPreferenceConstants.PREF_TABLE_RENDERING_PAGE_SIZE, DebugUIMessages.TableRenderingPreferencePage_2, fComposite);
87         fPageSize.setPreferenceStore(getPreferenceStore());
88         fPageSize.load();
89         
90         fPreBufferSize.setPropertyChangeListener(this);
91         fPostBufferSize.setPropertyChangeListener(this);
92         fPageSize.setPropertyChangeListener(this);
93         
94         fAuto.addSelectionListener(this);
95         fManual.addSelectionListener(this);
96         
97         loadLoadingModeFromPreference();
98         updateTextEditorsEnablement();
99         
100         return fComposite;
101     }
102
103     /**
104      *
105      */

106     private void loadLoadingModeFromPreference() {
107         boolean isAuto = getPreferenceStore().getBoolean(IDebugPreferenceConstants.PREF_DYNAMIC_LOAD_MEM);
108         fAuto.setSelection(isAuto);
109         fManual.setSelection(!isAuto);
110     }
111
112     public void propertyChange(PropertyChangeEvent event) {
113         if (event.getProperty().equals(FieldEditor.VALUE))
114         {
115             if (event.getSource().equals(fPageSize) ||
116                 event.getSource().equals(fPostBufferSize) ||
117                 event.getSource().equals(fPreBufferSize))
118             {
119                 validatePageSize();
120             }
121         }
122         
123     }
124     
125     private void validatePageSize() {
126         boolean autoLoad = fAuto.getSelection();
127         try {
128             int bufferSize = fPageSize.getIntValue();
129             int preBuffer = fPreBufferSize.getIntValue();
130             int postBuffer = fPostBufferSize.getIntValue();
131             if (!autoLoad && bufferSize < 1)
132             {
133                 setValid(false);
134                 setErrorMessage(DebugUIMessages.TableRenderingPreferencePage_3);
135             }
136             else if (autoLoad)
137             {
138                 // For auto load mode, we must have have > 1 buffer size
139
// otherwise, the rendering cannot be loaded dynamically
140

141                 if (preBuffer < 1 || postBuffer < 1)
142                 {
143                     setValid(false);
144                     setErrorMessage(DebugUIMessages.TableRenderingPreferencePage_9);
145                 }
146                 else
147                 {
148                     setValid(true);
149                     setErrorMessage(null);
150                 }
151             }
152             else
153             {
154                 setValid(true);
155                 setErrorMessage(null);
156                 
157             }
158         } catch (NumberFormatException JavaDoc e) {
159                 setValid(false);
160                 setErrorMessage(DebugUIMessages.TableRenderingPreferencePage_4);
161         }
162     }
163     
164     protected IPreferenceStore doGetPreferenceStore() {
165         return DebugUIPlugin.getDefault().getPreferenceStore();
166     }
167     
168     public void dispose() {
169         fAuto.removeSelectionListener(this);
170         fManual.removeSelectionListener(this);
171         fPageSize.setPropertyChangeListener(null);
172         fPreBufferSize.setPropertyChangeListener(null);
173         fPostBufferSize.setPropertyChangeListener(null);
174         super.dispose();
175     }
176
177     public void widgetDefaultSelected(SelectionEvent e) {
178         // do nothing
179
}
180
181     public void widgetSelected(SelectionEvent e) {
182         updateTextEditorsEnablement();
183     }
184     
185     public boolean performOk() {
186         boolean auto = fAuto.getSelection();
187         boolean currentValue = getPreferenceStore().getBoolean(IDebugPreferenceConstants.PREF_DYNAMIC_LOAD_MEM);
188         if (auto != currentValue)
189             getPreferenceStore().setValue(IDebugPreferenceConstants.PREF_DYNAMIC_LOAD_MEM, auto);
190         
191         fPageSize.store();
192         fPreBufferSize.store();
193         fPostBufferSize.store();
194         return super.performOk();
195     }
196     
197     protected void performDefaults() {
198         
199         boolean auto = getPreferenceStore().getDefaultBoolean(IDebugPreferenceConstants.PREF_DYNAMIC_LOAD_MEM);
200         fAuto.setSelection(auto);
201         fManual.setSelection(!auto);
202         updateTextEditorsEnablement();
203         
204         fPageSize.loadDefault();
205         fPreBufferSize.loadDefault();
206         fPostBufferSize.loadDefault();
207         super.performDefaults();
208     }
209
210     /**
211      *
212      */

213     private void updateTextEditorsEnablement() {
214         boolean auto = fAuto.getSelection();
215         fPreBufferSize.setEnabled(auto, fGroup);
216         fPostBufferSize.setEnabled(auto, fGroup);
217         fPageSize.setEnabled(!auto, fComposite);
218     }
219 }
220
Popular Tags