Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Kinzler2010-10-19 23:19:52 +0000
committerMatthias Sohn2010-10-19 23:19:52 +0000
commitd9e9e865c6dca8e9fa2f687d28795f6008244c57 (patch)
tree5c2eef4a759e72a27c11b33a9231db848b1f2f61
parent0afe023665d9d2536773a9a10be65b0ea1779cb8 (diff)
downloadegit-d9e9e865c6dca8e9fa2f687d28795f6008244c57.tar.gz
egit-d9e9e865c6dca8e9fa2f687d28795f6008244c57.tar.xz
egit-d9e9e865c6dca8e9fa2f687d28795f6008244c57.zip
[historyView] Refactoring first part
Refactor ResourceList from egit core into HistoryPageInput in egit ui and move the GitHistoryPageSource into the history package. Add a Repository parameter to the HistoryPageInput constructor to simplify Repository handling in case of multi-selection. Also change GitHistoryPageSource so that it does not set the input anymore. Change-Id: I5f7ea6abc278e4d518e7bbeab0004bf0353479fd Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/plugin.xml7
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ShowHistoryActionHandler.java25
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/factories/GitAdapterFactory.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPageSource.java (renamed from org.eclipse.egit.ui/src/org/eclipse/egit/ui/GitHistoryPageSource.java)20
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java (renamed from org.eclipse.egit.core/src/org/eclipse/egit/core/ResourceList.java)35
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java16
7 files changed, 67 insertions, 62 deletions
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 00216820b..86193e2b9 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -203,6 +203,13 @@
</adapter>
</factory>
<factory
+ adaptableType="org.eclipse.egit.ui.internal.history.HistoryPageInput"
+ class="org.eclipse.egit.ui.internal.factories.GitAdapterFactory">
+ <adapter
+ type="org.eclipse.team.ui.history.IHistoryPageSource">
+ </adapter>
+ </factory>
+ <factory
adaptableType="org.eclipse.egit.ui.internal.synchronize.model.GitModelRoot"
class="org.eclipse.egit.ui.internal.factories.GitAdapterFactory">
<adapter
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ShowHistoryActionHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ShowHistoryActionHandler.java
index e3acd8826..e13d230a3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ShowHistoryActionHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/ShowHistoryActionHandler.java
@@ -11,7 +11,10 @@ package org.eclipse.egit.ui.internal.actions;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
-import org.eclipse.egit.core.ResourceList;
+import org.eclipse.egit.core.project.RepositoryMapping;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.history.HistoryPageInput;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.team.ui.history.IHistoryView;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
@@ -20,7 +23,6 @@ import org.eclipse.ui.PlatformUI;
* An action to show the history for a resource.
*/
public class ShowHistoryActionHandler extends RepositoryActionHandler {
-
public Object execute(ExecutionEvent event) throws ExecutionException {
IHistoryView view;
try {
@@ -28,7 +30,24 @@ public class ShowHistoryActionHandler extends RepositoryActionHandler {
.getActiveWorkbenchWindow().getActivePage().showView(
IHistoryView.VIEW_ID);
IResource[] resources = getSelectedResources(event);
- ResourceList list = new ResourceList(resources);
+ if (resources.length == 1) {
+ view.showHistoryFor(resources[0]);
+ return null;
+ }
+
+ Repository repo = null;
+ for (IResource res : resources) {
+ RepositoryMapping map = RepositoryMapping.getMapping(res);
+ if (repo == null)
+ repo = map.getRepository();
+ if (repo != map.getRepository())
+ // we need to make sure are resources are from the same
+ // Repository
+ throw new ExecutionException(
+ UIText.AbstractHistoryCommanndHandler_NoUniqueRepository);
+
+ }
+ HistoryPageInput list = new HistoryPageInput(repo, resources);
view.showHistoryFor(list);
} catch (PartInitException e) {
throw new ExecutionException(e.getMessage(), e);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/factories/GitAdapterFactory.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/factories/GitAdapterFactory.java
index 36ac91af7..a757dad4a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/factories/GitAdapterFactory.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/factories/GitAdapterFactory.java
@@ -15,7 +15,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.egit.ui.GitHistoryPageSource;
+import org.eclipse.egit.ui.internal.history.GitHistoryPageSource;
import org.eclipse.egit.ui.internal.synchronize.mapping.GitModelWorkbenchAdapter;
import org.eclipse.egit.ui.internal.synchronize.mapping.GitObjectMapping;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index 3014532df..67869acf5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -29,7 +29,6 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.egit.core.ResourceList;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIIcons;
@@ -167,8 +166,8 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener {
* FOLDER or PROJECT and we can show it; false otherwise.
*/
public static boolean canShowHistoryFor(final Object object) {
- if (object instanceof ResourceList) {
- final IResource[] array = ((ResourceList) object).getItems();
+ if (object instanceof HistoryPageInput) {
+ final IResource[] array = ((HistoryPageInput) object).getItems();
if (array.length == 0)
return false;
for (final IResource r : array) {
@@ -999,7 +998,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener {
}
public Object getInput() {
- final ResourceList r = (ResourceList) super.getInput();
+ final HistoryPageInput r = (HistoryPageInput) super.getInput();
if (r == null)
return null;
final IResource[] in = r.getItems();
@@ -1013,15 +1012,12 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener {
public boolean setInput(final Object o) {
final Object in;
if (o instanceof IResource)
- in = new ResourceList(new IResource[] { (IResource) o });
- else if (o instanceof ResourceList)
+ in = new HistoryPageInput(RepositoryMapping.getMapping(
+ (IResource) o).getRepository(),
+ new IResource[] { (IResource) o });
+ else if (o instanceof HistoryPageInput)
in = o;
- else if (o instanceof IAdaptable) {
- IResource resource = (IResource) ((IAdaptable) o)
- .getAdapter(IResource.class);
- in = resource == null ? null : new ResourceList(
- new IResource[] { resource });
- } else
+ else
in = null;
return super.setInput(in);
}
@@ -1039,7 +1035,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener {
return false;
}
- final IResource[] in = ((ResourceList) super.getInput()).getItems();
+ final IResource[] in = ((HistoryPageInput) super.getInput()).getItems();
if (in == null || in.length == 0)
return false;
@@ -1277,7 +1273,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener {
// as it wrongly pollutes the navigation history
final String repositoryName = Activator.getDefault()
.getRepositoryUtil().getRepositoryName(db);
- final ResourceList in = (ResourceList) super.getInput();
+ final HistoryPageInput in = (HistoryPageInput) super.getInput();
if (currentWalk == null || in == null || in.getItems().length == 0)
return ""; //$NON-NLS-1$
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/GitHistoryPageSource.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPageSource.java
index 8c9fac7cf..8b8504ca7 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/GitHistoryPageSource.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPageSource.java
@@ -1,17 +1,15 @@
/*******************************************************************************
* Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
*
* 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;
+package org.eclipse.egit.ui.internal.history;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.egit.core.ResourceList;
-import org.eclipse.egit.ui.internal.history.GitHistoryPage;
import org.eclipse.team.ui.history.HistoryPageSource;
import org.eclipse.ui.part.Page;
@@ -24,17 +22,7 @@ public class GitHistoryPageSource extends HistoryPageSource {
}
public Page createPage(final Object object) {
- final ResourceList input;
-
- if (object instanceof ResourceList)
- input = (ResourceList) object;
- else if (object instanceof IResource)
- input = new ResourceList(new IResource[] { (IResource) object });
- else
- input = new ResourceList(new IResource[0]);
-
- final GitHistoryPage pg = new GitHistoryPage();
- pg.setInput(input);
- return pg;
+ // don't set the input, the framework does this for us
+ return new GitHistoryPage();
}
}
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/ResourceList.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java
index 94c763ccf..953711688 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/ResourceList.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/HistoryPageInput.java
@@ -1,43 +1,48 @@
/*******************************************************************************
* Copyright (C) 2006, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2010, Mathias Kinzler <mathias.kinzler@sap.com>
*
* 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.core;
+package org.eclipse.egit.ui.internal.history;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jgit.lib.Repository;
-/** A list of IResource, adaptable to the first item. */
-public class ResourceList implements IAdaptable {
+/**
+ * Input for the {@link GitHistoryPage}
+ **/
+public class HistoryPageInput {
private final IResource[] list;
+ private final Repository repo;
+
/**
- * Create a new list of resources.
- *
+ * @param repository
+ * the {@link Repository}
* @param items
* the items to contain in this list.
*/
- public ResourceList(final IResource[] items) {
+ public HistoryPageInput(final Repository repository, final IResource[] items) {
+ this.repo = repository;
list = items;
}
/**
- * Get the items stored in this list.
- *
+ * @return the {@link Repository} provided to the constructor
+ */
+ public Repository getRepository() {
+ return repo;
+ }
+
+ /**
* @return the list provided to our constructor.
*/
public IResource[] getItems() {
return list;
}
-
- public Object getAdapter(final Class adapter) {
- if (adapter == IResource.class && list != null && list.length > 0)
- return list[0];
- return null;
- }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java
index 728f9f260..1f369cfc9 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/command/AbstractHistoryCommanndHandler.java
@@ -21,11 +21,11 @@ import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.egit.core.ResourceList;
import org.eclipse.egit.core.project.RepositoryMapping;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.GitCompareFileRevisionEditorInput;
import org.eclipse.egit.ui.internal.history.GitHistoryPage;
+import org.eclipse.egit.ui.internal.history.HistoryPageInput;
import org.eclipse.jface.util.OpenStrategy;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -143,18 +143,8 @@ abstract class AbstractHistoryCommanndHandler extends AbstractHandler {
protected Repository getRepository(ExecutionEvent event)
throws ExecutionException {
Object input = getInput(event);
- Repository repo = null;
- if (input instanceof ResourceList) {
- for (IResource res : ((ResourceList) input).getItems()) {
- Repository resourceRepo = RepositoryMapping.getMapping(res)
- .getRepository();
- if (repo == null)
- repo = resourceRepo;
- if (repo != resourceRepo)
- throw new ExecutionException(
- UIText.AbstractHistoryCommanndHandler_NoUniqueRepository);
- }
- return repo;
+ if (input instanceof HistoryPageInput) {
+ return ((HistoryPageInput) input).getRepository();
} else
return RepositoryMapping.getMapping((IResource) input)
.getRepository();

Back to the top