diff options
author | Michael Valenta | 2005-08-11 14:34:11 +0000 |
---|---|---|
committer | Michael Valenta | 2005-08-11 14:34:11 +0000 |
commit | 3d19ba849f79445e2c6b22027f4bad4aa5fe2c5d (patch) | |
tree | 3638266cebbda56ea4d2f772f3358a96ccd3eaa2 /bundles | |
parent | 1c012134b21ae7f36476f664e7ee5b465830fd51 (diff) | |
download | eclipse.platform.team-3d19ba849f79445e2c6b22027f4bad4aa5fe2c5d.tar.gz eclipse.platform.team-3d19ba849f79445e2c6b22027f4bad4aa5fe2c5d.tar.xz eclipse.platform.team-3d19ba849f79445e2c6b22027f4bad4aa5fe2c5d.zip |
Bug 106700 (PatchAttached)Provide context menu import of team project sets
Diffstat (limited to 'bundles')
5 files changed, 222 insertions, 92 deletions
diff --git a/bundles/org.eclipse.team.ui/plugin.properties b/bundles/org.eclipse.team.ui/plugin.properties index 0e4449e13..85eb60956 100644 --- a/bundles/org.eclipse.team.ui/plugin.properties +++ b/bundles/org.eclipse.team.ui/plugin.properties @@ -26,6 +26,8 @@ IgnorePreferencePage.name=Ignored Resources ConfigureProject.label=&Share Project... ConfigureProject.tooltip=Share the project with others using a version and configuration management system. +ImportProjectSet.label=Import Project &Set... + TeamGroupMenu.label=T&eam Team.viewCategory=Team diff --git a/bundles/org.eclipse.team.ui/plugin.xml b/bundles/org.eclipse.team.ui/plugin.xml index 6f587f98e..ebe153b7a 100644 --- a/bundles/org.eclipse.team.ui/plugin.xml +++ b/bundles/org.eclipse.team.ui/plugin.xml @@ -100,7 +100,19 @@ enablesFor="1" id="nonbound.org.eclipse.team.ui.ConfigureProject"> </action> - </objectContribution> + </objectContribution> + <objectContribution + objectClass="org.eclipse.core.resources.IFile" + nameFilter="*.psf" + id="org.eclipse.team.ui.ProjectSetFileContributions"> + <action + label="%ImportProjectSet.label" + class="org.eclipse.team.internal.ui.actions.ImportProjectSetAction" + menubarPath="team.main" + enablesFor="*" + id="nonbound.org.eclipse.team.ui.ImportProjectSetAction"> + </action> + </objectContribution> </extension> <!-- ************** Views ********************** --> <extension diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java new file mode 100644 index 000000000..de1fc3d29 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/ProjectSetImporter.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.team.core.IProjectSetSerializer; +import org.eclipse.team.core.ProjectSetCapability; +import org.eclipse.team.core.RepositoryProviderType; +import org.eclipse.team.core.Team; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.internal.core.TeamPlugin; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +public class ProjectSetImporter { + + public static IProject[] importProjectSet(String filename, Shell shell, IProgressMonitor monitor) throws InvocationTargetException { + InputStreamReader reader = null; + try { + reader = new InputStreamReader(new FileInputStream(filename), "UTF-8"); //$NON-NLS-1$ + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser parser = factory.newSAXParser(); + ProjectSetContentHandler handler = new ProjectSetContentHandler(); + InputSource source = new InputSource(reader); + parser.parse(source, handler); + + Map map = handler.getReferences(); + List newProjects = new ArrayList(); + if (map.size() == 0 && handler.isVersionOne()) { + IProjectSetSerializer serializer = Team.getProjectSetSerializer("versionOneSerializer"); //$NON-NLS-1$ + if (serializer != null) { + IProject[] projects = serializer.addToWorkspace(new String[0], filename, shell, monitor); + if (projects != null) + newProjects.addAll(Arrays.asList(projects)); + } + } else { + UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(shell, filename); + Iterator it = map.keySet().iterator(); + List errors = new ArrayList(); + while (it.hasNext()) { + try { + String id = (String)it.next(); + List references = (List)map.get(id); + RepositoryProviderType providerType = RepositoryProviderType.getProviderType(id); + if (providerType == null) { + // The provider type is absent. Perhaps there is another provider that can import this type + providerType = TeamPlugin.getAliasType(id); + } + if (providerType == null) { + throw new TeamException(new Status(IStatus.ERROR, TeamUIPlugin.ID, 0, NLS.bind(TeamUIMessages.ProjectSetImportWizard_0, new String[] { id }), null)); + } + ProjectSetCapability serializer = providerType.getProjectSetCapability(); + ProjectSetCapability.ensureBackwardsCompatible(providerType, serializer); + if (serializer != null) { + IProject[] projects = serializer.addToWorkspace((String[])references.toArray(new String[references.size()]), context, monitor); + if (projects != null) + newProjects.addAll(Arrays.asList(projects)); + } + } catch (TeamException e) { + errors.add(e); + } + } + if (!errors.isEmpty()) { + if (errors.size() == 1) { + throw (TeamException)errors.get(0); + } else { + TeamException[] exceptions = (TeamException[]) errors.toArray(new TeamException[errors.size()]); + IStatus[] status = new IStatus[exceptions.length]; + for (int i = 0; i < exceptions.length; i++) { + status[i] = exceptions[i].getStatus(); + } + throw new TeamException(new MultiStatus(TeamUIPlugin.ID, 0, status, TeamUIMessages.ProjectSetImportWizard_1, null)); + } + } + } + return (IProject[]) newProjects.toArray(new IProject[newProjects.size()]); + } catch (IOException e) { + throw new InvocationTargetException(e); + } catch (SAXException e) { + throw new InvocationTargetException(e); + } catch (TeamException e) { + throw new InvocationTargetException(e); + } catch (ParserConfigurationException e) { + throw new InvocationTargetException(e); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + throw new InvocationTargetException(e); + } + } + } + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java new file mode 100644 index 000000000..436fda2da --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.internal.ui.actions; + +import java.lang.reflect.InvocationTargetException; +import java.util.Iterator; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.team.internal.ui.ProjectSetImporter; +import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.actions.ActionDelegate; + +public class ImportProjectSetAction extends ActionDelegate implements IObjectActionDelegate { + + private IStructuredSelection fSelection; + + public void run(IAction action) { + final Shell shell= Display.getDefault().getActiveShell(); + try { + new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + Iterator iterator= fSelection.iterator(); + while (iterator.hasNext()) { + IFile file= (IFile) iterator.next(); + ProjectSetImporter.importProjectSet(file.getLocation().toString(), shell, monitor); + } + } + }); + } catch (InvocationTargetException exception) { + ErrorDialog.openError(shell, null, null, new Status(IStatus.ERROR, TeamUIPlugin.PLUGIN_ID, IStatus.ERROR, "Exception importing project set.", exception.getTargetException())); + } catch (InterruptedException exception) { + } + } + + public void selectionChanged(IAction action, ISelection sel) { + if (sel instanceof IStructuredSelection) { + fSelection= (IStructuredSelection) sel; + } + } + + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java index 21367ad6c..cac6bc0ce 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java @@ -10,25 +10,27 @@ *******************************************************************************/ package org.eclipse.team.internal.ui.wizards; -import java.io.*; import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import javax.xml.parsers.*; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.osgi.util.NLS; -import org.eclipse.team.core.*; -import org.eclipse.team.internal.core.TeamPlugin; -import org.eclipse.team.internal.ui.*; -import org.eclipse.ui.*; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.internal.ui.ITeamUIImages; +import org.eclipse.team.internal.ui.ProjectSetImporter; +import org.eclipse.team.internal.ui.TeamUIMessages; +import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class ProjectSetImportWizard extends Wizard implements IImportWizard { @@ -60,87 +62,11 @@ public class ProjectSetImportWizard extends Wizard implements IImportWizard { try { getContainer().run(true, true, new WorkspaceModifyOperation(null) { public void execute(IProgressMonitor monitor) throws InvocationTargetException { - InputStreamReader reader = null; - try { - String filename = mainPage.getFileName(); - lastFile = filename; - reader = new InputStreamReader(new FileInputStream(filename), "UTF-8"); //$NON-NLS-1$ - - SAXParserFactory factory = SAXParserFactory.newInstance(); - SAXParser parser = factory.newSAXParser(); - ProjectSetContentHandler handler = new ProjectSetContentHandler(); - InputSource source = new InputSource(reader); - parser.parse(source, handler); - - Map map = handler.getReferences(); - List newProjects = new ArrayList(); - if (map.size() == 0 && handler.isVersionOne()) { - IProjectSetSerializer serializer = Team.getProjectSetSerializer("versionOneSerializer"); //$NON-NLS-1$ - if (serializer != null) { - IProject[] projects = serializer.addToWorkspace(new String[0], filename, getShell(), monitor); - if (projects != null) - newProjects.addAll(Arrays.asList(projects)); - } - } else { - UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(getShell(), filename); - Iterator it = map.keySet().iterator(); - List errors = new ArrayList(); - while (it.hasNext()) { - try { - String id = (String)it.next(); - List references = (List)map.get(id); - RepositoryProviderType providerType = RepositoryProviderType.getProviderType(id); - if (providerType == null) { - // The provider type is absent. Perhaps there is another provider that can import this type - providerType = TeamPlugin.getAliasType(id); - } - if (providerType == null) { - throw new TeamException(new Status(IStatus.ERROR, TeamUIPlugin.ID, 0, NLS.bind(TeamUIMessages.ProjectSetImportWizard_0, new String[] { id }), null)); - } - ProjectSetCapability serializer = providerType.getProjectSetCapability(); - ProjectSetCapability.ensureBackwardsCompatible(providerType, serializer); - if (serializer != null) { - IProject[] projects = serializer.addToWorkspace((String[])references.toArray(new String[references.size()]), context, monitor); - if (projects != null) - newProjects.addAll(Arrays.asList(projects)); - } - } catch (TeamException e) { - errors.add(e); - } - } - if (!errors.isEmpty()) { - if (errors.size() == 1) { - throw (TeamException)errors.get(0); - } else { - TeamException[] exceptions = (TeamException[]) errors.toArray(new TeamException[errors.size()]); - IStatus[] status = new IStatus[exceptions.length]; - for (int i = 0; i < exceptions.length; i++) { - status[i] = exceptions[i].getStatus(); - } - throw new TeamException(new MultiStatus(TeamUIPlugin.ID, 0, status, TeamUIMessages.ProjectSetImportWizard_1, null)); - } - } - } - if (workingSetName != null) - createWorkingSet(workingSetName, (IProject[]) newProjects.toArray(new IProject[newProjects.size()])); - result[0] = true; - } catch (IOException e) { - throw new InvocationTargetException(e); - } catch (SAXException e) { - throw new InvocationTargetException(e); - } catch (TeamException e) { - throw new InvocationTargetException(e); - } catch (ParserConfigurationException e) { - throw new InvocationTargetException(e); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - throw new InvocationTargetException(e); - } - } - } + lastFile= mainPage.getFileName(); + IProject[] newProjects= ProjectSetImporter.importProjectSet(lastFile, getShell(), monitor); + if (workingSetName != null) + createWorkingSet(workingSetName, newProjects); + result[0] = true; } }); } catch (InterruptedException e) { |