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;
23 import net.sourceforge.phpeclipse.ui.WebUI;
25 import org.eclipse.jface.preference.IPreferenceStore;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.events.SelectionListener;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Control;
34 import org.eclipse.swt.widgets.Label;
37 * Java default folding preferences.
41 public class DefaultJavaFoldingPreferenceBlock implements
42 IJavaFoldingPreferenceBlock {
44 private IPreferenceStore fStore;
46 private OverlayPreferenceStore fOverlayStore;
48 private OverlayKey[] fKeys;
50 private Map fCheckBoxes = new HashMap();
52 private SelectionListener fCheckBoxListener = new SelectionListener() {
53 public void widgetDefaultSelected(SelectionEvent e) {
56 public void widgetSelected(SelectionEvent e) {
57 Button button = (Button) e.widget;
58 fOverlayStore.setValue((String) fCheckBoxes.get(button), button
63 public DefaultJavaFoldingPreferenceBlock() {
64 fStore = WebUI.getDefault().getPreferenceStore();
66 fOverlayStore = new OverlayPreferenceStore(fStore, fKeys);
69 private OverlayKey[] createKeys() {
70 ArrayList overlayKeys = new ArrayList();
72 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
73 OverlayPreferenceStore.BOOLEAN,
74 PreferenceConstants.EDITOR_FOLDING_JAVADOC));
75 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
76 OverlayPreferenceStore.BOOLEAN,
77 PreferenceConstants.EDITOR_FOLDING_HEADERS));
78 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
79 OverlayPreferenceStore.BOOLEAN,
80 PreferenceConstants.EDITOR_FOLDING_INNERTYPES));
81 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(
82 OverlayPreferenceStore.BOOLEAN,
83 PreferenceConstants.EDITOR_FOLDING_METHODS));
84 // overlayKeys.add(new
85 // OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN,
86 // PreferenceConstants.EDITOR_FOLDING_IMPORTS));
88 return (OverlayKey[]) overlayKeys.toArray(new OverlayKey[overlayKeys
93 * @see net.sourceforge.phpdt.internal.ui.text.folding.IJavaFoldingPreferences#createControl(org.eclipse.swt.widgets.Group)
95 public Control createControl(Composite composite) {
97 fOverlayStore.start();
99 Composite inner = new Composite(composite, SWT.NONE);
100 GridLayout layout = new GridLayout(1, true);
101 layout.verticalSpacing = 3;
102 layout.marginWidth = 0;
103 inner.setLayout(layout);
105 Label label = new Label(inner, SWT.LEFT);
106 label.setText(FoldingMessages
107 .getString("DefaultJavaFoldingPreferenceBlock.title")); //$NON-NLS-1$
112 .getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$
116 .getString("DefaultJavaFoldingPreferenceBlock.headers"), PreferenceConstants.EDITOR_FOLDING_HEADERS, 0);//$NON-NLS-1$
117 addCheckBox(inner, FoldingMessages
118 .getString("DefaultJavaFoldingPreferenceBlock.innerTypes"),
119 PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); //$NON-NLS-1$
123 .getString("DefaultJavaFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$
124 // addCheckBox(inner,
125 // FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.imports"),
126 // PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); //$NON-NLS-1$
131 private Button addCheckBox(Composite parent, String label, String key,
133 Button checkBox = new Button(parent, SWT.CHECK);
134 checkBox.setText(label);
136 GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
137 gd.horizontalIndent = indentation;
138 gd.horizontalSpan = 1;
139 gd.grabExcessVerticalSpace = false;
140 checkBox.setLayoutData(gd);
141 checkBox.addSelectionListener(fCheckBoxListener);
143 fCheckBoxes.put(checkBox, key);
148 private void initializeFields() {
149 Iterator it = fCheckBoxes.keySet().iterator();
150 while (it.hasNext()) {
151 Button b = (Button) it.next();
152 String key = (String) fCheckBoxes.get(b);
153 b.setSelection(fOverlayStore.getBoolean(key));
158 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performOk()
160 public void performOk() {
161 fOverlayStore.propagate();
165 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#initialize()
167 public void initialize() {
172 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performDefaults()
174 public void performDefaults() {
175 fOverlayStore.loadDefaults();
180 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#dispose()
182 public void dispose() {
183 fOverlayStore.stop();