From 2a37cbe8457669294d7bdd2e930f5f7cb0fc88bb Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Mon, 26 Apr 2010 13:20:19 +0200 Subject: RepositoriesView: use the GitImportProject wizard The generic ImportExistingProject wizard from the org.eclipse.ui.ide plug-in does not allow to specify a directory in 3.4. Instead of the generic ImportExistingProject wizard, the RepositoriesView should use the Git wizard which allows to limit the scope to a directory in the file system and also adds project filtering capabilities as well as the option to add the imported projects to Team support. Change-Id: I4b66358e98a960af6c88e8d6656d24a6ee5279bb Signed-off-by: Mathias Kinzler Signed-off-by: Chris Aniszczyk --- .../ui/internal/clone/GitImportProjectsWizard.java | 64 +++++++++++++ .../ui/internal/clone/GitProjectsImportPage.java | 11 +-- .../ui/internal/repository/RepositoriesView.java | 102 +++------------------ 3 files changed, 77 insertions(+), 100 deletions(-) create mode 100644 org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitImportProjectsWizard.java diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitImportProjectsWizard.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitImportProjectsWizard.java new file mode 100644 index 0000000000..51607558b3 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitImportProjectsWizard.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2010 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.clone; + +import java.io.File; + +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.jgit.lib.Repository; + +/** + * A wizard used to import existing projects from a {@link Repository} + */ +public class GitImportProjectsWizard extends Wizard { + + private final String myWorkingDir; + + private final File myGitDir; + + /** + * @param repository + * the repository + * @param path + * a path, either the working directory of the repository or a + * sub-directory thereof + */ + public GitImportProjectsWizard(Repository repository, String path) { + super(); + myWorkingDir = path; + myGitDir = repository.getDirectory(); + setWindowTitle("Import existing projects"); + } + + @Override + public void addPages() { + + GitProjectsImportPage page = new GitProjectsImportPage() { + + @Override + public void setVisible(boolean visible) { + setGitDir(myGitDir); + setProjectsList(myWorkingDir); + super.setVisible(visible); + } + + }; + addPage(page); + } + + @Override + public boolean performFinish() { + GitProjectsImportPage page = (GitProjectsImportPage) getPages()[0]; + return page.createProjects(); + + } + +} diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java index e6134a41d3..43ec84c6d7 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/clone/GitProjectsImportPage.java @@ -220,16 +220,7 @@ public class GitProjectsImportPage extends WizardPage { * Creates a new project creation wizard page. */ public GitProjectsImportPage() { - this("gitWizardExternalProjectsPage"); //$NON-NLS-1$ - } - - /** - * Create a new instance of the receiver. - * - * @param pageName - */ - public GitProjectsImportPage(String pageName) { - super(pageName); + super("gitWizardExternalProjectsPage"); //$NON-NLS-1$ setPageComplete(false); setTitle(UIText.WizardProjectsImportPage_ImportProjectsTitle); setDescription(UIText.WizardProjectsImportPage_ImportProjectsDescription); 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 68898d6148..ed3fc59e40 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 @@ -50,6 +50,7 @@ import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.UIIcons; import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.internal.clone.GitCloneWizard; +import org.eclipse.egit.ui.internal.clone.GitImportProjectsWizard; import org.eclipse.egit.ui.internal.repository.RepositoryTreeNode.RepositoryTreeNodeType; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; @@ -97,7 +98,6 @@ import org.eclipse.ui.progress.IWorkbenchSiteProgressService; import org.eclipse.ui.views.properties.IPropertySheetPage; import org.eclipse.ui.views.properties.PropertySheet; import org.eclipse.ui.views.properties.PropertySheetPage; -import org.eclipse.ui.wizards.datatransfer.ExternalProjectImportWizard; import org.osgi.service.prefs.BackingStoreException; /** @@ -834,97 +834,19 @@ public class RepositoriesView extends ViewPart implements ISelectionProvider { @Override public void widgetSelected(SelectionEvent e) { - // TODO the ExternalProjectImportWizard - // does not allow to set a path in 3.4 - // use the GitCloneWizard page in a new - // GitImportWizard instead - Wizard wiz = new ExternalProjectImportWizard() { - - @Override - public void addPages() { - super.addPages(); - // we could add some page with a single - } - - @Override - public boolean performFinish() { - - final Set previousLocations = new HashSet(); - // we want to share only new projects - for (IProject project : ResourcesPlugin.getWorkspace() - .getRoot().getProjects()) { - previousLocations.add(project.getLocation()); - } - - boolean success = super.performFinish(); - if (success) { - // IWizardPage page = getPage("Share"); - // TODO evaluate checkbox or such, but - // if we do share - // always, we don't even need another - // page - - IWorkspaceRunnable wsr = new IWorkspaceRunnable() { - - public void run(IProgressMonitor monitor) - throws CoreException { - File gitDir = repo.getDirectory(); - File gitWorkDir = repo.getWorkDir(); - Path workPath = new Path(gitWorkDir - .getAbsolutePath()); - - // we check which projects are - // in the workspace - // pointing to a location in the - // repo's - // working directory - // and share them - for (IProject prj : ResourcesPlugin - .getWorkspace().getRoot() - .getProjects()) { - - if (workPath.isPrefixOf(prj - .getLocation())) { - if (previousLocations.contains(prj - .getLocation())) { - continue; - } - ConnectProviderOperation connectProviderOperation = new ConnectProviderOperation( - prj, gitDir); - connectProviderOperation - .run(new SubProgressMonitor( - monitor, 20)); - - } - } - - } - }; - - try { - ResourcesPlugin.getWorkspace().run( - wsr, - ResourcesPlugin.getWorkspace() - .getRoot(), - IWorkspace.AVOID_UPDATE, - new NullProgressMonitor()); - scheduleRefresh(); - } catch (CoreException ce) { - MessageDialog - .openError( - getShell(), - UIText.RepositoriesView_Error_WindowTitle, - ce.getMessage()); - } - - } - return success; - } - - }; + // Instead of the generic ExternalProjectImportWizard + // from the org.eclipse.ui.ide plug-in, we use our + // own wizard (the generic one does not allow to set the + // path in 3.4; in addition, we have added project filtering + // capabilities) + Wizard wiz = new GitImportProjectsWizard(repo, path); WizardDialog dlg = new WizardDialog(getSite().getShell(), wiz); - dlg.open(); + if (dlg.open() == Window.OK) + // TODO if we drop the "existing projects" node, we can + // probably do without refresh + scheduleRefresh(); + } }); -- cgit v1.2.3