f46d66ef50e69eb90ce4637ef9963be88d0c7a25
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / PHPEclipseBasePreferencePage.java
1 package net.sourceforge.phpeclipse;
2
3 import java.util.ArrayList;
4
5 import net.sourceforge.phpeclipse.preferences.PHPPreferencesMessages;
6
7 import org.eclipse.jface.preference.BooleanFieldEditor;
8 import org.eclipse.jface.preference.DirectoryFieldEditor;
9 import org.eclipse.jface.preference.IPreferenceStore;
10 import org.eclipse.jface.preference.PreferencePage;
11 import org.eclipse.jface.preference.RadioGroupFieldEditor;
12 import org.eclipse.jface.preference.StringFieldEditor;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.ModifyListener;
15 import org.eclipse.swt.events.SelectionListener;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.layout.RowLayout;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Group;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.ui.IWorkbench;
24 import org.eclipse.ui.IWorkbenchPreferencePage;
25
26 public class PHPEclipseBasePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
27
28   private SelectionListener SelectionListener;
29   private ModifyListener ModifyListener;
30   private ModifyListener TextModifyListener;
31
32   private ArrayList CheckBoxes = new ArrayList();
33   private ArrayList ComboBoxes = new ArrayList();
34   private ArrayList TextBoxes = new ArrayList();
35   private ArrayList RadioButtons = new ArrayList();
36
37   StringFieldEditor localHostSFE;
38   DirectoryFieldEditor documentRootDFE;
39   BooleanFieldEditor showExternalPreviewBFE;
40   BooleanFieldEditor externalBrowserBFE;
41   StringFieldEditor externalBrowserSFE;
42   StringFieldEditor apacheStartSFE;
43   StringFieldEditor apacheStopSFE;
44   StringFieldEditor apacheRestartSFE;
45   StringFieldEditor mySQLCommandSFE;
46   StringFieldEditor phpRunSFE;
47   RadioGroupFieldEditor chooseParser;
48   StringFieldEditor externalParserSFE;
49   BooleanFieldEditor parseOnSave;
50
51   public PHPEclipseBasePreferencePage() {
52     super();
53     setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
54     setDescription(PHPPreferencesMessages.getString("PHPBasePreferencePage.description")); //$NON-NLS-1$
55   }
56   public void init(IWorkbench workbench) {
57   }
58   protected void performDefaults() {
59     localHostSFE.loadDefault();
60     documentRootDFE.loadDefault();
61     showExternalPreviewBFE.loadDefault();
62     externalBrowserBFE.loadDefault();
63     externalBrowserSFE.loadDefault();
64     apacheStartSFE.loadDefault();
65     apacheStopSFE.loadDefault();
66     apacheRestartSFE.loadDefault();
67     mySQLCommandSFE.loadDefault();
68     phpRunSFE.loadDefault();
69     chooseParser.loadDefault();
70     externalParserSFE.loadDefault();
71     parseOnSave.loadDefault();
72     super.performDefaults();
73   }
74
75   public boolean performOk() {
76     localHostSFE.store();
77     documentRootDFE.store();
78     showExternalPreviewBFE.store();
79     externalBrowserBFE.store();
80     externalBrowserSFE.store();
81     apacheStartSFE.store();
82     apacheStopSFE.store();
83     apacheRestartSFE.store();
84     mySQLCommandSFE.store();
85     phpRunSFE.store();
86     chooseParser.store();
87     externalParserSFE.store();
88     parseOnSave.store();
89     return super.performOk();
90   }
91
92   protected Control createContents(Composite parent) {
93     initializeDialogUnits(parent);
94     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
95     Composite composite = new Composite(parent, SWT.LEFT);
96     composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
97     composite.setLayout(new GridLayout());
98     //Create Websettings
99     Composite webSettingsComposite = new Composite(composite, SWT.NONE);
100     webSettingsComposite.setLayout(new GridLayout());
101     webSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
102
103     showExternalPreviewBFE =
104       new BooleanFieldEditor(
105         IPreferenceConstants.SHOW_EXTERNAL_PREVIEW_PREF,
106         PHPPreferencesMessages.getString("PHPBasePreferencePage.websettingsGroup.showexternalpreview"),
107         webSettingsComposite);
108     showExternalPreviewBFE.setPreferencePage(this);
109     showExternalPreviewBFE.setPreferenceStore(getPreferenceStore());
110     showExternalPreviewBFE.load();
111
112     Group webSettingsGroup = new Group(webSettingsComposite, SWT.NONE);
113     webSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.websettingsGroup"));
114     GridLayout gridLayout = new GridLayout();
115     //  gridLayout.numColumns = 3;
116     GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
117     webSettingsGroup.setLayoutData(gridData);
118     webSettingsGroup.setLayout(gridLayout);
119
120     // new Label(webSettingsGroup, SWT.NONE);
121     externalBrowserBFE =
122       new BooleanFieldEditor(
123         IPreferenceConstants.USE_EXTERNAL_BROWSER_PREF,
124         PHPPreferencesMessages.getString("PHPBasePreferencePage.websettingsGroup.useexternal"),
125         webSettingsGroup);
126     externalBrowserBFE.setPreferencePage(this);
127     externalBrowserBFE.setPreferenceStore(getPreferenceStore());
128     externalBrowserBFE.load();
129     new Label(webSettingsGroup, SWT.NONE);
130     new Label(webSettingsGroup, SWT.NONE);
131     //  new Label(webSettingsGroup, SWT.NONE);
132     externalBrowserSFE =
133       new StringFieldEditor(
134         IPreferenceConstants.EXTERNAL_BROWSER_PREF,
135         PHPPreferencesMessages.getString("PHPBasePreferencePage.websettingsGroup.browser"),
136         webSettingsGroup);
137     externalBrowserSFE.setPreferencePage(this);
138     externalBrowserSFE.setPreferenceStore(getPreferenceStore());
139     externalBrowserSFE.load();
140     new Label(webSettingsGroup, SWT.NONE);
141
142     localHostSFE =
143       new StringFieldEditor(
144         IPreferenceConstants.LOCALHOST_PREF,
145         PHPPreferencesMessages.getString("PHPBasePreferencePage.websettingsGroup.localhost"),
146         webSettingsGroup);
147     localHostSFE.setPreferencePage(this);
148     localHostSFE.setPreferenceStore(getPreferenceStore());
149     localHostSFE.load();
150     new Label(webSettingsGroup, SWT.NONE);
151
152     documentRootDFE =
153       new DirectoryFieldEditor(
154         IPreferenceConstants.DOCUMENTROOT_PREF,
155         PHPPreferencesMessages.getString("PHPBasePreferencePage.websettingsGroup.docroot"),
156         webSettingsGroup);
157     documentRootDFE.setPreferencePage(this);
158     documentRootDFE.setPreferenceStore(getPreferenceStore());
159     documentRootDFE.load();
160     //Create apache
161     Composite apacheSettingsComposite = new Composite(composite, SWT.NULL);
162     apacheSettingsComposite.setLayout(new GridLayout());
163     apacheSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
164     Group apacheSettingsGroup = new Group(apacheSettingsComposite, SWT.NONE);
165     apacheSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.apacheGroup"));
166     apacheSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
167     apacheSettingsGroup.setLayout(new GridLayout());
168     apacheStartSFE =
169       new StringFieldEditor(
170         IPreferenceConstants.APACHE_START_PREF,
171         PHPPreferencesMessages.getString("PHPBasePreferencePage.apacheGroup.start"),
172         apacheSettingsGroup);
173     apacheStartSFE.setPreferencePage(this);
174     apacheStartSFE.setPreferenceStore(getPreferenceStore());
175     apacheStartSFE.load();
176     apacheStopSFE =
177       new StringFieldEditor(
178         IPreferenceConstants.APACHE_STOP_PREF,
179         PHPPreferencesMessages.getString("PHPBasePreferencePage.apacheGroup.stop"),
180         apacheSettingsGroup);
181     apacheStopSFE.setPreferencePage(this);
182     apacheStopSFE.setPreferenceStore(getPreferenceStore());
183     apacheStopSFE.load();
184     apacheRestartSFE =
185       new StringFieldEditor(
186         IPreferenceConstants.APACHE_RESTART_PREF,
187         PHPPreferencesMessages.getString("PHPBasePreferencePage.apacheGroup.restart"),
188         apacheSettingsGroup);
189     apacheRestartSFE.setPreferencePage(this);
190     apacheRestartSFE.setPreferenceStore(getPreferenceStore());
191     apacheRestartSFE.load();
192
193     phpRunSFE =
194       new StringFieldEditor(
195         IPreferenceConstants.PHP_RUN_PREF,
196         PHPPreferencesMessages.getString("PHPBasePreferencePage.console.php"),
197         apacheSettingsGroup);
198     phpRunSFE.setPreferencePage(this);
199     phpRunSFE.setPreferenceStore(getPreferenceStore());
200     phpRunSFE.load();
201
202     //Create mySQL
203     Composite mySQLSettingsComposite = new Composite(composite, SWT.NULL);
204     mySQLSettingsComposite.setLayout(new GridLayout());
205     mySQLSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
206
207     Group mySQLSettingsGroup = new Group(mySQLSettingsComposite, SWT.NONE);
208     mySQLSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.mySQLGroup"));
209     mySQLSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
210     mySQLSettingsGroup.setLayout(new GridLayout());
211     mySQLCommandSFE =
212       new StringFieldEditor(
213         IPreferenceConstants.MYSQL_PREF,
214         PHPPreferencesMessages.getString("PHPBasePreferencePage.mySQLGroup.command"),
215         mySQLSettingsGroup);
216     mySQLCommandSFE.setPreferencePage(this);
217     mySQLCommandSFE.setPreferenceStore(getPreferenceStore());
218     mySQLCommandSFE.load();
219
220     //Create parser settings composite
221     Composite parserSettingsComposite = new Composite(composite, SWT.NONE);
222     parserSettingsComposite.setLayout(new GridLayout());
223     parserSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
224     Group parserSettingsGroup = new Group(parserSettingsComposite, SWT.NONE);
225     parserSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers"));
226     parserSettingsGroup.setLayout(new GridLayout());
227     parserSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
228
229     chooseParser =
230       new RadioGroupFieldEditor(
231         IPreferenceConstants.PHP_PARSER_DEFAULT,
232         PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.choose"),
233         1,
234         new String[][] {
235           { PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.internal"), IPreferenceConstants.PHP_INTERNAL_PARSER },
236           {
237         PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.external"), IPreferenceConstants.PHP_EXTERNAL_PARSER }
238     }, parserSettingsGroup);
239     chooseParser.setPreferencePage(this);
240     chooseParser.setPreferenceStore(getPreferenceStore());
241     chooseParser.load();
242     //create a copmposte just for the StringEditor - makes layout simpler
243     Composite externalParserCompo = new Composite(parserSettingsGroup, SWT.NONE);
244     externalParserSFE =
245       new StringFieldEditor(
246         IPreferenceConstants.EXTERNAL_PARSER_PREF,
247         PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.extcommand"),
248         externalParserCompo
249     /*parserSettingsGroup*/
250     );
251     externalParserSFE.setPreferencePage(this);
252     externalParserSFE.setPreferenceStore(getPreferenceStore());
253     externalParserSFE.load();
254
255     parseOnSave =
256       new BooleanFieldEditor(
257         PHPeclipsePlugin.PHP_PARSE_ON_SAVE,
258         PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.pos"),
259         parserSettingsGroup);
260     parseOnSave.setPreferencePage(this);
261     parseOnSave.setPreferenceStore(getPreferenceStore());
262     parseOnSave.load();
263
264     return composite;
265   }
266 }