From de6da8e38d81eba100149e2d9e37326d2e0f9f43 Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Thu, 6 May 2010 17:46:43 +0200 Subject: [PATCH] Git Repositories View: remove "Existing Projects" node During the corresponding discussion on the egit mailing list, no requests were made to keep this node. Change-Id: Ie09d224f10162dff6ec8a48f1c6ef0b47c4aa64a Signed-off-by: Mathias Kinzler Signed-off-by: Chris Aniszczyk --- .../ui/internal/repository/RepositoriesView.java | 90 ++-------------------- .../RepositoriesViewContentProvider.java | 89 --------------------- .../repository/RepositoriesViewLabelProvider.java | 30 +------- .../ui/internal/repository/RepositoryTreeNode.java | 44 +++-------- 4 files changed, 21 insertions(+), 232 deletions(-) diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java index 5f65e6bc..7d5b2fc6 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesView.java @@ -26,7 +26,6 @@ import java.util.TreeSet; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileStore; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRunnable; @@ -39,14 +38,12 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.egit.core.op.BranchOperation; -import org.eclipse.egit.core.op.ConnectProviderOperation; import org.eclipse.egit.core.project.RepositoryMapping; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIIcons; @@ -118,7 +115,7 @@ import org.eclipse.ui.views.properties.PropertySheetPage; import org.osgi.service.prefs.BackingStoreException; /** - * + * * The Git Repositories view. *

* This keeps track of a bunch of local directory names each of which represent @@ -130,7 +127,7 @@ import org.osgi.service.prefs.BackingStoreException; *

* TODO *

  • Clarification whether to show projects, perhaps configurable switch
  • - * + * */ public class RepositoriesView extends ViewPart implements ISelectionProvider, IShowInTarget { @@ -175,7 +172,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, /** * TODO move to utility class - * + * * @return the directories as configured for this view */ public static List getDirs() { @@ -454,86 +451,11 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, } - @SuppressWarnings("unchecked") private void addMenuItemsForTreeSelection(Menu men) { final IStructuredSelection sel = (IStructuredSelection) tv .getSelection(); - boolean importableProjectsOnly = true; - - for (Object node : sel.toArray()) { - RepositoryTreeNode tnode = (RepositoryTreeNode) node; - importableProjectsOnly = tnode.getType() == RepositoryTreeNodeType.PROJ; - if (!importableProjectsOnly) - break; - } - - if (importableProjectsOnly) { - MenuItem sync = new MenuItem(men, SWT.PUSH); - sync.setText(UIText.RepositoriesView_ImportProject_MenuItem); - - sync.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - - IWorkspaceRunnable wsr = new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) - throws CoreException { - - for (Object selected : sel.toArray()) { - RepositoryTreeNode projectNode = (RepositoryTreeNode) selected; - File file = projectNode.getObject(); - - IProjectDescription pd = ResourcesPlugin - .getWorkspace().newProjectDescription( - file.getName()); - IPath locationPath = new Path(file - .getAbsolutePath()); - - pd.setLocation(locationPath); - - ResourcesPlugin.getWorkspace().getRoot() - .getProject(pd.getName()).create(pd, - monitor); - IProject project = ResourcesPlugin - .getWorkspace().getRoot().getProject( - pd.getName()); - project.open(monitor); - - File gitDir = projectNode.getRepository() - .getDirectory(); - - ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation( - project, gitDir); - connectProviderOperation - .execute(new SubProgressMonitor( - monitor, 20)); - - } - - } - }; - - try { - - ResourcesPlugin.getWorkspace().run(wsr, - ResourcesPlugin.getWorkspace().getRoot(), - IWorkspace.AVOID_UPDATE, - new NullProgressMonitor()); - - scheduleRefresh(); - } catch (CoreException e1) { - Activator.logError(e1.getMessage(), e1); - } - - } - - }); - } - // from here on, we only deal with single selection if (sel.size() > 1) return; @@ -1610,7 +1532,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, /** * Adds a directory to the list if it is not already there - * + * * @param file * @return see {@link Collection#add(Object)} */ @@ -1640,7 +1562,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, * {@link Repository} objects suitable for the tree content provider *

    * TODO move to some utility class - * + * * @param monitor * @return a list of nodes * @throws InterruptedException @@ -1735,7 +1657,7 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider, /** * Opens the tree and marks the folder to which a project is pointing - * + * * @param resource * TODO exceptions? */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java index 2d30bf4a..415da925 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java @@ -15,20 +15,14 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.Map.Entry; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIText; -import org.eclipse.egit.ui.internal.clone.GitProjectsImportPage; import org.eclipse.egit.ui.internal.repository.RepositoryTreeNode.RepositoryTreeNodeType; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; @@ -37,7 +31,6 @@ import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.RemoteConfig; -import org.eclipse.osgi.util.NLS; /** * Content Provider for the Git Repositories View @@ -184,42 +177,12 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider { node.getRepository())); nodeList.add(new RepositoryTreeNode(node, - RepositoryTreeNodeType.PROJECTS, node.getRepository(), node - .getRepository())); - - nodeList.add(new RepositoryTreeNode(node, RepositoryTreeNodeType.REMOTES, node.getRepository(), node .getRepository())); return nodeList.toArray(); } - case PROJECTS: { - List> projects = new ArrayList>(); - - // TODO do we want to show the projects here? - Collection result = new HashSet(); - Set traversed = new HashSet(); - collectProjectFilesFromDirectory(result, repo.getDirectory() - .getParentFile(), traversed, new NullProgressMonitor()); - for (File file : result) { - projects.add(new RepositoryTreeNode(node, - RepositoryTreeNodeType.PROJ, repo, file)); - } - - Comparator> sorter = new Comparator>() { - - public int compare(RepositoryTreeNode o1, - RepositoryTreeNode o2) { - return o1.getObject().getName().compareTo( - o2.getObject().getName()); - } - }; - Collections.sort(projects, sorter); - - return projects.toArray(); - } - case WORKINGDIR: { List> children = new ArrayList>(); @@ -325,10 +288,6 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider { // fall through case PUSH: // fall through - case PROJ: - // fall through - case HEAD: - // fall through case TAG: // fall through case FETCH: @@ -362,52 +321,4 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider { return children != null && children.length > 0; } - private boolean collectProjectFilesFromDirectory(Collection files, - File directory, Set directoriesVisited, - IProgressMonitor monitor) { - - // stolen from the GitCloneWizard; perhaps we should completely drop - // the projects from this view, though - if (monitor.isCanceled()) { - return false; - } - monitor.subTask(NLS.bind(UIText.RepositoriesView_Checking_Message, - directory.getPath())); - File[] contents = directory.listFiles(); - if (contents == null) - return false; - - // first look for project description files - final String dotProject = IProjectDescription.DESCRIPTION_FILE_NAME; - for (int i = 0; i < contents.length; i++) { - File file = contents[i]; - if (file.isFile() && file.getName().equals(dotProject)) { - files.add(file.getParentFile()); - // don't search sub-directories since we can't have nested - // projects - return true; - } - } - // no project description found, so recurse into sub-directories - for (int i = 0; i < contents.length; i++) { - if (contents[i].isDirectory()) { - if (!contents[i].getName().equals( - GitProjectsImportPage.METADATA_FOLDER)) { - try { - String canonicalPath = contents[i].getCanonicalPath(); - if (!directoriesVisited.add(canonicalPath)) { - // already been here --> do not recurse - continue; - } - } catch (IOException e) { - Activator.handleError(e.getMessage(), e, false); - } - collectProjectFilesFromDirectory(files, contents[i], - directoriesVisited, monitor); - } - } - } - return true; - } - } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java index 40cf3650..7a731ae6 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java @@ -15,9 +15,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; import org.eclipse.egit.ui.UIIcons; import org.eclipse.egit.ui.UIText; import org.eclipse.jface.resource.CompositeImageDescriptor; @@ -42,7 +39,7 @@ public class RepositoriesViewLabelProvider extends LabelProvider { // private DefaultInformationControl infoControl; /** - * + * * @param viewer */ public RepositoriesViewLabelProvider(final ColumnViewer viewer) { @@ -168,12 +165,8 @@ public class RepositoriesViewLabelProvider extends LabelProvider { // fall through case ERROR: return (String) node.getObject(); - case PROJECTS: - return UIText.RepositoriesView_ExistingProjects_Nodetext; case REF: // fall through - case HEAD: - // fall through case TAG: // fall through case SYMBOLICREF: @@ -185,17 +178,12 @@ public class RepositoriesViewLabelProvider extends LabelProvider { + ref.getLeaf().getName(); } return refName; - case PROJ: - - File file = (File) node.getObject(); - return file.getName(); - case WORKINGDIR: return UIText.RepositoriesView_WorkingDir_treenode + " - " //$NON-NLS-1$ + node.getRepository().getWorkDir().getAbsolutePath(); - - case PUSH: // fall through + case PUSH: + // fall through case FETCH: return (String) node.getObject(); @@ -233,18 +221,6 @@ public class RepositoriesViewLabelProvider extends LabelProvider { } return image; - case PROJ: - - File file = (File) node.getObject(); - - for (IProject proj : ResourcesPlugin.getWorkspace().getRoot() - .getProjects()) { - if (proj.getLocation().equals(new Path(file.getAbsolutePath()))) { - return getDecoratedImage(image); - } - } - return image; - default: return image; } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNode.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNode.java index 2e585e79..3245f9e6 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNode.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoryTreeNode.java @@ -19,7 +19,6 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE.SharedImages; /** * A node in the Git Repositories view tree @@ -98,14 +97,6 @@ public class RepositoryTreeNode implements Comparable { * {@link String} * * - * {@link RepositoryTreeNodeType#PROJ} - * {@link File} - * - * - * {@link RepositoryTreeNodeType#PROJECTS} - * {@link String} - * - * * {@link RepositoryTreeNodeType#LOCALBRANCHES} * {@link String} * @@ -144,8 +135,6 @@ public class RepositoryTreeNode implements Comparable { switch (myType) { case REPO: // fall through - case PROJECTS: - // fall through case REMOTES: // fall through case LOCALBRANCHES: @@ -162,8 +151,6 @@ public class RepositoryTreeNode implements Comparable { + ((myObject == null) ? 0 : ((Repository) myObject) .getDirectory().hashCode()); break; - case HEAD: - // fall through case REF: // fall through case TAG: @@ -174,8 +161,8 @@ public class RepositoryTreeNode implements Comparable { + ((myObject == null) ? 0 : ((Ref) myObject).getName() .hashCode()); break; - case PROJ: case FILE: + // fall through case FOLDER: result = prime * result @@ -255,17 +242,21 @@ public class RepositoryTreeNode implements Comparable { case BRANCHES: // fall through - case PROJECTS: + case LOCALBRANCHES: + // fall through + case REMOTEBRANCHES: // fall through case REMOTES: // fall through + case SYMBOLICREFS: + // fall through + case TAGS: + // fall through case WORKINGDIR: return 0; case FETCH: // fall through - case PROJ: - // fall through case PUSH: // fall through case REMOTE: @@ -276,6 +267,10 @@ public class RepositoryTreeNode implements Comparable { case FOLDER: return ((File) myObject).getName().compareTo( ((File) otherNode.getObject()).getName()); + case TAG: + // fall through + case SYMBOLICREF: + // fall through case REF: return ((Ref) myObject).getName().compareTo( ((Ref) otherNode.getObject()).getName()); @@ -301,8 +296,6 @@ public class RepositoryTreeNode implements Comparable { switch (myType) { case REPO: // fall through - case PROJECTS: - // fall through case REMOTES: // fall through case BRANCHES: @@ -320,15 +313,11 @@ public class RepositoryTreeNode implements Comparable { ((Repository) otherObject).getDirectory()); case REF: // fall through - case HEAD: - // fall through case TAG: // fall through case SYMBOLICREF: return ((Ref) myObject).getName().equals( ((Ref) otherObject).getName()); - case PROJ: - // fall through case FOLDER: // fall through case FILE: @@ -354,16 +343,10 @@ public class RepositoryTreeNode implements Comparable { /** */ REPO(UIIcons.REPOSITORY.createImage()), // /** */ - PROJ(PlatformUI.getWorkbench().getSharedImages().getImage( - SharedImages.IMG_OBJ_PROJECT_CLOSED)), // - /** */ BRANCHES(UIIcons.BRANCHES.createImage()), // /** */ REF(UIIcons.BRANCH.createImage()), // /** */ - HEAD(PlatformUI.getWorkbench().getSharedImages().getImage( - ISharedImages.IMG_OBJ_FILE)), // TODO icon - /** */ LOCALBRANCHES(PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_FOLDER)), // /** */ @@ -386,9 +369,6 @@ public class RepositoryTreeNode implements Comparable { FOLDER(PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_FOLDER)), // /** */ - PROJECTS(PlatformUI.getWorkbench().getSharedImages().getImage( - SharedImages.IMG_OBJ_PROJECT_CLOSED)), // - /** */ REMOTES(UIIcons.REMOTE_REPOSITORY.createImage()), // /** */ REMOTE(PlatformUI.getWorkbench().getSharedImages().getImage( -- 2.11.4.GIT