Skip to content
This repository
  • 1 commit
  • 12 files changed
  • 0 comments
  • 1 contributor
Jun 22, 2009
Thomas ten Cate Reworking the preference system.
Parts of the old system, with the preference store overlay, are still in use.
The new system is cleaner, simpler, and easier to use and extend.
8d0358f

Showing 12 changed files with 1,309 additions and 937 deletions. Show diff stats Hide diff stats

  1. 109  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/AbstractPreferencePage.java
  2. 71  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/CheckboxPreferenceControl.java
  3. 12  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/IValueChangedListener.java
  4. 55  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/IntegerPreferenceControl.java
  5. 130  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/PreferenceControl.java
  6. 48  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/StringPreferenceControl.java
  7. 72  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/TextPreferenceControl.java
  8. 200  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/HaskellPreferencePage.java
  9. 422  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/AnnotationsPP.java
  10. 341  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/ContentAssistPP.java
  11. 335  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/HaskellEditorPP.java
  12. 451  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/SyntaxColoringPP.java
109  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/AbstractPreferencePage.java
... ...
@@ -0,0 +1,109 @@
  1
+package net.sf.eclipsefp.common.ui.preferences;
  2
+
  3
+import java.util.ArrayList;
  4
+import java.util.List;
  5
+
  6
+import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
  7
+
  8
+import org.eclipse.core.runtime.preferences.InstanceScope;
  9
+import org.eclipse.jface.preference.IPreferenceStore;
  10
+import org.eclipse.jface.preference.PreferencePage;
  11
+import org.eclipse.jface.resource.ImageDescriptor;
  12
+import org.eclipse.swt.SWT;
  13
+import org.eclipse.swt.widgets.Composite;
  14
+import org.eclipse.swt.widgets.Label;
  15
+import org.eclipse.ui.IWorkbench;
  16
+import org.eclipse.ui.IWorkbenchPreferencePage;
  17
+import org.osgi.service.prefs.BackingStoreException;
  18
+
  19
+public abstract class AbstractPreferencePage extends PreferencePage
  20
+implements IWorkbenchPreferencePage {
  21
+
  22
+	/**
  23
+	 * List of all preference controls managed by this object.
  24
+	 */
  25
+	private final List<PreferenceControl> controls = new ArrayList<PreferenceControl>();
  26
+
  27
+	public AbstractPreferencePage() {
  28
+		super();
  29
+	}
  30
+
  31
+	public AbstractPreferencePage(final String title) {
  32
+		super(title);
  33
+	}
  34
+
  35
+	public AbstractPreferencePage(final String title, final ImageDescriptor image) {
  36
+		super(title, image);
  37
+	}
  38
+
  39
+	public void init(final IWorkbench workbench) {
  40
+		// do nothing; subclasses may override
  41
+	}
  42
+
  43
+	/**
  44
+	 * Loads the values of all {@link PreferenceControl}s on this page.
  45
+	 */
  46
+	public void loadControlValues() {
  47
+		IPreferenceStore prefStore = getPreferenceStore();
  48
+		for (PreferenceControl control : controls) {
  49
+			control.load(prefStore);
  50
+		}
  51
+	}
  52
+
  53
+	/**
  54
+	 * Stores preferences from the controls created by the createXxx methods
  55
+	 * into the preference store returned by {@link #getPreferenceStore},
  56
+	 * then saves the preference store.
  57
+	 *
  58
+	 * @return true if saving succeeded
  59
+	 */
  60
+	@Override
  61
+	public boolean performOk() {
  62
+		IPreferenceStore prefStore = getPreferenceStore();
  63
+		for (PreferenceControl control : controls) {
  64
+			control.store(prefStore);
  65
+		}
  66
+		try {
  67
+			new InstanceScope().getNode(HaskellUIPlugin.getPluginId()).flush();
  68
+		} catch (BackingStoreException ex) {
  69
+			return false;
  70
+		}
  71
+		return true;
  72
+	}
  73
+
  74
+	/**
  75
+	 * Loads the default values into the controls.
  76
+	 */
  77
+	@Override
  78
+	public void performDefaults() {
  79
+		IPreferenceStore prefStore = getPreferenceStore();
  80
+		for (PreferenceControl control : controls) {
  81
+			control.loadDefault(prefStore);
  82
+		}
  83
+	}
  84
+
  85
+	protected Label createLabel(final Composite parent, final String text) {
  86
+		Label label = new Label(parent, SWT.LEFT);
  87
+		label.setText(text);
  88
+		return label;
  89
+	}
  90
+
  91
+	protected CheckboxPreferenceControl createCheckboxControl(final Composite parent, final String text, final String name) {
  92
+		CheckboxPreferenceControl control = new CheckboxPreferenceControl(parent, text, name);
  93
+		controls.add(control);
  94
+		return control;
  95
+	}
  96
+
  97
+	protected StringPreferenceControl createStringControl(final Composite parent, final String label, final String name, final int maxLength) {
  98
+		StringPreferenceControl control = new StringPreferenceControl(parent, label, name, maxLength);
  99
+		controls.add(control);
  100
+		return control;
  101
+	}
  102
+
  103
+	protected IntegerPreferenceControl createIntegerControl(final Composite parent, final String label, final String name, final int maxLength) {
  104
+		IntegerPreferenceControl control = new IntegerPreferenceControl(parent, label, name, maxLength);
  105
+		controls.add(control);
  106
+		return control;
  107
+	}
  108
+
  109
+}
71  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/CheckboxPreferenceControl.java
... ...
@@ -0,0 +1,71 @@
  1
+package net.sf.eclipsefp.common.ui.preferences;
  2
+
  3
+
  4
+import org.eclipse.jface.preference.IPreferenceStore;
  5
+import org.eclipse.swt.SWT;
  6
+import org.eclipse.swt.events.SelectionAdapter;
  7
+import org.eclipse.swt.events.SelectionEvent;
  8
+import org.eclipse.swt.widgets.Button;
  9
+import org.eclipse.swt.widgets.Composite;
  10
+import org.eclipse.swt.widgets.Control;
  11
+
  12
