KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > wizards > ImportProjectSetOperation


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.wizards;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
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 JavaDoc psfFile;
27     private String JavaDoc workingSetName;
28
29     public ImportProjectSetOperation(IRunnableContext context, String JavaDoc psfFile,
30             String JavaDoc workingSetName) {
31         super(context);
32         this.psfFile = psfFile;
33         this.workingSetName = workingSetName;
34     }
35
36     /*
37      * (non-Javadoc)
38      *
39      * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
40      */

41     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc,
42             InterruptedException JavaDoc {
43         PsfFilenameStore.remember(psfFile);
44         IProject[] newProjects = ProjectSetImporter.importProjectSet(psfFile,
45                 getShell(), monitor);
46         if (workingSetName != null)
47             createWorkingSet(workingSetName, newProjects);
48     }
49
50     /*
51      * (non-Javadoc)
52      *
53      * @see org.eclipse.team.ui.TeamOperation#canRunAsJob()
54      */

55     protected boolean canRunAsJob() {
56         return true;
57     }
58
59     /*
60      * (non-Javadoc)
61      *
62      * @see org.eclipse.team.ui.TeamOperation#getJobName()
63      */

64     protected String JavaDoc getJobName() {
65         return TeamUIMessages.ImportProjectSetMainPage_jobName;
66     }
67     
68     private void createWorkingSet(String JavaDoc 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             //don't overwrite the old elements
76
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