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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.preferences;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.Iterator;
19 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
20 //import net.sourceforge.phpdt.internal.ui.util.PixelConverter;
21 import net.sourceforge.phpdt.ui.PreferenceConstants;
23 import org.eclipse.core.runtime.IStatus;
25 //import org.eclipse.jface.text.Assert;
26 import org.eclipse.core.runtime.Assert;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.events.SelectionListener;
30 import org.eclipse.swt.layout.GridData;
31 import org.eclipse.swt.layout.GridLayout;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 //import org.eclipse.swt.widgets.Label;
38 * Configures Java Editor hover preferences.
42 class MarkOccurrencesConfigurationBlock implements
43 IPreferenceConfigurationBlock {
45 private OverlayPreferenceStore fStore;
47 private Map fCheckBoxes = new HashMap();
49 private SelectionListener fCheckBoxListener = new SelectionListener() {
50 public void widgetDefaultSelected(SelectionEvent e) {
53 public void widgetSelected(SelectionEvent e) {
54 Button button = (Button) e.widget;
55 fStore.setValue((String) fCheckBoxes.get(button), button
61 * List of master/slave listeners when there's a dependency.
63 * @see #createDependency(Button, String, Control)
66 private ArrayList fMasterSlaveListeners = new ArrayList();
68 private StatusInfo fStatus;
70 public MarkOccurrencesConfigurationBlock(OverlayPreferenceStore store) {
71 Assert.isNotNull(store);
74 fStore.addKeys(createOverlayStoreKeys());
77 private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
79 ArrayList overlayKeys = new ArrayList();
81 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
82 OverlayPreferenceStore.BOOLEAN,
83 PreferenceConstants.EDITOR_MARK_OCCURRENCES));
84 // overlayKeys.add(new
85 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
86 // PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES));
87 // overlayKeys.add(new
88 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
89 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES));
90 // overlayKeys.add(new
91 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
92 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES));
93 // overlayKeys.add(new
94 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
95 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES));
96 // overlayKeys.add(new
97 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
98 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES));
99 // overlayKeys.add(new
100 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
101 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES));
102 // overlayKeys.add(new
103 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
104 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS));
105 // overlayKeys.add(new
106 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
107 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS));
108 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
109 OverlayPreferenceStore.BOOLEAN,
110 PreferenceConstants.EDITOR_STICKY_OCCURRENCES));
112 OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys
114 overlayKeys.toArray(keys);
119 * Creates page for mark occurrences preferences.
122 * the parent composite
123 * @return the control for the preference page
125 public Control createControl(Composite parent) {
127 Composite composite = new Composite(parent, SWT.NONE);
128 GridLayout layout = new GridLayout();
129 layout.numColumns = 1;
130 composite.setLayout(layout);
132 GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_VERTICAL);
133 composite.setLayoutData(gd);
137 label = PreferencesMessages
138 .getString("JavaEditorPreferencePage.markOccurrences");
139 Button master = addCheckBox(composite, label,
140 PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
143 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences;
144 // Button slave= addCheckBox(composite, label,
145 // PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0); //$NON-NLS-1$
146 // createDependency(master,
147 // PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);
150 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences;
151 // slave= addCheckBox(composite, label,
152 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0); //$NON-NLS-1$
153 // createDependency(master,
154 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave);
157 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences;
158 // slave= addCheckBox(composite, label,
159 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0);
161 // createDependency(master,
162 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave);
165 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences;
166 // slave= addCheckBox(composite, label,
167 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0); //$NON-NLS-1$
168 // createDependency(master,
169 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave);
172 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences;
173 // slave= addCheckBox(composite, label,
174 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0);
176 // createDependency(master,
177 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave);
180 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences;
181 // slave= addCheckBox(composite, label,
182 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0);
184 // createDependency(master,
185 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave);
188 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints;
189 // slave= addCheckBox(composite, label,
190 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0); //$NON-NLS-1$
191 // createDependency(master,
192 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave);
195 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markImplementors;
196 // slave= addCheckBox(composite, label,
197 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, 0); //$NON-NLS-1$
198 // createDependency(master,
199 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, slave);
201 //addFiller(composite);
203 label = PreferencesMessages
204 .getString("JavaEditorPreferencePage.stickyOccurrences");
205 Button slave = addCheckBox(composite, label,
206 PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); //$NON-NLS-1$
207 createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES,
213 // private void addFiller(Composite composite) {
214 // PixelConverter pixelConverter = new PixelConverter(composite);
216 // Label filler = new Label(composite, SWT.LEFT);
217 // GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
218 // gd.horizontalSpan = 2;
219 // gd.heightHint = pixelConverter.convertHeightInCharsToPixels(1) / 2;
220 // filler.setLayoutData(gd);
223 private Button addCheckBox(Composite parent, String label, String key,
225 Button checkBox = new Button(parent, SWT.CHECK);
226 checkBox.setText(label);
228 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
229 gd.horizontalIndent = indentation;
230 gd.horizontalSpan = 2;
231 checkBox.setLayoutData(gd);
232 checkBox.addSelectionListener(fCheckBoxListener);
234 fCheckBoxes.put(checkBox, key);
239 private void createDependency(final Button master, String masterKey,
240 final Control slave) {
242 boolean masterState = fStore.getBoolean(masterKey);
243 slave.setEnabled(masterState);
244 SelectionListener listener = new SelectionListener() {
245 public void widgetSelected(SelectionEvent e) {
246 slave.setEnabled(master.getSelection());
249 public void widgetDefaultSelected(SelectionEvent e) {
252 master.addSelectionListener(listener);
253 fMasterSlaveListeners.add(listener);
256 private static void indent(Control control) {
257 GridData gridData = new GridData();
258 gridData.horizontalIndent = 20;
259 control.setLayoutData(gridData);
262 public void initialize() {
266 void initializeFields() {
268 Iterator iter = fCheckBoxes.keySet().iterator();
269 while (iter.hasNext()) {
270 Button b = (Button) iter.next();
271 String key = (String) fCheckBoxes.get(b);
272 b.setSelection(fStore.getBoolean(key));
276 iter = fMasterSlaveListeners.iterator();
277 while (iter.hasNext()) {
278 SelectionListener listener = (SelectionListener) iter.next();
279 listener.widgetSelected(null);
284 public void performOk() {
287 public void performDefaults() {
288 restoreFromPreferences();
292 private void restoreFromPreferences() {
296 IStatus getStatus() {
298 fStatus = new StatusInfo();
303 * @see net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose()
306 public void dispose() {