aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Stocker2011-11-21 09:08:55 (EST)
committerMatthias Sohn2011-12-01 17:21:53 (EST)
commit08ecea67447d9ff5824108e9ee854625d297b037 (patch)
treee96894c41d648a0bf3656c305ca8ca3e5954a62b
parent4e84585b1cf167f8adf88d447f2d954f072481e4 (diff)
downloadegit-08ecea67447d9ff5824108e9ee854625d297b037.zip
egit-08ecea67447d9ff5824108e9ee854625d297b037.tar.gz
egit-08ecea67447d9ff5824108e9ee854625d297b037.tar.bz2
Refactor anonymous subclasses of EditableRevision into FileEditableRevisionrefs/changes/55/4655/2
They were doing the same thing twice. Change-Id: I35a552948832f541ef8137238ebd395503568bf0 Signed-off-by: Robin Stocker <robin@nibor.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/FileEditableRevision.java70
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CompareTreeView.java34
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java38
3 files changed, 80 insertions, 62 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/FileEditableRevision.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/FileEditableRevision.java
new file mode 100644
index 0000000..5246ad1
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/FileEditableRevision.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Robin Stocker <robin@nibor.org>
+ *
+ * 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 org.eclipse.egit.ui.internal;
+
+import java.io.ByteArrayInputStream;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.team.core.history.IFileRevision;
+
+/**
+ * Editable revision backed by an {@link IFile}.
+ */
+public class FileEditableRevision extends EditableRevision {
+
+ private final IFile file;
+
+ private final IRunnableContext runnableContext;
+
+ /**
+ * Create a new FileEditableRevision.
+ *
+ * @param fileRevision
+ * @param file
+ * the file to write the changed contents to
+ * @param runnableContext
+ * the context to use for the file write operation
+ */
+ public FileEditableRevision(IFileRevision fileRevision, IFile file,
+ IRunnableContext runnableContext) {
+ super(fileRevision);
+ this.file = file;
+ Assert.isNotNull(runnableContext);
+ this.runnableContext = runnableContext;
+ }
+
+ @Override
+ public void setContent(final byte[] newContent) {
+ try {
+ runnableContext.run(false, false, new IRunnableWithProgress() {
+ public void run(IProgressMonitor myMonitor)
+ throws InvocationTargetException, InterruptedException {
+ try {
+ file.setContents(new ByteArrayInputStream(newContent),
+ false, true, myMonitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ });
+ } catch (InvocationTargetException e) {
+ Activator.handleError(e.getTargetException().getMessage(),
+ e.getTargetException(), true);
+ } catch (InterruptedException e) {
+ // ignore here
+ }
+ }
+}
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 813d618..1aa908e 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
@@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.dialogs;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
@@ -27,7 +26,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -43,7 +41,7 @@ import org.eclipse.egit.ui.UIIcons;
import org.eclipse.egit.ui.UIPreferences;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.CompareUtils;
-import org.eclipse.egit.ui.internal.EditableRevision;
+import org.eclipse.egit.ui.internal.FileEditableRevision;
import org.eclipse.egit.ui.internal.FileRevisionTypedElement;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
import org.eclipse.egit.ui.internal.LocalFileRevision;
@@ -220,34 +218,8 @@ public class CompareTreeView extends ViewPart {
return;
} else if (selected instanceof IFile) {
final IFile res = (IFile) selected;
- left = new EditableRevision(new LocalFileRevision(res)) {
- @Override
- public void setContent(final byte[] newContent) {
- try {
- PlatformUI.getWorkbench().getProgressService().run(
- false, false, new IRunnableWithProgress() {
- public void run(IProgressMonitor myMonitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- res.setContents(
- new ByteArrayInputStream(
- newContent), false,
- true, myMonitor);
- } catch (CoreException e) {
- throw new InvocationTargetException(
- e);
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator.handleError(e.getTargetException()
- .getMessage(), e.getTargetException(), true);
- } catch (InterruptedException e) {
- // ignore here
- }
- }
- };
+ LocalFileRevision revision = new LocalFileRevision(res);
+ left = new FileEditableRevision(revision, res, PlatformUI.getWorkbench().getProgressService());
GitFileRevision rightRevision = compareVersionMap.get(new Path(
repositoryMapping.getRepoRelativePath(res)));
if (rightRevision == null) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java
index f87aa43..5e75499 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/merge/GitMergeEditorInput.java
@@ -8,7 +8,6 @@
*******************************************************************************/
package org.eclipse.egit.ui.internal.merge;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -34,10 +33,10 @@ import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.CompareUtils;
-import org.eclipse.egit.ui.internal.EditableRevision;
+import org.eclipse.egit.ui.internal.FileEditableRevision;
import org.eclipse.egit.ui.internal.LocalFileRevision;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput.EmptyTypedElement;
-import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jgit.api.RebaseCommand;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator;
@@ -339,34 +338,11 @@ public class GitMergeEditorInput extends CompareEditorInput {
rev = GitFileRevision.inCommit(repository, headCommit,
gitPath, null);
- EditableRevision leftEditable = new EditableRevision(rev) {
- @Override
- public void setContent(final byte[] newContent) {
- try {
- run(false, false, new IRunnableWithProgress() {
- public void run(IProgressMonitor myMonitor)
- throws InvocationTargetException,
- InterruptedException {
- try {
- file.setContents(
- new ByteArrayInputStream(
- newContent), false,
- true, myMonitor);
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
- }
- }
- });
- } catch (InvocationTargetException e) {
- Activator
- .handleError(e.getTargetException()
- .getMessage(), e
- .getTargetException(), true);
- } catch (InterruptedException e) {
- // ignore here
- }
- }
- };
+ IRunnableContext runnableContext = getContainer();
+ if (runnableContext == null)
+ runnableContext = PlatformUI.getWorkbench().getProgressService();
+
+ FileEditableRevision leftEditable = new FileEditableRevision(rev, file, runnableContext);
// make sure we don't need a round trip later
try {
leftEditable.cacheContents(monitor);