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;
37 * Java default folding preferences.
41 public class DefaultJavaFoldingPreferenceBlock implements IJavaFoldingPreferenceBlock {
43 private IPreferenceStore fStore;
44 private OverlayPreferenceStore fOverlayStore;
45 private OverlayKey[] fKeys;
46 private Map fCheckBoxes= new HashMap();
47 private SelectionListener fCheckBoxListener= new SelectionListener() {
48 public void widgetDefaultSelected(SelectionEvent e) {
50 public void widgetSelected(SelectionEvent e) {
51 Button button= (Button) e.widget;
52 fOverlayStore.setValue((String) fCheckBoxes.get(button), button.getSelection());
57 public DefaultJavaFoldingPreferenceBlock() {
58 fStore= PHPeclipsePlugin.getDefault().getPreferenceStore();
60 fOverlayStore= new OverlayPreferenceStore(fStore, fKeys);
63 private OverlayKey[] createKeys() {
64 ArrayList overlayKeys= new ArrayList();
66 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_JAVADOC));
67 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_INNERTYPES));
68 overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_METHODS));
69 // overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, PreferenceConstants.EDITOR_FOLDING_IMPORTS));
71 return (OverlayKey[]) overlayKeys.toArray(new OverlayKey[overlayKeys.size()]);
75 * @see net.sourceforge.phpdt.internal.ui.text.folding.IJavaFoldingPreferences#createControl(org.eclipse.swt.widgets.Group)
77 public Control createControl(Composite composite) {
79 fOverlayStore.start();
81 Composite inner= new Composite(composite, SWT.NONE);
82 GridLayout layout= new GridLayout(1, true);
83 layout.verticalSpacing= 3;
84 layout.marginWidth= 0;
85 inner.setLayout(layout);
87 Label label= new Label(inner, SWT.LEFT);
88 label.setText(FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.title")); //$NON-NLS-1$
90 // addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.comments"), PreferenceConstants.EDITOR_FOLDING_JAVADOC, 0); //$NON-NLS-1$
91 // addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.innerTypes"), PreferenceConstants.EDITOR_FOLDING_INNERTYPES, 0); //$NON-NLS-1$
92 addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.methods"), PreferenceConstants.EDITOR_FOLDING_METHODS, 0); //$NON-NLS-1$
93 // addCheckBox(inner, FoldingMessages.getString("DefaultJavaFoldingPreferenceBlock.imports"), PreferenceConstants.EDITOR_FOLDING_IMPORTS, 0); //$NON-NLS-1$
98 private Button addCheckBox(Composite parent, String label, String key, int indentation) {
99 Button checkBox= new Button(parent, SWT.CHECK);
100 checkBox.setText(label);
102 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
103 gd.horizontalIndent= indentation;
104 gd.horizontalSpan= 1;
105 gd.grabExcessVerticalSpace= false;
106 checkBox.setLayoutData(gd);
107 checkBox.addSelectionListener(fCheckBoxListener);
109 fCheckBoxes.put(checkBox, key);
114 private void initializeFields() {
115 Iterator it= fCheckBoxes.keySet().iterator();
116 while (it.hasNext()) {
117 Button b= (Button) it.next();
118 String key= (String) fCheckBoxes.get(b);
119 b.setSelection(fOverlayStore.getBoolean(key));
124 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performOk()
126 public void performOk() {
127 fOverlayStore.propagate();
132 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#initialize()
134 public void initialize() {
139 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#performDefaults()
141 public void performDefaults() {
142 fOverlayStore.loadDefaults();
147 * @see net.sourceforge.phpdt.internal.ui.text.folding.AbstractJavaFoldingPreferences#dispose()
149 public void dispose() {
150 fOverlayStore.stop();