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;
24 import org.eclipse.jface.text.Assert;
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.Label;
36 * Configures Java Editor hover preferences.
40 class MarkOccurrencesConfigurationBlock implements
41 IPreferenceConfigurationBlock {
43 private OverlayPreferenceStore fStore;
45 private Map fCheckBoxes = new HashMap();
47 private SelectionListener fCheckBoxListener = new SelectionListener() {
48 public void widgetDefaultSelected(SelectionEvent e) {
51 public void widgetSelected(SelectionEvent e) {
52 Button button = (Button) e.widget;
53 fStore.setValue((String) fCheckBoxes.get(button), button
59 * List of master/slave listeners when there's a dependency.
61 * @see #createDependency(Button, String, Control)
64 private ArrayList fMasterSlaveListeners = new ArrayList();
66 private StatusInfo fStatus;
68 public MarkOccurrencesConfigurationBlock(OverlayPreferenceStore store) {
69 Assert.isNotNull(store);
72 fStore.addKeys(createOverlayStoreKeys());
75 private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
77 ArrayList overlayKeys = new ArrayList();
79 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
80 OverlayPreferenceStore.BOOLEAN,
81 PreferenceConstants.EDITOR_MARK_OCCURRENCES));
82 // overlayKeys.add(new
83 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
84 // PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES));
85 // overlayKeys.add(new
86 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
87 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES));
88 // overlayKeys.add(new
89 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
90 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES));
91 // overlayKeys.add(new
92 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
93 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES));
94 // overlayKeys.add(new
95 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
96 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES));
97 // overlayKeys.add(new
98 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
99 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES));
100 // overlayKeys.add(new
101 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
102 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS));
103 // overlayKeys.add(new
104 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
105 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS));
106 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
107 OverlayPreferenceStore.BOOLEAN,
108 PreferenceConstants.EDITOR_STICKY_OCCURRENCES));
110 OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys
112 overlayKeys.toArray(keys);
117 * Creates page for mark occurrences preferences.
120 * the parent composite
121 * @return the control for the preference page
123 public Control createControl(Composite parent) {
125 Composite composite = new Composite(parent, SWT.NONE);
126 GridLayout layout = new GridLayout();
127 layout.numColumns = 1;
128 composite.setLayout(layout);
132 label = PreferencesMessages
133 .getString("JavaEditorPreferencePage.markOccurrences");
134 Button master = addCheckBox(composite, label,
135 PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
138 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences;
139 // Button slave= addCheckBox(composite, label,
140 // PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0); //$NON-NLS-1$
141 // createDependency(master,
142 // PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);
145 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences;
146 // slave= addCheckBox(composite, label,
147 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0); //$NON-NLS-1$
148 // createDependency(master,
149 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave);
152 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences;
153 // slave= addCheckBox(composite, label,
154 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0);
156 // createDependency(master,
157 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave);
160 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences;
161 // slave= addCheckBox(composite, label,
162 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0); //$NON-NLS-1$
163 // createDependency(master,
164 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave);
167 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences;
168 // slave= addCheckBox(composite, label,
169 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0);
171 // createDependency(master,
172 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave);
175 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences;
176 // slave= addCheckBox(composite, label,
177 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0);
179 // createDependency(master,
180 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave);
183 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints;
184 // slave= addCheckBox(composite, label,
185 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0); //$NON-NLS-1$
186 // createDependency(master,
187 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave);
190 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markImplementors;
191 // slave= addCheckBox(composite, label,
192 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, 0); //$NON-NLS-1$
193 // createDependency(master,
194 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, slave);
196 addFiller(composite);
198 label = PreferencesMessages
199 .getString("JavaEditorPreferencePage.stickyOccurrences");
200 Button slave = addCheckBox(composite, label,
201 PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); //$NON-NLS-1$
202 createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES,
208 private void addFiller(Composite composite) {
209 PixelConverter pixelConverter = new PixelConverter(composite);
211 Label filler = new Label(composite, SWT.LEFT);
212 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
213 gd.horizontalSpan = 2;
214 gd.heightHint = pixelConverter.convertHeightInCharsToPixels(1) / 2;
215 filler.setLayoutData(gd);
218 private Button addCheckBox(Composite parent, String label, String key,
220 Button checkBox = new Button(parent, SWT.CHECK);
221 checkBox.setText(label);
223 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
224 gd.horizontalIndent = indentation;
225 gd.horizontalSpan = 2;
226 checkBox.setLayoutData(gd);
227 checkBox.addSelectionListener(fCheckBoxListener);
229 fCheckBoxes.put(checkBox, key);
234 private void createDependency(final Button master, String masterKey,
235 final Control slave) {
237 boolean masterState = fStore.getBoolean(masterKey);
238 slave.setEnabled(masterState);
239 SelectionListener listener = new SelectionListener() {
240 public void widgetSelected(SelectionEvent e) {
241 slave.setEnabled(master.getSelection());
244 public void widgetDefaultSelected(SelectionEvent e) {
247 master.addSelectionListener(listener);
248 fMasterSlaveListeners.add(listener);
251 private static void indent(Control control) {
252 GridData gridData = new GridData();
253 gridData.horizontalIndent = 20;
254 control.setLayoutData(gridData);
257 public void initialize() {
261 void initializeFields() {
263 Iterator iter = fCheckBoxes.keySet().iterator();
264 while (iter.hasNext()) {
265 Button b = (Button) iter.next();
266 String key = (String) fCheckBoxes.get(b);
267 b.setSelection(fStore.getBoolean(key));
271 iter = fMasterSlaveListeners.iterator();
272 while (iter.hasNext()) {
273 SelectionListener listener = (SelectionListener) iter.next();
274 listener.widgetSelected(null);
279 public void performOk() {
282 public void performDefaults() {
283 restoreFromPreferences();
287 private void restoreFromPreferences() {
291 IStatus getStatus() {
293 fStatus = new StatusInfo();
298 * @see net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose()
301 public void dispose() {