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