In progress: [Issue 104] 	Update "Next Id" comment when generating a the
tag number of a field or literal

Code cleanup.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/StringListPreference.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/StringListPreference.java
new file mode 100644
index 0000000..b2a3df4
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/StringListPreference.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.preferences;
+
+import static org.eclipse.xtext.util.Strings.*;
+
+import java.util.List;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * A preference that stores a list of {@code String} values.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class StringListPreference extends Preference<List<String>> {
+
+  private final String delimiter;
+
+  /**
+   * Creates a new </code>{@link StringListPreference}</code>.
+   * @param name the name of this preference.
+   * @param delimiter the delimiter to split a single {@code String} into a list.
+   * @param store the store for this preference.
+   */
+  public StringListPreference(String name, String delimiter, IPreferenceStore store) {
+    super(name, store);
+    this.delimiter = delimiter;
+  }
+
+  /** {@inheritDoc} */
+  @Override public List<String> value() {
+    return doSplit(store.getString(name));
+  }
+
+  /** {@inheritDoc} */
+  @Override public List<String> defaultValue() {
+    return doSplit(store.getDefaultString(name));
+  }
+
+  private List<String> doSplit(String value) {
+    return split(value, delimiter);
+  }
+
+  /** {@inheritDoc} */
+  @Override public void value(List<String> value) {
+    store.setValue(name, doConcat(value));
+  }
+
+  /** {@inheritDoc} */
+  @Override public void defaultValue(List<String> value) {
+    store.setDefault(name, doConcat(value));
+  }
+
+  private String doConcat(List<String> value) {
+    return concat(delimiter, value);
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToListItems.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToListItems.java
new file mode 100644
index 0000000..3544396
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToListItems.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.preferences.binding;
+
+import static java.util.Arrays.asList;
+
+import java.util.Collection;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.swt.widgets.List;
+
+import com.google.eclipse.protobuf.ui.preferences.StringListPreference;
+
+/**
+ * Binds a {@code String} value from a <code>{@link IPreferenceStore}</code> to a list of items of a
+ * <code>{@link List}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class BindingToListItems implements Binding {
+
+  private final List list;
+  private final StringListPreference preference;
+
+  public static BindingBuilder bindItemsOf(List list) {
+    return new BindingBuilder(list);
+  }
+
+  /**
+   * Creates a new </code>{@link BindingToListItems}</code>.
+   * @param list the control to bind to the preference.
+   * @param preference the given preference.
+   */
+  private BindingToListItems(List list, StringListPreference preference) {
+    this.list = list;
+    this.preference = preference;
+  }
+
+  /** {@inheritDoc} */
+  public void applyPreferenceValueToTarget() {
+    applyValue(preference.value());
+  }
+
+  /** {@inheritDoc} */
+  public void applyDefaultPreferenceValueToTarget() {
+    applyValue(preference.defaultValue());
+  }
+
+  private void applyValue(Collection<String> value) {
+    list.removeAll();
+    for (String s : value) list.add(s);
+  }
+
+  /** {@inheritDoc} */
+  public void savePreferenceValue() {
+    preference.value(asList(list.getItems()));
+  }
+
+  public static class BindingBuilder {
+    private final List list;
+
+    /**
+     * Creates a new </code>{@link BindingBuilder}</code>.
+     * @param list the list whose items will be bound to a preference value.
+     */
+    public BindingBuilder(List list) {
+      this.list = list;
+    }
+
+    /**
+     * Creates a new <code>{@link BindingToListItems}</code>.
+     * @param preference the preference to bind to the value of this builder's list.
+     * @return the created binding.
+     */
+    public BindingToListItems to(StringListPreference preference) {
+      return new BindingToListItems(list, preference);
+    }
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToTextValue.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToTextValue.java
index 92c2e5b..002e4a0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToTextValue.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToTextValue.java
@@ -14,7 +14,7 @@
 import com.google.eclipse.protobuf.ui.preferences.StringPreference;
 
 /**
- * Binds a {@code boolean} value from a <code>{@link IPreferenceStore}</code> to the value of a
+ * Binds a {@code String} value from a <code>{@link IPreferenceStore}</code> to the value of a
  * <code>{@link Text}</code>.
  *
  * @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
index 6495ce1..4b5f513 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
@@ -8,9 +8,8 @@
  */
 package com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag;
 
+import static com.google.eclipse.protobuf.ui.preferences.binding.BindingToListItems.bindItemsOf;
 import static com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag.Messages.*;
-import static java.util.Arrays.asList;
-import static org.eclipse.xtext.util.Strings.*;
 
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.ListViewer;
@@ -20,7 +19,7 @@
 import org.eclipse.swt.widgets.*;
 
 import com.google.eclipse.protobuf.ui.preferences.*;
-import com.google.eclipse.protobuf.ui.preferences.binding.*;
+import com.google.eclipse.protobuf.ui.preferences.binding.PreferenceBinder;
 import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage;
 
 /**
@@ -30,7 +29,6 @@
  */
 public class NumericTagPreferencePage extends PreferenceAndPropertyPage {
 
-  private static final String PATTERN_DELIMITER = "//t"; //$NON-NLS-1$
   private static final String PREFERENCE_PAGE_ID = NumericTagPreferencePage.class.getName();
 
   private List lstPaths;
@@ -102,30 +100,8 @@
 
   @Override protected void setupBinding(PreferenceBinder preferenceBinder) {
     RawPreferences preferences = new RawPreferences(getPreferenceStore());
-    final StringPreference patterns = preferences.patterns();
-    preferenceBinder.add(new Binding() {
-      public void applyPreferenceValueToTarget() {
-        setPatterns(patterns.value());
-      }
-
-      public void applyDefaultPreferenceValueToTarget() {
-        setPatterns(patterns.defaultValue());
-      }
-
-      public void savePreferenceValue() {
-        patterns.value(patterns());
-      }
-    });
-  }
-
-  private void setPatterns(String value) {
-    lstPaths.removeAll();
-    for (String pattern : split(value, PATTERN_DELIMITER))
-      lstPaths.add(pattern);
-  }
-
-  private String patterns() {
-    return concat(PATTERN_DELIMITER, asList(lstPaths.getItems()));
+    StringListPreference patterns = preferences.patterns();
+    preferenceBinder.add(bindItemsOf(lstPaths).to(patterns));
   }
 
   @Override protected void onProjectSettingsActivation(boolean projectSettingsActive) {}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferenceStoreInitializer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferenceStoreInitializer.java
index 5e6499a..8ca44a0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferenceStoreInitializer.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferenceStoreInitializer.java
@@ -8,6 +8,8 @@
  */
 package com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag;
 
+import static java.util.Collections.singletonList;
+
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.xtext.ui.editor.preferences.*;
 
@@ -22,6 +24,6 @@
   public void initialize(IPreferenceStoreAccess access) {
     IPreferenceStore store = access.getWritablePreferenceStore();
     RawPreferences preferences = new RawPreferences(store);
-    preferences.patterns().defaultValue("Next[\\s]+Id:[\\s]+[\\d]+");
+    preferences.patterns().defaultValue(singletonList("Next[\\s]+Id:[\\s]+[\\d]+"));
   }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/RawPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/RawPreferences.java
index 5c6cee2..f414aab 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/RawPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/RawPreferences.java
@@ -11,20 +11,20 @@
 
 import org.eclipse.jface.preference.IPreferenceStore;
 
-import com.google.eclipse.protobuf.ui.preferences.StringPreference;
+import com.google.eclipse.protobuf.ui.preferences.StringListPreference;
 
 /**
  * @author alruiz@google.com (Alex Ruiz)
  */
 class RawPreferences {
 
-  private final StringPreference patterns;
+  private final StringListPreference patterns;
 
   RawPreferences(IPreferenceStore store) {
-    patterns = new StringPreference("numericTag.patterns", store);
+    patterns = new StringListPreference("numericTag.patterns", "\\t", store);
   }
 
-  StringPreference patterns() {
+  StringListPreference patterns() {
     return patterns;
   }
 }