+public class CheckboxPreferenceControl extends PreferenceControl<Boolean> {
  13
+
  14
+	private final Button checkbox;
  15
+
  16
+	public CheckboxPreferenceControl(final Composite parent, final String text, final String name) {
  17
+		super(name);
  18
+
  19
+		checkbox = new Button(parent, SWT.CHECK);
  20
+		checkbox.setText(text);
  21
+
  22
+		checkbox.addSelectionListener(new SelectionAdapter() {
  23
+			@Override
  24
+			public void widgetSelected(final SelectionEvent e) {
  25
+				fireValueChanged();
  26
+			}
  27
+		});
  28
+	}
  29
+
  30
+	@Override
  31
+	protected Boolean doLoad(final IPreferenceStore prefStore) {
  32
+		return new Boolean(prefStore.getBoolean(getName()));
  33
+	}
  34
+
  35
+	@Override
  36
+	protected Boolean doLoadDefault(final IPreferenceStore prefStore) {
  37
+		return new Boolean(prefStore.getDefaultBoolean(getName()));
  38
+	}
  39
+
  40
+	@Override
  41
+	protected void doStore(final IPreferenceStore prefStore, final Boolean value) {
  42
+		prefStore.setValue(getName(), value.booleanValue());
  43
+	}
  44
+
  45
+	@Override
  46
+	public Control getControl() {
  47
+		return checkbox;
  48
+	}
  49
+
  50
+	@Override
  51
+	public boolean isEnabled() {
  52
+		return checkbox.isEnabled();
  53
+	}
  54
+
  55
+	@Override
  56
+	public void setEnabled(final boolean enabled) {
  57
+		checkbox.setEnabled(enabled);
  58
+	}
  59
+
  60
+	@Override
  61
+	public Boolean getValue() {
  62
+		return new Boolean(checkbox.getSelection());
  63
+	}
  64
+
  65
+	@Override
  66
+	public void setValue(final Boolean value) {
  67
+		checkbox.setSelection(value.booleanValue());
  68
+		fireValueChanged();
  69
+	}
  70
+
  71
+}
12  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/IValueChangedListener.java
... ...
@@ -0,0 +1,12 @@
  1
+package net.sf.eclipsefp.common.ui.preferences;
  2
+
  3
+/**
  4
+ * A listener that listens for changes in the value of a preference control.
  5
+ *
  6
+ * @author Thomas ten Cate
  7
+ */
  8
+public interface IValueChangedListener<T> {
  9
+
  10
+	public void valueChanged(PreferenceControl<T> control, T value);
  11
+
  12
+}
55  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/IntegerPreferenceControl.java
... ...
@@ -0,0 +1,55 @@
  1
+package net.sf.eclipsefp.common.ui.preferences;
  2
+
  3
+import net.sf.eclipsefp.common.ui.util.DialogUtil;
  4
+
  5
+import org.eclipse.jface.preference.IPreferenceStore;
  6
+import org.eclipse.swt.SWT;
  7
+import org.eclipse.swt.layout.GridData;
  8
+import org.eclipse.swt.widgets.Composite;
  9
+
  10
+public class IntegerPreferenceControl extends TextPreferenceControl<Integer> {
  11
+
  12
+	public IntegerPreferenceControl(final Composite parent, final String labelText,
  13
+			final String name, final int maxLength) {
  14
+		super(parent, labelText, name);
  15
+
  16
+		if (maxLength > 0) {
  17
+			text.setTextLimit(maxLength);
  18
+			GridData gd = new GridData();
  19
+			gd.widthHint = DialogUtil.convertWidthInCharsToPixels(text, maxLength + 1);
  20
+			text.setLayoutData(gd);
  21
+		}
  22
+	}
  23
+
  24
+	@Override
  25
+	protected int getTextStyle() {
  26
+		return super.getTextStyle() | SWT.RIGHT;
  27
+	}
  28
+
  29
+	@Override
  30
+	protected Integer doLoad(final IPreferenceStore prefStore) {
  31
+		return new Integer(prefStore.getInt(getName()));
  32
+	}
  33
+
  34
+	@Override
  35
+	protected Integer doLoadDefault(final IPreferenceStore prefStore) {
  36
+		return new Integer(prefStore.getDefaultInt(getName()));
  37
+	}
  38
+
  39
+	@Override
  40
+	protected void doStore(final IPreferenceStore prefStore, final Integer value) {
  41
+		prefStore.setValue(getName(), value.intValue());
  42
+	}
  43
+
  44
+	@Override
  45
+	public Integer getValue() {
  46
+		return new Integer(text.getText());
  47
+	}
  48
+
  49
+	@Override
  50
+	public void setValue(final Integer value) {
  51
+		text.setText(value.toString());
  52
+		fireValueChanged();
  53
+	}
  54
+
  55
+}
130  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/PreferenceControl.java
... ...
@@ -0,0 +1,130 @@
  1
+package net.sf.eclipsefp.common.ui.preferences;
  2
+
  3
+import java.util.ArrayList;
  4
+import java.util.List;
  5
+
  6
+import org.eclipse.jface.preference.IPreferenceStore;
  7
+import org.eclipse.swt.widgets.Control;
  8
+
  9
+/**
  10
+ * A control that represents a preference on a preference page.
  11
+ *
  12
+ * @author Thomas ten Cate
  13
+ */
  14
+public abstract class PreferenceControl<T> {
  15
+
  16
+	private List<IValueChangedListener<T>> valueChangedListeners = null;
  17
+	private final String name;
  18
+
  19
+	protected PreferenceControl(final String name) {
  20
+		this.name = name;
  21
+	}
  22
+
  23
+	/**
  24
+	 * Returns the name of the associated preference.
  25
+	 */
  26
+	protected String getName() {
  27
+		return name;
  28
+	}
  29
+
  30
+	/**
  31
+	 * Loads the value from the preference store into the control.
  32
+	 */
  33
+	public void load(final IPreferenceStore prefStore) {
  34
+		setValue(doLoad(prefStore));
  35
+	}
  36
+
  37
+	/**
  38
+	 * Loads the default value from the preference store into the control.
  39
+	 */
  40
+	public void loadDefault(final IPreferenceStore prefStore) {
  41
+		setValue(doLoadDefault(prefStore));
  42
+	}
  43
+
  44
+	/**
  45
+	 * Saves the value from the control into the preference store.
  46
+	 */
  47
+	public void store(final IPreferenceStore prefStore) {
  48
+		doStore(prefStore, getValue());
  49
+	}
  50
+
  51
+	/**
  52
+	 * Loads the value from the given preference store, and returns it.
  53
+	 * Does not change the actual value in the control.
  54
+	 */
  55
+	protected abstract T doLoad(IPreferenceStore prefStore);
  56
+
  57
+	/**
  58
+	 * Loads the default value from the given preference store, and returns it.
  59
+	 * Does not change the actual value in the control.
  60
+	 */
  61
+	protected abstract T doLoadDefault(IPreferenceStore prefStore);
  62
+
  63
+	/**
  64
+	 * Saves the given value to the given preference store.
  65
+	 * Does not read the actual value from the control.
  66
+	 */
  67
+	protected abstract void doStore(IPreferenceStore prefStore, T value);
  68
+
  69
+	/**
  70
+	 * Returns the control implementing this preference.
  71
+	 */
  72
+	public abstract Control getControl();
  73
+
  74
+	/**
  75
+	 * Returns whether the control is currently enabled.
  76
+	 */
  77
+	public abstract boolean isEnabled();
  78
+
  79
+	/**
  80
+	 * Sets the enablement of the control.
  81
+	 */
  82
+	public abstract void setEnabled(boolean enabled);
  83
+
  84
+	/**
  85
+	 * Returns the current value of this control.
  86
+	 */
  87
+	public abstract T getValue();
  88
+
  89
+	/**
  90
+	 * Sets a new value for the control.
  91
+	 * Subclasses should probably cal {@link #fireValueChanged()} from their implementations.
  92
+	 */
  93
+	public abstract void setValue(T value);
  94
+
  95
+	/**
  96
+	 * Adds a new listener that will be notified after the value of this
  97
+	 * control has changed.
  98
+	 * @param init If true, an event will be fired immediately to the new listener.
  99
+	 */
  100
+	public void addValueChangedListener(final IValueChangedListener<T> listener, final boolean init) {
  101
+		if (valueChangedListeners == null) {
  102
+			valueChangedListeners = new ArrayList<IValueChangedListener<T>>();
  103
+		}
  104
+		valueChangedListeners.add(listener);
  105
+		if (init) {
  106
+			listener.valueChanged(this, getValue());
  107
+		}
  108
+	}
  109
+
  110
+	/**
  111
+	 * Removes a value-changed listener.
  112
+	 */
  113
+	public void removeValueChangedListener(final IValueChangedListener listener) {
  114
+		if (valueChangedListeners != null) {
  115
+			valueChangedListeners.remove(listener);
  116
+		}
  117
+	}
  118
+
  119
+	/**
  120
+	 * Fires a value-changed event.
  121
+	 */
  122
+	protected void fireValueChanged() {
  123
+		if (valueChangedListeners != null) {
  124
+			for (IValueChangedListener<T> listener : valueChangedListeners) {
  125
+				listener.valueChanged(this, getValue());
  126
+			}
  127
+		}
  128
+	}
  129
+
  130
+}
48  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/StringPreferenceControl.java
... ...
@@ -0,0 +1,48 @@
  1
