Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSzymon Brandys2010-05-07 15:11:26 +0000
committerSzymon Brandys2010-05-07 15:11:26 +0000
commit52741963d9bc96d998c210ced19ef0ba98ec9a0a (patch)
treecc602ab098bea9a5fa6ee616d77f3125392c86fd
parent41b9e242c2afd1608256525eb29f58b394ab062b (diff)
downloadeclipse.platform.team-52741963d9bc96d998c210ced19ef0ba98ec9a0a.tar.gz
eclipse.platform.team-52741963d9bc96d998c210ced19ef0ba98ec9a0a.tar.xz
eclipse.platform.team-52741963d9bc96d998c210ced19ef0ba98ec9a0a.zip
bug 256396 - Duplicated code in Team's compare actions
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java46
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareAction.java9
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareRevisionAction.java48
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java50
4 files changed, 60 insertions, 93 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
index 611acb1b3..6c035f601 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/Utils.java
@@ -16,6 +16,7 @@ import java.util.*;
import java.util.List;
import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
import org.eclipse.compare.structuremergeviewer.IDiffContainer;
import org.eclipse.compare.structuremergeviewer.IDiffElement;
import org.eclipse.core.resources.*;
@@ -1176,4 +1177,49 @@ public class Utils {
return id;
}
+ /**
+ * Returns an editor that can be re-used. An open compare editor that has
+ * un-saved changes cannot be re-used.
+ *
+ * @param input
+ * the input being opened
+ * @param page
+ * @param editorInputClasses
+ * @return an EditorPart or <code>null</code> if none can be found
+ */
+ public static IEditorPart findReusableCompareEditor(
+ CompareEditorInput input, IWorkbenchPage page,
+ Class[] editorInputClasses) {
+ IEditorReference[] editorRefs = page.getEditorReferences();
+ // first loop looking for an editor with the same input
+ for (int i = 0; i < editorRefs.length; i++) {
+ IEditorPart part = editorRefs[i].getEditor(false);
+ if (part != null && part instanceof IReusableEditor) {
+ for (int j = 0; j < editorInputClasses.length; j++) {
+ // check if the editor input type
+ // complies with the types given by the caller
+ if (editorInputClasses[j].isInstance(part.getEditorInput())
+ && part.getEditorInput().equals(input))
+ return part;
+ }
+ }
+ }
+ // if none found and "Reuse open compare editors" preference is on use
+ // a non-dirty editor
+ if (TeamUIPlugin.getPlugin().getPreferenceStore()
+ .getBoolean(IPreferenceIds.REUSE_OPEN_COMPARE_EDITOR)) {
+ for (int i = 0; i < editorRefs.length; i++) {
+ IEditorPart part = editorRefs[i].getEditor(false);
+ if (part != null
+ && (part.getEditorInput() instanceof SaveableCompareEditorInput)
+ && part instanceof IReusableEditor && !part.isDirty()) {
+ return part;
+ }
+ }
+ }
+
+ // no re-usable editor found
+ return null;
+ }
+
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareAction.java
index bf3cd86eb..e0286576c 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008, 2010 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
@@ -25,6 +25,8 @@ import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.team.internal.ui.TeamUIMessages;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput;
import org.eclipse.team.internal.ui.synchronize.SaveablesCompareEditorInput;
import org.eclipse.ui.*;
@@ -68,8 +70,9 @@ public class CompareAction extends TeamAction {
IWorkbenchPage workBenchPage = getTargetPage();
CompareEditorInput input = new SaveablesCompareEditorInput(ancestor,
left, right, workBenchPage);
- IEditorPart editor = CompareRevisionAction.findReusableCompareEditor(
- input, workBenchPage);
+ IEditorPart editor = Utils.findReusableCompareEditor(input,
+ workBenchPage,
+ new Class[] { CompareFileRevisionEditorInput.class });
if (editor != null) {
IEditorInput otherInput = editor.getEditorInput();
if (otherInput.equals(input)) {
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareRevisionAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareRevisionAction.java
index 5c7d0e2da..c01712cef 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareRevisionAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/CompareRevisionAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 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
@@ -122,7 +122,9 @@ public class CompareRevisionAction extends BaseSelectionListenerAction {
private void openInCompare(ITypedElement left, ITypedElement right) {
CompareEditorInput input = createCompareEditorInput(left, right, page.getSite().getPage());
IWorkbenchPage workBenchPage = page.getSite().getPage();
- IEditorPart editor = findReusableCompareEditor(input, workBenchPage);
+ IEditorPart editor = Utils.findReusableCompareEditor(input,
+ workBenchPage,
+ new Class[] { CompareFileRevisionEditorInput.class });
if (editor != null) {
IEditorInput otherInput = editor.getEditorInput();
if (otherInput.equals(input)) {
@@ -166,44 +168,6 @@ public class CompareRevisionAction extends BaseSelectionListenerAction {
public void setCurrentFileRevision(IFileRevision fileRevision){
this.currentFileRevision = fileRevision;
}
-
- /**
- * Returns an editor that can be re-used. An open compare editor that
- * has un-saved changes cannot be re-used.
- * @param input the input being opened
- * @param page
- * @return an EditorPart or <code>null</code> if none can be found
- */
- public static IEditorPart findReusableCompareEditor(
- CompareEditorInput input, IWorkbenchPage page) {
- IEditorReference[] editorRefs = page.getEditorReferences();
- // first loop looking for an editor with the same input
- for (int i = 0; i < editorRefs.length; i++) {
- IEditorPart part = editorRefs[i].getEditor(false);
- if (part != null
- && (part.getEditorInput() instanceof CompareFileRevisionEditorInput)
- && part instanceof IReusableEditor
- && part.getEditorInput().equals(input)) {
- return part;
- }
- }
-
- // if none found and "Reuse open compare editors" preference is on use
- // a non-dirty editor
- if (isReuseOpenEditor()) {
- for (int i = 0; i < editorRefs.length; i++) {
- IEditorPart part = editorRefs[i].getEditor(false);
- if (part != null
- && (part.getEditorInput() instanceof SaveableCompareEditorInput)
- && part instanceof IReusableEditor && !part.isDirty()) {
- return part;
- }
- }
- }
-
- // no re-usable editor found
- return null;
- }
protected boolean updateSelection(IStructuredSelection selection) {
this.selection = selection;
@@ -248,8 +212,4 @@ public class CompareRevisionAction extends BaseSelectionListenerAction {
return true;
}
-
- private static boolean isReuseOpenEditor() {
- return TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.REUSE_OPEN_COMPARE_EDITOR);
- }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java
index 99cfa7d28..8fbfdab0b 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java
@@ -24,7 +24,7 @@ import org.eclipse.jface.util.OpenStrategy;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.internal.ui.*;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.internal.ui.mapping.ModelCompareEditorInput;
import org.eclipse.team.internal.ui.synchronize.SyncInfoModelElement;
import org.eclipse.team.internal.ui.synchronize.patch.ApplyPatchModelCompareEditorInput;
@@ -205,7 +205,9 @@ public class OpenInCompareAction extends Action {
public static void openCompareEditor(CompareEditorInput input, IWorkbenchPage page, boolean reuseEditorIfPossible) {
if (page == null || input == null)
return;
- IEditorPart editor = findReusableCompareEditor(input, page);
+ IEditorPart editor = Utils.findReusableCompareEditor(input, page,
+ new Class[] { SyncInfoCompareInput.class,
+ ModelCompareEditorInput.class });
// reuse editor only for single selection
if(editor != null && reuseEditorIfPossible) {
IEditorInput otherInput = editor.getEditorInput();
@@ -221,46 +223,6 @@ public class OpenInCompareAction extends Action {
CompareUI.openCompareEditorOnPage(input, page);
}
}
-
- /**
- * Returns an editor that can be re-used. An open compare editor that has
- * un-saved changes cannot be re-used.
- *
- * @param input
- * the input being opened
- * @param page
- * @return an EditorPart or <code>null</code> if none can be found
- */
- public static IEditorPart findReusableCompareEditor(
- CompareEditorInput input, IWorkbenchPage page) {
- IEditorReference[] editorRefs = page.getEditorReferences();
- // first loop looking for an editor with the same input
- for (int i = 0; i < editorRefs.length; i++) {
- IEditorPart part = editorRefs[i].getEditor(false);
- if (part != null
- && (part.getEditorInput() instanceof SyncInfoCompareInput || part
- .getEditorInput() instanceof ModelCompareEditorInput)
- && part instanceof IReusableEditor
- && part.getEditorInput().equals(input)) {
- return part;
- }
- }
- // if none found and "Reuse open compare editors" preference is on use
- // a non-dirty editor
- if (isReuseOpenEditor()) {
- for (int i = 0; i < editorRefs.length; i++) {
- IEditorPart part = editorRefs[i].getEditor(false);
- if (part != null
- && (part.getEditorInput() instanceof SaveableCompareEditorInput)
- && part instanceof IReusableEditor && !part.isDirty()) {
- return part;
- }
- }
- }
-
- // no re-usable editor found
- return null;
- }
/**
* Returns an editor handle if a SyncInfoCompareInput compare editor is opened on
@@ -317,8 +279,4 @@ public class OpenInCompareAction extends Action {
}
return null;
}
-
- private static boolean isReuseOpenEditor() {
- return TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.REUSE_OPEN_COMPARE_EDITOR);
- }
}

Back to the top