Cleaning up preferences-related code.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java index 9d9c461..cb22c3a 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java
@@ -8,6 +8,7 @@ */ package com.google.eclipse.protobuf.ui.preferences.pages; +import static com.google.eclipse.protobuf.ui.preferences.binding.BindingToButtonSelection.bindSelectionOf; import static com.google.eclipse.protobuf.ui.preferences.pages.Messages.*; import static org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialogOn; @@ -23,6 +24,7 @@ import org.eclipse.ui.*; import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess; +import com.google.eclipse.protobuf.ui.preferences.BooleanPreference; import com.google.eclipse.protobuf.ui.preferences.binding.PreferenceBinder; import com.google.inject.Inject; @@ -33,7 +35,7 @@ */ public abstract class PreferenceAndPropertyPage extends PreferencePage implements IWorkbenchPreferencePage, IWorkbenchPropertyPage { - protected Button btnEnableProjectSettings; + private Button btnEnableProjectSettings; private Link lnkEnableWorkspaceSettings; @@ -47,6 +49,7 @@ @Override protected final Control createContents(Composite parent) { Composite contents = contentParent(parent); doCreateContents(contents); + setupBtnEnabledProjectSettingsBinding(); setupBinding(preferenceBinder); preferenceBinder.applyValues(); updateContents(); @@ -117,6 +120,21 @@ */ protected abstract void doCreateContents(Composite parent); + private void setupBtnEnabledProjectSettingsBinding() { + BooleanPreference preference = enableProjectSettingsPreference(getPreferenceStore()); + if (preference == null) return; + preferenceBinder.add(bindSelectionOf(btnEnableProjectSettings).to(preference)); + } + + /** + * Returns the preference that indicates whether this page is a "Project Properties" or a "Workspace Preferences" + * page. + * @param store the store where the preference value is stored. + * @return the preference that indicates whether this page is a "Project Properties" or a "Workspace Preferences" + * page. + */ + protected abstract BooleanPreference enableProjectSettingsPreference(IPreferenceStore store); + /** * Sets up data binding. * @param preferenceBinder the preference binder; @@ -155,9 +173,9 @@ } /** - * Indicates whether this page is a "Project Properties" page or not. + * Indicates whether this page is a "Project Properties" or a "Workspace Preferences" page. * @return {@code true} if this page is a "Project Properties" page, or {@code false} if this page is a - * "Workspace Settings" page. + * "Workspace Preferences" page. */ protected final boolean isPropertyPage() { return project != null; @@ -201,13 +219,9 @@ @Override public final boolean performOk() { preferenceBinder.saveValues(); - okPerformed(); return true; } - /** Method invoked after this page's defaults have been saved. By default this method does nothing. */ - protected void okPerformed() {} - @Override protected final void performDefaults() { preferenceBinder.applyDefaults(); updateContents();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java index 81c9908..50b0976 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java
@@ -11,6 +11,7 @@ import static com.google.eclipse.protobuf.ui.preferences.binding.BindingToButtonSelection.bindSelectionOf; import static com.google.eclipse.protobuf.ui.preferences.binding.BindingToTextValue.bindTextOf; import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.BindingToCodeGeneration.bindCodeGeneration; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.EnableProjectSettingsPreference.enableProjectSettings; import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.Messages.*; import static com.google.eclipse.protobuf.ui.swt.EventListeners.addSelectionListener; import static java.util.Arrays.asList; @@ -18,13 +19,14 @@ import java.io.File; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; import org.eclipse.xtext.ui.PluginImageHelper; -import com.google.eclipse.protobuf.ui.preferences.DataChangedListener; +import com.google.eclipse.protobuf.ui.preferences.*; import com.google.eclipse.protobuf.ui.preferences.binding.PreferenceBinder; import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage; import com.google.inject.Inject; @@ -194,11 +196,12 @@ pageIsNowValid(); } + @Override protected BooleanPreference enableProjectSettingsPreference(IPreferenceStore store) { + return enableProjectSettings(store); + } + @Override protected void setupBinding(PreferenceBinder preferenceBinder) { RawPreferences preferences = new RawPreferences(getPreferenceStore()); - if (isPropertyPage()) { - preferenceBinder.add(bindSelectionOf(btnEnableProjectSettings).to(preferences.enableProjectSettings())); - } preferenceBinder.addAll( bindSelectionOf(btnCompileProtoFiles).to(preferences.compileProtoFiles()), bindSelectionOf(btnUseProtocInSystemPath).to(preferences.useProtocInSystemPath()),
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferenceStoreInitializer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferenceStoreInitializer.java index 4e2b046..23d49f7 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferenceStoreInitializer.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferenceStoreInitializer.java
@@ -8,6 +8,8 @@ */ package com.google.eclipse.protobuf.ui.preferences.pages.compiler; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.EnableProjectSettingsPreference.enableProjectSettings; + import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.xtext.ui.editor.preferences.*; @@ -23,8 +25,8 @@ /** {@inheritDoc} */ public void initialize(IPreferenceStoreAccess access) { IPreferenceStore store = access.getWritablePreferenceStore(); + enableProjectSettings(store).defaultValue(false); RawPreferences preferences = new RawPreferences(store); - preferences.enableProjectSettings().defaultValue(false); preferences.useProtocInSystemPath().defaultValue(true); preferences.javaCodeGenerationEnabled().defaultValue(false); preferences.cppCodeGenerationEnabled().defaultValue(false);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java index 658fc05..1b5ca2f 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java
@@ -8,6 +8,8 @@ */ package com.google.eclipse.protobuf.ui.preferences.pages.compiler; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.EnableProjectSettingsPreference.enableProjectSettings; + import org.eclipse.core.resources.IProject; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess; @@ -25,8 +27,7 @@ public CompilerPreferences getPreferences(IProject project) { IPreferenceStore store = storeAccess.getWritablePreferenceStore(project); - RawPreferences preferences = new RawPreferences(store); - boolean useProjectPreferences = preferences.enableProjectSettings().value(); + boolean useProjectPreferences = enableProjectSettings(store).value(); if (!useProjectPreferences) store = storeAccess.getWritablePreferenceStore(); return new CompilerPreferences(new RawPreferences(store)); }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EnableProjectSettingsPreference.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EnableProjectSettingsPreference.java new file mode 100644 index 0000000..a21d9a8 --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EnableProjectSettingsPreference.java
@@ -0,0 +1,25 @@ +/* + * 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.pages.compiler; + +import org.eclipse.jface.preference.IPreferenceStore; + +import com.google.eclipse.protobuf.ui.preferences.BooleanPreference; + +/** + * @author alruiz@google.com (Alex Ruiz) + */ +class EnableProjectSettingsPreference { + + static BooleanPreference enableProjectSettings(IPreferenceStore store) { + return new BooleanPreference("compiler.enableProjectSettings", store); + } + + private EnableProjectSettingsPreference() {} +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java index 1394d3b..6336819 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java
@@ -17,7 +17,6 @@ */ class RawPreferences { - private final BooleanPreference enableProjectSettings; private final BooleanPreference compileProtoFiles; private final BooleanPreference useProtocInSystemPath; private final BooleanPreference useProtocInCustomPath; @@ -33,7 +32,6 @@ private final BooleanPreference refreshOutputDirectory; RawPreferences(IPreferenceStore store) { - enableProjectSettings = new BooleanPreference("compiler.enableProjectSettings", store); compileProtoFiles = new BooleanPreference("compiler.compileProtoFiles", store); useProtocInSystemPath = new BooleanPreference("compiler.useProtocInSystemPath", store); useProtocInCustomPath = new BooleanPreference("compiler.useProtocInCustomPath", store); @@ -49,10 +47,6 @@ refreshOutputDirectory = new BooleanPreference("compiler.refreshOutputDirectory", store); } - BooleanPreference enableProjectSettings() { - return enableProjectSettings; - } - BooleanPreference compileProtoFiles() { return compileProtoFiles; }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java index ef637d1..f07ba22 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java
@@ -8,10 +8,12 @@ */ package com.google.eclipse.protobuf.ui.preferences.pages.general; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; +import com.google.eclipse.protobuf.ui.preferences.BooleanPreference; import com.google.eclipse.protobuf.ui.preferences.binding.PreferenceBinder; import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage; @@ -35,6 +37,11 @@ } /** {@inheritDoc} */ + @Override protected BooleanPreference enableProjectSettingsPreference(IPreferenceStore store) { + return null; + } + + /** {@inheritDoc} */ @Override protected void setupBinding(PreferenceBinder preferenceBinder) {} /** {@inheritDoc} */
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java index 3c5f8d0..5d96567 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java
@@ -18,6 +18,7 @@ import java.util.*; import java.util.List; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.events.*; import org.eclipse.swt.layout.*; @@ -97,6 +98,10 @@ pageIsNowValid(); } + @Override protected BooleanPreference enableProjectSettingsPreference(IPreferenceStore store) { + return null; // this page is always a "Project Properties" page + } + @Override protected void setupBinding(PreferenceBinder preferenceBinder) { RawPreferences preferences = new RawPreferences(getPreferenceStore()); preferenceBinder.addAll(