+package net.sf.eclipsefp.common.ui.preferences;
  2
+
  3
+import net.sf.eclipsefp.common.ui.util.DialogUtil;
  4
+
  5
+import org.eclipse.jface.preference.IPreferenceStore;
  6
+import org.eclipse.swt.layout.GridData;
  7
+import org.eclipse.swt.widgets.Composite;
  8
+
  9
+public class StringPreferenceControl extends TextPreferenceControl<String> {
  10
+
  11
+	public StringPreferenceControl(final Composite parent, final String labelText, final String name, final int maxLength) {
  12
+		super(parent, labelText, name);
  13
+
  14
+		if (maxLength > 0) {
  15
+			text.setTextLimit(maxLength);
  16
+			GridData gd = new GridData();
  17
+			gd.widthHint = DialogUtil.convertWidthInCharsToPixels(text, maxLength + 1);
  18
+			text.setLayoutData(gd);
  19
+		}
  20
+	}
  21
+
  22
+	@Override
  23
+	public String getValue() {
  24
+		return text.getText();
  25
+	}
  26
+
  27
+	@Override
  28
+	public void setValue(final String value) {
  29
+		text.setText(value);
  30
+		fireValueChanged();
  31
+	}
  32
+
  33
+	@Override
  34
+	public String doLoad(final IPreferenceStore prefStore) {
  35
+		return prefStore.getString(getName());
  36
+	}
  37
+
  38
+	@Override
  39
+	public String doLoadDefault(final IPreferenceStore prefStore) {
  40
+		return prefStore.getDefaultString(getName());
  41
+	}
  42
+
  43
+	@Override
  44
+	public void doStore(final IPreferenceStore prefStore, final String value) {
  45
+		prefStore.setValue(getName(), value);
  46
+	}
  47
+
  48
+}
72  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/common/ui/preferences/TextPreferenceControl.java
... ...
@@ -0,0 +1,72 @@
  1
+package net.sf.eclipsefp.common.ui.preferences;
  2
+
  3
+import org.eclipse.swt.SWT;
  4
+import org.eclipse.swt.events.ModifyEvent;
  5
+import org.eclipse.swt.events.ModifyListener;
  6
+import org.eclipse.swt.layout.GridData;
  7
+import org.eclipse.swt.layout.GridLayout;
  8
+import org.eclipse.swt.widgets.Composite;
  9
+import org.eclipse.swt.widgets.Control;
  10
+import org.eclipse.swt.widgets.Label;
  11
+import org.eclipse.swt.widgets.Text;
  12
+
  13
+/**
  14
+ * A preference control based on a text field.
  15
+ *
  16
+ * @author Thomas ten Cate
  17
+ */
  18
+public abstract class TextPreferenceControl<T> extends PreferenceControl<T> {
  19
+
  20
+	protected final Label label;
  21
+	protected final Text text;
  22
+	private final Composite composite;
  23
+
  24
+	public TextPreferenceControl(final Composite parent, final String labelText, final String name) {
  25
+		super(name);
  26
+
  27
+		composite = new Composite(parent, SWT.NONE);
  28
+		GridLayout gl = new GridLayout();
  29
+		gl.numColumns = 2;
  30
+		gl.marginWidth = gl.marginHeight = 0;
  31
+		composite.setLayout(gl);
  32
+
  33
+		label = new Label(composite, SWT.NONE);
  34
+		label.setText(labelText);
  35
+		GridData gd = new GridData();
  36
+		gd.grabExcessHorizontalSpace = true;
  37
+		label.setLayoutData(gd);
  38
+
  39
+		text = new Text(composite, getTextStyle());
  40
+		this.text.addModifyListener(new ModifyListener(){
  41
+			public void modifyText(final ModifyEvent e) {
  42
+				fireValueChanged();
  43
+			}
  44
+		});
  45
+	}
  46
+
  47
+	/**
  48
+	 * Returns the style in which the text label should be created.
  49
+	 * Called from the {@link #TextPreferenceControl} constructor.
  50
+	 * Subclasses may override.
  51
+	 */
  52
+	protected int getTextStyle() {
  53
+		return SWT.BORDER | SWT.SINGLE;
  54
+	}
  55
+
  56
+	@Override
  57
+	public Control getControl() {
  58
+		return composite;
  59
+	}
  60
+
  61
+	@Override
  62
+	public boolean isEnabled() {
  63
+		return label.isEnabled();
  64
+	}
  65
+
  66
+	@Override
  67
+	public void setEnabled(final boolean enabled) {
  68
+		label.setEnabled(enabled);
  69
+		text.setEnabled(enabled);
  70
+	}
  71
+
  72
+}
200  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/HaskellPreferencePage.java
... ...
@@ -1,194 +1,26 @@
1 1
 // Copyright (c) 2003-2004 by Leif Frenzel - see http://leiffrenzel.de
2 2
 package net.sf.eclipsefp.haskell.ui.internal.preferences;
3 3
 
4  
-import java.util.HashMap;
5  
-import java.util.Iterator;
6  
-import java.util.Map;
7 4
 
