KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > MarkOccurrencesConfigurationBlock


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  * Sebastian Davids, sdavids@gmx.de - 187316 [preferences] Mark Occurences Pref Page; Link to
11  *******************************************************************************/

12
13 package org.eclipse.jdt.internal.ui.preferences;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.eclipse.core.runtime.Assert;
21 import org.eclipse.core.runtime.IStatus;
22
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionAdapter;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.events.SelectionListener;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Link;
34
35 import org.eclipse.ui.dialogs.PreferencesUtil;
36
37
38 import org.eclipse.jdt.ui.PreferenceConstants;
39
40 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
41 import org.eclipse.jdt.internal.ui.util.PixelConverter;
42
43 /**
44  * Configures Java Editor hover preferences.
45  *
46  * @since 2.1
47  */

48 class MarkOccurrencesConfigurationBlock implements IPreferenceConfigurationBlock {
49
50     private OverlayPreferenceStore fStore;
51     
52     
53     private Map JavaDoc fCheckBoxes= new HashMap JavaDoc();
54     private SelectionListener fCheckBoxListener= new SelectionListener() {
55         public void widgetDefaultSelected(SelectionEvent e) {
56         }
57         public void widgetSelected(SelectionEvent e) {
58             Button button= (Button) e.widget;
59             fStore.setValue((String JavaDoc) fCheckBoxes.get(button), button.getSelection());
60         }
61     };
62     
63     /**
64      * List of master/slave listeners when there's a dependency.
65      *
66      * @see #createDependency(Button, String, Control)
67      * @since 3.0
68      */

69     private ArrayList JavaDoc fMasterSlaveListeners= new ArrayList JavaDoc();
70     
71     private StatusInfo fStatus;
72
73     public MarkOccurrencesConfigurationBlock(OverlayPreferenceStore store) {
74         Assert.isNotNull(store);
75         fStore= store;
76         
77         fStore.addKeys(createOverlayStoreKeys());
78     }
79     
80     private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
81         
82         ArrayList JavaDoc overlayKeys= new ArrayList JavaDoc();
83
84         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_OCCURRENCES));
85         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES));
86         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES));
87         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES));
88         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES));
89         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES));
90         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES));
91         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS));
92         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS));
93         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS));
94         overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STICKY_OCCURRENCES));
95         
96         OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
97         overlayKeys.toArray(keys);
98         return keys;
99     }
100
101     /**
102      * Creates page for mark occurrences preferences.
103      *
104      * @param parent the parent composite
105      * @return the control for the preference page
106      */

107     public Control createControl(final Composite parent) {
108     
109         Composite composite= new Composite(parent, SWT.NONE);
110         GridLayout layout= new GridLayout();
111         layout.numColumns= 1;
112         layout.marginHeight= 0;
113         layout.marginWidth= 0;
114         composite.setLayout(layout);
115         
116         Link link= new Link(composite, SWT.NONE);
117         link.setText(PreferencesMessages.MarkOccurrencesConfigurationBlock_link);
118         link.addSelectionListener(new SelectionAdapter() {
119             public void widgetSelected(SelectionEvent e) {
120                 PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null);
121             }
122         });
123         // TODO replace by link-specific tooltips when
124
// bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88866 gets fixed
125
link.setToolTipText(PreferencesMessages.MarkOccurrencesConfigurationBlock_link_tooltip);
126         
127         addFiller(composite);
128         
129         String JavaDoc label;
130         
131         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markOccurrences;
132         Button master= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0);
133         
134         addFiller(composite);
135         
136         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences;
137         Button slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0);
138         createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);
139         
140         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences;
141         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0);
142         createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave);
143         
144         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences;
145         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0);
146         createDependency(master, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave);
147
148         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences;
149         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0);
150         createDependency(master, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave);
151
152         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences;
153         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0);
154         createDependency(master, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave);
155         
156         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences;
157         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0);
158         createDependency(master, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave);
159
160         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints;
161         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0);
162         createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave);
163
164         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markImplementors;
165         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, 0);
166         createDependency(master, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, slave);
167
168         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markBreakContinueTargets;
169         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS, 0);
170         createDependency(master, PreferenceConstants.EDITOR_MARK_BREAK_CONTINUE_TARGETS, slave);
171
172         addFiller(composite);
173         
174         label= PreferencesMessages.MarkOccurrencesConfigurationBlock_stickyOccurrences;
175         slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0);
176         createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);
177
178         return composite;
179     }
180     
181     private void addFiller(Composite composite) {
182         PixelConverter pixelConverter= new PixelConverter(composite);
183         
184         Label filler= new Label(composite, SWT.LEFT );
185         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
186         gd.horizontalSpan= 2;
187         gd.heightHint= pixelConverter.convertHeightInCharsToPixels(1) / 2;
188         filler.setLayoutData(gd);
189     }
190
191     private Button addCheckBox(Composite parent, String JavaDoc label, String JavaDoc key, int indentation) {
192         Button checkBox= new Button(parent, SWT.CHECK);
193         checkBox.setText(label);
194         
195         GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
196         gd.horizontalIndent= indentation;
197         gd.horizontalSpan= 2;
198         checkBox.setLayoutData(gd);
199         checkBox.addSelectionListener(fCheckBoxListener);
200         
201         fCheckBoxes.put(checkBox, key);
202         
203         return checkBox;
204     }
205
206     private void createDependency(final Button master, String JavaDoc masterKey, final Control slave) {
207         indent(slave);
208         boolean masterState= fStore.getBoolean(masterKey);
209         slave.setEnabled(masterState);
210         SelectionListener listener= new SelectionListener() {
211             public void widgetSelected(SelectionEvent e) {
212                 slave.setEnabled(master.getSelection());
213             }
214
215             public void widgetDefaultSelected(SelectionEvent e) {}
216         };
217         master.addSelectionListener(listener);
218         fMasterSlaveListeners.add(listener);
219     }
220
221     private static void indent(Control control) {
222         GridData gridData= new GridData();
223         gridData.horizontalIndent= 10;
224         control.setLayoutData(gridData);
225     }
226
227     public void initialize() {
228         initializeFields();
229     }
230
231     void initializeFields() {
232         
233         Iterator JavaDoc iter= fCheckBoxes.keySet().iterator();
234         while (iter.hasNext()) {
235             Button b= (Button) iter.next();
236             String JavaDoc key= (String JavaDoc) fCheckBoxes.get(b);
237             b.setSelection(fStore.getBoolean(key));
238         }
239         
240         // Update slaves
241
iter= fMasterSlaveListeners.iterator();
242         while (iter.hasNext()) {
243             SelectionListener listener= (SelectionListener)iter.next();
244             listener.widgetSelected(null);
245         }
246         
247     }
248
249     public void performOk() {
250     }
251
252     public void performDefaults() {
253         restoreFromPreferences();
254         initializeFields();
255     }
256
257     private void restoreFromPreferences() {
258
259     }
260
261     IStatus getStatus() {
262         if (fStatus == null)
263             fStatus= new StatusInfo();
264         return fStatus;
265     }
266
267     /*
268      * @see org.eclipse.jdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose()
269      * @since 3.0
270      */

271     public void dispose() {
272     }
273 }
274
Popular Tags