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