Cleaning up preferences-related code.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java index 89845d8..01dc172 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
@@ -31,8 +31,8 @@ import com.google.eclipse.protobuf.ui.internal.ProtobufActivator; import com.google.eclipse.protobuf.ui.outline.*; import com.google.eclipse.protobuf.ui.preferences.PreferenceStoreAccess; -import com.google.eclipse.protobuf.ui.preferences.compiler.CompilerPreferenceStoreInitializer; -import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferenceStoreInitializer; +import com.google.eclipse.protobuf.ui.preferences.pages.compiler.CompilerPreferenceStoreInitializer; +import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathsPreferenceStoreInitializer; import com.google.eclipse.protobuf.ui.scoping.FileUriResolver; import com.google.eclipse.protobuf.ui.validation.ValidateOnActivation; import com.google.inject.*;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/OutputDirectories.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/OutputDirectories.java index bf37387..a2b2214 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/OutputDirectories.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/OutputDirectories.java
@@ -13,7 +13,7 @@ import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; -import com.google.eclipse.protobuf.ui.preferences.compiler.*; +import com.google.eclipse.protobuf.ui.preferences.pages.compiler.*; /** * @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java index 6aa9563..d690534 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtobufBuildParticipant.java
@@ -9,7 +9,7 @@ package com.google.eclipse.protobuf.ui.builder; import static com.google.eclipse.protobuf.ui.builder.OutputDirectories.findOrCreateOutputDirectories; -import static com.google.eclipse.protobuf.ui.preferences.compiler.PostCompilationRefreshTarget.PROJECT; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.PostCompilationRefreshTarget.PROJECT; import static java.util.Collections.unmodifiableList; import static org.eclipse.core.resources.IResource.DEPTH_INFINITE; @@ -25,8 +25,8 @@ import org.eclipse.xtext.resource.*; import org.eclipse.xtext.resource.IResourceDescription.Delta; -import com.google.eclipse.protobuf.ui.preferences.compiler.*; -import com.google.eclipse.protobuf.ui.preferences.paths.*; +import com.google.eclipse.protobuf.ui.preferences.pages.compiler.*; +import com.google.eclipse.protobuf.ui.preferences.pages.paths.*; import com.google.inject.Inject; /**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocCommandFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocCommandFactory.java index c44f2fb..43c9b7f 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocCommandFactory.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/ProtocCommandFactory.java
@@ -12,7 +12,7 @@ import org.eclipse.core.resources.*; -import com.google.eclipse.protobuf.ui.preferences.compiler.SupportedLanguage; +import com.google.eclipse.protobuf.ui.preferences.pages.compiler.SupportedLanguage; /** * @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/Binding.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/Binding.java new file mode 100644 index 0000000..bf52b15 --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/Binding.java
@@ -0,0 +1,43 @@ +/* + * 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 org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.widgets.Control; + +/** + * Binds a value from a <code>{@link IPreferenceStore}</code> to the selection of a + * <code>{@link Control}</code>. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public interface Binding { + + /** + * Reads a preference from the given <code>{@link IPreferenceStore}</code> and applies it to this binding's + * <code>{@link Control}</code>. + * @param store the preference store. + */ + void read(IPreferenceStore store); + + /** + * Reads a default value preference from the given <code>{@link IPreferenceStore}</code> and applies it to the this + * binding's <code>{@link Control}</code>. + * @param store the preference store. + */ + void readDefault(IPreferenceStore store); + + /** + * Applies the value of this binding's <code>{@link Control}</code> to a preference in the given + * <code>{@link IPreferenceStore}</code>. + * @param store the preference store. + */ + void save(IPreferenceStore store); + +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceBinder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceBinder.java new file mode 100644 index 0000000..b31b6d5 --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceBinder.java
@@ -0,0 +1,50 @@ +/* + * 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 java.util.*; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.widgets.Button; + +/** + * Binds preferences to UI controls. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public class PreferenceBinder { + + private final List<Binding> bindings = new ArrayList<Binding>(); + + public void bind(String preferenceName, Button button) { + add(new PreferenceToButtonBinding(preferenceName, button)); + } + + public void add(Binding binding) { + bindings.add(binding); + } + + public void readPreferences(IPreferenceStore store) { + for (Binding binding : bindings) { + binding.read(store); + } + } + + public void readDefaultPreferences(IPreferenceStore store) { + for (Binding binding : bindings) { + binding.readDefault(store); + } + } + + public void savePreferences(IPreferenceStore store) { + for (Binding binding : bindings) { + binding.save(store); + } + } +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceToButtonBinding.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceToButtonBinding.java new file mode 100644 index 0000000..f3eee93 --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceToButtonBinding.java
@@ -0,0 +1,63 @@ +/* + * 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 org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.widgets.Button; + +/** + * Binds a {@code boolean} value from a <code>{@link IPreferenceStore}</code> to the selection of a + * <code>{@link Button}</code>. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public class PreferenceToButtonBinding implements Binding { + + private final String preferenceName; + private final Button button; + + /** + * Creates a new </code>{@link PreferenceToButtonBinding}</code>. + * @param preferenceName the name of the preference to read/write. + * @param button the control to bind to the preference. + */ + public PreferenceToButtonBinding(String preferenceName, Button button) { + this.preferenceName = preferenceName; + this.button = button; + } + + /** + * Reads a {@code boolean} preference from the given <code>{@link IPreferenceStore}</code> and applies it to the + * selection of this binding's button. + * @param store the preference store. + */ + public void read(IPreferenceStore store) { + boolean value = store.getBoolean(preferenceName); + button.setSelection(value); + } + + /** + * Reads the default {@code boolean} preference value from the given <code>{@link IPreferenceStore}</code> and applies + * it to the selection of this binding's button. + * @param store the preference store. + */ + public void readDefault(IPreferenceStore store) { + boolean value = store.getDefaultBoolean(preferenceName); + button.setSelection(value); + } + + /** + * Applies the value of the selection of this binding's button to a preference in the given + * <code>{@link IPreferenceStore}</code>. + * @param store the preference store. + */ + public void save(IPreferenceStore store) { + store.setValue(preferenceName, button.getSelection()); + } +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.java similarity index 91% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Messages.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.java index 79f3b24..59ae611 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Messages.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences; +package com.google.eclipse.protobuf.ui.preferences.pages; import org.eclipse.osgi.util.NLS;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Messages.properties b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.properties similarity index 100% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Messages.properties rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.properties
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/PreferenceAndPropertyPage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java similarity index 95% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/PreferenceAndPropertyPage.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java index 523b149..bfdc354 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/PreferenceAndPropertyPage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences; +package com.google.eclipse.protobuf.ui.preferences.pages; -import static com.google.eclipse.protobuf.ui.preferences.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.Messages.*; import static org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialogOn; import java.util.Map; @@ -41,12 +41,12 @@ @Inject private IPreferenceStoreAccess preferenceStoreAccess; /** - * Creates the <code>{@link Composite}</code> to be used as the base container in implementations of - * <code>{@link #createContents(Composite)}</code>. + * Creates the <code>{@link Composite}</code> that contains the options to switch between "Project" and "Workspace" + * settings. * @param parent the parent {@code Composite}. * @return the created {@code Composite}. */ - protected final Composite contentsComposite(Composite parent) { + protected final Composite switchBetweenProjectAndWorkspaceSettings(Composite parent) { // generated by WindowBuilder Composite contents = new Composite(parent, NONE); contents.setLayout(new GridLayout(3, false));
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGeneration.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGeneration.java similarity index 96% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGeneration.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGeneration.java index 2f57790..ca93f43 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGeneration.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGeneration.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; /**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationEditor.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationEditor.java similarity index 96% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationEditor.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationEditor.java index f4bd419..49e42f6 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationEditor.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationEditor.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; -import static com.google.eclipse.protobuf.ui.preferences.compiler.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.Messages.*; import static java.util.Collections.unmodifiableList; import static org.eclipse.jface.window.Window.OK;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationPreferencesProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationPreferencesProvider.java similarity index 97% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationPreferencesProvider.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationPreferencesProvider.java index e660e87..8eff006 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CodeGenerationPreferencesProvider.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationPreferencesProvider.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; import static java.util.Collections.unmodifiableList;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java similarity index 96% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferencePage.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java index 0814dd4..c0eea98 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferencePage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java
@@ -6,15 +6,16 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; -import static com.google.eclipse.protobuf.ui.preferences.compiler.Messages.*; -import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.PreferenceNames.*; import static com.google.eclipse.protobuf.ui.swt.EventListeners.addSelectionListener; import static java.util.Arrays.asList; import static org.eclipse.xtext.util.Strings.isEmpty; import com.google.eclipse.protobuf.ui.preferences.*; +import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage; import com.google.inject.Inject; import org.eclipse.jface.preference.IPreferenceStore; @@ -57,7 +58,7 @@ /** {@inheritDoc} */ @Override protected Control createContents(Composite parent) { // generated by WindowBuilder - Composite contents = contentsComposite(parent); + Composite contents = switchBetweenProjectAndWorkspaceSettings(parent); btnCompileProtoFiles = new Button(contents, SWT.CHECK); btnCompileProtoFiles.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferenceStoreInitializer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferenceStoreInitializer.java similarity index 90% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferenceStoreInitializer.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferenceStoreInitializer.java index a161b7c..6f41722 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferenceStoreInitializer.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferenceStoreInitializer.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; -import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.PreferenceNames.*; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferences.java similarity index 91% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferences.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferences.java index e6203f9..57cda26 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferences.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferences.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; -import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.PreferenceNames.*; import static java.util.Collections.unmodifiableList; import java.util.List;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferencesProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java similarity index 86% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferencesProvider.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java index 664966c..531ca77 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/CompilerPreferencesProvider.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; -import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.ENABLE_PROJECT_SETTINGS; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.PreferenceNames.ENABLE_PROJECT_SETTINGS; import org.eclipse.core.resources.IProject; import org.eclipse.jface.preference.IPreferenceStore;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/EditCodeGenerationDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EditCodeGenerationDialog.java similarity index 96% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/EditCodeGenerationDialog.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EditCodeGenerationDialog.java index 8b56731..59fe93c 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/EditCodeGenerationDialog.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EditCodeGenerationDialog.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; -import static com.google.eclipse.protobuf.ui.preferences.compiler.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.Messages.*; import static org.eclipse.core.resources.IResource.FOLDER; import static org.eclipse.jface.dialogs.IDialogConstants.OK_ID; import static org.eclipse.swt.layout.GridData.*;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/Messages.java similarity index 96% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/Messages.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/Messages.java index 7b1b423..f8d5299 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/Messages.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/Messages.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; import org.eclipse.osgi.util.NLS;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/Messages.properties b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/Messages.properties similarity index 100% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/Messages.properties rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/Messages.properties
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PostCompilationRefreshTarget.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/PostCompilationRefreshTarget.java similarity index 80% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PostCompilationRefreshTarget.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/PostCompilationRefreshTarget.java index e64710a..ba7a750 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PostCompilationRefreshTarget.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/PostCompilationRefreshTarget.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; -import static com.google.eclipse.protobuf.ui.preferences.compiler.PreferenceNames.REFRESH_PROJECT; +import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.PreferenceNames.REFRESH_PROJECT; import org.eclipse.jface.preference.IPreferenceStore;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PreferenceNames.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/PreferenceNames.java similarity index 95% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PreferenceNames.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/PreferenceNames.java index f4c0444..0157080 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/PreferenceNames.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/PreferenceNames.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; /** * @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/SupportedLanguage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/SupportedLanguage.java similarity index 94% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/SupportedLanguage.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/SupportedLanguage.java index aa6a111..365f94b 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/compiler/SupportedLanguage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/SupportedLanguage.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.compiler; /**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/general/GeneralSettingsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java similarity index 88% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/general/GeneralSettingsPreferencePage.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java index e95946e..40066aa 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/general/GeneralSettingsPreferencePage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.general; +package com.google.eclipse.protobuf.ui.preferences.pages.general; -import com.google.eclipse.protobuf.ui.preferences.PreferenceAndPropertyPage; +import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; @@ -28,7 +28,7 @@ /** {@inheritDoc} */ @Override protected Control createContents(Composite parent) { // generated by WindowBuilder - Composite contents = super.contentsComposite(parent); + Composite contents = super.switchBetweenProjectAndWorkspaceSettings(parent); GridLayout gridLayout = (GridLayout) contents.getLayout(); gridLayout.numColumns = 2;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/AddDirectoryDialog.java similarity index 93% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/AddDirectoryDialog.java index da8704c..934e0b7 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/AddDirectoryDialog.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/AddDirectoryDialog.java
@@ -6,11 +6,11 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; -import static com.google.eclipse.protobuf.ui.preferences.paths.DirectorySelectionDialogs.*; -import static com.google.eclipse.protobuf.ui.preferences.paths.Messages.*; -import static com.google.eclipse.protobuf.ui.preferences.paths.ProjectVariable.useProjectVariable; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.DirectorySelectionDialogs.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.ProjectVariable.useProjectVariable; import static org.eclipse.jface.dialogs.IDialogConstants.OK_ID; import static org.eclipse.xtext.util.Strings.isEmpty;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath.java similarity index 89% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath.java index 5e25ed4..51a5886 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPath.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; -import static com.google.eclipse.protobuf.ui.preferences.paths.ProjectVariable.useProjectName; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.ProjectVariable.useProjectName; import org.eclipse.core.resources.IProject;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPathsEditor.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPathsEditor.java similarity index 97% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPathsEditor.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPathsEditor.java index 6f4694c..9240bb2 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectoryPathsEditor.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPathsEditor.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; -import static com.google.eclipse.protobuf.ui.preferences.paths.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.Messages.*; import static java.util.Collections.unmodifiableList; import static org.eclipse.jface.window.Window.OK;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectorySelectionDialogs.java similarity index 95% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectorySelectionDialogs.java index cf088d0..855aff0 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/DirectorySelectionDialogs.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectorySelectionDialogs.java
@@ -6,10 +6,10 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID; -import static com.google.eclipse.protobuf.ui.preferences.paths.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.Messages.*; import static org.eclipse.core.runtime.IStatus.ERROR; import static org.eclipse.core.runtime.Status.OK_STATUS; import static org.eclipse.jface.window.Window.OK;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/Messages.java similarity index 95% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Messages.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/Messages.java index 3284f08..e24e4e9 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Messages.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/Messages.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; import org.eclipse.osgi.util.NLS;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Messages.properties b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/Messages.properties similarity index 100% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/Messages.properties rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/Messages.properties
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathResolutionType.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathResolutionType.java similarity index 79% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathResolutionType.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathResolutionType.java index c2d5382..bb8e24c 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathResolutionType.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathResolutionType.java
@@ -5,9 +5,9 @@ * 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.paths; + */package com.google.eclipse.protobuf.ui.preferences.pages.paths; -import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.FILES_IN_ONE_DIRECTORY_ONLY; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PreferenceNames.FILES_IN_ONE_DIRECTORY_ONLY; import org.eclipse.jface.preference.IPreferenceStore;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java similarity index 66% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencePage.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java index c7faae3..64e0e5c 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencePage.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java
@@ -6,17 +6,17 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; -import static com.google.eclipse.protobuf.ui.preferences.paths.Messages.*; -import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.Messages.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PreferenceNames.*; import static com.google.eclipse.protobuf.ui.swt.EventListeners.addSelectionListener; import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableList; import static org.eclipse.xtext.util.Strings.*; -import com.google.eclipse.protobuf.ui.preferences.*; -import com.google.inject.Inject; +import java.util.*; +import java.util.List; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; @@ -25,8 +25,10 @@ import org.eclipse.swt.widgets.*; import org.eclipse.xtext.ui.PluginImageHelper; -import java.util.*; -import java.util.List; +import com.google.eclipse.protobuf.ui.preferences.*; +import com.google.eclipse.protobuf.ui.preferences.binding.*; +import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage; +import com.google.inject.Inject; /** * Preference page for import paths. @@ -39,12 +41,14 @@ private static final String PREFERENCE_PAGE_ID = PathsPreferencePage.class.getName(); private Group grpResolutionOfImported; - private Button btnOneFolderOnly; - private Button btnMultipleFolders; + private Button btnOneDirectoryOnly; + private Button btnMultipleDirectories; private DirectoryPathsEditor directoryPathsEditor; @Inject private PluginImageHelper imageHelper; + private final PreferenceBinder preferenceBinder = new PreferenceBinder(); + /** {@inheritDoc} */ @Override protected Control createContents(Composite parent) { // generated by WindowBuilder @@ -56,40 +60,75 @@ grpResolutionOfImported.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); grpResolutionOfImported.setText(importedFilesPathResolution); - btnOneFolderOnly = new Button(grpResolutionOfImported, SWT.RADIO); - btnOneFolderOnly.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); - btnOneFolderOnly.setText(filesInOneDirectoryOnly); + btnOneDirectoryOnly = new Button(grpResolutionOfImported, SWT.RADIO); + btnOneDirectoryOnly.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + btnOneDirectoryOnly.setText(filesInOneDirectoryOnly); - btnMultipleFolders = new Button(grpResolutionOfImported, SWT.RADIO); - btnMultipleFolders.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); - btnMultipleFolders.setText(filesInMultipleDirectories); + btnMultipleDirectories = new Button(grpResolutionOfImported, SWT.RADIO); + btnMultipleDirectories.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); + btnMultipleDirectories.setText(filesInMultipleDirectories); directoryPathsEditor = new DirectoryPathsEditor(grpResolutionOfImported, project(), imageHelper); directoryPathsEditor.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); new Label(contents, SWT.NONE); + setUpBinding(); updateFromPreferenceStore(); addEventListeners(); return contents; } + private void setUpBinding() { + preferenceBinder.bind(FILES_IN_ONE_DIRECTORY_ONLY, btnOneDirectoryOnly); + preferenceBinder.bind(FILES_IN_MULTIPLE_DIRECTORIES, btnMultipleDirectories); + preferenceBinder.add(new Binding() { + public void read(IPreferenceStore store) { + setDirectoryPaths(store.getString(IMPORT_ROOTS)); + } + + public void readDefault(IPreferenceStore store) { + setDirectoryPaths(store.getDefaultString(IMPORT_ROOTS)); + } + + public void save(IPreferenceStore store) { + store.setValue(IMPORT_ROOTS, directoryNames()); + } + }); + } + + private String directoryNames() { + List<DirectoryPath> paths = directoryPathsEditor.directoryPaths(); + if (paths.isEmpty()) return ""; + List<String> pathsAsText = new ArrayList<String>(); + for (DirectoryPath path : paths) { + pathsAsText.add(path.toString()); + } + return concat(COMMA_DELIMITER, pathsAsText); + } + + private void setDirectoryPaths(String directoryPaths) { + List<DirectoryPath> paths = new ArrayList<DirectoryPath>(); + for (String path : split(directoryPaths, COMMA_DELIMITER)) { + if (isEmpty(path)) continue; + paths.add(DirectoryPath.parse(path)); + } + directoryPathsEditor.directoryPaths(unmodifiableList(paths)); + } + private void updateFromPreferenceStore() { - IPreferenceStore store = getPreferenceStore(); - btnOneFolderOnly.setSelection(store.getBoolean(FILES_IN_ONE_DIRECTORY_ONLY)); - btnMultipleFolders.setSelection(store.getBoolean(FILES_IN_MULTIPLE_DIRECTORIES)); - setDirectoryPaths(store.getString(IMPORT_ROOTS)); + preferenceBinder.readPreferences(getPreferenceStore()); enableProjectOptions(true); } private void addEventListeners() { addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - boolean selected = btnMultipleFolders.getSelection(); + boolean selected = btnMultipleDirectories.getSelection(); directoryPathsEditor.setEnabled(selected); checkState(); } - }, asList(btnOneFolderOnly, btnMultipleFolders)); + }, asList(btnOneDirectoryOnly, btnMultipleDirectories)); directoryPathsEditor.setDataChangedListener(new DataChangedListener() { public void dataChanged() { checkState(); @@ -111,44 +150,21 @@ } @Override protected void performDefaults(IPreferenceStore store) { - btnOneFolderOnly.setSelection(store.getDefaultBoolean(FILES_IN_ONE_DIRECTORY_ONLY)); - btnMultipleFolders.setSelection(store.getDefaultBoolean(FILES_IN_MULTIPLE_DIRECTORIES)); - setDirectoryPaths(store.getDefaultString(IMPORT_ROOTS)); + preferenceBinder.readDefaultPreferences(store); enableProjectOptions(true); super.performDefaults(); } - private void setDirectoryPaths(String directoryPaths) { - List<DirectoryPath> paths = new ArrayList<DirectoryPath>(); - for (String path : split(directoryPaths, COMMA_DELIMITER)) { - if (isEmpty(path)) continue; - paths.add(DirectoryPath.parse(path)); - } - directoryPathsEditor.directoryPaths(unmodifiableList(paths)); - } - private void enableProjectOptions(boolean enabled) { grpResolutionOfImported.setEnabled(enabled); - btnOneFolderOnly.setEnabled(enabled); - btnMultipleFolders.setEnabled(enabled); - directoryPathsEditor.setEnabled(btnMultipleFolders.getSelection() && enabled); + btnOneDirectoryOnly.setEnabled(enabled); + btnMultipleDirectories.setEnabled(enabled); + directoryPathsEditor.setEnabled(btnMultipleDirectories.getSelection() && enabled); } /** {@inheritDoc} */ @Override protected void savePreferences(IPreferenceStore store) { - store.setValue(FILES_IN_ONE_DIRECTORY_ONLY, btnOneFolderOnly.getSelection()); - store.setValue(FILES_IN_MULTIPLE_DIRECTORIES, btnMultipleFolders.getSelection()); - store.setValue(IMPORT_ROOTS, directoryNames()); - } - - private String directoryNames() { - List<DirectoryPath> paths = directoryPathsEditor.directoryPaths(); - if (paths.isEmpty()) return ""; - List<String> pathsAsText = new ArrayList<String>(); - for (DirectoryPath path : paths) { - pathsAsText.add(path.toString()); - } - return concat(COMMA_DELIMITER, pathsAsText); + preferenceBinder.savePreferences(store); } /** {@inheritDoc} */
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferenceStoreInitializer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferenceStoreInitializer.java similarity index 86% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferenceStoreInitializer.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferenceStoreInitializer.java index 0eb2245..794538f 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferenceStoreInitializer.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferenceStoreInitializer.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; -import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PreferenceNames.*; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferences.java similarity index 79% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferences.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferences.java index 8d25a04..dab2d73 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferences.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferences.java
@@ -6,10 +6,10 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; -import static com.google.eclipse.protobuf.ui.preferences.paths.PathResolutionType.SINGLE_DIRECTORY; -import static com.google.eclipse.protobuf.ui.preferences.paths.PreferenceNames.IMPORT_ROOTS; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PathResolutionType.SINGLE_DIRECTORY; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PreferenceNames.IMPORT_ROOTS; import static com.google.eclipse.protobuf.ui.util.Strings.CSV_PATTERN; import static java.util.Collections.*; @@ -34,8 +34,8 @@ importRoots = importRoots(pathResolutionType, store, project); } - private static List<DirectoryPath> importRoots(PathResolutionType types, IPreferenceStore store, IProject project) { - if (types.equals(SINGLE_DIRECTORY)) return emptyList(); + private static List<DirectoryPath> importRoots(PathResolutionType resolutionType, IPreferenceStore store, IProject project) { + if (resolutionType.equals(SINGLE_DIRECTORY)) return emptyList(); List<DirectoryPath> roots = new ArrayList<DirectoryPath>(); for (String root : store.getString(IMPORT_ROOTS).split(CSV_PATTERN)) { roots.add(DirectoryPath.parse(root, project));
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencesProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencesProvider.java similarity index 92% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencesProvider.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencesProvider.java index 96e0675..0f11255 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PathsPreferencesProvider.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencesProvider.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; import org.eclipse.core.resources.IProject; import org.eclipse.jface.preference.IPreferenceStore;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceNames.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PreferenceNames.java similarity index 90% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceNames.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PreferenceNames.java index 4bd8025..c76d17d 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/PreferenceNames.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PreferenceNames.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; /** * @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/ProjectVariable.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable.java similarity index 94% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/ProjectVariable.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable.java index 1ec0657..840e4c4 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/ProjectVariable.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.paths; +package com.google.eclipse.protobuf.ui.preferences.pages.paths; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.*;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java index 8b9c2b6..6d606fd 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java
@@ -8,12 +8,12 @@ */ package com.google.eclipse.protobuf.ui.scoping; -import static com.google.eclipse.protobuf.ui.preferences.paths.PathResolutionType.*; +import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PathResolutionType.*; import java.util.HashMap; import java.util.Map; -import com.google.eclipse.protobuf.ui.preferences.paths.PathResolutionType; +import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathResolutionType; import com.google.eclipse.protobuf.ui.util.Resources; import com.google.inject.Inject; import com.google.inject.Singleton;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java index e7101a9..9310ccd 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategy.java
@@ -11,7 +11,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.emf.common.util.URI; -import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferences; +import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathsPreferences; /** * @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java index 05acd5c..dffb88c 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
@@ -15,7 +15,7 @@ import org.eclipse.emf.ecore.resource.Resource; import com.google.eclipse.protobuf.scoping.IFileUriResolver; -import com.google.eclipse.protobuf.ui.preferences.paths.*; +import com.google.eclipse.protobuf.ui.preferences.pages.paths.*; import com.google.eclipse.protobuf.ui.util.Resources; import com.google.inject.Inject;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java index 597c712..ebf20e4 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
@@ -8,7 +8,7 @@ */ package com.google.eclipse.protobuf.ui.scoping; -import com.google.eclipse.protobuf.ui.preferences.paths.*; +import com.google.eclipse.protobuf.ui.preferences.pages.paths.*; import com.google.eclipse.protobuf.ui.util.Resources; import org.eclipse.core.filesystem.*;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java index 1841e83..28f4ab9 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java
@@ -16,7 +16,7 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.xtext.util.Pair; -import com.google.eclipse.protobuf.ui.preferences.paths.PathsPreferences; +import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathsPreferences; import com.google.eclipse.protobuf.ui.util.Resources; /**