8  
-import net.sf.eclipsefp.common.ui.dialog.BooleanDialogField;
9  
-import net.sf.eclipsefp.common.ui.dialog.DialogField;
10  
-import net.sf.eclipsefp.common.ui.dialog.IDialogFieldListener;
11  
-import net.sf.eclipsefp.common.ui.util.DialogUtil;
  5
+import net.sf.eclipsefp.common.ui.preferences.AbstractPreferencePage;
12 6
 import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
13 7
 
  8
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
14 9
 import org.eclipse.jface.preference.IPreferenceStore;
15  
-import org.eclipse.jface.preference.PreferencePage;
16  
-import org.eclipse.swt.SWT;
17  
-import org.eclipse.swt.events.ModifyEvent;
18  
-import org.eclipse.swt.events.ModifyListener;
19  
-import org.eclipse.swt.events.SelectionAdapter;
20  
-import org.eclipse.swt.events.SelectionEvent;
21  
-import org.eclipse.swt.events.SelectionListener;
22  
-import org.eclipse.swt.layout.GridData;
23  
-import org.eclipse.swt.widgets.Button;
24  
-import org.eclipse.swt.widgets.Composite;
25  
-import org.eclipse.swt.widgets.Control;
26  
-import org.eclipse.swt.widgets.Label;
27  
-import org.eclipse.swt.widgets.Text;
28  
-import org.eclipse.ui.IWorkbench;
29  
-import org.eclipse.ui.IWorkbenchPreferencePage;
30 10
 
31  
-/** <p>the super class for all preference pages.</p>
32  
-  *
33  
-  * @author Leif Frenzel
34  
-  */
35  
-public abstract class HaskellPreferencePage extends PreferencePage
36  
-implements IWorkbenchPreferencePage, IPreferenceConstants {
37  
-
38  
-  private final Map<Button, String> checkBoxes = new HashMap<Button, String>();
39  
-  private final Map<Control, Control> labels = new HashMap<Control, Control>();
40  
-  private final Map<Text, String> textFields = new HashMap<Text, String>();
41  
-
42  
-  private final SelectionListener fCheckBoxListener = new SelectionAdapter() {
43  
-    @Override
44  
-    public void widgetSelected( final SelectionEvent event ) {
45  
-      Button button = ( Button )event.widget;
46  
-      String key = checkBoxes.get( button );
47  
-      getPreferenceStore().setValue( key, button.getSelection() );
48  
-    }
49  
-  };
50  
-
51  
-  private final ModifyListener fTextFieldListener = new ModifyListener() {
52  
-    public void modifyText( final ModifyEvent event ) {
53  
-      Text text = ( Text )event.widget;
54  
-      String key = textFields.get( text );
55  
-      getPreferenceStore().setValue( key, text.getText() );
56  
-    }
57  
-  };
58  
-
59  
-  public void init(final IWorkbench workbench) {
60  
-	  // do nothing; subclasses may override
61  
-  }
62  
-
63  
-  @Override
64  
-  protected IPreferenceStore doGetPreferenceStore() {
65  
-	  return HaskellUIPlugin.getDefault().getPreferenceStore();
66  
-  }
67  
-
68  
-  public void initializeFields() {
69  
-    initializeCheckboxes();
70  
-    initializeTexts();
71  
-  }
72  
-
73  
-  @Override
74  
-  public boolean performOk() {
75  
-    HaskellUIPlugin.getDefault().savePluginPreferences();
76  
-    return true;
77  
-  }
78  
-
79  
-  protected Control getLabel( final Control field ) {
80  
-    return labels.get( field );
81  
-  }
82  
-
83  
-  // UI creation helping methods for subclasses
84  
-  /////////////////////////////////////////////
85  
-
86  
-  protected void createLabel( final Composite parent, final String text ) {
87  
-    Label label = new Label( parent, SWT.LEFT );
88  
-    label.setText( text );
89  
-    GridData gridData = new GridData();
90  
-    gridData.horizontalAlignment = GridData.BEGINNING;
91  
-    label.setLayoutData( gridData );
92  
-  }
93  
-
94  
-  protected final Button addBooleanField( final Composite parent,
95  
-                                          final String label,
96  
-                                          final String key,
97  
-                                          final int indentation ) {
98  
-    Button checkBox = new Button( parent, SWT.CHECK );
99  
-    checkBox.setText( label );
100  
-
101  
-    GridData gd = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
102  
-    gd.horizontalIndent = indentation;
103  
-    gd.horizontalSpan = 2;
104  
-    checkBox.setLayoutData( gd );
105  
-    checkBox.addSelectionListener( fCheckBoxListener );
106  
-
107  
-    checkBoxes.put( checkBox, key );
108  
-
109  
-    return checkBox;
110  
-  }
111  
-
112  
-  protected DialogField createBooleanField( final Composite parent,
113  
-		  final String text,
114  
-		  final String name ) {
115  
-	  BooleanDialogField result = new BooleanDialogField( parent, text );
116  
-	  result.addDialogFieldListener( new IDialogFieldListener() {
117  
-		  public void infoChanged( final Object newInfo ) {
118  
-			  boolean selected = ( ( Boolean )newInfo ).booleanValue();
119  
-			  getPreferenceStore().setValue( name, selected );
120  
-		  }
121  
-	  } );
122  
-	  result.setInfo( getFromStore( name ) );
123  
-	  return result;
124  
-  }
125  
-
126  
-  protected Control addIntegerField( final Composite composite,
127  
-                                     final String label,
128  
-                                     final String key,
129  
-                                     final int textLimit,
130  
-                                     final int indentation ) {
131  
-    Text result = addStringField( composite, label, textLimit, indentation );
132  
-    textFields.put( result, key );
133  
-    return result;
134  
-  }
135  
-
136  
-  protected Control addTextField( final Composite composite,
137  
-                                  final String label,
138  
-                                  final String key,
139  
-                                  final int textLimit,
140  
-                                  final int indentation ) {
141  
-    Text result = addStringField( composite, label, textLimit, indentation );
142  
-    textFields.put( result, key );
143  
-    result.addModifyListener( fTextFieldListener );
144  
-    return result;
145  
-  }
146  
-
147  
-  // helping methods
148  
-  //////////////////
149  
-
150  
-  private Text addStringField( final Composite composite,
151  
-                               final String label,
152  
-                               final int textLimit,
153  
-                               final int indentation ) {
154  
-    Label labelControl = new Label( composite, SWT.NONE );
155  
-    labelControl.setText( label );
156  
-    GridData gd = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
157  
-    gd.horizontalIndent = indentation;
158  
-    labelControl.setLayoutData( gd );
159  
-
160  
-    Text textControl = new Text( composite, SWT.BORDER | SWT.SINGLE );
161  
-    gd = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING );
162  
-    gd.widthHint = DialogUtil.convertWidthInCharsToPixels( textControl,
163  
-                                                           textLimit + 1 );
164  
-    textControl.setLayoutData( gd );
165  
-    textControl.setTextLimit( textLimit );
166  
-
167  
-    labels.put( textControl, labelControl );
168  
-    return textControl;
169  
-  }
170  
-
171  
-  private void initializeTexts() {
172  
-    Iterator<Text> iter = textFields.keySet().iterator();
173  
-    while( iter.hasNext() ) {
174  
-      Text text = iter.next();
175  
-      String key = textFields.get( text );
176  
-      text.setText( getPreferenceStore().getString( key ) );
177  
-    }
178  
-  }
179  
-
180  
-  private void initializeCheckboxes() {
181  
-    Iterator<Button> iter = checkBoxes.keySet().iterator();
182  
-    while( iter.hasNext() ) {
183  
-      Button button = iter.next();
184  
-      String key = checkBoxes.get( button );
185  
-      button.setSelection( getPreferenceStore().getBoolean( key ) );
186  
-    }
187  
-  }
188  
-
189  
-  private Boolean getFromStore( final String name ) {
190  
-	boolean value = getPreferenceStore().getBoolean( name );
191  
-	return ( value ) ? Boolean.TRUE : Boolean.FALSE;
192  
-  }
  11
