New Xdebug configuration manual. contributed by Ian MacLennan .
[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 net.sourceforge.phpdt.internal.ui.dialogs.StatusInfo;
20 import net.sourceforge.phpdt.internal.ui.util.PixelConverter;
21 import net.sourceforge.phpdt.ui.PreferenceConstants;
22
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;
34
35 /**
36  * Configures Java Editor hover preferences.
37  * 
38  * @since 2.1
39  */
40 class MarkOccurrencesConfigurationBlock implements
41                 IPreferenceConfigurationBlock {
42
43         private OverlayPreferenceStore fStore;
44
45         private Map fCheckBoxes = new HashMap();
46
47         private SelectionListener fCheckBoxListener = new SelectionListener() {
48                 public void widgetDefaultSelected(SelectionEvent e) {
49                 }
50
51                 public void widgetSelected(SelectionEvent e) {
52                         Button button = (Button) e.widget;
53                         fStore.setValue((String) fCheckBoxes.get(button), button
54                                         .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(
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));
109
110                 OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys
111                                 .size()];
112                 overlayKeys.toArray(keys);
113                 return keys;
114         }
115
116         /**
117          * Creates page for mark occurrences preferences.
118          * 
119          * @param parent
120          *            the parent composite
121          * @return the control for the preference page
122          */
123         public Control createControl(Composite parent) {
124
125                 Composite composite = new Composite(parent, SWT.NONE);
126                 GridLayout layout = new GridLayout();
127                 layout.numColumns = 1;
128                 composite.setLayout(layout);
129
130                 GridData gd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_VERTICAL);
131                 composite.setLayoutData(gd);
132
133                 String label;
134
135                 label = PreferencesMessages
136                                 .getString("JavaEditorPreferencePage.markOccurrences");
137                 Button master = addCheckBox(composite, label,
138                                 PreferenceConstants.EDITOR_MARK_OCCURRENCES, 0); //$NON-NLS-1$
139
140                 // label=
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);
146                 //
147                 // label=
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);
153                 //
154                 // label=
155                 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markConstantOccurrences;
156                 // slave= addCheckBox(composite, label,
157                 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, 0);
158                 // //$NON-NLS-1$
159                 // createDependency(master,
160                 // PreferenceConstants.EDITOR_MARK_CONSTANT_OCCURRENCES, slave);
161                 //
162                 // label=
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);
168                 //
169                 // label=
170                 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markLocalVariableOccurrences;
171                 // slave= addCheckBox(composite, label,
172                 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, 0);
173                 // //$NON-NLS-1$
174                 // createDependency(master,
175                 // PreferenceConstants.EDITOR_MARK_LOCAL_VARIABLE_OCCURRENCES, slave);
176                 //
177                 // label=
178                 // PreferencesMessages.MarkOccurrencesConfigurationBlock_markExceptionOccurrences;
179                 // slave= addCheckBox(composite, label,
180                 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, 0);
181                 // //$NON-NLS-1$
182                 // createDependency(master,
183                 // PreferenceConstants.EDITOR_MARK_EXCEPTION_OCCURRENCES, slave);
184                 //
185                 // label=
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);
191                 //
192                 // label=
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);
198
199                 //addFiller(composite);
200
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,
206                                 slave);
207
208                 return composite;
209         }
210
211         private void addFiller(Composite composite) {
212                 PixelConverter pixelConverter = new PixelConverter(composite);
213
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);
219         }
220
221         private Button addCheckBox(Composite parent, String label, String key,
222                         int indentation) {
223                 Button checkBox = new Button(parent, SWT.CHECK);
224                 checkBox.setText(label);
225
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);
231
232                 fCheckBoxes.put(checkBox, key);
233
234                 return checkBox;
235         }
236
237         private void createDependency(final Button master, String masterKey,
238                         final Control slave) {
239                 indent(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());
245                         }
246
247                         public void widgetDefaultSelected(SelectionEvent e) {
248                         }
249                 };
250                 master.addSelectionListener(listener);
251                 fMasterSlaveListeners.add(listener);
252         }
253
254         private static void indent(Control control) {
255                 GridData gridData = new GridData();
256                 gridData.horizontalIndent = 20;
257                 control.setLayoutData(gridData);
258         }
259
260         public void initialize() {
261                 initializeFields();
262         }
263
264         void initializeFields() {
265
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));
271                 }
272
273                 // Update slaves
274                 iter = fMasterSlaveListeners.iterator();
275                 while (iter.hasNext()) {
276                         SelectionListener listener = (SelectionListener) iter.next();
277                         listener.widgetSelected(null);
278                 }
279
280         }
281
282         public void performOk() {
283         }
284
285         public void performDefaults() {
286                 restoreFromPreferences();
287                 initializeFields();
288         }
289
290         private void restoreFromPreferences() {
291
292         }
293
294         IStatus getStatus() {
295                 if (fStatus == null)
296                         fStatus = new StatusInfo();
297                 return fStatus;
298         }
299
300         /*
301          * @see net.sourceforge.phpdt.internal.ui.preferences.IPreferenceConfigurationBlock#dispose()
302          * @since 3.0
303          */
304         public void dispose() {
305         }
306 }