01: package org.drools.eclipse.preferences;
02:
03: import org.drools.eclipse.DroolsEclipsePlugin;
04: import org.eclipse.jface.preference.IPreferenceStore;
05: import org.eclipse.jface.preference.PreferencePage;
06: import org.eclipse.swt.SWT;
07: import org.eclipse.swt.layout.GridData;
08: import org.eclipse.swt.widgets.Button;
09: import org.eclipse.swt.widgets.Composite;
10: import org.eclipse.swt.widgets.Control;
11: import org.eclipse.ui.IWorkbench;
12: import org.eclipse.ui.IWorkbenchPreferencePage;
13:
14: public class DroolsPreferencePage extends PreferencePage implements
15: IWorkbenchPreferencePage {
16:
17: private Button buildAllCheckBox;
18: private Button collapseEditorCheckBox;
19: private Button cacheParsedRulesCheckBox;
20:
21: protected Control createContents(Composite parent) {
22: buildAllCheckBox = createCheckBox(parent,
23: "Automatically reparse all rules if a Java resource is changed.");
24: collapseEditorCheckBox = createCheckBox(parent,
25: "Use code folding in DRL editor.");
26: cacheParsedRulesCheckBox = createCheckBox(
27: parent,
28: "When parsing rules, always cache the result for future use. Warning: when disabled, debugging of rules will not work.");
29:
30: initializeValues();
31:
32: return new Composite(parent, SWT.NULL);
33: }
34:
35: private Button createCheckBox(Composite group, String label) {
36: Button button = new Button(group, SWT.CHECK | SWT.LEFT);
37: button.setText(label);
38: GridData data = new GridData();
39: button.setLayoutData(data);
40: return button;
41: }
42:
43: protected IPreferenceStore doGetPreferenceStore() {
44: return DroolsEclipsePlugin.getDefault().getPreferenceStore();
45: }
46:
47: private void initializeDefaults() {
48: IPreferenceStore store = getPreferenceStore();
49: buildAllCheckBox.setSelection(store
50: .getDefaultBoolean(IDroolsConstants.BUILD_ALL));
51: collapseEditorCheckBox.setSelection(store
52: .getDefaultBoolean(IDroolsConstants.EDITOR_FOLDING));
53: cacheParsedRulesCheckBox
54: .setSelection(store
55: .getDefaultBoolean(IDroolsConstants.CACHE_PARSED_RULES));
56: }
57:
58: private void initializeValues() {
59: IPreferenceStore store = getPreferenceStore();
60: buildAllCheckBox.setSelection(store
61: .getBoolean(IDroolsConstants.BUILD_ALL));
62: collapseEditorCheckBox.setSelection(store
63: .getBoolean(IDroolsConstants.EDITOR_FOLDING));
64: cacheParsedRulesCheckBox.setSelection(store
65: .getBoolean(IDroolsConstants.CACHE_PARSED_RULES));
66: }
67:
68: protected void performDefaults() {
69: super .performDefaults();
70: initializeDefaults();
71: }
72:
73: public boolean performOk() {
74: storeValues();
75: DroolsEclipsePlugin.getDefault().savePluginPreferences();
76: return true;
77: }
78:
79: private void storeValues() {
80: IPreferenceStore store = getPreferenceStore();
81: store.setValue(IDroolsConstants.BUILD_ALL, buildAllCheckBox
82: .getSelection());
83: store.setValue(IDroolsConstants.EDITOR_FOLDING,
84: collapseEditorCheckBox.getSelection());
85: store.setValue(IDroolsConstants.CACHE_PARSED_RULES,
86: cacheParsedRulesCheckBox.getSelection());
87: }
88:
89: public void init(IWorkbench workbench) {
90: // do nothing
91: }
92: }
|