+/**
  12
+ * A class similar to Eclipse's {@link FieldEditorPreferencePage},
  13
+ * but with more flexibility.
  14
+ *
  15
+ * @author Leif Frenzel
  16
+ * @author Thomas ten Cate
  17
+ */
  18
+public abstract class HaskellPreferencePage extends AbstractPreferencePage
  19
+implements IPreferenceConstants {
  20
+
  21
+	@Override
  22
+	protected IPreferenceStore doGetPreferenceStore() {
  23
+		return HaskellUIPlugin.getDefault().getPreferenceStore();
  24
+	}
193 25
 
194 26
 }
422  net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/AnnotationsPP.java
@@ -19,224 +19,224 @@
19 19
 import org.eclipse.swt.widgets.Button;
20 20
 import org.eclipse.swt.widgets.Composite;
21 21
 import org.eclipse.swt.widgets.Control;
22  
-import org.eclipse.swt.widgets.Label;
  22
+import org.eclipse.swt.widgets.Group;
23 23
 import org.eclipse.swt.widgets.List;
24 24
 import org.eclipse.ui.IWorkbench;
  25
+import org.eclipse.ui.forms.widgets.ColumnLayout;
25 26
 import org.eclipse.ui.texteditor.AnnotationPreference;
26 27
 import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
27 28
 
28 29
 
29 30
 /** <p>Preference page for the annotation color preference settings.</p>
30  
-  *
31  
-  * @author Leif Frenzel
32  
-  *
33  
-  * TODO: Preferences probably take effect immediately, instead of waiting for Apply.
34  
-  * TODO: Restore Defaults button does not work.
35  
-  * TODO: There are many unnecessary items in the list.
36  
-  */
  31
+ *
  32
+ * @author Leif Frenzel
  33
+ *
  34
+ * TODO: Preferences probably take effect immediately, instead of waiting for Apply.
  35
+ * TODO: Restore Defaults button does not work.
  36
+ * TODO: There are many unnecessary items in the list.
  37
