1 package net.sourceforge.phpeclipse;
3 import java.util.ArrayList;
5 import net.sourceforge.phpeclipse.preferences.PHPPreferencesMessages;
7 import org.eclipse.jface.preference.IPreferenceStore;
8 import org.eclipse.jface.preference.PreferencePage;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.widgets.Button;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Group;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.ui.IWorkbench;
18 import org.eclipse.ui.IWorkbenchPreferencePage;
20 public class PHPLanguagePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
21 private ArrayList RadioButtons = new ArrayList();
23 protected Control createContents(Composite parent) {
24 Composite lingoComposite= new Composite(parent, SWT.NULL);
25 lingoComposite.setLayout(new GridLayout());
26 Group lingoGroup= new Group(lingoComposite, SWT.NONE);
27 lingoGroup.setText(PHPPreferencesMessages.getString("PHPLanguagePreferencePage.preflingo"));
28 lingoGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
29 lingoGroup.setLayout(new GridLayout());
30 Label lg = new Label(lingoGroup, SWT.WRAP);
31 lg.setText(PHPPreferencesMessages.getString("PHPLanguagePreferencePage.choose"));
32 addRadioButton(lingoGroup, PHPPreferencesMessages.getString("PHPLanguagePreferencePage.english"), IPreferenceConstants.RESOURCE_BUNDLE, IPreferenceConstants.RESOURCE_BUNDLE_EN_GB); //$NON-NLS-1$
33 addRadioButton(lingoGroup, PHPPreferencesMessages.getString("PHPLanguagePreferencePage.german"), IPreferenceConstants.RESOURCE_BUNDLE, IPreferenceConstants.RESOURCE_BUNDLE_DE); //$NON-NLS-1$
34 addRadioButton(lingoGroup, PHPPreferencesMessages.getString("PHPLanguagePreferencePage.french"), IPreferenceConstants.RESOURCE_BUNDLE, IPreferenceConstants.RESOURCE_BUNDLE_FR); //$NON-NLS-1$
35 return lingoComposite;
37 public void init(IWorkbench arg0) {
39 private Button addRadioButton(Composite parent, String label, String key, String value) {
40 GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL);
41 Button button= new Button(parent, SWT.RADIO);
42 button.setText(label);
43 button.setData(new String[] { key, value });
44 button.setLayoutData(gd);
45 button.setSelection(value.equals(PHPeclipsePlugin.getDefault().getPreferenceStore().getString(key)));
46 RadioButtons.add(button);
50 protected void performDefaults() {
51 IPreferenceStore store= getPreferenceStore();
52 for (int i= 0; i < RadioButtons.size(); i++) {
53 Button button= (Button) RadioButtons.get(i);
54 String[] info= (String[]) button.getData();
55 button.setSelection(info[1].equals(store.getDefaultString(info[0])));
57 super.performDefaults();
60 public boolean performOk() {
61 IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore();
62 for (int i= 0; i < RadioButtons.size(); i++) {
63 Button button= (Button) RadioButtons.get(i);
64 if (button.getSelection()) {
65 String[] info= (String[]) button.getData();
66 store.setValue(info[0], info[1]);
69 PHPeclipsePlugin.getDefault().savePluginPreferences();
70 PHPPreferencesMessages.setResourceBundle(
71 PHPeclipsePlugin.getDefault().getPreferenceStore().getString(IPreferenceConstants.RESOURCE_BUNDLE));
73 return super.performOk();