refactory: added UI removed from core plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / preferences / EditorConfigurationBlock.java
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
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.HashMap;
15 import java.util.Map;
16
17 import net.sourceforge.phpdt.core.IJavaProject;
18 import net.sourceforge.phpdt.internal.ui.wizards.IStatusChangeListener;
19 import net.sourceforge.phpdt.ui.PreferenceConstants;
20
21 import org.eclipse.jface.preference.IPreferenceStore;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Group;
28
29 /**
30  * Options configuration block for editor related settings.
31  * 
32  * @since 3.0
33  */
34 public class EditorConfigurationBlock extends OptionsConfigurationBlock {
35
36         /** Preference keys for the preferences in this block */
37         private static final String PREF_EDITOR_SAVE_ON_BLUR = PreferenceConstants.EDITOR_SAVE_ON_BLUR;
38
39         private static final String PREF_EDITOR_P_RTRIM_ON_SAVE = PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE;
40         
41         /**
42          * Creates a new editor configuration block.
43          * 
44          * @param context
45          *            The status change listener
46          * @param project
47          *            The Java project
48          */
49         public EditorConfigurationBlock(final IStatusChangeListener context,
50                         final IJavaProject project) {
51                 super(context, project, getAllKeys());
52         }
53
54         /*
55          * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#createContents(org.eclipse.swt.widgets.Composite)
56          */
57         protected Control createContents(final Composite parent) {
58
59                 Composite composite = new Composite(parent, SWT.NONE);
60                 GridLayout layout = new GridLayout();
61                 layout.numColumns = 1;
62                 composite.setLayout(layout);
63
64                 final String[] trueFalse = new String[] { IPreferenceStore.TRUE,
65                                 IPreferenceStore.FALSE };
66
67                 Group user = new Group(composite, SWT.NONE);
68                 user.setText(PreferencesMessages
69                                 .getString("EditorPreferencePage.file.title")); //$NON-NLS-1$
70                 user.setLayout(new GridLayout());
71                 user.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
72
73                 String label = PreferencesMessages
74                                 .getString("EditorPreferencePage.save_on_blur"); //$NON-NLS-1$
75                 addCheckBox(user, label, PREF_EDITOR_SAVE_ON_BLUR, trueFalse, 0);
76
77                 label = PreferencesMessages
78                                 .getString("EditorPreferencePage.p_rtrim_on_save"); //$NON-NLS-1$
79                 addCheckBox(user, label, PREF_EDITOR_P_RTRIM_ON_SAVE, trueFalse, 0);
80
81                 return composite;
82         }
83
84         private static String[] getAllKeys() {
85                 return new String[] { PREF_EDITOR_SAVE_ON_BLUR,
86                                 PREF_EDITOR_P_RTRIM_ON_SAVE };
87         }
88
89         /*
90          * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#getDefaultOptions()
91          */
92         protected Map getDefaultOptions() {
93
94                 final String[] keys = fAllKeys;
95                 final Map options = new HashMap();
96                 final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
97
98                 for (int index = 0; index < keys.length; index++)
99                         options.put(keys[index], store.getDefaultString(keys[index]));
100
101                 return options;
102         }
103
104         /*
105          * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#getFullBuildDialogStrings(boolean)
106          */
107         protected final String[] getFullBuildDialogStrings(final boolean workspace) {
108                 return null;
109         }
110
111         /*
112          * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#getOptions(boolean)
113          */
114         protected Map getOptions(final boolean inherit) {
115
116                 final String[] keys = fAllKeys;
117                 final Map options = new HashMap();
118                 final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
119
120                 for (int index = 0; index < keys.length; index++)
121                         options.put(keys[index], store.getString(keys[index]));
122
123                 return options;
124         }
125
126         /*
127          * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#setOptions(java.util.Map)
128          */
129         protected void setOptions(final Map options) {
130
131                 final String[] keys = fAllKeys;
132                 final IPreferenceStore store = PreferenceConstants.getPreferenceStore();
133
134                 for (int index = 0; index < keys.length; index++)
135                         store.setValue(keys[index], (String) fWorkingValues
136                                         .get(keys[index]));
137         }
138
139         /*
140          * @see net.sourceforge.phpdt.internal.ui.preferences.OptionsConfigurationBlock#validateSettings(java.lang.String,java.lang.String)
141          */
142         protected void validateSettings(final String key, final String value) {
143         }
144 }