1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text.folding;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.Iterator;
18 import net.sourceforge.phpdt.internal.ui.preferences.OverlayPreferenceStore;
19 import net.sourceforge.phpdt.internal.ui.preferences.OverlayPreferenceStore.OverlayKey;
20 import net.sourceforge.phpdt.ui.PreferenceConstants;
21 import net.sourceforge.phpdt.ui.text.folding.IJavaFoldingPreferenceBlock;
22 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
24 import org.eclipse.jface.preference.IPreferenceStore;
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 * Java default folding preferences.
40 public class DefaultJavaFoldingPreferenceBlock implements IJavaFoldingPreferenceBlock {
42 private IPreferenceStore fStore;
44 private OverlayPreferenceStore fOverlayStore;
46 private OverlayKey[] fKeys;
48 private Map fCheckBoxes = new HashMap();
50 private SelectionListener fCheckBoxListener = new SelectionListener() {
51 public void widgetDefaultSelected(SelectionEvent e) {
54 public void widgetSelected(SelectionEvent e) {
55 Button button = (Button) e.widget;
56 fOverlayStore.setValue((String) fCheckBoxes.get(button), button.getSelection());
60 public DefaultJavaFoldingPreferenceBlock() {
61 fStore = PHPeclipsePlugin.getDefault().getPreferenceStore();
63 fOverlayStore = new OverlayPreferenceStore(fStore, fKeys);
66 private OverlayKey[] createKeys() {
67 ArrayList overlayKeys = new ArrayList();
69 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
70 PreferenceConstants.EDITOR_FOLDING_JAVADOC));
71 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
72 PreferenceConstants.EDITOR_FOLDING_HEADERS));
73 // overlayKeys.add(new
74 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
75 // PreferenceConstants.EDITOR_FOLDING_INNERTYPES));
76 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
77 PreferenceConstants.EDITOR_FOLDING_METHODS));
78 // overlayKeys.add(new
79 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
80 // PreferenceConstants.EDITOR_FOLDING_IMPORTS));
82 return (OverlayKey[]) overlayKeys.toArray(new OverlayKey[overlayKeys.size()]);
86 * @see net.sourceforge.phpdt.internal.ui.text.folding.IJavaFoldingPreferences#createControl(org.eclipse.swt.widgets.Group)
88 public Control createControl(Composite composite) {
90 fOverlayStore.start();
92 Composite inner = new Composite(composite, SWT.NONE);
93 GridLayout layout = new GridLayout(1, true);
94 layout.verticalSpacing = 3;
95 layout.marginWidth = 0;
96 inner.setLayout(layout);
98 Label label = new Label(inner, SWT.LEFT);
99 label.setText(FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.title")); //$NON-NLS-1$
102 FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$
104 FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.headers"), PreferenceConstants.EDITOR_FOLDING_HEADERS, 0);//$NON-NLS-1$
105 // addCheckBox(inner,
106 // FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.innerTypes"),
107 // PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); //$NON-NLS-1$
109 FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$
110 // addCheckBox(inner,
111 // FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.imports"),
112 // PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); //$NON-NLS-1$
117 private Button addCheckBox(Composite parent, String label, String key, int indentation) {
118 Button checkBox = new Button(parent, SWT.CHECK);
119 checkBox.setText(label);
121 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
122 gd.horizontalIndent = indentation;
123 gd.horizontalSpan = 1;
124 gd.grabExcessVerticalSpace = false;
125 checkBox.setLayoutData(gd);
126 checkBox.addSelectionListener(fCheckBoxListener);
128 fCheckBoxes.put(checkBox, key);
133 private void initializeFields() {
134 Iterator it = fCheckBoxes.keySet().iterator();
135 while (it.hasNext()) {
136 Button b = (Button) it.next();
137 String key = (String) fCheckBoxes.get(b);
138 b.setSelection(fOverlayStore.getBoolean(key));
143 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performOk()
145 public void performOk() {
146 fOverlayStore.propagate();
150 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#initialize()
152 public void initialize() {
157 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performDefaults()
159 public void performDefaults() {
160 fOverlayStore.loadDefaults();
165 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#dispose()
167 public void dispose() {
168 fOverlayStore.stop();