+ */
37 38
 public class AnnotationsPP extends HaskellPreferencePage {
38 39
 
39  
-  private List colorList;
40  
-
41  
-  private String[][] colorListModel;
42  
-  private ColorSelector colorSelector;
43  
-  private Button cbShowInText;
44  
-  private Button cbShowInOverviewRuler;
45  
-
46  
-  @Override
47  
-  public void init(final IWorkbench workbench) {
48  
-	super.init(workbench);
49  
-    colorListModel = createAnnotationTypeListModel();
50  
-  }
51  
-
52  
-  @Override
53  
-  public Control createContents( final Composite parent ) {
54  
-    Composite composite = new Composite( parent, SWT.NONE );
55  
-    GridLayout layout = new GridLayout();
56  
-    layout.numColumns = 2;
57  
-    composite.setLayout( layout );
58  
-
59  
-    initializeAnnPresLabel( composite );
60  
-    Composite editorComposite = initializeEditorComposite( composite );
61  
-    initializeColorList( composite, editorComposite );
62  
-    Composite optionsComposite = initializeOptionsComposite( editorComposite );
63  
-    initializeShowInTextCB( optionsComposite );
64  
-    initializeShowInOverviewRulerCB( optionsComposite );
65  
-    createLabel( optionsComposite, "C&olor:" );
66  
-    initializeColorSelector( optionsComposite );
67  
-
68  
-    initialize();
69  
-
70  
-    return composite;
71  
-  }
72  
-
73  
-  void addPreferences( final OverlayPreferenceStore store ) {
74  
-    MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
75  
-    Iterator iter = preferences.getAnnotationPreferences().iterator();
76  
-    while( iter.hasNext() ) {
77  
-      AnnotationPreference info = ( AnnotationPreference )iter.next();
78  
-      store.addStringKey( info.getColorPreferenceKey() );
79  
-      store.addBooleanKey( info.getTextPreferenceKey() );
80  
-      store.addBooleanKey( info.getOverviewRulerPreferenceKey() );
81  
-    }
82  
-  }
83  
-
84  
-
85  
-  // UI initialization methods
86  
-  ////////////////////////////
87  
-
88  
-  private Composite initializeOptionsComposite( final Composite parent ) {
89  
-    Composite optionsComposite = new Composite( parent, SWT.NONE );
90  
-    GridLayout layout = new GridLayout();
91  
-    layout.marginHeight = 0;
92  
-    layout.marginWidth = 0;
93  
-    layout.numColumns = 2;
94  
-    optionsComposite.setLayout( layout );
95  
-    optionsComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
96  
-    return optionsComposite;
97  
-  }
98  
-
99  
-  private void initializeColorList( final Composite composite,
100  
-                                    final Composite parent ) {
101  
-    colorList = new List( parent, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
102  
-    GridData gridData = new GridData(   GridData.VERTICAL_ALIGN_BEGINNING
103  
-                                      | GridData.FILL_HORIZONTAL );
104  
-    gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
105  
-                                                                   8 );
106  
-    colorList.setLayoutData( gridData );
107  
-    colorList.addSelectionListener( new SelectionAdapter() {
108  
-      @Override
109  
-      public void widgetSelected( final SelectionEvent e ) {
110  
-        handleAnnotationColorListSelection();
111  
-      }
112  
-    } );
113  
-  }
114  
-
115  
-  private void initializeColorSelector( final Composite parent ) {
116  
-    colorSelector = new ColorSelector( parent );
117  
-    Button foregroundColorButton = colorSelector.getButton();
118  
-    GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
119  
-    gridData.horizontalAlignment = GridData.BEGINNING;
120  
-    foregroundColorButton.setLayoutData( gridData );
121  
-    foregroundColorButton.addSelectionListener( new SelectionAdapter() {
122  
-      @Override
123  
-      public void widgetSelected( final SelectionEvent e ) {
124  
-        int i = colorList.getSelectionIndex();
125  
-        String key = colorListModel[ i ][ 1 ];
126  
-        RGB colorValue = colorSelector.getColorValue();
127  
-        PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
128  
-      }
129  
-    } );
130  
-  }
131  
-
132  
-  private void initializeAnnPresLabel( final Composite parent ) {
133  
-    Label label = new Label( parent, SWT.LEFT );
134  
-    label.setText( "Annotation &presentation:" );
135  
-    GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL );
136  
-    gridData.horizontalSpan = 2;
137  
-    label.setLayoutData( gridData );
138  
-  }
139  
-
140  
-  private Composite initializeEditorComposite( final Composite parent ) {
141  
-    Composite editorComposite = new Composite( parent, SWT.NONE );
142  
-    GridLayout layout = new GridLayout();
143  
-    layout.numColumns = 2;
144  
-    layout.marginHeight = 0;
145  
-    layout.marginWidth = 0;
146  
-    editorComposite.setLayout( layout );
147  
-    GridData gridData = new GridData(   GridData.HORIZONTAL_ALIGN_FILL
148  
-                                      | GridData.FILL_VERTICAL );
149  
-    gridData.horizontalSpan = 2;
150  
-    editorComposite.setLayoutData( gridData );
151  
-    return editorComposite;
152  
-  }
153  
-
154  
-  private void initializeShowInOverviewRulerCB( final Composite parent ) {
155  
-    cbShowInOverviewRuler = new Button( parent, SWT.CHECK );
156  
-    cbShowInOverviewRuler.setText( "Show in overview &ruler" );
157  
-    GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
158  
-    gridData.horizontalAlignment = GridData.BEGINNING;
159  
-    gridData.horizontalSpan = 2;
160  
-    cbShowInOverviewRuler.setLayoutData( gridData );
161  
-    cbShowInOverviewRuler.addSelectionListener( new SelectionAdapter() {
162  
-      @Override
163  
-      public void widgetSelected( final SelectionEvent e ) {
164  
-        int i = colorList.getSelectionIndex();
165  
-        String key = colorListModel[ i ][ 3 ];
166  
-        boolean selected = cbShowInOverviewRuler.getSelection();
167  
-        getPreferenceStore().setValue( key, selected );
168  
-      }
169  
-    } );
170  
-  }
171  
-
172  
-  private void initializeShowInTextCB( final Composite parent ) {
173  
-    cbShowInText = new Button( parent, SWT.CHECK );
174  
-    cbShowInText.setText( "Show in &text" );
175  
-    GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
176  
-    gridData.horizontalAlignment = GridData.BEGINNING;
177  
-    gridData.horizontalSpan = 2;
178  
-    cbShowInText.setLayoutData( gridData );
179  
-    cbShowInText.addSelectionListener( new SelectionAdapter() {
180  
-      @Override
181  
-      public void widgetSelected( final SelectionEvent e ) {
182  
-        int i = colorList.getSelectionIndex();
183  
-        String key = colorListModel[ i ][ 2 ];
184  
-        boolean selected = cbShowInText.getSelection();
185  
-        getPreferenceStore().setValue( key, selected );
186  
-      }
187  
-    } );
188  
-  }
189  
-
190  
-
191  
-  // helping methods
192  
-  //////////////////
193  
-
194  
-  private void handleAnnotationColorListSelection() {
195  
-    int i = colorList.getSelectionIndex();
196  
-    String key = colorListModel[ i ][ 1 ];
197  
-    RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
198  
-    colorSelector.setColorValue( rgb );
199  
-    key = colorListModel[ i ][ 2 ];
200  
-    boolean sel = getPreferenceStore().getBoolean( key );
201  
-    cbShowInText.setSelection( sel );
202  
-    key = colorListModel[ i ][ 3 ];
203  
-    cbShowInOverviewRuler.setSelection( sel );
204  
-  }
205  
-
206  
-  private String[][] createAnnotationTypeListModel() {
207  
-    MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
208  
-    ArrayList<String[]> listModelItems = new ArrayList<String[]>();
209  
-    Iterator i = preferences.getAnnotationPreferences().iterator();
210  
-    while( i.hasNext() ) {
211  
-      AnnotationPreference info = ( AnnotationPreference )i.next();
212  
-      listModelItems.add( new String[] {
213  
-        info.getPreferenceLabel(),
214  
-        info.getColorPreferenceKey(),
215  
-        info.getTextPreferenceKey(),
216  
-        info.getOverviewRulerPreferenceKey() }
217  
-      );
218  
-    }
219  
-
220  
-    String[][] listModel = new String[ listModelItems.size() ][];
221  
-    listModelItems.toArray( listModel );
222  
-    return listModel;
223  
-  }
224  
-
225  
-  private void initialize() {
226  
-    for( int i = 0; i < colorListModel.length; i++ ) {
227  
-      String color = colorListModel[ i ][ 0 ];
228  
-      if( color != null ) {
229  
-        colorList.add( color );
230  
-      }
231  
-    }
232  
-    colorList.getDisplay().asyncExec( new Runnable() {
233  
-      public void run() {
234  
-        if( ( colorList != null ) && !colorList.isDisposed() ) {
235  
-          colorList.select( 0 );
236  
-          handleAnnotationColorListSelection();
237  
-        }
238  
-      }
239  
-    } );
240  
-    initializeFields();
241  
-  }
  40
+	private List colorList;
  41
+
  42
+	private String[][] colorListModel;
  43
+	private ColorSelector colorSelector;
  44
+	private Button cbShowInText;
  45
+	private Button cbShowInOverviewRuler;
  46
+
  47
+	@Override
  48
+	public void init(final IWorkbench workbench) {
  49
+		super.init(workbench);
  50
+		colorListModel = createAnnotationTypeListModel();
  51
+	}
  52
+
  53
+	@Override
  54
+	protected Control createContents( final Composite parent ) {
  55
+		Composite composite = new Composite( parent, SWT.NONE );
  56
+		ColumnLayout layout = new ColumnLayout();
  57
+		layout.maxNumColumns = 1;
  58
+		composite.setLayout(layout);
  59
+
  60
+		createAppearanceGroup(composite);
  61
+
  62
+		initialize();
  63
+		return composite;
  64
+	}
  65
+
  66
+	void addPreferences( final OverlayPreferenceStore store ) {
  67
+		MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
  68
+		Iterator iter = preferences.getAnnotationPreferences().iterator();
  69
+		while( iter.hasNext() ) {
  70
+			AnnotationPreference info = ( AnnotationPreference )iter.next();
  71
+			store.addStringKey( info.getColorPreferenceKey() );
  72
+			store.addBooleanKey( info.getTextPreferenceKey() );
  73
+			store.addBooleanKey( info.getOverviewRulerPreferenceKey() );
  74
+		}
  75
+	}
  76
