Fixed: [ Issue 70 ] Validation doesn't start until editing https://code.google.com/p/protobuf-dt/issues/detail?id=70 Working on preference page for validation options.
diff --git a/com.google.eclipse.protobuf.ui/plugin.xml b/com.google.eclipse.protobuf.ui/plugin.xml index ee1e0c4..1d7833d 100644 --- a/com.google.eclipse.protobuf.ui/plugin.xml +++ b/com.google.eclipse.protobuf.ui/plugin.xml
@@ -48,7 +48,7 @@ </extension> <extension point="org.eclipse.ui.preferencePages"> <page - class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.pages.general.GeneralSettingsPreferencePage" + class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.pages.general.GeneralPreferencePage" id="com.google.eclipse.protobuf.Protobuf" name="%page.name"> <keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" /> </page> @@ -161,7 +161,7 @@ </extension> <extension point="org.eclipse.ui.propertyPages"> <page - class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.pages.general.GeneralSettingsPreferencePage" + class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.pages.general.GeneralPreferencePage" id="com.google.eclipse.protobuf.Protobuf" name="%page.name" selectionFilter="single"> </page>
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 01dc172..a8b5b8e 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
@@ -32,10 +32,11 @@ import com.google.eclipse.protobuf.ui.outline.*; import com.google.eclipse.protobuf.ui.preferences.PreferenceStoreAccess; import com.google.eclipse.protobuf.ui.preferences.pages.compiler.CompilerPreferenceStoreInitializer; +import com.google.eclipse.protobuf.ui.preferences.pages.general.GeneralPreferenceStoreInitializer; 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.*; +import com.google.inject.Binder; /** * Use this class to register components to be used within the IDE. @@ -45,7 +46,7 @@ public class ProtobufUiModule extends AbstractProtobufUiModule { public static final String PLUGIN_ID = "com.google.eclipse.protobuf.ui"; - + public ProtobufUiModule(AbstractUIPlugin plugin) { super(plugin); setValidationTrigger(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), plugin); @@ -75,6 +76,10 @@ .to(LinkWithEditor.class); } + public void configureGeneralSettingsPreferencesInitializer(Binder binder) { + configurePreferenceInitializer(binder, "generalPreferences", GeneralPreferenceStoreInitializer.class); + } + public void configureCompilerPreferencesInitializer(Binder binder) { configurePreferenceInitializer(binder, "compilerPreferences", CompilerPreferenceStoreInitializer.class); } @@ -106,7 +111,7 @@ public void configureSemanticHighlightingCalculator(Binder binder) { binder.bind(ISemanticHighlightingCalculator.class).to(ProtobufSemanticHighlightingCalculator.class); } - + public void configurePreferenceStoreAccess(Binder binder) { binder.bind(IPreferenceStoreAccess.class).to(PreferenceStoreAccess.class); }
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 e99e78e..60f8aaf 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
@@ -40,12 +40,12 @@ @Inject private ProtocOutputParser outputParser; @Inject private ProtocCommandFactory commandFactory; - @Inject private CompilerPreferencesProvider compilerPreferencesProvider; + @Inject private CompilerPreferencesFactory compilerPreferencesFactory; @Inject private PathsPreferencesFactory pathsPreferencesFactory; public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException { IProject project = context.getBuiltProject(); - CompilerPreferences preferences = compilerPreferencesProvider.getPreferences(project); + CompilerPreferences preferences = compilerPreferencesFactory.preferences(project); if (!preferences.shouldCompileProtoFiles()) return; List<Delta> deltas = context.getDeltas(); if (deltas.isEmpty()) return;
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/CompilerPreferencesFactory.java similarity index 87% rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesFactory.java index 1b5ca2f..343560d 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/CompilerPreferencesFactory.java
@@ -17,15 +17,15 @@ import com.google.inject.Inject; /** - * Reads compiler preferences. + * Factory of <code>{@link CompilerPreferences}</code>. * * @author alruiz@google.com (Alex Ruiz) */ -public class CompilerPreferencesProvider { +public class CompilerPreferencesFactory { @Inject private IPreferenceStoreAccess storeAccess; - public CompilerPreferences getPreferences(IProject project) { + public CompilerPreferences preferences(IProject project) { IPreferenceStore store = storeAccess.getWritablePreferenceStore(project); boolean useProjectPreferences = enableProjectSettings(store).value(); if (!useProjectPreferences) store = storeAccess.getWritablePreferenceStore();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/EnableProjectSettingsPreference.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/EnableProjectSettingsPreference.java new file mode 100644 index 0000000..729f3b4 --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/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.general; + +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("general.enableProjectSettings", store); + } + + private EnableProjectSettingsPreference() {} +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencePage.java new file mode 100644 index 0000000..0f22af1 --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencePage.java
@@ -0,0 +1,60 @@ +/* + * 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.general; + +import static com.google.eclipse.protobuf.ui.preferences.binding.BindingToButtonSelection.bindSelectionOf; +import static com.google.eclipse.protobuf.ui.preferences.pages.general.EnableProjectSettingsPreference.enableProjectSettings; +import static com.google.eclipse.protobuf.ui.preferences.pages.general.Messages.*; + +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; + +/** + * @author alruiz@google.com (Alex Ruiz) + */ +public class GeneralPreferencePage extends PreferenceAndPropertyPage { + + private static final String PREFERENCE_PAGE_ID = "com.google.eclipse.protobuf.Protobuf"; + + private Button btnValidateOnActivation; + + @Override protected void doCreateContents(Composite contents) { + // generated by WindowBuilder + Group grpValidation = new Group(contents, SWT.NONE); + grpValidation.setLayout(new GridLayout(1, false)); + grpValidation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); + grpValidation.setText(contentValidation); + + btnValidateOnActivation = new Button(grpValidation, SWT.CHECK); + btnValidateOnActivation.setText(validateFilesOnActivation); + } + + @Override protected BooleanPreference enableProjectSettingsPreference(IPreferenceStore store) { + return enableProjectSettings(store); + } + + @Override protected void setupBinding(PreferenceBinder preferenceBinder) { + RawPreferences preferences = new RawPreferences(getPreferenceStore()); + preferenceBinder.addAll( + bindSelectionOf(btnValidateOnActivation).to(preferences.validateFilesOnActivation()) + ); + } + + @Override protected void onProjectSettingsActivation(boolean active) {} + + @Override protected String preferencePageId() { + return PREFERENCE_PAGE_ID; + } +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferenceStoreInitializer.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferenceStoreInitializer.java new file mode 100644 index 0000000..7151133 --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferenceStoreInitializer.java
@@ -0,0 +1,30 @@ +/* + * 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.general; + +import static com.google.eclipse.protobuf.ui.preferences.pages.general.EnableProjectSettingsPreference.enableProjectSettings; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.xtext.ui.editor.preferences.*; + +/** + * Initializes default values for the "Paths" preferences. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public class GeneralPreferenceStoreInitializer implements IPreferenceStoreInitializer { + + /** {@inheritDoc} */ + public void initialize(IPreferenceStoreAccess access) { + IPreferenceStore store = access.getWritablePreferenceStore(); + enableProjectSettings(store).defaultValue(false); + RawPreferences preferences = new RawPreferences(store); + preferences.validateFilesOnActivation().defaultValue(true); + } +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferences.java new file mode 100644 index 0000000..fa96a0c --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferences.java
@@ -0,0 +1,31 @@ +/* + * 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.general; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.preference.IPreferenceStore; + +/** + * General preferences, retrieved from an <code>{@link IPreferenceStore}</code>. To create a new instance invoke + * <code>{@link GeneralPreferencesFactory#preferences(IProject)}</code> + * + * @author alruiz@google.com (Alex Ruiz) + */ +public class GeneralPreferences { + + private final boolean validateFilesOnActivation; + + GeneralPreferences(RawPreferences preferences) { + validateFilesOnActivation = preferences.validateFilesOnActivation().value(); + } + + public boolean validateFilesOnActivation() { + return validateFilesOnActivation; + } +}
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/general/GeneralPreferencesFactory.java similarity index 66% copy from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesProvider.java copy to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencesFactory.java index 1b5ca2f..fb58e94 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/general/GeneralPreferencesFactory.java
@@ -6,9 +6,9 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.ui.preferences.pages.compiler; +package com.google.eclipse.protobuf.ui.preferences.pages.general; -import static com.google.eclipse.protobuf.ui.preferences.pages.compiler.EnableProjectSettingsPreference.enableProjectSettings; +import static com.google.eclipse.protobuf.ui.preferences.pages.general.EnableProjectSettingsPreference.enableProjectSettings; import org.eclipse.core.resources.IProject; import org.eclipse.jface.preference.IPreferenceStore; @@ -17,18 +17,18 @@ import com.google.inject.Inject; /** - * Reads compiler preferences. + * Factory of <code>{@link GeneralPreferences}</code>. * * @author alruiz@google.com (Alex Ruiz) */ -public class CompilerPreferencesProvider { +public class GeneralPreferencesFactory { @Inject private IPreferenceStoreAccess storeAccess; - public CompilerPreferences getPreferences(IProject project) { + public GeneralPreferences preferences(IProject project) { IPreferenceStore store = storeAccess.getWritablePreferenceStore(project); boolean useProjectPreferences = enableProjectSettings(store).value(); if (!useProjectPreferences) store = storeAccess.getWritablePreferenceStore(); - return new CompilerPreferences(new RawPreferences(store)); + return new GeneralPreferences(new RawPreferences(store)); } }
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 deleted file mode 100644 index f07ba22..0000000 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralSettingsPreferencePage.java +++ /dev/null
@@ -1,54 +0,0 @@ -/* - * 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.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; - -/** - * @author alruiz@google.com (Alex Ruiz) - */ -public class GeneralSettingsPreferencePage extends PreferenceAndPropertyPage { - - private static final String PREFERENCE_PAGE_ID = GeneralSettingsPreferencePage.class.getName(); - - /** {@inheritDoc} */ - @Override protected void doCreateContents(Composite contents) { - // generated by WindowBuilder - Group grpValidation = new Group(contents, SWT.NONE); - grpValidation.setLayout(new GridLayout(1, false)); - grpValidation.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); - grpValidation.setText("Content Validation"); - - Button btnValidateOnActivation = new Button(grpValidation, SWT.CHECK); - btnValidateOnActivation.setText("Validate files when activated"); - } - - /** {@inheritDoc} */ - @Override protected BooleanPreference enableProjectSettingsPreference(IPreferenceStore store) { - return null; - } - - /** {@inheritDoc} */ - @Override protected void setupBinding(PreferenceBinder preferenceBinder) {} - - /** {@inheritDoc} */ - @Override protected void onProjectSettingsActivation(boolean active) {} - - /** {@inheritDoc} */ - @Override protected String preferencePageId() { - return PREFERENCE_PAGE_ID; - } -}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/Messages.java new file mode 100644 index 0000000..cfba0ba --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/Messages.java
@@ -0,0 +1,27 @@ +/* + * 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.general; + +import org.eclipse.osgi.util.NLS; + +/** + * @author alruiz@google.com (Alex Ruiz) + */ +public class Messages extends NLS { + + public static String contentValidation; + public static String validateFilesOnActivation; + + static { + Class<Messages> targetType = Messages.class; + NLS.initializeMessages(targetType.getName(), targetType); + } + + private Messages() {} +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/Messages.properties b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/Messages.properties new file mode 100644 index 0000000..35c51ce --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/Messages.properties
@@ -0,0 +1,2 @@ +contentValidation=Content Validation +validateFilesOnActivation=Validate files when activated in editor
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/RawPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/RawPreferences.java new file mode 100644 index 0000000..1297dfc --- /dev/null +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/RawPreferences.java
@@ -0,0 +1,29 @@ +/* + * 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.general; + +import org.eclipse.jface.preference.IPreferenceStore; + +import com.google.eclipse.protobuf.ui.preferences.BooleanPreference; + +/** + * @author alruiz@google.com (Alex Ruiz) + */ +class RawPreferences { + + private final BooleanPreference validateFilesOnActivation; + + RawPreferences(IPreferenceStore store) { + validateFilesOnActivation = new BooleanPreference("validation.validateFilesOnActivation", store); + } + + BooleanPreference validateFilesOnActivation() { + return validateFilesOnActivation; + } +}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencesFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencesFactory.java index 8b48810..f5f3009 100644 --- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencesFactory.java +++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencesFactory.java
@@ -19,7 +19,6 @@ * * @author alruiz@google.com (Alex Ruiz) */ - public class PathsPreferencesFactory { @Inject private IPreferenceStoreAccess storeAccess;