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
41 IJavaFoldingPreferenceBlock {
43 private IPreferenceStore fStore;
45 private OverlayPreferenceStore fOverlayStore;
47 private OverlayKey[] fKeys;
49 private Map fCheckBoxes = new HashMap();
51 private SelectionListener fCheckBoxListener = new SelectionListener() {
52 public void widgetDefaultSelected(SelectionEvent e) {
55 public void widgetSelected(SelectionEvent e) {
56 Button button = (Button) e.widget;
57 fOverlayStore.setValue((String) fCheckBoxes.get(button), button
62 public DefaultJavaFoldingPreferenceBlock() {
63 fStore = PHPeclipsePlugin.getDefault().getPreferenceStore();
65 fOverlayStore = new OverlayPreferenceStore(fStore, fKeys);
68 private OverlayKey[] createKeys() {
69 ArrayList overlayKeys = new ArrayList();
71 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
72 OverlayPreferenceStore.BOOLEAN,
73 PreferenceConstants.EDITOR_FOLDING_JAVADOC));
74 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
75 OverlayPreferenceStore.BOOLEAN,
76 PreferenceConstants.EDITOR_FOLDING_HEADERS));
77 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
78 OverlayPreferenceStore.BOOLEAN,
79 PreferenceConstants.EDITOR_FOLDING_INNERTYPES));
80 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
81 OverlayPreferenceStore.BOOLEAN,
82 PreferenceConstants.EDITOR_FOLDING_METHODS));
83 // overlayKeys.add(new
84 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
85 // PreferenceConstants.EDITOR_FOLDING_IMPORTS));
87 return (OverlayKey[]) overlayKeys.toArray(new OverlayKey[overlayKeys
92 * @see net.sourceforge.phpdt.internal.ui.text.folding.IJavaFoldingPreferences#createControl(org.eclipse.swt.widgets.Group)
94 public Control createControl(Composite composite) {
96 fOverlayStore.start();
98 Composite inner = new Composite(composite, SWT.NONE);
99 GridLayout layout = new GridLayout(1, true);
100 layout.verticalSpacing = 3;
101 layout.marginWidth = 0;
102 inner.setLayout(layout);
104 Label label = new Label(inner, SWT.LEFT);
105 label.setText(FoldingMessages
106 .getString("DefaultJavaFoldingPreferenceBlock.title")); //$NON-NLS-1$
111 .getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$
115 .getString("DefaultJavaFoldingPreferenceBlock.headers"), PreferenceConstants.EDITOR_FOLDING_HEADERS, 0);//$NON-NLS-1$
116 addCheckBox(inner, FoldingMessages
117 .getString("DefaultJavaFoldingPreferenceBlock.innerTypes"),
118 PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); //$NON-NLS-1$
122 .getString("DefaultJavaFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$
123 // addCheckBox(inner,
124 // FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.imports"),
125 // PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); //$NON-NLS-1$
130 private Button addCheckBox(Composite parent, String label, String key,
132 Button checkBox = new Button(parent, SWT.CHECK);
133 checkBox.setText(label);
135 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
136 gd.horizontalIndent = indentation;
137 gd.horizontalSpan = 1;
138 gd.grabExcessVerticalSpace = false;
139 checkBox.setLayoutData(gd);
140 checkBox.addSelectionListener(fCheckBoxListener);
142 fCheckBoxes.put(checkBox, key);
147 private void initializeFields() {
148 Iterator it = fCheckBoxes.keySet().iterator();
149 while (it.hasNext()) {
150 Button b = (Button) it.next();
151 String key = (String) fCheckBoxes.get(b);
152 b.setSelection(fOverlayStore.getBoolean(key));
157 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performOk()
159 public void performOk() {
160 fOverlayStore.propagate();
164 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#initialize()
166 public void initialize() {
171 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performDefaults()
173 public void performDefaults() {
174 fOverlayStore.loadDefaults();
179 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#dispose()
181 public void dispose() {
182 fOverlayStore.stop();