aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaloyan Raev2014-01-14 10:21:10 (EST)
committerGerrit Code Review @ Eclipse.org2014-01-15 14:30:12 (EST)
commit709354346bffcbf15fe3c887aa0cc788d468447a (patch)
tree3efdda654c39563e235d26a52c7ade7867d1ed58
parent2ae4454072fcbc41df65f895cd3ba35a497380fe (diff)
downloadorg.eclipse.pdt-709354346bffcbf15fe3c887aa0cc788d468447a.zip
org.eclipse.pdt-709354346bffcbf15fe3c887aa0cc788d468447a.tar.gz
org.eclipse.pdt-709354346bffcbf15fe3c887aa0cc788d468447a.tar.bz2
Bug 412345 - It's not possible to disable project-specific formatterrefs/changes/52/20652/2
preferences This patch improves the previous fix for the bug. The Code Formatter preference page now uses correctly a working copy for the changed settings and avoids additional flushes of the preferences on selection change, which caused a number of problem in other preference types. Bug: 412345 Change-Id: Ic0aacd7ff7f5bd87a774a9d5ba614df80ef1c6ba Signed-off-by: Kaloyan Raev <kaloyan.r@zend.com>
-rw-r--r--plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/CodeFormatterConfigurationBlock.java10
-rw-r--r--plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/PreferencesAccess.java147
-rw-r--r--plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/ProfileManager.java9
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/util/Key.java11
4 files changed, 154 insertions, 23 deletions
diff --git a/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/CodeFormatterConfigurationBlock.java b/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/CodeFormatterConfigurationBlock.java
index 51c9378..85a03c4 100644
--- a/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/CodeFormatterConfigurationBlock.java
+++ b/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/CodeFormatterConfigurationBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Zend Techologies Ltd.
+ * Copyright (c) 2013, 2014 Zend Techologies Ltd.
* 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
@@ -15,7 +15,6 @@ import java.util.*;
import java.util.List;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IScopeContext;
@@ -425,10 +424,13 @@ public class CodeFormatterConfigurationBlock extends
if (profiles == null)
profiles = new ArrayList<Profile>();
+ PreferencesAccess access = PreferencesAccess
+ .getWorkingCopyPreferences(fManager);
+
if (project != null) {
- fCurrContext = new ProjectScope(project);
+ fCurrContext = access.getProjectScope(project);
} else {
- fCurrContext = fInstanceScope;
+ fCurrContext = access.getInstanceScope();
}
fProfileManager = new ProfileManager(profiles, fCurrContext);
diff --git a/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/PreferencesAccess.java b/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/PreferencesAccess.java
new file mode 100644
index 0000000..ab0b446
--- /dev/null
+++ b/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/PreferencesAccess.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Zend Technologies
+ *******************************************************************************/
+package org.eclipse.php.formatter.ui.preferences;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.ui.preferences.IWorkingCopyManager;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ *
+ */
+public class PreferencesAccess {
+
+ public static PreferencesAccess getOriginalPreferences() {
+ return new PreferencesAccess();
+ }
+
+ public static PreferencesAccess getWorkingCopyPreferences(
+ IWorkingCopyManager workingCopyManager) {
+ return new WorkingCopyPreferencesAccess(workingCopyManager);
+ }
+
+ private PreferencesAccess() {
+ // can only extends in this file
+ }
+
+ public IScopeContext getDefaultScope() {
+ return DefaultScope.INSTANCE;
+ }
+
+ public IScopeContext getInstanceScope() {
+ return InstanceScope.INSTANCE;
+ }
+
+ public IScopeContext getProjectScope(IProject project) {
+ return new ProjectScope(project);
+ }
+
+ /**
+ * Applies the changes
+ *
+ * @throws BackingStoreException
+ * thrown when the changes could not be applied
+ */
+ public void applyChanges() throws BackingStoreException {
+ }
+
+ private static class WorkingCopyPreferencesAccess extends PreferencesAccess {
+
+ private final IWorkingCopyManager fWorkingCopyManager;
+
+ private WorkingCopyPreferencesAccess(
+ IWorkingCopyManager workingCopyManager) {
+ fWorkingCopyManager = workingCopyManager;
+ }
+
+ private final IScopeContext getWorkingCopyScopeContext(
+ IScopeContext original) {
+ return new WorkingCopyScopeContext(fWorkingCopyManager, original);
+ }
+
+ @Override
+ public IScopeContext getDefaultScope() {
+ return getWorkingCopyScopeContext(super.getDefaultScope());
+ }
+
+ @Override
+ public IScopeContext getInstanceScope() {
+ return getWorkingCopyScopeContext(super.getInstanceScope());
+ }
+
+ @Override
+ public IScopeContext getProjectScope(IProject project) {
+ return getWorkingCopyScopeContext(super.getProjectScope(project));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jdt.internal.ui.preferences.PreferencesAccess#applyChanges
+ * ()
+ */
+ @Override
+ public void applyChanges() throws BackingStoreException {
+ fWorkingCopyManager.applyChanges();
+ }
+ }
+
+ private static class WorkingCopyScopeContext implements IScopeContext {
+
+ private final IWorkingCopyManager fWorkingCopyManager;
+ private final IScopeContext fOriginal;
+
+ public WorkingCopyScopeContext(IWorkingCopyManager workingCopyManager,
+ IScopeContext original) {
+ fWorkingCopyManager = workingCopyManager;
+ fOriginal = original;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.IScopeContext#getName()
+ */
+ public String getName() {
+ return fOriginal.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.preferences.IScopeContext#getNode(java.lang
+ * .String)
+ */
+ public IEclipsePreferences getNode(String qualifier) {
+ return fWorkingCopyManager.getWorkingCopy(fOriginal
+ .getNode(qualifier));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.IScopeContext#getLocation()
+ */
+ public IPath getLocation() {
+ return fOriginal.getLocation();
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/ProfileManager.java b/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/ProfileManager.java
index 8644601..8d1e985 100644
--- a/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/ProfileManager.java
+++ b/plugins/org.eclipse.php.formatter.ui/src/org/eclipse/php/formatter/ui/preferences/ProfileManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Zend Techologies Ltd.
+ * Copyright (c) 2013, 2014 Zend Techologies Ltd.
* 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
@@ -27,12 +27,10 @@ import org.eclipse.php.core.format.IProfileManager;
import org.eclipse.php.formatter.core.CodeFormatterPreferences;
import org.eclipse.php.formatter.core.FormatterCorePlugin;
import org.eclipse.php.formatter.core.ICodeFormatterPreferencesInitializer;
-import org.eclipse.php.formatter.core.Logger;
import org.eclipse.php.formatter.ui.FormatterMessages;
import org.eclipse.php.formatter.ui.FormatterUIPlugin;
import org.eclipse.php.internal.ui.preferences.PreferenceConstants;
import org.eclipse.php.internal.ui.util.Messages;
-import org.osgi.service.prefs.BackingStoreException;
/**
* The model for the set of profiles which are available in the workbench.
@@ -493,11 +491,6 @@ public class ProfileManager extends Observable implements IProfileManager {
&& !profile.isSharedProfile()) {
prefs.put(PROFILE_KEY, profile.getID());
}
- try {
- prefs.flush();
- } catch (BackingStoreException e) {
- Logger.logException(e);
- }
}
/**
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/util/Key.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/util/Key.java
index 73299ac..a0c4f92 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/util/Key.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/util/Key.java
@@ -16,7 +16,6 @@ package org.eclipse.php.internal.ui.preferences.util;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
-import org.eclipse.php.internal.ui.PHPUiPlugin;
import org.eclipse.ui.preferences.IWorkingCopyManager;
import org.osgi.service.prefs.BackingStoreException;
@@ -75,11 +74,6 @@ public final class Key {
} else {
getNode(context, manager).remove(fKey);
}
- try {
- getNode(context, manager).flush();
- } catch (BackingStoreException e) {
- PHPUiPlugin.log(e);
- }
}
public void setStoredValue(IScopeContext[] context, String value,
@@ -89,11 +83,6 @@ public final class Key {
} else {
getNode(context[0], manager).remove(fKey);
}
- try {
- getNode(context[0], manager).flush();
- } catch (BackingStoreException e) {
- PHPUiPlugin.log(e);
- }
}
/*