+
  77
+
  78
+	// UI initialization methods
  79
+	////////////////////////////
  80
+
  81
+	private void createAppearanceGroup(final Composite parent) {
  82
+		Group group = new Group(parent, SWT.SHADOW_ETCHED_IN);
  83
+		group.setText("Appearance");
  84
+		GridLayout groupLayout = new GridLayout();
  85
+		groupLayout.numColumns = 1;
  86
+		group.setLayout(groupLayout);
  87
+
  88
+		Composite editorComposite = initializeEditorComposite(group);
  89
+		initializeColorList(group, editorComposite );
  90
+		Composite optionsComposite = initializeOptionsComposite( editorComposite );
  91
+		initializeShowInTextCB( optionsComposite );
  92
+		initializeShowInOverviewRulerCB( optionsComposite );
  93
+		createLabel( optionsComposite, "C&olor:" );
  94
+		initializeColorSelector( optionsComposite );
  95
+	}
  96
+
  97
+	private Composite initializeOptionsComposite( final Composite parent ) {
  98
+		Composite optionsComposite = new Composite( parent, SWT.NONE );
  99
+		GridLayout layout = new GridLayout();
  100
+		layout.marginHeight = 0;
  101
+		layout.marginWidth = 0;
  102
+		layout.numColumns = 2;
  103
+		optionsComposite.setLayout( layout );
  104
+		optionsComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
  105
+		return optionsComposite;
  106
+	}
  107
+
  108
+	private void initializeColorList( final Composite composite,
  109
+			final Composite parent ) {
  110
+		colorList = new List( parent, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER );
  111
+		GridData gridData = new GridData(   GridData.VERTICAL_ALIGN_BEGINNING
  112
+				| GridData.FILL_HORIZONTAL );
  113
+		gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
  114
+				8 );
  115
+		colorList.setLayoutData( gridData );
  116
+		colorList.addSelectionListener( new SelectionAdapter() {
  117
+			@Override
  118
+			public void widgetSelected( final SelectionEvent e ) {
  119
+				handleAnnotationColorListSelection();
  120
+			}
  121
+		} );
  122
+	}
  123
+
  124
+	private void initializeColorSelector( final Composite parent ) {
  125
+		colorSelector = new ColorSelector( parent );
  126
+		Button foregroundColorButton = colorSelector.getButton();
  127
+		GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
  128
+		gridData.horizontalAlignment = GridData.BEGINNING;
  129
+		foregroundColorButton.setLayoutData( gridData );
  130
+		foregroundColorButton.addSelectionListener( new SelectionAdapter() {
  131
+			@Override
  132
+			public void widgetSelected( final SelectionEvent e ) {
  133
+				int i = colorList.getSelectionIndex();
  134
+				String key = colorListModel[ i ][ 1 ];
  135
+				RGB colorValue = colorSelector.getColorValue();
  136
+				PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
  137
+			}
  138
+		} );
  139
+	}
  140
+
  141
+	private Composite initializeEditorComposite( final Composite parent ) {
  142
+		Composite editorComposite = new Composite( parent, SWT.NONE );
  143
+		GridLayout layout = new GridLayout();
  144
+		layout.numColumns = 2;
  145
+		layout.horizontalSpacing = 10;
  146
+		editorComposite.setLayout( layout );
  147
+		GridData gridData = new GridData(   GridData.HORIZONTAL_ALIGN_FILL
  148
+				| GridData.FILL_VERTICAL );
  149
+		gridData.horizontalSpan = 2;
  150
+		editorComposite.setLayoutData( gridData );
  151
+		return editorComposite;
  152
+	}
  153
+
  154
+	private void initializeShowInOverviewRulerCB( final Composite parent ) {
  155
+		cbShowInOverviewRuler = new Button( parent, SWT.CHECK );
  156
+		cbShowInOverviewRuler.setText( "Show in overview &ruler" );
  157
+		GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
  158
+		gridData.horizontalAlignment = GridData.BEGINNING;
  159
+		gridData.horizontalSpan = 2;
  160
+		cbShowInOverviewRuler.setLayoutData( gridData );
  161
+		cbShowInOverviewRuler.addSelectionListener( new SelectionAdapter() {
  162
+			@Override
  163
+			public void widgetSelected( final SelectionEvent e ) {
  164
+				int i = colorList.getSelectionIndex();
  165
+				String key = colorListModel[ i ][ 3 ];
  166
+				boolean selected = cbShowInOverviewRuler.getSelection();
  167
+				getPreferenceStore().setValue( key, selected );
  168
+			}
  169
+		} );
  170
+	}
  171
+
  172
+	private void initializeShowInTextCB( final Composite parent ) {
  173
+		cbShowInText = new Button( parent, SWT.CHECK );
  174
+		cbShowInText.setText( "Show in &text" );
  175
+		GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
  176
+		gridData.horizontalAlignment = GridData.BEGINNING;
  177
+		gridData.horizontalSpan = 2;
  178
+		cbShowInText.setLayoutData( gridData );
  179
+		cbShowInText.addSelectionListener( new SelectionAdapter() {
  180
+			@Override
  181
+			public void widgetSelected( final SelectionEvent e ) {
  182
+				int i = colorList.getSelectionIndex();
  183
+				String key = colorListModel[ i ][ 2 ];
  184
+				boolean selected = cbShowInText.getSelection();
  185
+				getPreferenceStore().setValue( key, selected );
  186
+			}
  187
+		} );
  188
+	}
  189
+
  190
+
  191
+	// helping methods
  192
+	//////////////////
  193
+
  194
+	private void handleAnnotationColorListSelection() {
  195
+		int i = colorList.getSelectionIndex();
  196
+		String key = colorListModel[ i ][ 1 ];
  197
+		RGB rgb = PreferenceConverter.getColor( getPreferenceStore(), key );
  198
+		colorSelector.setColorValue( rgb );
  199
+		key = colorListModel[ i ][ 2 ];
  200
+		boolean sel = getPreferenceStore().getBoolean( key );
  201
+		cbShowInText.setSelection( sel );
  202
+		key = colorListModel[ i ][ 3 ];
  203
+		cbShowInOverviewRuler.setSelection( sel );
  204
+	}
  205
+
  206
+	private String[][] createAnnotationTypeListModel() {
  207
+		MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
  208
+		ArrayList<String[]> listModelItems = new ArrayList<String[]>();
  209
+		Iterator i = preferences.getAnnotationPreferences().iterator();
  210
+		while( i.hasNext() ) {
  211
+			AnnotationPreference info = ( AnnotationPreference )i.next();
  212
+			listModelItems.add( new String[] {
  213
+					info.getPreferenceLabel(),
  214
+					info.getColorPreferenceKey(),
  215
+					info.getTextPreferenceKey(),
  216
+					info.getOverviewRulerPreferenceKey() }
  217
+			);
  218
+		}
  219
+
  220
+		String[][] listModel = new String[ listModelItems.size() ][];
  221
+		listModelItems.toArray( listModel );
  222
+		return listModel;
  223
+	}
  224
