Make PHPeclipse compile correctly under Eclipse Version: 3.2.0 Build id: I20060519...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / MarkOccurrencesConfigurationBlock.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.preferences;
13
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.Iterator;
17 import java.util.Map;
18
19 import org.eclipse.core.runtime.IStatus;
20
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;
30
31 import org.eclipse.jface.text.Assert;
32
33 import net.sourceforge.phpdt.ui.PreferenceConstants;
34
35 import net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
36 import net.sourceforge.phpdt.internal.ui.util.PixelConverter;
37
38 /**
39  * Configures Java Editor hover preferences.
40  *
41  * @since 2.1
42  */
43 class MarkOccurrencesConfigurationBlock implements IPreferenceConfigurationBlock {
44
45         private OverlayPreferenceStore fStore;
46
47
48         private Map fCheckBoxes= new HashMap();
49         private SelectionListener fCheckBoxListener= new SelectionListener() {
50                 public void widgetDefaultSelected(SelectionEvent e) {
51                 }
52                 public void widgetSelected(SelectionEvent e) {
53                         Button button= (Button) e.widget;
54                         fStore.setValue((String) fCheckBoxes.get(button), button.getSelection());
55                 }
56         };
57
58         /**
59          * List of master/slave listeners when there's a dependency.
60          *
61          * @see #createDependency(Button, String, Control)
62          * @since 3.0
63          */
64         private ArrayList fMasterSlaveListeners= new ArrayList();
65
66         private StatusInfo fStatus;
67
68         public MarkOccurrencesConfigurationBlock(OverlayPreferenceStore store) {
69                 Assert.isNotNull(store);
70                 fStore= store;
71
72                 fStore.addKeys(createOverlayStoreKeys());
73         }
74
75         private OverlayPreferenceStore.OverlayKey[] createOverlayStoreKeys() {
76
77                 ArrayList overlayKeys= new ArrayList();
78
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));
89
90                 OverlayPreferenceStore.OverlayKey[] keys= new OverlayPreferenceStore.OverlayKey[overlayKeys.size()];
91                 overlayKeys.toArray(keys);
92                 return keys;
93         }
94
95         /**
96          * Creates page for mark occurrences preferences.
97          *
98          * @param parent the parent composite
99          * @return the control for the preference page
100          */
101         public Control createControl(Composite parent) {
102
103                 Composite composite= new Composite(parent, SWT.NONE);
104                 GridLayout layout= new GridLayout();
105                 layout.numColumns= 1;
106                 composite.setLayout(layout);
107
108                 String label;
109
110                 label= PreferencesMessages.getString("JavaEditorPreferencePage.markOccurrences");
111                 Button master= addCheckBox(composite, label, PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
112
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);
116 //
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);
120 //
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);
124 //
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);
128 //
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);
132 //
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);
136 //
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);
140 //
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);
144
145                 addFiller(composite);
146
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);
150
151                 return composite;
152         }
153
154         private void addFiller(Composite composite) {
155                 PixelConverter pixelConverter= new PixelConverter(composite);
156
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);
162         }
163
164         private Button addCheckBox(Composite parent, String label, String key, int indentation) {
165                 Button checkBox= new Button(parent, SWT.CHECK);
166                 checkBox.setText(label);
167
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);
173
174                 fCheckBoxes.put(checkBox, key);
175
176                 return checkBox;
177         }
178
179         private void createDependency(final Button master, String masterKey, final Control slave) {
180                 indent(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());
186                         }
187
188                         public void widgetDefaultSelected(SelectionEvent e) {}
189                 };
190                 master.addSelectionListener(listener);
191                 fMasterSlaveListeners.add(listener);
192         }
193
194         private static void indent(Control control) {
195                 GridData gridData= new GridData();
196                 gridData.horizontalIndent= 20;
197                 control.setLayoutData(gridData);
198         }
199
200         public void initialize() {
201                 initializeFields();
202         }
203
204         void initializeFields() {
205
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));
211                 }
212
213         // Update slaves
214         iter= fMasterSlaveListeners.iterator();
215         while (iter.hasNext()) {
216             SelectionListener listener= (SelectionListener)iter.next();
217             listener.widgetSelected(null);
218         }
219
220         }
221
222         public void performOk() {
223         }
224
225         public void performDefaults() {
226                 restoreFromPreferences();
227                 initializeFields();
228         }
229
230         private void restoreFromPreferences() {
231
232         }
233
234         IStatus getStatus() {
235                 if (fStatus == null)
236                         fStatus= new StatusInfo();
237                 return fStatus;
238         }
239
240         /*
241          * @see net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose()
242          * @since 3.0
243          */
244         public void dispose() {
245         }
246 }