aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernard Leach2011-05-28 01:42:42 (EDT)
committerChris Aniszczyk2011-06-01 09:52:04 (EDT)
commitbc358b9ee27d0dabeb90fa666e02cf746754565d (patch)
tree966464bcb1c146b4f11c707142d7537aa10128d0
parent9ca67d3bc62e1e85ec059a0c87046b96239fcac5 (diff)
downloadegit-bc358b9ee27d0dabeb90fa666e02cf746754565d.zip
egit-bc358b9ee27d0dabeb90fa666e02cf746754565d.tar.gz
egit-bc358b9ee27d0dabeb90fa666e02cf746754565d.tar.bz2
Refactor BooleanPrefAction to top-level classrefs/changes/14/3614/1
This refactor enables classes other than CompareTreeView to use the functionality. Change-Id: I908719dd71a0cd11384ec26c8d89c075bbbdcf4d Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BooleanPrefAction.java73
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CompareTreeView.java46
2 files changed, 75 insertions, 44 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BooleanPrefAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BooleanPrefAction.java
new file mode 100644
index 0000000..3b79cd7
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/BooleanPrefAction.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SAP AG.
+ *
+ * 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:
+ * Mathias Kinzler (SAP AG) - initial implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.actions;
+
+import java.io.IOException;
+
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.preference.IPersistentPreferenceStore;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
+
+/**
+ * An Action linked to a boolean preference value.
+ */
+public abstract class BooleanPrefAction extends Action implements
+ IPropertyChangeListener, IWorkbenchAction {
+ private final String prefName;
+
+ private final IPersistentPreferenceStore store;
+
+ /**
+ * @param store the preference store
+ * @param pn the preference name
+ * @param text the text for the action
+ */
+ protected BooleanPrefAction(final IPersistentPreferenceStore store,
+ final String pn, final String text) {
+ this.store = store;
+ setText(text);
+ prefName = pn;
+ store.addPropertyChangeListener(this);
+ setChecked(store.getBoolean(prefName));
+ }
+
+ public void run() {
+ store.setValue(prefName, isChecked());
+ if (store.needsSaving())
+ try {
+ store.save();
+ } catch (IOException e) {
+ Activator.handleError(e.getMessage(), e, false);
+ }
+ }
+
+ /**
+ * Update to the new value
+ * @param value the current value
+ */
+ protected abstract void apply(boolean value);
+
+ public void propertyChange(final PropertyChangeEvent event) {
+ if (prefName.equals(event.getProperty())) {
+ setChecked(store.getBoolean(prefName));
+ apply(isChecked());
+ }
+ }
+
+ public void dispose() {
+ // stop listening
+ store.removePropertyChangeListener(this);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CompareTreeView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CompareTreeView.java
index 04d6a8e..22611ea 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CompareTreeView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CompareTreeView.java
@@ -46,6 +46,7 @@ import org.eclipse.egit.ui.internal.EditableRevision;
import org.eclipse.egit.ui.internal.FileRevisionTypedElement;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
import org.eclipse.egit.ui.internal.LocalFileRevision;
+import org.eclipse.egit.ui.internal.actions.BooleanPrefAction;
import org.eclipse.egit.ui.internal.dialogs.CompareTreeView.PathNode.Type;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
@@ -55,8 +56,6 @@ import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPersistentPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.BaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -188,7 +187,7 @@ public class CompareTreeView extends ViewPart {
UIPreferences.TREE_COMPARE_SHOW_EQUALS,
UIText.CompareTreeView_EqualFilesTooltip) {
@Override
- void apply(boolean value) {
+ public void apply(boolean value) {
buildTrees(false);
}
};
@@ -950,47 +949,6 @@ public class CompareTreeView extends ViewPart {
}
}
- private static abstract class BooleanPrefAction extends Action implements
- IPropertyChangeListener, IWorkbenchAction {
- private final String prefName;
-
- private final IPersistentPreferenceStore store;
-
- BooleanPrefAction(final IPersistentPreferenceStore store,
- final String pn, final String text) {
- this.store = store;
- setText(text);
- prefName = pn;
- store.addPropertyChangeListener(this);
- setChecked(store.getBoolean(prefName));
- }
-
- public void run() {
- store.setValue(prefName, isChecked());
- if (store.needsSaving()) {
- try {
- store.save();
- } catch (IOException e) {
- Activator.handleError(e.getMessage(), e, false);
- }
- }
- }
-
- abstract void apply(boolean value);
-
- public void propertyChange(final PropertyChangeEvent event) {
- if (prefName.equals(event.getProperty())) {
- setChecked(store.getBoolean(prefName));
- apply(isChecked());
- }
- }
-
- public void dispose() {
- // stop listening
- store.removePropertyChangeListener(this);
- }
- }
-
/**
* Used to render the tree in case we have no workspace
*/