Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 162608 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ui/ProjectSetImporter.java (-76 / +187 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 30-104 Link Here
30
import org.eclipse.ui.*;
30
import org.eclipse.ui.*;
31
31
32
public class ProjectSetImporter {
32
public class ProjectSetImporter {
33
	
33
34
	public static IProject[] importProjectSet(String filename, Shell shell, IProgressMonitor monitor) throws InvocationTargetException {
34
	/**
35
	 * Imports a psf file based on a file content. This may be used when psf
36
	 * file is imported from any other location that local filesystem.
37
	 * 
38
	 * @param psfContents
39
	 *            the content of the psf file.
40
	 * @param filename
41
	 *            the name of the source file. This is included in case the
42
	 *            provider needs to deduce relative paths
43
	 * @param shell
44
	 * @param monitor
45
	 * @return list of new projects
46
	 * @throws InvocationTargetException
47
	 */
48
	public static IProject[] importProjectSetFromString(String psfContents,
49
			String filename, Shell shell, IProgressMonitor monitor)
50
			throws InvocationTargetException {
51
		XMLMemento xmlMemento = stringToXMLMemento(psfContents);
52
		return importProjectSet(xmlMemento, filename, shell, monitor);
53
	}
54
55
	/**
56
	 * Imports a psf file.
57
	 * 
58
	 * @param filename
59
	 * @param shell
60
	 * @param monitor
61
	 * @return list of new projects
62
	 * @throws InvocationTargetException
63
	 */
64
	public static IProject[] importProjectSet(String filename, Shell shell,
65
			IProgressMonitor monitor) throws InvocationTargetException {
66
		XMLMemento xmlMemento = filenameToXMLMemento(filename);
67
		return importProjectSet(xmlMemento, filename, shell, monitor);
68
	}
69
70
	private static IProject[] importProjectSet(XMLMemento xmlMemento,
71
			String filename, Shell shell, IProgressMonitor monitor)
72
			throws InvocationTargetException {
35
		try {
73
		try {
36
			XMLMemento xmlMemento = filenameToXMLMemento(filename);
74
37
			String version = xmlMemento.getString("version"); //$NON-NLS-1$
75
			String version = xmlMemento.getString("version"); //$NON-NLS-1$
38
			
76
39
			List newProjects = new ArrayList();
77
			List newProjects = new ArrayList();
40
			if (version.equals("1.0")){ //$NON-NLS-1$
78
			if (version.equals("1.0")) { //$NON-NLS-1$
41
				IProjectSetSerializer serializer = Team.getProjectSetSerializer("versionOneSerializer"); //$NON-NLS-1$
79
				IProjectSetSerializer serializer = Team
80
						.getProjectSetSerializer("versionOneSerializer"); //$NON-NLS-1$
42
				if (serializer != null) {
81
				if (serializer != null) {
43
					IProject[] projects = serializer.addToWorkspace(new String[0], filename, shell, monitor);
82
					IProject[] projects = serializer.addToWorkspace(
83
							new String[0], filename, shell, monitor);
44
					if (projects != null)
84
					if (projects != null)
45
						newProjects.addAll(Arrays.asList(projects));
85
						newProjects.addAll(Arrays.asList(projects));
46
				}
86
				}
47
			} else {
87
			} else {
48
				UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(shell, filename);
88
				UIProjectSetSerializationContext context = new UIProjectSetSerializationContext(
89
						shell, filename);
49
				List errors = new ArrayList();
90
				List errors = new ArrayList();
50
				ArrayList referenceStrings = new ArrayList();
91
				ArrayList referenceStrings = new ArrayList();
51
			  	IMemento[] providers = xmlMemento.getChildren("provider"); //$NON-NLS-1$
92
				IMemento[] providers = xmlMemento.getChildren("provider"); //$NON-NLS-1$
52
			  	for (int i = 0; i < providers.length; i++) {
93
				for (int i = 0; i < providers.length; i++) {
53
					IMemento[] projects = providers[i].getChildren("project"); //$NON-NLS-1$
94
					IMemento[] projects = providers[i].getChildren("project"); //$NON-NLS-1$
54
					for (int j = 0; j < projects.length; j++) {
95
					for (int j = 0; j < projects.length; j++) {
55
						referenceStrings.add(projects[j].getString("reference")); //$NON-NLS-1$
96
						referenceStrings
97
								.add(projects[j].getString("reference")); //$NON-NLS-1$
56
					}
98
					}
57
					try {
99
					try {
58
                        String id = providers[i].getString("id"); //$NON-NLS-1$
100
						String id = providers[i].getString("id"); //$NON-NLS-1$
59
                        TeamCapabilityHelper.getInstance().processRepositoryId(id, 
101
						TeamCapabilityHelper.getInstance().processRepositoryId(
60
                        		PlatformUI.getWorkbench().getActivitySupport());
102
								id,
61
                        RepositoryProviderType providerType = RepositoryProviderType.getProviderType(id);
103
								PlatformUI.getWorkbench().getActivitySupport());
62
                        if (providerType == null) {
104
						RepositoryProviderType providerType = RepositoryProviderType
63
                            // The provider type is absent. Perhaps there is another provider that can import this type
105
								.getProviderType(id);
64
                            providerType = TeamPlugin.getAliasType(id);
106
						if (providerType == null) {
65
                        }
107
							// The provider type is absent. Perhaps there is
66
                        if (providerType == null) {
108
							// another provider that can import this type
67
                            throw new TeamException(new Status(IStatus.ERROR, TeamUIPlugin.ID, 0, NLS.bind(TeamUIMessages.ProjectSetImportWizard_0, new String[] { id }), null)); 
109
							providerType = TeamPlugin.getAliasType(id);
68
                        }
110
						}
69
                    	ProjectSetCapability serializer = providerType.getProjectSetCapability();
111
						if (providerType == null) {
70
                    	ProjectSetCapability.ensureBackwardsCompatible(providerType, serializer);
112
							throw new TeamException(
71
                    	if (serializer != null) {
113
									new Status(
72
                    		IProject[] allProjects = serializer.addToWorkspace((String[])referenceStrings.toArray(new String[referenceStrings.size()]), context, monitor);
114
											IStatus.ERROR,
73
                    		if (allProjects != null)
115
											TeamUIPlugin.ID,
74
                    			newProjects.addAll(Arrays.asList(allProjects));
116
											0,
75
                    	}
117
											NLS.bind(
76
                    	referenceStrings.clear();
118
													TeamUIMessages.ProjectSetImportWizard_0,
77
                    } catch (TeamException e) {
119
													new String[] { id }), null));
78
                        errors.add(e);
120
						}
79
                    }
121
						ProjectSetCapability serializer = providerType
80
				}
122
								.getProjectSetCapability();
81
			  	if (!errors.isEmpty()) {
123
						ProjectSetCapability.ensureBackwardsCompatible(
82
				    if (errors.size() == 1) {
124
								providerType, serializer);
83
				        throw (TeamException)errors.get(0);
125
						if (serializer != null) {
84
				    } else {
126
							IProject[] allProjects = serializer
85
				        TeamException[] exceptions = (TeamException[]) errors.toArray(new TeamException[errors.size()]);
127
									.addToWorkspace(
86
				        IStatus[] status = new IStatus[exceptions.length];
128
											(String[]) referenceStrings
87
				        for (int i = 0; i < exceptions.length; i++) {
129
													.toArray(new String[referenceStrings
88
                            status[i] = exceptions[i].getStatus();
130
															.size()]), context,
89
                        }
131
											monitor);
90
				        throw new TeamException(new MultiStatus(TeamUIPlugin.ID, 0, status, TeamUIMessages.ProjectSetImportWizard_1, null)); 
132
							if (allProjects != null)
91
				    }
133
								newProjects.addAll(Arrays.asList(allProjects));
92
				}
134
						}
93
			  	
135
						referenceStrings.clear();
94
			  	//try working sets
136
					} catch (TeamException e) {
95
			  	IMemento[] sets = xmlMemento.getChildren("workingSets"); //$NON-NLS-1$
137
						errors.add(e);
96
			  	IWorkingSetManager wsManager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager();
138
					}
97
			  	boolean replaceAll = false;
139
				}
98
			  	boolean mergeAll = false;
140
				if (!errors.isEmpty()) {
99
			  	boolean skipAll = false;
141
					if (errors.size() == 1) {
100
			  	
142
						throw (TeamException) errors.get(0);
101
			  	for (int i = 0; i < sets.length; i++) {
143
					} else {
144
						TeamException[] exceptions = (TeamException[]) errors
145
								.toArray(new TeamException[errors.size()]);
146
						IStatus[] status = new IStatus[exceptions.length];
147
						for (int i = 0; i < exceptions.length; i++) {
148
							status[i] = exceptions[i].getStatus();
149
						}
150
						throw new TeamException(new MultiStatus(
151
								TeamUIPlugin.ID, 0, status,
152
								TeamUIMessages.ProjectSetImportWizard_1, null));
153
					}
154
				}
155
156
				// try working sets
157
				IMemento[] sets = xmlMemento.getChildren("workingSets"); //$NON-NLS-1$
158
				IWorkingSetManager wsManager = TeamUIPlugin.getPlugin()
159
						.getWorkbench().getWorkingSetManager();
160
				boolean replaceAll = false;
161
				boolean mergeAll = false;
162
				boolean skipAll = false;
163
164
				for (int i = 0; i < sets.length; i++) {
102
					IWorkingSet newWs = wsManager.createWorkingSet(sets[i]);
165
					IWorkingSet newWs = wsManager.createWorkingSet(sets[i]);
103
					if (newWs != null) {
166
					if (newWs != null) {
104
						IWorkingSet oldWs = wsManager.getWorkingSet(newWs
167
						IWorkingSet oldWs = wsManager.getWorkingSet(newWs
Lines 113-136 Link Here
113
							// a working set with the same name has been found
176
							// a working set with the same name has been found
114
							String title = TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_title;
177
							String title = TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_title;
115
							String msg = NLS
178
							String msg = NLS
116
									.bind(
179
									.bind(TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_message,
117
											TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_message,
118
											newWs.getName());
180
											newWs.getName());
119
							String[] buttons = new String[] {
181
							String[] buttons = new String[] {
120
									TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replace,
182
									TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replace,
121
									TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_merge,
183
									TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_merge,
122
									TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skip,
184
									TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skip,
123
									IDialogConstants.CANCEL_LABEL };
185
									IDialogConstants.CANCEL_LABEL };
124
							final AdviceDialog dialog = new AdviceDialog(
186
							final AdviceDialog dialog = new AdviceDialog(shell,
125
									shell, title, null, msg,
187
									title, null, msg, MessageDialog.QUESTION,
126
									MessageDialog.QUESTION, buttons, 0);
188
									buttons, 0);
127
							
189
128
							shell.getDisplay().syncExec(new Runnable() {
190
							shell.getDisplay().syncExec(new Runnable() {
129
								public void run() {
191
								public void run() {
130
									 dialog.open();
192
									dialog.open();
131
								}
193
								}
132
							});
194
							});
133
							
195
134
							switch (dialog.getReturnCode()) {
196
							switch (dialog.getReturnCode()) {
135
							case 0: // overwrite
197
							case 0: // overwrite
136
								replaceWorkingSet(wsManager, newWs, oldWs);
198
								replaceWorkingSet(wsManager, newWs, oldWs);
Lines 151-167 Link Here
151
					}
213
					}
152
				}
214
				}
153
			}
215
			}
154
			
216
155
			return (IProject[]) newProjects.toArray(new IProject[newProjects.size()]);
217
			return (IProject[]) newProjects.toArray(new IProject[newProjects
218
					.size()]);
156
		} catch (TeamException e) {
219
		} catch (TeamException e) {
157
			throw new InvocationTargetException(e);
220
			throw new InvocationTargetException(e);
158
		}
221
		}
159
	}
222
	}
160
223
161
	private static XMLMemento filenameToXMLMemento(String filename) throws InvocationTargetException {
224
	private static XMLMemento filenameToXMLMemento(String filename)
225
			throws InvocationTargetException {
162
		InputStreamReader reader = null;
226
		InputStreamReader reader = null;
163
		try {
227
		try {
164
			reader = new InputStreamReader(new FileInputStream(filename), "UTF-8"); //$NON-NLS-1$
228
			reader = new InputStreamReader(new FileInputStream(filename),
229
					"UTF-8"); //$NON-NLS-1$
165
			return XMLMemento.createReadRoot(reader);
230
			return XMLMemento.createReadRoot(reader);
166
		} catch (UnsupportedEncodingException e) {
231
		} catch (UnsupportedEncodingException e) {
167
			throw new InvocationTargetException(e);
232
			throw new InvocationTargetException(e);
Lines 179-185 Link Here
179
			}
244
			}
180
		}
245
		}
181
	}
246
	}
182
	
247
248
	private static XMLMemento stringToXMLMemento(String stringContents)
249
			throws InvocationTargetException {
250
		StringReader reader = null;
251
		try {
252
			reader = new StringReader(stringContents);
253
			return XMLMemento.createReadRoot(reader);
254
		} catch (WorkbenchException e) {
255
			throw new InvocationTargetException(e);
256
		} finally {
257
			if (reader != null) {
258
				reader.close();
259
			}
260
		}
261
	}
262
263
	/**
264
	 * Check if given file is a valid psf file
265
	 * 
266
	 * @param filename
267
	 * @return <code>true</code> is file is a valid psf file
268
	 */
183
	public static boolean isValidProjectSetFile(String filename) {
269
	public static boolean isValidProjectSetFile(String filename) {
184
		try {
270
		try {
185
			return filenameToXMLMemento(filename).getString("version") != null; //$NON-NLS-1$
271
			return filenameToXMLMemento(filename).getString("version") != null; //$NON-NLS-1$
Lines 187-205 Link Here
187
			return false;
273
			return false;
188
		}
274
		}
189
	}
275
	}
190
	
276
277
	/**
278
	 * Check if given string is a valid project set
279
	 * 
280
	 * @param psfContent
281
	 * @return <code>true</code> if psfContent is a valid project set
282
	 */
283
	public static boolean isValidProjectSetString(String psfContent) {
284
		if (psfContent == null) {
285
			return false;
286
		}
287
		try {
288
			return stringToXMLMemento(psfContent).getString("version") != null; //$NON-NLS-1$
289
		} catch (InvocationTargetException e) {
290
			return false;
291
		}
292
	}
293
191
	private static void mergeWorkingSets(IWorkingSet newWs, IWorkingSet oldWs) {
294
	private static void mergeWorkingSets(IWorkingSet newWs, IWorkingSet oldWs) {
192
		IAdaptable[] oldElements = oldWs.getElements();
295
		IAdaptable[] oldElements = oldWs.getElements();
193
		IAdaptable[] newElements = newWs.getElements();
296
		IAdaptable[] newElements = newWs.getElements();
194
		
297
195
		Set combinedElements = new HashSet();
298
		Set combinedElements = new HashSet();
196
		combinedElements.addAll(Arrays.asList(oldElements));
299
		combinedElements.addAll(Arrays.asList(oldElements));
197
		combinedElements.addAll(Arrays.asList(newElements));
300
		combinedElements.addAll(Arrays.asList(newElements));
198
		
301
199
		oldWs.setElements((IAdaptable[]) combinedElements.toArray(new IAdaptable[0]));
302
		oldWs.setElements((IAdaptable[]) combinedElements
303
				.toArray(new IAdaptable[0]));
200
	}
304
	}
201
305
202
	private static void replaceWorkingSet(IWorkingSetManager wsManager, IWorkingSet newWs, IWorkingSet oldWs) {
306
	private static void replaceWorkingSet(IWorkingSetManager wsManager,
307
			IWorkingSet newWs, IWorkingSet oldWs) {
203
		if (oldWs != null)
308
		if (oldWs != null)
204
			wsManager.removeWorkingSet(oldWs);
309
			wsManager.removeWorkingSet(oldWs);
205
		wsManager.addWorkingSet(newWs);
310
		wsManager.addWorkingSet(newWs);
Lines 207-215 Link Here
207
312
208
	private static class AdviceDialog extends MessageDialog {
313
	private static class AdviceDialog extends MessageDialog {
209
		boolean applyToAll;
314
		boolean applyToAll;
210
		public AdviceDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
315
211
			super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
316
		public AdviceDialog(Shell parentShell, String dialogTitle,
317
				Image dialogTitleImage, String dialogMessage,
318
				int dialogImageType, String[] dialogButtonLabels,
319
				int defaultIndex) {
320
			super(parentShell, dialogTitle, dialogTitleImage, dialogMessage,
321
					dialogImageType, dialogButtonLabels, defaultIndex);
212
		}
322
		}
323
213
		protected Control createCustomArea(Composite parent) {
324
		protected Control createCustomArea(Composite parent) {
214
			final Button checkBox = new Button(parent, SWT.CHECK);
325
			final Button checkBox = new Button(parent, SWT.CHECK);
215
			checkBox.setText(TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_applyToAll);
326
			checkBox.setText(TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_applyToAll);
(-)src/org/eclipse/team/internal/ui/TeamUIMessages.java (-1 / +7 lines)
Lines 105-110 Link Here
105
	public static String HistoryPageCompareEditorInput_0;
105
	public static String HistoryPageCompareEditorInput_0;
106
106
107
	public static String ImportProjectSetMainPage_AddToWorkingSet;
107
	public static String ImportProjectSetMainPage_AddToWorkingSet;
108
	public static String ImportProjectSetMainPage_Project_Set_File;
109
	public static String ImportProjectSetMainPage_Project_Set_Url;
108
110
109
	public static String ImportProjectSetMainPage_Browse;
111
	public static String ImportProjectSetMainPage_Browse;
110
	
112
	
Lines 114-119 Link Here
114
	public static String ImportProjectSetDialog_duplicatedWorkingSet_merge;
116
	public static String ImportProjectSetDialog_duplicatedWorkingSet_merge;
115
	public static String ImportProjectSetDialog_duplicatedWorkingSet_skip;
117
	public static String ImportProjectSetDialog_duplicatedWorkingSet_skip;
116
	public static String ImportProjectSetDialog_duplicatedWorkingSet_applyToAll;
118
	public static String ImportProjectSetDialog_duplicatedWorkingSet_applyToAll;
119
	public static String ImportProjectSetDialog_malformed_url;
120
	public static String ImportProjectSetDialog_URLConnecting;
121
	public static String ImportProjectSetDialog_URLFetchingContent;
117
122
118
	public static String information;
123
	public static String information;
119
    
124
    
Lines 310-317 Link Here
310
	public static String ExportProjectSetMainPage_Initial_description;
315
	public static String ExportProjectSetMainPage_Initial_description;
311
	public static String ExportProjectSetMainPage_specifyFile;
316
	public static String ExportProjectSetMainPage_specifyFile;
312
317
313
	public static String ImportProjectSetMainPage_Project_Set_File_Name__2;
314
	public static String ImportProjectSetMainPage_Browse_3;
318
	public static String ImportProjectSetMainPage_Browse_3;
319
	public static String ImportProjectSetMainPage_The_given_URL_cannot_be_loaded;
315
	public static String ImportProjectSetMainPage_The_specified_file_does_not_exist_4;
320
	public static String ImportProjectSetMainPage_The_specified_file_does_not_exist_4;
316
	public static String ImportProjectSetMainPage_You_have_specified_a_folder_5;
321
	public static String ImportProjectSetMainPage_You_have_specified_a_folder_5;
317
	public static String ImportProjectSetMainPage_workingSetNameEmpty;
322
	public static String ImportProjectSetMainPage_workingSetNameEmpty;
Lines 320-325 Link Here
320
	public static String ImportProjectSetMainPage_runInBackground;
325
	public static String ImportProjectSetMainPage_runInBackground;
321
	public static String ImportProjectSetMainPage_jobName;
326
	public static String ImportProjectSetMainPage_jobName;
322
	public static String ImportProjectSetMainPage_specifyFile;
327
	public static String ImportProjectSetMainPage_specifyFile;
328
	public static String ImportProjectSetMainPage_specifyURL;
323
	public static String ImportProjectSetMainPage_selectWorkingSet;
329
	public static String ImportProjectSetMainPage_selectWorkingSet;
324
	public static String ImportProjectSetMainPage_projectSetFileInvalid;
330
	public static String ImportProjectSetMainPage_projectSetFileInvalid;
325
331
(-)src/org/eclipse/team/internal/ui/messages.properties (-1 / +7 lines)
Lines 104-112 Link Here
104
ExportProjectSetMainPage_Initial_description=Define which projects or working sets should be exported into the team project file.
104
ExportProjectSetMainPage_Initial_description=Define which projects or working sets should be exported into the team project file.
105
ExportProjectSetMainPage_specifyFile=Please specify the destination file.
105
ExportProjectSetMainPage_specifyFile=Please specify the destination file.
106
106
107
ImportProjectSetMainPage_Project_Set_File_Name__2=F&ile name:
107
ImportProjectSetMainPage_Project_Set_File=File
108
ImportProjectSetMainPage_Project_Set_Url=URL
108
ImportProjectSetMainPage_Browse_3=B&rowse...
109
ImportProjectSetMainPage_Browse_3=B&rowse...
109
ImportProjectSetMainPage_Browse=Br&owse...
110
ImportProjectSetMainPage_Browse=Br&owse...
111
ImportProjectSetMainPage_The_given_URL_cannot_be_loaded=File from given URL cannot be loaded
110
ImportProjectSetMainPage_The_specified_file_does_not_exist_4=The specified file does not exist
112
ImportProjectSetMainPage_The_specified_file_does_not_exist_4=The specified file does not exist
111
ImportProjectSetMainPage_You_have_specified_a_folder_5=You have specified a folder
113
ImportProjectSetMainPage_You_have_specified_a_folder_5=You have specified a folder
112
ImportProjectSetMainPage_workingSetNameEmpty=The working set name must not be empty
114
ImportProjectSetMainPage_workingSetNameEmpty=The working set name must not be empty
Lines 116-121 Link Here
116
ImportProjectSetMainPage_runInBackground=Run the import in the bac&kground
118
ImportProjectSetMainPage_runInBackground=Run the import in the bac&kground
117
ImportProjectSetMainPage_jobName=Importing project set...
119
ImportProjectSetMainPage_jobName=Importing project set...
118
ImportProjectSetMainPage_specifyFile=Please specify a file to import.
120
ImportProjectSetMainPage_specifyFile=Please specify a file to import.
121
ImportProjectSetMainPage_specifyURL=Please specify an URL to import.
119
ImportProjectSetMainPage_selectWorkingSet=Select a working set.
122
ImportProjectSetMainPage_selectWorkingSet=Select a working set.
120
ImportProjectSetMainPage_projectSetFileInvalid=The specified file is not a valid Team Project Set file.
123
ImportProjectSetMainPage_projectSetFileInvalid=The specified file is not a valid Team Project Set file.
121
ImportProjectSetDialog_duplicatedWorkingSet_title=Working Set Exists
124
ImportProjectSetDialog_duplicatedWorkingSet_title=Working Set Exists
Lines 124-129 Link Here
124
ImportProjectSetDialog_duplicatedWorkingSet_merge=&Merge
127
ImportProjectSetDialog_duplicatedWorkingSet_merge=&Merge
125
ImportProjectSetDialog_duplicatedWorkingSet_skip=&Skip
128
ImportProjectSetDialog_duplicatedWorkingSet_skip=&Skip
126
ImportProjectSetDialog_duplicatedWorkingSet_applyToAll=&Apply to all working sets in this import
129
ImportProjectSetDialog_duplicatedWorkingSet_applyToAll=&Apply to all working sets in this import
130
ImportProjectSetDialog_malformed_url=Malformed URL
131
ImportProjectSetDialog_URLConnecting=Opening connection to the URL
132
ImportProjectSetDialog_URLFetchingContent=Fetching content from the URL
127
133
128
ProjectSetContentHandler_Element_provider_must_be_contained_in_element_psf_4=Element provider must be contained in element psf
134
ProjectSetContentHandler_Element_provider_must_be_contained_in_element_psf_4=Element provider must be contained in element psf
129
ProjectSetContentHandler_Element_project_must_be_contained_in_element_provider_7=Element project must be contained in element provider
135
ProjectSetContentHandler_Element_project_must_be_contained_in_element_provider_7=Element project must be contained in element provider
(-)src/org/eclipse/team/internal/ui/actions/ImportProjectSetAction.java (-2 / +2 lines)
Lines 24-30 Link Here
24
import org.eclipse.swt.widgets.Display;
24
import org.eclipse.swt.widgets.Display;
25
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.team.internal.ui.*;
26
import org.eclipse.team.internal.ui.*;
27
import org.eclipse.team.internal.ui.wizards.ImportProjectSetOperation;
27
import org.eclipse.team.internal.ui.wizards.ImportFromFileProjectSetOperation;
28
import org.eclipse.ui.*;
28
import org.eclipse.ui.*;
29
import org.eclipse.ui.actions.ActionDelegate;
29
import org.eclipse.ui.actions.ActionDelegate;
30
import org.eclipse.ui.actions.WorkspaceModifyOperation;
30
import org.eclipse.ui.actions.WorkspaceModifyOperation;
Lines 42-48 Link Here
42
					while (iterator.hasNext()) {
42
					while (iterator.hasNext()) {
43
						IFile file = (IFile) iterator.next();
43
						IFile file = (IFile) iterator.next();
44
						if (isRunInBackgroundPreferenceOn()) {
44
						if (isRunInBackgroundPreferenceOn()) {
45
							ImportProjectSetOperation op = new ImportProjectSetOperation(null, file.getLocation().toString(), new IWorkingSet[0]);
45
							ImportFromFileProjectSetOperation op = new ImportFromFileProjectSetOperation(null, file.getLocation().toString(), new IWorkingSet[0]);
46
							op.run();
46
							op.run();
47
						} else { 
47
						} else { 
48
							ProjectSetImporter.importProjectSet(file.getLocation().toString(), shell, monitor);
48
							ProjectSetImporter.importProjectSet(file.getLocation().toString(), shell, monitor);
(-)src/org/eclipse/team/internal/ui/wizards/ExportProjectSetLocationPage.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2008 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 91-98 Link Here
91
		inner.setLayoutData(data);
91
		inner.setLayoutData(data);
92
92
93
		fileCombo = createDropDownCombo(inner);
93
		fileCombo = createDropDownCombo(inner);
94
		file = PsfFilenameStore.getSuggestedDefault();
94
		file = PsfFilenameStore.getInstance().getSuggestedDefault();
95
		fileCombo.setItems(PsfFilenameStore.getHistory());
95
		fileCombo.setItems(PsfFilenameStore.getInstance().getHistory());
96
		fileCombo.setText(file);
96
		fileCombo.setText(file);
97
		fileCombo.addListener(SWT.Modify, new Listener() {
97
		fileCombo.addListener(SWT.Modify, new Listener() {
98
			public void handleEvent(Event event) {
98
			public void handleEvent(Event event) {
(-)src/org/eclipse/team/internal/ui/wizards/ImportFromFileProjectSetOperation.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 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;
14
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.jface.operation.IRunnableContext;
18
import org.eclipse.team.internal.ui.ProjectSetImporter;
19
import org.eclipse.ui.IWorkingSet;
20
21
public class ImportFromFileProjectSetOperation extends ImportProjectSetOperation {
22
23
	private String psfFile;
24
	private IWorkingSet[] workingSets;
25
26
	/**
27
	 * Operation for importing a Team Project Set file
28
	 * 
29
	 * @param context
30
	 *            a runnable context
31
	 * @param psfFile
32
	 *            a psf file name
33
	 * @param workingSets
34
	 *            an array of working sets where imported project should be
35
	 *            added. If a working set doesn't exist it will be created. The
36
	 *            array cannot be <code>null</code>, pass an empty array if you
37
	 *            don't want to add projects to any working set.
38
	 */
39
	public ImportFromFileProjectSetOperation(IRunnableContext context, String psfFile,
40
			IWorkingSet[] workingSets) {
41
		super(context);
42
		this.psfFile = psfFile;
43
		this.workingSets = workingSets;
44
	}
45
46
	/*
47
	 * (non-Javadoc)
48
	 * 
49
	 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
50
	 */
51
	public void run(IProgressMonitor monitor) throws InvocationTargetException,
52
			InterruptedException {
53
		PsfFilenameStore.getInstance().remember(psfFile);
54
		IProject[] newProjects = ProjectSetImporter.importProjectSet(psfFile,
55
				getShell(), monitor);
56
		createWorkingSet(workingSets, newProjects);
57
	}
58
}
(-)src/org/eclipse/team/internal/ui/wizards/ImportProjectSetMainPage.java (-10 / +208 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.wizards;
11
package org.eclipse.team.internal.ui.wizards;
12
12
13
import java.io.File;
13
import java.io.*;
14
import java.lang.reflect.InvocationTargetException;
15
import java.net.*;
14
16
15
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.*;
16
import org.eclipse.jface.dialogs.Dialog;
19
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.dialogs.IDialogConstants;
20
import org.eclipse.jface.dialogs.IDialogConstants;
21
import org.eclipse.jface.operation.IRunnableWithProgress;
18
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.SelectionAdapter;
24
import org.eclipse.swt.events.SelectionAdapter;
Lines 32-47 Link Here
32
	String file = ""; //$NON-NLS-1$
36
	String file = ""; //$NON-NLS-1$
33
	Button browseButton;
37
	Button browseButton;
34
	
38
	
39
	String urlString = ""; //$NON-NLS-1$
40
	Combo urlCombo;
41
	
42
	//input type radios
43
	private Button fileInputButton;
44
	private Button urlInputButton;
45
	
46
	//input type
47
	public static final int InputType_file = 0;
48
	public static final int InputType_URL = 1;
49
	private int inputType = InputType_file;
50
	
35
	private boolean runInBackground = isRunInBackgroundPreferenceOn();
51
	private boolean runInBackground = isRunInBackgroundPreferenceOn();
36
	// a wizard shouldn't be in an error state until the state has been modified by the user
52
	// a wizard shouldn't be in an error state until the state has been modified by the user
37
	private int messageType = NONE;
53
	private int messageType = NONE;
38
	private WorkingSetGroup workingSetGroup; 
54
	private WorkingSetGroup workingSetGroup; 
39
	
55
	
56
	private PsfFilenameStore psfFilenameStore = PsfFilenameStore.getInstance();
57
	private PsfUrlStore psfUrlStore = PsfUrlStore.getInstance();
58
	
40
	public ImportProjectSetMainPage(String pageName, String title, ImageDescriptor titleImage) {
59
	public ImportProjectSetMainPage(String pageName, String title, ImageDescriptor titleImage) {
41
		super(pageName, title, titleImage);
60
		super(pageName, title, titleImage);
42
		setDescription(TeamUIMessages.ImportProjectSetMainPage_description); 
61
		setDescription(TeamUIMessages.ImportProjectSetMainPage_description); 
43
	}
62
	}
44
	
63
	
64
	private void setInputyType(int inputTypeSelected){
65
		this.inputType = inputTypeSelected;
66
		//reset the message type and give the user fresh chance to input correct data
67
		messageType = NONE;
68
		//update controls
69
		fileInputButton.setSelection(inputType==InputType_file);
70
		fileCombo.setEnabled(inputType==InputType_file);
71
		browseButton.setEnabled(inputType==InputType_file);
72
		urlInputButton.setSelection(inputType==InputType_URL);
73
		urlCombo.setEnabled(inputType==InputType_URL);
74
		//validate field
75
		if(inputType==InputType_file) updateFileEnablement();
76
		if(inputType==InputType_URL) updateUrlEnablement();
77
		
78
	}
79
	
45
	/*
80
	/*
46
	 * @see IDialogPage#createControl(Composite)
81
	 * @see IDialogPage#createControl(Composite)
47
	 */
82
	 */
Lines 60-80 Link Here
60
		layout.marginWidth = 0;
95
		layout.marginWidth = 0;
61
		inner.setLayout(layout);
96
		inner.setLayout(layout);
62
		
97
		
63
		createLabel(inner, TeamUIMessages.ImportProjectSetMainPage_Project_Set_File_Name__2); 
98
		fileInputButton = new Button(inner, SWT.RADIO);
99
		fileInputButton.setText(TeamUIMessages.ImportProjectSetMainPage_Project_Set_File);
100
		fileInputButton.setEnabled(true);
101
		fileInputButton.addSelectionListener(new SelectionAdapter() {
102
			public void widgetSelected(SelectionEvent e) {
103
				setInputyType(InputType_file);
104
			}
105
		});
64
106
65
		fileCombo = createDropDownCombo(inner);
107
		fileCombo = createDropDownCombo(inner);
66
		file = PsfFilenameStore.getSuggestedDefault();
108
		file = psfFilenameStore.getSuggestedDefault();
67
		fileCombo.setItems(PsfFilenameStore.getHistory());
109
		fileCombo.setItems(psfFilenameStore.getHistory());
68
		fileCombo.setText(file);
110
		fileCombo.setText(file);
69
		fileCombo.addListener(SWT.Modify, new Listener() {
111
		fileCombo.addListener(SWT.Modify, new Listener() {
70
			public void handleEvent(Event event) {
112
			public void handleEvent(Event event) {
71
				file = fileCombo.getText();				
113
				file = fileCombo.getText();				
72
				updateEnablement();
114
				updateFileEnablement();
73
			}
115
			}
74
		});
116
		});
75
117
76
		browseButton = new Button(inner, SWT.PUSH);
118
		browseButton = new Button(inner, SWT.PUSH);
77
		browseButton.setText(TeamUIMessages.ImportProjectSetMainPage_Browse_3); 
119
		browseButton.setText(TeamUIMessages.ImportProjectSetMainPage_Browse_3); 
120
		
121
		urlInputButton = new Button(inner, SWT.RADIO);
122
		urlInputButton.setText(TeamUIMessages.ImportProjectSetMainPage_Project_Set_Url);
123
		urlInputButton.addSelectionListener(new SelectionAdapter() {
124
			public void widgetSelected(SelectionEvent e) {
125
				setInputyType(InputType_URL);
126
			}
127
		});
128
		urlCombo = createDropDownCombo(inner);
129
		urlString = psfUrlStore.getSuggestedDefault();
130
		urlCombo.setItems(psfUrlStore.getHistory());
131
		urlCombo.setText(urlString);
132
		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
133
		gd.horizontalSpan=2;
134
		urlCombo.setLayoutData(gd);
135
		urlCombo.addListener(SWT.Modify, new Listener() {
136
			public void handleEvent(Event event) {
137
				urlString=urlCombo.getText();
138
				updateUrlEnablement();
139
			}
140
		});
141
				
142
		
78
		GridData data = new GridData();
143
		GridData data = new GridData();
79
		data.horizontalAlignment = GridData.FILL;
144
		data.horizontalAlignment = GridData.FILL;
80
		int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
145
		int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
Lines 115-124 Link Here
115
		});
180
		});
116
		
181
		
117
		setControl(composite);
182
		setControl(composite);
118
		updateEnablement();
183
		setInputyType(InputType_file);
119
		Dialog.applyDialogFont(parent);
184
		Dialog.applyDialogFont(parent);
120
		// future messages will be of type error
121
		messageType = ERROR;
122
	}
185
	}
123
186
124
	private void addWorkingSetSection(Composite composite) {
187
	private void addWorkingSetSection(Composite composite) {
Lines 129-137 Link Here
129
						"org.eclipse.jdt.ui.JavaWorkingSetPage" /* JavaWorkingSetUpdater.ID */}); //$NON-NLS-1$
192
						"org.eclipse.jdt.ui.JavaWorkingSetPage" /* JavaWorkingSetUpdater.ID */}); //$NON-NLS-1$
130
	}
193
	}
131
	
194
	
132
	private void updateEnablement() {
195
	private void updateUrlEnablement() {
196
		boolean complete = false;
197
		setMessage(null);
198
		setErrorMessage(null);
199
200
		if (urlString.length() == 0) {
201
			setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyURL, messageType);
202
			complete = false;
203
		} else {
204
205
			try {
206
				new URL(urlString);
207
				// the URL is correct, we can clear the error message
208
				complete = true;
209
			} catch (MalformedURLException e) {
210
				messageType = ERROR;
211
				setMessage(TeamUIMessages.ImportProjectSetDialog_malformed_url, messageType);
212
				complete = false;
213
			}
214
		}
215
216
		if (complete) {
217
			setErrorMessage(null);
218
			setDescription(TeamUIMessages.ImportProjectSetMainPage_description);
219
		}
220
221
		setPageComplete(complete);
222
	}
223
224
	private void updateFileEnablement() {
133
		boolean complete = false;
225
		boolean complete = false;
134
		setMessage(null);
226
		setMessage(null);
227
		setErrorMessage(null);
135
		
228
		
136
		if (file.length() == 0) {
229
		if (file.length() == 0) {
137
			setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyFile, messageType);
230
			setMessage(TeamUIMessages.ImportProjectSetMainPage_specifyFile, messageType);
Lines 141-154 Link Here
141
			// See if the file exists
234
			// See if the file exists
142
			File f = new File(file);
235
			File f = new File(file);
143
			if (!f.exists()) {
236
			if (!f.exists()) {
237
				messageType = ERROR;
144
				setMessage(TeamUIMessages.ImportProjectSetMainPage_The_specified_file_does_not_exist_4, messageType); 
238
				setMessage(TeamUIMessages.ImportProjectSetMainPage_The_specified_file_does_not_exist_4, messageType); 
145
				setPageComplete(false);
239
				setPageComplete(false);
146
				return;
240
				return;
147
			} else if (f.isDirectory()) {
241
			} else if (f.isDirectory()) {
242
				messageType = ERROR;
148
				setMessage(TeamUIMessages.ImportProjectSetMainPage_You_have_specified_a_folder_5, messageType); 
243
				setMessage(TeamUIMessages.ImportProjectSetMainPage_You_have_specified_a_folder_5, messageType); 
149
				setPageComplete(false);
244
				setPageComplete(false);
150
				return;
245
				return;
151
			} else if (!ProjectSetImporter.isValidProjectSetFile(file)) {
246
			} else if (!ProjectSetImporter.isValidProjectSetFile(file)) {
247
				messageType = ERROR;
152
				setMessage(TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, messageType);
248
				setMessage(TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, messageType);
153
				setPageComplete(false);
249
				setPageComplete(false);
154
				return;
250
				return;
Lines 167-172 Link Here
167
	public String getFileName() {
263
	public String getFileName() {
168
		return file;
264
		return file;
169
	}
265
	}
266
	
267
	public String getUrl(){
268
		return urlString;
269
	}
170
270
171
	public void setVisible(boolean visible) {
271
	public void setVisible(boolean visible) {
172
		super.setVisible(visible);
272
		super.setVisible(visible);
Lines 193-196 Link Here
193
	public boolean isRunInBackgroundOn() {
293
	public boolean isRunInBackgroundOn() {
194
		return runInBackground;
294
		return runInBackground;
195
	}
295
	}
296
	
297
	public int getInputType(){
298
		return inputType;
299
	}
300
	
301
	public String getURLContents() {
302
		final URL url;
303
		try {
304
			url = new URL(urlString);
305
			PsfUrlStore.getInstance().remember(urlString);
306
			final String[] result = new String[1];
307
			try {
308
				getContainer().run(true, true, new IRunnableWithProgress() {
309
					public void run(IProgressMonitor monitor)
310
							throws InvocationTargetException,
311
							InterruptedException {
312
						SubMonitor progress = SubMonitor
313
								.convert(
314
										monitor,
315
										TeamUIMessages.ImportProjectSetDialog_URLConnecting,
316
										100);
317
						try {
318
							URLConnection connection = url.openConnection();
319
							progress.worked(10);
320
							if (monitor.isCanceled())
321
								throw new OperationCanceledException();
322
							connection.setReadTimeout(60 * 1000);
323
							progress.setTaskName(TeamUIMessages.ImportProjectSetDialog_URLFetchingContent);
324
							String enc = connection.getContentEncoding();
325
							if (enc == null)
326
								enc = ResourcesPlugin.getEncoding();
327
							result[0] = readPsfFromURL(
328
									connection.getInputStream(), enc,
329
									connection.getContentLength(),
330
									progress.newChild(90));
331
						} catch (SocketTimeoutException e) { // timeout
332
							throw new InvocationTargetException(e);
333
						} catch (IOException e) { //cannot load file
334
							throw new InvocationTargetException(e);
335
						}finally{
336
							monitor.done();
337
						}
338
					}
339
				});
340
				
341
				if(ProjectSetImporter.isValidProjectSetString(result[0])){
342
					return result[0];	
343
				}else{
344
					messageType = ERROR;
345
					setMessage(TeamUIMessages.ImportProjectSetMainPage_projectSetFileInvalid, messageType);
346
					setPageComplete(false);
347
					return null;
348
				}
349
				
350
			} catch (OperationCanceledException e) { // ignore
351
			} catch (InvocationTargetException e) { // ignore
352
				messageType = ERROR;
353
				setMessage(TeamUIMessages.ImportProjectSetMainPage_The_given_URL_cannot_be_loaded, messageType);
354
				setPageComplete(false);
355
			} catch (InterruptedException e) { // ignore
356
			}
357
		} catch (MalformedURLException e) {
358
			// ignore as we tested it with modify listener on combo
359
		}
360
		return null;
361
	}
362
363
	private String readPsfFromURL(InputStream is, String encoding, int length,
364
			IProgressMonitor monitor) throws IOException {
365
		SubMonitor progress = SubMonitor.convert(monitor);
366
		progress.setWorkRemaining(length);
367
		if (is == null)
368
			return null;
369
		BufferedReader reader = null;
370
		try {
371
			StringBuffer buffer = new StringBuffer();
372
			char[] part = new char[2048];
373
			int read = 0;
374
			reader = new BufferedReader(new InputStreamReader(is, encoding));
375
			while ((read = reader.read(part)) != -1) {
376
				buffer.append(part, 0, read);
377
				progress.worked(2048);
378
				if (progress.isCanceled())
379
					throw new OperationCanceledException();
380
			}
381
382
			return buffer.toString();
383
		} finally {
384
			if (reader != null) {
385
				try {
386
					reader.close();
387
				} catch (IOException ex) {
388
					// silently ignored
389
				}
390
			}
391
		}
392
	}
393
	
196
}
394
}
(-)src/org/eclipse/team/internal/ui/wizards/ImportProjectSetOperation.java (-40 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
2
 * Copyright (c) 2007, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-63 Link Here
16
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.jface.operation.IRunnableContext;
18
import org.eclipse.jface.operation.IRunnableContext;
19
import org.eclipse.team.internal.ui.*;
19
import org.eclipse.team.internal.ui.TeamUIMessages;
20
import org.eclipse.team.internal.ui.TeamUIPlugin;
20
import org.eclipse.team.ui.TeamOperation;
21
import org.eclipse.team.ui.TeamOperation;
21
import org.eclipse.ui.IWorkingSet;
22
import org.eclipse.ui.IWorkingSet;
22
import org.eclipse.ui.IWorkingSetManager;
23
import org.eclipse.ui.IWorkingSetManager;
23
24
24
public class ImportProjectSetOperation extends TeamOperation {
25
public abstract class ImportProjectSetOperation extends TeamOperation {
25
26
26
	private String psfFile;
27
	protected ImportProjectSetOperation(IRunnableContext context) {
27
	private IWorkingSet[] workingSets;
28
29
	/**
30
	 * Operation for importing a Team Project Set file
31
	 * 
32
	 * @param context
33
	 *            a runnable context
34
	 * @param psfFile
35
	 *            a psf file name
36
	 * @param workingSets
37
	 *            an array of working sets where imported project should be
38
	 *            added. If a working set doesn't exist it will be created. The
39
	 *            array cannot be <code>null</code>, pass an empty array if you
40
	 *            don't want to add projects to any working set.
41
	 */
42
	public ImportProjectSetOperation(IRunnableContext context, String psfFile,
43
			IWorkingSet[] workingSets) {
44
		super(context);
28
		super(context);
45
		this.psfFile = psfFile;
46
		this.workingSets = workingSets;
47
	}
29
	}
48
30
49
	/*
31
	/*
50
	 * (non-Javadoc)
32
	 * (non-Javadoc)
51
	 * 
33
	 * 
52
	 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
34
	 * @see
35
	 * org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core
36
	 * .runtime.IProgressMonitor)
53
	 */
37
	 */
54
	public void run(IProgressMonitor monitor) throws InvocationTargetException,
38
	public abstract void run(IProgressMonitor monitor)
55
			InterruptedException {
39
			throws InvocationTargetException, InterruptedException;
56
		PsfFilenameStore.remember(psfFile);
57
		IProject[] newProjects = ProjectSetImporter.importProjectSet(psfFile,
58
				getShell(), monitor);
59
		createWorkingSet(workingSets, newProjects);
60
	}
61
40
62
	/*
41
	/*
63
	 * (non-Javadoc)
42
	 * (non-Javadoc)
Lines 76-100 Link Here
76
	protected String getJobName() {
55
	protected String getJobName() {
77
		return TeamUIMessages.ImportProjectSetMainPage_jobName;
56
		return TeamUIMessages.ImportProjectSetMainPage_jobName;
78
	}
57
	}
79
	
58
80
	private void createWorkingSet(IWorkingSet[] workingSets, IProject[] projects) {
59
	protected void createWorkingSet(IWorkingSet[] workingSets,
81
		IWorkingSetManager manager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager();
60
			IProject[] projects) {
61
		IWorkingSetManager manager = TeamUIPlugin.getPlugin().getWorkbench()
62
				.getWorkingSetManager();
82
		String workingSetName;
63
		String workingSetName;
83
		for (int i = 0; i < workingSets.length; i++) {
64
		for (int i = 0; i < workingSets.length; i++) {
84
			workingSetName = workingSets[i].getName();
65
			workingSetName = workingSets[i].getName();
85
			IWorkingSet oldSet = manager.getWorkingSet(workingSetName);
66
			IWorkingSet oldSet = manager.getWorkingSet(workingSetName);
86
			if (oldSet == null) {
67
			if (oldSet == null) {
87
				IWorkingSet newSet = manager.createWorkingSet(workingSetName, projects);
68
				IWorkingSet newSet = manager.createWorkingSet(workingSetName,
69
						projects);
88
				manager.addWorkingSet(newSet);
70
				manager.addWorkingSet(newSet);
89
			} else {
71
			} else {
90
				//don't overwrite the old elements
72
				// don't overwrite the old elements
91
				IAdaptable[] tempElements = oldSet.getElements();
73
				IAdaptable[] tempElements = oldSet.getElements();
92
				IAdaptable[] adaptedProjects = oldSet.adaptElements(projects);
74
				IAdaptable[] adaptedProjects = oldSet.adaptElements(projects);
93
				IAdaptable[] finalElementList = new IAdaptable[tempElements.length + adaptedProjects.length];
75
				IAdaptable[] finalElementList = new IAdaptable[tempElements.length
94
				System.arraycopy(tempElements, 0, finalElementList, 0, tempElements.length);
76
						+ adaptedProjects.length];
95
				System.arraycopy(adaptedProjects, 0,finalElementList, tempElements.length, adaptedProjects.length);
77
				System.arraycopy(tempElements, 0, finalElementList, 0,
78
						tempElements.length);
79
				System.arraycopy(adaptedProjects, 0, finalElementList,
80
						tempElements.length, adaptedProjects.length);
96
				oldSet.setElements(finalElementList);
81
				oldSet.setElements(finalElementList);
97
			}	
82
			}
98
		}
83
		}
99
	}
84
	}
100
}
85
}
(-)src/org/eclipse/team/internal/ui/wizards/ImportProjectSetStringOperation.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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;
14
15
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.jface.operation.IRunnableContext;
18
import org.eclipse.team.internal.ui.ProjectSetImporter;
19
import org.eclipse.ui.IWorkingSet;
20
21
public class ImportProjectSetStringOperation extends ImportProjectSetOperation {
22
23
	private String psfFileContents;
24
	private String urlString;
25
	private IWorkingSet[] workingSets;
26
27
28
	/**
29
	 * Operation for importing a Team Project Set stored in a String
30
	 * 
31
	 * @param context
32
	 *            a runnable context, <code>null</null> for running in background
33
	 * @param psfFileContents
34
	 *            the psf file content to load
35
	 * @param workingSets
36
	 *            an array of working sets where imported project should be
37
	 *            added. If a working set doesn't exist it will be created. The
38
	 *            array cannot be <code>null</code>, pass an empty array if you
39
	 *            don't want to add projects to any working set.
40
	 */
41
	public ImportProjectSetStringOperation(IRunnableContext context,
42
			String psfFileContents, IWorkingSet[] workingSets) {
43
		super(context);
44
		this.psfFileContents = psfFileContents;
45
		this.workingSets = workingSets;
46
	}
47
48
	/*
49
	 * (non-Javadoc)
50
	 * 
51
	 * @see
52
	 * org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core
53
	 * .runtime.IProgressMonitor)
54
	 */
55
	public void run(IProgressMonitor monitor) throws InvocationTargetException,
56
			InterruptedException {
57
		IProject[] newProjects = ProjectSetImporter.importProjectSetFromString(
58
				psfFileContents, urlString, getShell(), monitor);
59
		createWorkingSet(workingSets, newProjects);
60
	}
61
}
(-)src/org/eclipse/team/internal/ui/wizards/ProjectSetExportWizard.java (-1 / +1 lines)
Lines 59-65 Link Here
59
					if (path.getFileExtension() == null) {
59
					if (path.getFileExtension() == null) {
60
						filename = filename + ".psf"; //$NON-NLS-1$
60
						filename = filename + ".psf"; //$NON-NLS-1$
61
					}
61
					}
62
					PsfFilenameStore.remember(filename);
62
					PsfFilenameStore.getInstance().remember(filename);
63
					File file = new File(filename);
63
					File file = new File(filename);
64
					File parentFile = file.getParentFile();
64
					File parentFile = file.getParentFile();
65
					if (parentFile != null && !parentFile.exists()) {
65
					if (parentFile != null && !parentFile.exists()) {
(-)src/org/eclipse/team/internal/ui/wizards/ProjectSetImportWizard.java (-5 / +16 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 40-48 Link Here
40
	public boolean performFinish() {
40
	public boolean performFinish() {
41
		final boolean[] result = new boolean[] {false};
41
		final boolean[] result = new boolean[] {false};
42
		try {
42
		try {
43
			ImportProjectSetOperation op = new ImportProjectSetOperation(
43
			ImportProjectSetOperation op;
44
					mainPage.isRunInBackgroundOn() ? null : getContainer(),
44
			if (mainPage.getInputType() == ImportProjectSetMainPage.InputType_URL) {
45
					mainPage.getFileName(), mainPage.getWorkingSets());
45
				String psfContent = mainPage.getURLContents();
46
				if(psfContent==null){
47
					return false;
48
				}
49
				op = new ImportProjectSetStringOperation(
50
						mainPage.isRunInBackgroundOn() ? null : getContainer(),
51
						psfContent, mainPage.getWorkingSets());
52
			} else {
53
				op = new ImportFromFileProjectSetOperation(
54
						mainPage.isRunInBackgroundOn() ? null : getContainer(),
55
						mainPage.getFileName(), mainPage.getWorkingSets());
56
			}
46
			op.run();
57
			op.run();
47
			result[0] = true;
58
			result[0] = true;
48
		} catch (InterruptedException e) {
59
		} catch (InterruptedException e) {
Lines 71-76 Link Here
71
	public void init(IWorkbench workbench, IStructuredSelection selection) {
82
	public void init(IWorkbench workbench, IStructuredSelection selection) {
72
		// The code that finds "selection" is broken (it is always empty), so we
83
		// The code that finds "selection" is broken (it is always empty), so we
73
		// must dig for the selection in the workbench.
84
		// must dig for the selection in the workbench.
74
		PsfFilenameStore.setDefaultFromSelection(workbench);
85
		PsfFilenameStore.getInstance().setDefaultFromSelection(workbench);
75
	}
86
	}
76
}
87
}
(-)src/org/eclipse/team/internal/ui/wizards/PsfFilenameStore.java (-77 / +20 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-36 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.wizards;
11
package org.eclipse.team.internal.ui.wizards;
12
12
13
import java.util.Vector;
14
15
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IWorkspace;
14
import org.eclipse.core.resources.IWorkspace;
17
import org.eclipse.core.runtime.IAdaptable;
15
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.jface.dialogs.IDialogSettings;
20
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.team.internal.ui.TeamUIPlugin;
19
import org.eclipse.ui.*;
23
import org.eclipse.ui.IWorkbench;
20
24
import org.eclipse.ui.IWorkbenchPage;
21
public class PsfFilenameStore extends PsfStore {
25
import org.eclipse.ui.IWorkbenchWindow;
26
27
public class PsfFilenameStore {
28
	// Most recently used filename is first in the array.
29
	// Least recently used filename is at the end of the list.
30
	// When the list overflows, items drop off the end.
31
	private static final int HISTORY_LENGTH = 10;
32
22
33
	private static final String STORE_SECTION = "ImportPSFDialog"; //$NON-NLS-1$
34
	private static final String FILENAMES = "filenames"; //$NON-NLS-1$
23
	private static final String FILENAMES = "filenames"; //$NON-NLS-1$
35
	private static final String PREVIOUS = "previous"; //$NON-NLS-1$
24
	private static final String PREVIOUS = "previous"; //$NON-NLS-1$
36
25
Lines 38-50 Link Here
38
	// This is only a cache; it is not part of the history until the user has used it.
27
	// This is only a cache; it is not part of the history until the user has used it.
39
	private static String _selectedFilename = null;
28
	private static String _selectedFilename = null;
40
29
41
	private static IDialogSettings _section;
30
	private static PsfFilenameStore instance;
31
	
32
	public static PsfFilenameStore getInstance(){
33
		if(instance==null){
34
			instance = new PsfFilenameStore();
35
		}
36
		return instance;
37
	}
42
38
43
	private PsfFilenameStore() {
39
	private PsfFilenameStore() {
44
		// All-static
40
		// Signleton
45
	}
41
	}
46
42
47
	public static void setDefaultFromSelection(IWorkbench workbench) {
43
	public void setDefaultFromSelection(IWorkbench workbench) {
48
		// Scan the workbench for a selected PSF file
44
		// Scan the workbench for a selected PSF file
49
		IWorkbenchWindow wnd = workbench.getActiveWorkbenchWindow();
45
		IWorkbenchWindow wnd = workbench.getActiveWorkbenchWindow();
50
		IWorkbenchPage pg = wnd.getActivePage();
46
		IWorkbenchPage pg = wnd.getActivePage();
Lines 85-157 Link Here
85
		_selectedFilename = path.toOSString();
81
		_selectedFilename = path.toOSString();
86
	}
82
	}
87
83
88
	public static String getSuggestedDefault() {
84
	public String getSuggestedDefault() {
89
		if (_selectedFilename != null) {
85
		if (_selectedFilename != null) {
90
			return _selectedFilename;
86
			return _selectedFilename;
91
		}
87
		}
92
		return getPrevious();
88
		return getPrevious();
93
	}
89
	}
94
90
95
	private static String getPrevious() {
91
	protected String getPreviousTag() {
96
		IDialogSettings section = getSettingsSection();
92
		return PREVIOUS;
97
		String retval = section.get(PREVIOUS);
98
		if (retval == null) {
99
			retval = ""; //$NON-NLS-1$
100
		}
101
		return retval;
102
	}
93
	}
103
94
104
	public static String[] getHistory() {
95
	protected String getListTag() {
105
		IDialogSettings section = getSettingsSection();
96
		return FILENAMES;
106
		String[] arr = section.getArray(FILENAMES);
107
		if (arr == null) {
108
			arr = new String[0];
109
		}
110
		return arr;
111
	}
97
	}
112
98
113
	public static void remember(String filename) {
99
	
114
		Vector filenames = createVector(getHistory());
115
		if (filenames.contains(filename)) {
116
			// The item is in the list. Remove it and add it back at the
117
			// beginning. If it already was at the beginning this will be a
118
			// waste of time, but it's not even measurable so I don't care.
119
			filenames.remove(filename);
120
		}
121
		// Most recently used filename goes to the beginning of the list
122
		filenames.add(0, filename);
123
124
		// Forget any overflowing items
125
		while (filenames.size() > HISTORY_LENGTH) {
126
			filenames.remove(HISTORY_LENGTH);
127
		}
128
129
		// Make it an array
130
		String[] arr = (String[]) filenames.toArray(new String[filenames.size()]);
131
132
		IDialogSettings section = getSettingsSection();
133
		section.put(FILENAMES, arr);
134
		section.put(PREVIOUS, filename);
135
	}
136
137
	private static Vector createVector(Object[] arr) {
138
		Vector v = new Vector();
139
		for (int ix = 0; ix < arr.length; ++ix) {
140
			v.add(ix, arr[ix]);
141
		}
142
		return v;
143
	}
144
145
	private static IDialogSettings getSettingsSection() {
146
		if (_section != null)
147
			return _section;
148
149
		IDialogSettings settings = TeamUIPlugin.getPlugin().getDialogSettings();
150
		_section = settings.getSection(STORE_SECTION);
151
		if (_section != null)
152
			return _section;
153
154
		_section = settings.addNewSection(STORE_SECTION);
155
		return _section;
156
	}
157
}
100
}
(-)src/org/eclipse/team/internal/ui/wizards/PsfStore.java (+95 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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.util.Vector;
14
15
import org.eclipse.jface.dialogs.IDialogSettings;
16
import org.eclipse.team.internal.ui.TeamUIPlugin;
17
18
public abstract class PsfStore {
19
	// Most recently used filename is first in the array.
20
	// Least recently used filename is at the end of the list.
21
	// When the list overflows, items drop off the end.
22
	private static final int HISTORY_LENGTH = 10;
23
24
	private static final String STORE_SECTION = "ImportPSFDialog"; //$NON-NLS-1$
25
	
26
	private static IDialogSettings _section;
27
	
28
	protected abstract String getPreviousTag();
29
	protected abstract String getListTag();
30
	
31
	public abstract String getSuggestedDefault();
32
	
33
	protected String getPrevious() {
34
		IDialogSettings section = getSettingsSection();
35
		String retval = section.get(getPreviousTag());
36
		if (retval == null) {
37
			retval = ""; //$NON-NLS-1$
38
		}
39
		return retval;
40
	}
41
42
	public String[] getHistory() {
43
		IDialogSettings section = getSettingsSection();
44
		String[] arr = section.getArray(getListTag());
45
		if (arr == null) {
46
			arr = new String[0];
47
		}
48
		return arr;
49
	}
50
51
	public void remember(String filename) {
52
		Vector filenames = createVector(getHistory());
53
		if (filenames.contains(filename)) {
54
			// The item is in the list. Remove it and add it back at the
55
			// beginning. If it already was at the beginning this will be a
56
			// waste of time, but it's not even measurable so I don't care.
57
			filenames.remove(filename);
58
		}
59
		// Most recently used filename goes to the beginning of the list
60
		filenames.add(0, filename);
61
62
		// Forget any overflowing items
63
		while (filenames.size() > HISTORY_LENGTH) {
64
			filenames.remove(HISTORY_LENGTH);
65
		}
66
67
		// Make it an array
68
		String[] arr = (String[]) filenames.toArray(new String[filenames.size()]);
69
70
		IDialogSettings section = getSettingsSection();
71
		section.put(getListTag(), arr);
72
		section.put(getPreviousTag(), filename);
73
	}
74
75
	private Vector createVector(Object[] arr) {
76
		Vector v = new Vector();
77
		for (int ix = 0; ix < arr.length; ++ix) {
78
			v.add(ix, arr[ix]);
79
		}
80
		return v;
81
	}
82
83
	private IDialogSettings getSettingsSection() {
84
		if (_section != null)
85
			return _section;
86
87
		IDialogSettings settings = TeamUIPlugin.getPlugin().getDialogSettings();
88
		_section = settings.getSection(STORE_SECTION);
89
		if (_section != null)
90
			return _section;
91
92
		_section = settings.addNewSection(STORE_SECTION);
93
		return _section;
94
	}
95
}
(-)src/org/eclipse/team/internal/ui/wizards/PsfUrlStore.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
/**
14
 * Stores URL history for importing project sets window.
15
 * 
16
 */
17
public class PsfUrlStore extends PsfStore {
18
19
	private static final String URLS = "urls"; //$NON-NLS-1$
20
	private static final String PREVIOUS = "previous_url"; //$NON-NLS-1$
21
22
	private static PsfUrlStore instance;
23
24
	public static PsfUrlStore getInstance() {
25
		if (instance == null) {
26
			instance = new PsfUrlStore();
27
		}
28
		return instance;
29
	}
30
31
	private PsfUrlStore() {
32
		// signleton
33
	}
34
35
	protected String getPreviousTag() {
36
		return PREVIOUS;
37
	}
38
39
	protected String getListTag() {
40
		return URLS;
41
	}
42
43
	public String getSuggestedDefault() {
44
		return getPrevious();
45
	}
46
47
}

Return to bug 162608