1 11 package org.eclipse.team.internal.ui.wizards; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.runtime.IAdaptable; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.jface.operation.IRunnableContext; 19 import org.eclipse.team.internal.ui.*; 20 import org.eclipse.team.ui.TeamOperation; 21 import org.eclipse.ui.IWorkingSet; 22 import org.eclipse.ui.IWorkingSetManager; 23 24 public class ImportProjectSetOperation extends TeamOperation { 25 26 private String psfFile; 27 private String workingSetName; 28 29 public ImportProjectSetOperation(IRunnableContext context, String psfFile, 30 String workingSetName) { 31 super(context); 32 this.psfFile = psfFile; 33 this.workingSetName = workingSetName; 34 } 35 36 41 public void run(IProgressMonitor monitor) throws InvocationTargetException , 42 InterruptedException { 43 PsfFilenameStore.remember(psfFile); 44 IProject[] newProjects = ProjectSetImporter.importProjectSet(psfFile, 45 getShell(), monitor); 46 if (workingSetName != null) 47 createWorkingSet(workingSetName, newProjects); 48 } 49 50 55 protected boolean canRunAsJob() { 56 return true; 57 } 58 59 64 protected String getJobName() { 65 return TeamUIMessages.ImportProjectSetMainPage_jobName; 66 } 67 68 private void createWorkingSet(String workingSetName, IProject[] projects) { 69 IWorkingSetManager manager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager(); 70 IWorkingSet oldSet = manager.getWorkingSet(workingSetName); 71 if (oldSet == null) { 72 IWorkingSet newSet = manager.createWorkingSet(workingSetName, projects); 73 manager.addWorkingSet(newSet); 74 } else { 75 IAdaptable[] tempElements = oldSet.getElements(); 77 IAdaptable[] adaptedProjects = oldSet.adaptElements(projects); 78 IAdaptable[] finalElementList = new IAdaptable[tempElements.length + adaptedProjects.length]; 79 System.arraycopy(tempElements, 0, finalElementList, 0, tempElements.length); 80 System.arraycopy(adaptedProjects, 0,finalElementList, tempElements.length, adaptedProjects.length); 81 oldSet.setElements(finalElementList); 82 } 83 } 84 } 85 | Popular Tags |