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);
130 GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_VERTICAL);
131 composite.setLayoutData(gd);
135 label = PreferencesMessages
136 .getString("JavaEditorPreferencePage.markOccurrences");
137 Button master = addCheckBox(composite, label,
138 PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
141 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences;
142 // Button slave= addCheckBox(composite, label,
143 // PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0); //$NON-NLS-1$
144 // createDependency(master,
145 // PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);
148 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences;
149 // slave= addCheckBox(composite, label,
150 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0); //$NON-NLS-1$
151 // createDependency(master,
152 // PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave);
155 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences;
156 // slave= addCheckBox(composite, label,
157 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0);
159 // createDependency(master,
160 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave);
163 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences;
164 // slave= addCheckBox(composite, label,
165 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0); //$NON-NLS-1$
166 // createDependency(master,
167 // PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave);
170 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences;
171 // slave= addCheckBox(composite, label,
172 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0);
174 // createDependency(master,
175 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave);
178 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences;
179 // slave= addCheckBox(composite, label,
180 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0);
182 // createDependency(master,
183 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave);
186 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints;
187 // slave= addCheckBox(composite, label,
188 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0); //$NON-NLS-1$
189 // createDependency(master,
190 // PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave);
193 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markImplementors;
194 // slave= addCheckBox(composite, label,
195 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, 0); //$NON-NLS-1$
196 // createDependency(master,
197 // PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, slave);
199 //addFiller(composite);
201 label = PreferencesMessages
202 .getString("JavaEditorPreferencePage.stickyOccurrences");
203 Button slave = addCheckBox(composite, label,
204 PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); //$NON-NLS-1$
205 createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES,
211 private void addFiller(Composite composite) {
212 PixelConverter pixelConverter = new PixelConverter(composite);
214 Label filler = new Label(composite, SWT.LEFT);
215 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
216 gd.horizontalSpan = 2;
217 gd.heightHint = pixelConverter.convertHeightInCharsToPixels(1) / 2;
218 filler.setLayoutData(gd);
221 private Button addCheckBox(Composite parent, String label, String key,
223 Button checkBox = new Button(parent, SWT.CHECK);
224 checkBox.setText(label);
226 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
227 gd.horizontalIndent = indentation;
228 gd.horizontalSpan = 2;
229 checkBox.setLayoutData(gd);
230 checkBox.addSelectionListener(fCheckBoxListener);
232 fCheckBoxes.put(checkBox, key);
237 private void createDependency(final Button master, String masterKey,
238 final Control slave) {
240 boolean masterState = fStore.getBoolean(masterKey);
241 slave.setEnabled(masterState);
242 SelectionListener listener = new SelectionListener() {
243 public void widgetSelected(SelectionEvent e) {
244 slave.setEnabled(master.getSelection());
247 public void widgetDefaultSelected(SelectionEvent e) {
250 master.addSelectionListener(listener);
251 fMasterSlaveListeners.add(listener);
254 private static void indent(Control control) {
255 GridData gridData = new GridData();
256 gridData.horizontalIndent = 20;
257 control.setLayoutData(gridData);
260 public void initialize() {
264 void initializeFields() {
266 Iterator iter = fCheckBoxes.keySet().iterator();
267 while (iter.hasNext()) {
268 Button b = (Button) iter.next();
269 String key = (String) fCheckBoxes.get(b);
270 b.setSelection(fStore.getBoolean(key));
274 iter = fMasterSlaveListeners.iterator();
275 while (iter.hasNext()) {
276 SelectionListener listener = (SelectionListener) iter.next();
277 listener.widgetSelected(null);
282 public void performOk() {
285 public void performDefaults() {
286 restoreFromPreferences();
290 private void restoreFromPreferences() {
294 IStatus getStatus() {
296 fStatus = new StatusInfo();
301 * @see net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose()
304 public void dispose() {