avoid OutOfBoundsException and break of format action, when marker positions are...
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / preferences / PHPExternalToolsPreferencePage.java
1 package net.sourceforge.phpdt.externaltools.preferences;
2
3
4 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
5
6 import org.eclipse.jface.preference.BooleanFieldEditor;
7 import org.eclipse.jface.preference.FileFieldEditor;
8 import org.eclipse.jface.preference.IPreferenceStore;
9 import org.eclipse.jface.preference.PreferencePage;
10 import org.eclipse.jface.preference.StringFieldEditor;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Group;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.ui.IWorkbench;
19 import org.eclipse.ui.IWorkbenchPreferencePage;
20
21 public class PHPExternalToolsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
22
23 //  StringFieldEditor phpParserExtensionsSFE;
24   StringFieldEditor xamppStartSFE;
25   StringFieldEditor xamppStopSFE;
26   StringFieldEditor apacheStartSFE;
27
28   StringFieldEditor apacheStopSFE;
29
30   StringFieldEditor apacheRestartSFE;
31
32   StringFieldEditor mySQLCommandSFE;
33   
34   StringFieldEditor externalParserSFE;
35   
36   FileFieldEditor apacheRunFFE;
37
38   FileFieldEditor mysqlRunFFE;
39
40   FileFieldEditor phpRunFFE;
41
42   FileFieldEditor httpdConfFFE;
43   
44   FileFieldEditor etcHostsFFE;
45
46   BooleanFieldEditor apacheStartBFE;
47
48   BooleanFieldEditor apacheStopBFE;
49
50   BooleanFieldEditor apacheRestartBFE;
51
52   BooleanFieldEditor mysqlStartBFE;
53
54   public PHPExternalToolsPreferencePage() {
55     super();
56     setPreferenceStore(ExternalToolsPlugin.getDefault().getPreferenceStore());
57     setDescription(PHPPreferencesMessages.getString("PHPBasePreferencePage.description")); //$NON-NLS-1$
58   }
59
60   public void init(IWorkbench workbench) {
61   }
62
63   protected void performDefaults() {
64 //    phpParserExtensionsSFE.loadDefault();
65     xamppStartSFE.loadDefault();
66     xamppStopSFE.loadDefault();
67     apacheStartSFE.loadDefault();
68     apacheStopSFE.loadDefault();
69     apacheRestartSFE.loadDefault();
70     mySQLCommandSFE.loadDefault();
71     externalParserSFE.loadDefault();
72     phpRunFFE.loadDefault();
73     apacheRunFFE.loadDefault();
74     httpdConfFFE.loadDefault();
75     etcHostsFFE.loadDefault();
76     mysqlRunFFE.loadDefault();
77     apacheStartBFE.loadDefault();
78     apacheStopBFE.loadDefault();
79     apacheRestartBFE.loadDefault();
80     mysqlStartBFE.loadDefault();
81     super.performDefaults();
82   }
83
84   public boolean performOk() {
85 //    PHPFileUtil.setExtensions(null); 
86 //    phpParserExtensionsSFE.store();
87     xamppStartSFE.store();
88     xamppStopSFE.store();
89     apacheStartSFE.store();
90     apacheStopSFE.store();
91     apacheRestartSFE.store();
92     mySQLCommandSFE.store();
93     externalParserSFE.store();
94     phpRunFFE.store();
95     apacheRunFFE.store();
96     httpdConfFFE.store();
97     etcHostsFFE.store();
98     mysqlRunFFE.store();
99
100     apacheStartBFE.store();
101     apacheStopBFE.store();
102     apacheRestartBFE.store();
103     mysqlStartBFE.store();
104     return super.performOk();
105   }
106
107   protected Control createContents(Composite parent) {
108     initializeDialogUnits(parent);
109     final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore();
110     Composite composite = new Composite(parent, SWT.LEFT);
111     composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
112     composite.setLayout(new GridLayout());
113
114     //Create apache
115     Composite apacheSettingsComposite = new Composite(composite, SWT.NULL);
116     apacheSettingsComposite.setLayout(new GridLayout());
117     apacheSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
118     Group apacheSettingsGroup = new Group(apacheSettingsComposite, SWT.NONE);
119     apacheSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.apacheGroup"));
120     apacheSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
121     apacheSettingsGroup.setLayout(new GridLayout());
122
123     
124     xamppStartSFE = new StringFieldEditor(ExternalToolsPlugin.XAMPP_START_PREF, PHPPreferencesMessages
125         .getString("PHPBasePreferencePage.apacheGroup.xampp_start"), apacheSettingsGroup);
126     xamppStartSFE.setPreferencePage(this);
127     xamppStartSFE.setPreferenceStore(getPreferenceStore());
128     xamppStartSFE.load();
129     new Label(apacheSettingsGroup, SWT.NONE);
130     
131     xamppStopSFE = new StringFieldEditor(ExternalToolsPlugin.XAMPP_STOP_PREF, PHPPreferencesMessages
132         .getString("PHPBasePreferencePage.apacheGroup.xampp_stop"), apacheSettingsGroup);
133     xamppStopSFE.setPreferencePage(this);
134     xamppStopSFE.setPreferenceStore(getPreferenceStore());
135     xamppStopSFE.load();
136     new Label(apacheSettingsGroup, SWT.NONE);
137     
138     apacheStartBFE = new BooleanFieldEditor(ExternalToolsPlugin.APACHE_START_BACKGROUND, PHPPreferencesMessages
139         .getString("PHPBasePreferencePage.apacheGroup.start_background"), apacheSettingsGroup);
140     apacheStartBFE.setPreferencePage(this);
141     apacheStartBFE.setPreferenceStore(getPreferenceStore());
142     apacheStartBFE.load();
143
144     new Label(apacheSettingsGroup, SWT.NONE);
145     new Label(apacheSettingsGroup, SWT.NONE);
146     apacheStartSFE = new StringFieldEditor(ExternalToolsPlugin.APACHE_START_PREF, PHPPreferencesMessages
147         .getString("PHPBasePreferencePage.apacheGroup.start"), apacheSettingsGroup);
148     apacheStartSFE.setPreferencePage(this);
149     apacheStartSFE.setPreferenceStore(getPreferenceStore());
150     apacheStartSFE.load();
151     new Label(apacheSettingsGroup, SWT.NONE);
152
153     apacheStopBFE = new BooleanFieldEditor(ExternalToolsPlugin.APACHE_STOP_BACKGROUND, PHPPreferencesMessages
154         .getString("PHPBasePreferencePage.apacheGroup.stop_background"), apacheSettingsGroup);
155     apacheStopBFE.setPreferencePage(this);
156     apacheStopBFE.setPreferenceStore(getPreferenceStore());
157     apacheStopBFE.load();
158     new Label(apacheSettingsGroup, SWT.NONE);
159     new Label(apacheSettingsGroup, SWT.NONE);
160     apacheStopSFE = new StringFieldEditor(ExternalToolsPlugin.APACHE_STOP_PREF, PHPPreferencesMessages
161         .getString("PHPBasePreferencePage.apacheGroup.stop"), apacheSettingsGroup);
162     apacheStopSFE.setPreferencePage(this);
163     apacheStopSFE.setPreferenceStore(getPreferenceStore());
164     apacheStopSFE.load();
165     new Label(apacheSettingsGroup, SWT.NONE);
166
167     apacheRestartBFE = new BooleanFieldEditor(ExternalToolsPlugin.APACHE_RESTART_BACKGROUND, PHPPreferencesMessages
168         .getString("PHPBasePreferencePage.apacheGroup.restart_background"), apacheSettingsGroup);
169     apacheRestartBFE.setPreferencePage(this);
170     apacheRestartBFE.setPreferenceStore(getPreferenceStore());
171     apacheRestartBFE.load();
172     new Label(apacheSettingsGroup, SWT.NONE);
173     new Label(apacheSettingsGroup, SWT.NONE);
174     apacheRestartSFE = new StringFieldEditor(ExternalToolsPlugin.APACHE_RESTART_PREF, PHPPreferencesMessages
175         .getString("PHPBasePreferencePage.apacheGroup.restart"), apacheSettingsGroup);
176     apacheRestartSFE.setPreferencePage(this);
177     apacheRestartSFE.setPreferenceStore(getPreferenceStore());
178     apacheRestartSFE.load();
179     new Label(apacheSettingsGroup, SWT.NONE);
180
181     apacheRunFFE = new FileFieldEditor(ExternalToolsPlugin.APACHE_RUN_PREF, PHPPreferencesMessages
182         .getString("PHPBasePreferencePage.apacheGroup.run"), apacheSettingsGroup);
183     apacheRunFFE.setPreferencePage(this);
184     apacheRunFFE.setPreferenceStore(getPreferenceStore());
185     apacheRunFFE.load();
186
187     httpdConfFFE = new FileFieldEditor(ExternalToolsPlugin.HTTPD_CONF_PATH_PREF, 
188                 "Path to httpd.conf:", apacheSettingsGroup);
189     httpdConfFFE.setPreferencePage(this);
190     httpdConfFFE.setPreferenceStore(getPreferenceStore());
191     httpdConfFFE.load();
192
193     etcHostsFFE = new FileFieldEditor(ExternalToolsPlugin.ETC_HOSTS_PATH_PREF, 
194                 "Path to etc/hosts:", apacheSettingsGroup);
195     etcHostsFFE.setPreferencePage(this);
196     etcHostsFFE.setPreferenceStore(getPreferenceStore());
197     etcHostsFFE.load();
198
199     phpRunFFE = new FileFieldEditor(ExternalToolsPlugin.PHP_RUN_PREF, PHPPreferencesMessages
200         .getString("PHPBasePreferencePage.console.php"), apacheSettingsGroup);
201     phpRunFFE.setPreferencePage(this);
202     phpRunFFE.setPreferenceStore(getPreferenceStore());
203     phpRunFFE.load();
204
205     //Create mySQL
206     Composite mySQLSettingsComposite = new Composite(composite, SWT.NULL);
207     mySQLSettingsComposite.setLayout(new GridLayout());
208     mySQLSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
209
210     Group mySQLSettingsGroup = new Group(mySQLSettingsComposite, SWT.NONE);
211     mySQLSettingsGroup.setText(PHPPreferencesMessages.getString("PHPBasePreferencePage.mySQLGroup"));
212     mySQLSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
213     mySQLSettingsGroup.setLayout(new GridLayout());
214
215     mysqlStartBFE = new BooleanFieldEditor(ExternalToolsPlugin.MYSQL_START_BACKGROUND, PHPPreferencesMessages
216         .getString("PHPBasePreferencePage.mySQLGroup.start_background"), mySQLSettingsGroup);
217     mysqlStartBFE.setPreferencePage(this);
218     mysqlStartBFE.setPreferenceStore(getPreferenceStore());
219     mysqlStartBFE.load();
220     new Label(mySQLSettingsGroup, SWT.NONE);
221     new Label(mySQLSettingsGroup, SWT.NONE);
222
223     mySQLCommandSFE = new StringFieldEditor(ExternalToolsPlugin.MYSQL_PREF, PHPPreferencesMessages
224         .getString("PHPBasePreferencePage.mySQLGroup.command"), mySQLSettingsGroup);
225     mySQLCommandSFE.setPreferencePage(this);
226     mySQLCommandSFE.setPreferenceStore(getPreferenceStore());
227     mySQLCommandSFE.load();
228     new Label(mySQLSettingsGroup, SWT.NONE);
229
230     mysqlRunFFE = new FileFieldEditor(ExternalToolsPlugin.MYSQL_RUN_PREF, PHPPreferencesMessages
231         .getString("PHPBasePreferencePage.mySQLGroup.run"), mySQLSettingsGroup);
232     mysqlRunFFE.setPreferencePage(this);
233     mysqlRunFFE.setPreferenceStore(getPreferenceStore());
234     mysqlRunFFE.load();
235     
236     Composite parserSettingsComposite = new Composite(composite, SWT.NULL);
237     parserSettingsComposite.setLayout(new GridLayout());
238     parserSettingsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
239     
240     Group parserSettingsGroup = new Group(parserSettingsComposite, SWT.NONE);
241     parserSettingsGroup.setText("External parser command");
242     parserSettingsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
243     parserSettingsGroup.setLayout(new GridLayout());
244     
245     externalParserSFE =
246       new StringFieldEditor(
247         ExternalToolsPlugin.EXTERNAL_PARSER_PREF,
248         PHPPreferencesMessages.getString("PHPBasePreferencePage.parsers.extcommand"),
249         parserSettingsGroup
250     );
251     externalParserSFE.setPreferencePage(this);
252     externalParserSFE.setPreferenceStore(getPreferenceStore());
253     externalParserSFE.load();
254     
255     return composite;
256   }
257 }