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 org.eclipse.core.runtime.IStatus;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.events.SelectionListener;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Label;
31 import org.eclipse.jface.text.Assert;
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
35 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
36 import net.sourceforge.phpdt.internal.ui.util.PixelConverter;
39 * Configures Java Editor hover preferences.
43 class MarkOccurrencesConfigurationBlock implements IPreferenceConfigurationBlock {
45 private OverlayPreferenceStore fStore;
48 private Map fCheckBoxes= new HashMap();
49 private SelectionListener fCheckBoxListener= new SelectionListener() {
50 public void widgetDefaultSelected(SelectionEvent e) {
52 public void widgetSelected(SelectionEvent e) {
53 Button button= (Button) e.widget;
54 fStore.setValue((String) fCheckBoxes.get(button), button.getSelection());
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(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_OCCURRENCES));
80 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES));
81 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES));
82 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES));
83 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES));
84 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES));
85 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES));
86 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS));
87 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS));
88 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_STICKY_OCCURRENCES));
90 OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
91 overlayKeys.toArray(keys);
96 * Creates page for mark occurrences preferences.
98 * @param parent the parent composite
99 * @return the control for the preference page
101 public Control createControl(Composite parent) {
103 Composite composite= new Composite(parent, SWT.NONE);
104 GridLayout layout= new GridLayout();
105 layout.numColumns= 1;
106 composite.setLayout(layout);
110 label= PreferencesMessages.getString("JavaEditorPreferencePage.markOccurrences");
111 Button master= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
113 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markTypeOccurrences;
114 // Button slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_TYPE_OCCURRENCES, 0); //$NON-NLS-1$
115 // createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);
117 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodOccurrences;
118 // slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, 0); //$NON-NLS-1$
119 // createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_OCCURRENCES, slave);
121 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences;
122 // slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0); //$NON-NLS-1$
123 // createDependency(master, PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave);
125 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markFieldOccurrences;
126 // slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, 0); //$NON-NLS-1$
127 // createDependency(master, PreferenceConstants.EDITOR_MARK_FIELD_OCCURRENCES, slave);
129 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences;
130 // slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0); //$NON-NLS-1$
131 // createDependency(master, PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave);
133 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences;
134 // slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0); //$NON-NLS-1$
135 // createDependency(master, PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave);
137 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markMethodExitPoints;
138 // slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, 0); //$NON-NLS-1$
139 // createDependency(master, PreferenceConstants.EDITOR_MARK_METHOD_EXIT_POINTS, slave);
141 // label= PreferencesMessages.MarkOccurrencesConfigurationBlock_markImplementors;
142 // slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, 0); //$NON-NLS-1$
143 // createDependency(master, PreferenceConstants.EDITOR_MARK_IMPLEMENTORS, slave);
145 addFiller(composite);
147 label= PreferencesMessages.getString("JavaEditorPreferencePage.stickyOccurrences");
148 Button slave= addCheckBox(composite, label, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, 0); //$NON-NLS-1$
149 createDependency(master, PreferenceConstants.EDITOR_STICKY_OCCURRENCES, slave);
154 private void addFiller(Composite composite) {
155 PixelConverter pixelConverter= new PixelConverter(composite);
157 Label filler= new Label(composite, SWT.LEFT );
158 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
159 gd.horizontalSpan= 2;
160 gd.heightHint= pixelConverter.convertHeightInCharsToPixels(1) / 2;
161 filler.setLayoutData(gd);
164 private Button addCheckBox(Composite parent, String label, String key, int indentation) {
165 Button checkBox= new Button(parent, SWT.CHECK);
166 checkBox.setText(label);
168 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
169 gd.horizontalIndent= indentation;
170 gd.horizontalSpan= 2;
171 checkBox.setLayoutData(gd);
172 checkBox.addSelectionListener(fCheckBoxListener);
174 fCheckBoxes.put(checkBox, key);
179 private void createDependency(final Button master, String masterKey, final Control slave) {
181 boolean masterState= fStore.getBoolean(masterKey);
182 slave.setEnabled(masterState);
183 SelectionListener listener= new SelectionListener() {
184 public void widgetSelected(SelectionEvent e) {
185 slave.setEnabled(master.getSelection());
188 public void widgetDefaultSelected(SelectionEvent e) {}
190 master.addSelectionListener(listener);
191 fMasterSlaveListeners.add(listener);
194 private static void indent(Control control) {
195 GridData gridData= new GridData();
196 gridData.horizontalIndent= 20;
197 control.setLayoutData(gridData);
200 public void initialize() {
204 void initializeFields() {
206 Iterator iter= fCheckBoxes.keySet().iterator();
207 while (iter.hasNext()) {
208 Button b= (Button) iter.next();
209 String key= (String) fCheckBoxes.get(b);
210 b.setSelection(fStore.getBoolean(key));
214 iter= fMasterSlaveListeners.iterator();
215 while (iter.hasNext()) {
216 SelectionListener listener= (SelectionListener)iter.next();
217 listener.widgetSelected(null);
222 public void performOk() {
225 public void performDefaults() {
226 restoreFromPreferences();
230 private void restoreFromPreferences() {
234 IStatus getStatus() {
236 fStatus= new StatusInfo();
241 * @see net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose()
244 public void dispose() {