+
  225
+	private void initialize() {
  226
+		for( int i = 0; i < colorListModel.length; i++ ) {
  227
+			String color = colorListModel[ i ][ 0 ];
  228
+			if( color != null ) {
  229
+				colorList.add( color );
  230
+			}
  231
+		}
  232
+		colorList.getDisplay().asyncExec( new Runnable() {
  233
+			public void run() {
  234
+				if( ( colorList != null ) && !colorList.isDisposed() ) {
  235
+					colorList.select( 0 );
  236
+					handleAnnotationColorListSelection();
  237
+				}
  238
+			}
  239
+		} );
  240
+		loadControlValues();
  241
+	}
242 242
 }
341  ...sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/preferences/editor/ContentAssistPP.java
... ...
@@ -1,6 +1,9 @@
1 1
 // Copyright (c) 2003-2005 by Leif Frenzel - see http://leiffrenzel.de
2 2
 package net.sf.eclipsefp.haskell.ui.internal.preferences.editor;
3 3
 
  4
+import net.sf.eclipsefp.common.ui.preferences.CheckboxPreferenceControl;
  5
+import net.sf.eclipsefp.common.ui.preferences.IValueChangedListener;
  6
+import net.sf.eclipsefp.common.ui.preferences.PreferenceControl;
4 7
 import net.sf.eclipsefp.common.ui.util.DialogUtil;
5 8
 import net.sf.eclipsefp.haskell.ui.internal.preferences.HaskellPreferencePage;
6 9
 
@@ -15,177 +18,179 @@
15 18
 import org.eclipse.swt.widgets.Button;
16 19
 import org.eclipse.swt.widgets.Composite;
17 20
 import org.eclipse.swt.widgets.Control;
18  
-import org.eclipse.swt.widgets.Label;
  21
+import org.eclipse.swt.widgets.Group;
19 22
 import org.eclipse.swt.widgets.List;
  23
+import org.eclipse.ui.forms.widgets.ColumnLayout;
20 24
 
21 25
 /** <p>Preference page for the content assist preference settings.</p>
22  
-  *
23  
-  * @author Leif Frenzel
24  
-  *
25  
-  * TODO: None of these preferences have any effect yet, I think.
26  
-  * TODO: Preferences take effect immediately, instead of waiting for Apply.
27  
-  * TODO: Restore Defaults button does not work.
28  
-  */
  26
+ *
  27
+ * @author Leif Frenzel
  28
+ *
  29
+ * TODO: None of these preferences have any effect yet, I think.
  30
+ * TODO: Preferences take effect immediately, instead of waiting for Apply.
  31
+ * TODO: Restore Defaults button does not work.
  32
+ */
29 33
 public class ContentAssistPP extends HaskellPreferencePage implements IEditorPreferenceNames {
30 34
 
31  
-  private final ColorListEntry[] colorListModel = new ColorListEntry[] {
32  
-    new ColorListEntry( "Completion proposal background",
33  
-                        CA_PROPOSALS_BACKGROUND ),
34  
-    new ColorListEntry( "Completion proposal foreground",
35  
-                        CA_PROPOSALS_FOREGROUND ) };
36  
-
37  
-  private List colorList;
38  
-  private ColorSelector colorSelector;
39  
-  private Control txtAutoActDelay;
40  
-  private Control txtActTriggers;
41  
-
42  
-  @Override
43  
-  public Control createContents( final Composite parent ) {
44  
-    Composite composite = new Composite( parent, SWT.NONE );
45  
-    GridLayout layout = new GridLayout();
46  
-    layout.numColumns = 2;
47  
-    composite.setLayout( layout );
48  
-
49  
-    createFields( composite );
50  
-    createOptionsLabel( composite );
51  
-    Composite editorComposite = createEditorComposite( composite );
52  
-    createColorList( composite, editorComposite );
53  
-    Composite stylesComposite = createStylesComposite( editorComposite );
54  
-    createLabel( stylesComposite, "C&olor:" );
55  
-    createColorSelector( stylesComposite );
56  
-    initialize();
57  
-    return composite;
58  
-  }
59  
-
60  
-
61  
-  // UI creation methods
62  
-  //////////////////////
63  
-
64  
-  private void createColorList( final Composite composite,
65  
-                                final Composite editorComposite ) {
66  
-    int style = SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER;
67  
-    colorList = new List( editorComposite, style );
68  
-    GridData gridData = new GridData(   GridData.VERTICAL_ALIGN_BEGINNING
69  
-                                      | GridData.FILL_HORIZONTAL );
70  
-    gridData.heightHint = DialogUtil.convertHeightInCharsToPixels( composite,
71  
-                                                                   8 );
72  
-    colorList.setLayoutData( gridData );
73  
-    colorList.addSelectionListener( new SelectionAdapter() {
74  
-      @Override
75  
-      public void widgetSelected( final SelectionEvent e ) {
76  
-        handleColorListSelection();
77  
-      }
78  
-    } );
79  
-  }
80  
-
81  
-  private void createColorSelector( final Composite parent ) {
82  
-    colorSelector = new ColorSelector( parent );
83  
-    Button colorButton = colorSelector.getButton();
84  
-    GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
85  
-    gridData.horizontalAlignment = GridData.BEGINNING;
86  
-    colorButton.setLayoutData( gridData );
87  
-    colorButton.addSelectionListener( new SelectionAdapter() {
88  
-      @Override
89  
-      public void widgetSelected( final SelectionEvent e ) {
90  
-        int i = colorList.getSelectionIndex();
91  
-        String key = colorListModel[ i ].getColorKey();
92  
-        RGB colorValue = colorSelector.getColorValue();
93  
-        PreferenceConverter.setValue( getPreferenceStore(), key, colorValue );
94  
-      }
95  
-    } );
96  
-  }
97  
-
98  
-  private Composite createStylesComposite( final Composite parent ) {
99  
-    GridLayout layout;
100  
-    Composite stylesComposite = new Composite( parent, SWT.NONE );
101  
-    layout = new GridLayout();
102  
-    layout.marginHeight = 0;
103  
-    layout.marginWidth = 0;
104  
-    layout.numColumns = 2;
105  
-    stylesComposite.setLayout( layout );
106  
-    stylesComposite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
107  
-    return stylesComposite;
108  
-  }
109  
-
110  
-  private Composite createEditorComposite( final Composite parent ) {
111  
-    Composite editorComposite = new Composite( parent, SWT.NONE );
112  
-    GridLayout layout = new GridLayout();
113  
-    layout.numColumns = 2;
114  
-    layout.marginHeight = 0;
115  
-    layout.marginWidth = 0;
116  
-    editorComposite.setLayout( layout );