View | Details | Raw Unified | Return to bug 303751 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+1 lines)
Lines 34-39 Link Here
34
 org.eclipse.ui.internal.views.tasklist;x-internal:=true,
34
 org.eclipse.ui.internal.views.tasklist;x-internal:=true,
35
 org.eclipse.ui.internal.wizards.datatransfer;x-internal:=true,
35
 org.eclipse.ui.internal.wizards.datatransfer;x-internal:=true,
36
 org.eclipse.ui.internal.wizards.newresource;x-internal:=true,
36
 org.eclipse.ui.internal.wizards.newresource;x-internal:=true,
37
 org.eclipse.ui.internal.wizards.refreshsnapshot;x-internal:=true,
37
 org.eclipse.ui.model,
38
 org.eclipse.ui.model,
38
 org.eclipse.ui.part,
39
 org.eclipse.ui.part,
39
 org.eclipse.ui.views.bookmarkexplorer,
40
 org.eclipse.ui.views.bookmarkexplorer,
(-)plugin.properties (-1 / +5 lines)
Lines 28-36 Link Here
28
ExportWizards.FileSystem = File System
28
ExportWizards.FileSystem = File System
29
ExportWizards.Preferences = Preferences
29
ExportWizards.Preferences = Preferences
30
ExportWizards.ZipFile = Archive File
30
ExportWizards.ZipFile = Archive File
31
ExportWizards.ProjectRefreshSnapshot = Project Refresh Snapshot
31
ExportWizards.FileSystemDescription = Export resources to the local file system.
32
ExportWizards.FileSystemDescription = Export resources to the local file system.
32
ExportWizards.PreferencesDescription = Export preferences to the local file system.
33
ExportWizards.PreferencesDescription = Export preferences to the local file system.
33
ExportWizards.ZipFileDescription = Export resources to an archive file on the local file system.
34
ExportWizards.ZipFileDescription = Export resources to an archive file on the local file system.
35
ExportWizards.ProjectRefreshSnapshotDescription = Export a refresh snapshot from selected projects for trusted import in other workspaces. 
34
ImportWizards.FileSystem = File System
36
ImportWizards.FileSystem = File System
35
ImportWizards.Preferences = Preferences
37
ImportWizards.Preferences = Preferences
36
ImportWizards.ZipFile = Archive File
38
ImportWizards.ZipFile = Archive File
Lines 38-44 Link Here
38
ImportWizards.FileSystemDescription = Import resources from the local file system into an existing project.
40
ImportWizards.FileSystemDescription = Import resources from the local file system into an existing project.
39
ImportWizards.PreferencesDescription = Import preferences from the local file system.
41
ImportWizards.PreferencesDescription = Import preferences from the local file system.
40
ImportWizards.ZipFileDescription = Import resources from an archive file into an existing project.
42
ImportWizards.ZipFileDescription = Import resources from an archive file into an existing project.
41
ImportWizards.ExternalProjectDescription = Create new projects from an archive file or directory. 
43
ImportWizards.ExternalProjectDescription = Create new projects from an archive file or directory.
44
ImportWizards.ProjectRefreshSnapshot = Project Refresh Snapshot
45
ImportWizards.ProjectRefreshSnapshotDescription = Import project with refresh snapshot 
42
NewWizards.Category.Examples = Examples
46
NewWizards.Category.Examples = Examples
43
NewWizards.Category.Basic = General
47
NewWizards.Category.Basic = General
44
NewWizards.project = Project
48
NewWizards.project = Project
(-)plugin.xml (+20 lines)
Lines 75-80 Link Here
75
               id="org.eclipse.ui.ide.archive">
75
               id="org.eclipse.ui.ide.archive">
76
         </keywordReference>
76
         </keywordReference>
77
      </wizard>
77
      </wizard>
78
	   <wizard
79
			 category="org.eclipse.ui.Basic"
80
			 class="org.eclipse.ui.internal.wizards.refreshsnapshot.ProjectRefreshSnapshotImportWizard"
81
			 icon="$nl$/icons/full/etool16/newprj_wiz.gif"
82
			 id="org.eclipse.ui.wizards.import.ProjectRefreshSnapshot"
83
			 name="%ImportWizards.ProjectRefreshSnapshot">
84
	   </wizard>
78
   </extension>
85
   </extension>
79
   <extension
86
   <extension
80
         point="org.eclipse.ui.exportWizards">
87
         point="org.eclipse.ui.exportWizards">
Lines 132-137 Link Here
132
               id="org.eclipse.ui.ide.project">
139
               id="org.eclipse.ui.ide.project">
133
         </keywordReference>
140
         </keywordReference>
134
      </wizard>
141
      </wizard>
142
	   <wizard
143
			 category="org.eclipse.ui.Basic"
144
			 class="org.eclipse.ui.internal.wizards.refreshsnapshot.ProjectRefreshSnapshotExportWizard"
145
			 icon="$nl$/icons/full/etool16/newprj_wiz.gif"
146
			 id="org.eclipse.ui.wizards.export.ProjectRefreshSnapshot"
147
			 name="%ExportWizards.ProjectRefreshSnapshot">
148
		   <selection
149
				 class="org.eclipse.core.resources.IProject">
150
		   </selection>
151
		   <description>
152
			   %ExportWizards.ProjectRefreshSnapshotDescription
153
		   </description>
154
	   </wizard>
135
   </extension>
155
   </extension>
136
   <extension
156
   <extension
137
         point="org.eclipse.ui.ide.markerImageProviders">
157
         point="org.eclipse.ui.ide.markerImageProviders">
(-)src/org/eclipse/ui/internal/wizards/refreshsnapshot/Messages.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Wind River Systems, Inc. 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
 *    Francis Lynch (Wind River) - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui.internal.wizards.refreshsnapshot;
13
14
import org.eclipse.osgi.util.NLS;
15
16
/**
17
 * Messages for refresh snapshot wizards
18
 *
19
 */
20
public class Messages extends NLS {
21
	private static final String BUNDLE_NAME = "org.eclipse.ui.internal.wizards.refreshsnapshot.messages"; //$NON-NLS-1$
22
23
	//
24
	public static String ProjectRefreshSnapshotExportWizard_exportTitle;
25
	public static String ProjectRefreshSnapshotExportWizardPage_title;
26
	public static String ProjectRefreshSnapshotExportWizardPage_description;
27
	public static String ProjectRefreshSnapshotExportWizardPage_selectProjects;
28
	public static String ProjectRefreshSnapshotExportWizardPage_selectAll;
29
	public static String ProjectRefreshSnapshotExportWizardPage_deselectAll;
30
	public static String ProjectRefreshSnapshotExportWizardPage_errorsOccurred;
31
	public static String ProjectRefreshSnapshotExportWizardPage_needProjectSelected;
32
	public static String ProjectRefreshSnapshotExportWizardPage_errorDialogTitle;
33
	public static String ProjectRefreshSnapshotExportWizardPage_selectSnapshot;
34
	public static String ProjectRefreshSnapshotExportWizardPage_snapshotBrowse;
35
	public static String ProjectRefreshSnapshotExportWizardPage_browseSnapshot;
36
	public static String ProjectRefreshSnapshotExportWizardPage_overwrite;
37
	public static String ProjectRefreshSnapshotExportWizardPage_question;
38
	
39
	public static String ProjectRefreshSnapshotImportWizard_importTitle;
40
	public static String ProjectRefreshSnapshotImportWizardPage_projectLabel;
41
	public static String ProjectRefreshSnapshotImportWizardPage_title;
42
	public static String ProjectRefreshSnapshotImportWizardPage_description;
43
	public static String ProjectRefreshSnapshotImportWizardPage_selectProject;
44
	public static String ProjectRefreshSnapshotImportWizardPage_selectSnapshot;
45
	public static String ProjectRefreshSnapshotImportWizardPage_sourceBrowse;
46
	public static String ProjectRefreshSnapshotImportWizardPage_sourceDirectory;
47
	public static String ProjectRefreshSnapshotImportWizardPage_snapshotBrowse;
48
	public static String ProjectRefreshSnapshotImportWizardPage_selectProjects;
49
	public static String ProjectRefreshSnapshotImportWizardPage_searching;
50
	public static String ProjectRefreshSnapshotImportWizardPage_processing;
51
	public static String ProjectRefreshSnapshotImportWizardPage_hiddenProjects;
52
	public static String ProjectRefreshSnapshotImportWizardPage_internalError;
53
	public static String ProjectRefreshSnapshotImportWizardPage_snapshotError;
54
	public static String ProjectRefreshSnapshotImportWizardPage_checking;
55
	public static String ProjectRefreshSnapshotImportWizardPage_browseSource;
56
	public static String ProjectRefreshSnapshotImportWizardPage_browseSnapshot;
57
	public static String ProjectRefreshSnapshotImportWizardPage_creationProblems;
58
	public static String ProjectRefreshSnapshotImportWizardPage_createProjectsTask;
59
	public static String ProjectRefreshSnapshotImportWizardPage_overwrite;
60
	public static String ProjectRefreshSnapshotImportWizardPage_overwriteInFolder;
61
	public static String ProjectRefreshSnapshotImportWizardPage_question;
62
	public static String ProjectRefreshSnapshotImportWizardPage_recurse;
63
64
	static {
65
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
66
	}
67
68
}
(-)src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizard.java (+63 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Wind River Systems, Inc. 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
 *    Markus Schorn - initial API and implementation
10
 *    Francis Lynch (Wind River) - adapted from CDT TeamSharedExportWizard
11
 *******************************************************************************/ 
12
13
package org.eclipse.ui.internal.wizards.refreshsnapshot;
14
15
import org.eclipse.jface.dialogs.IDialogSettings;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.jface.wizard.Wizard;
18
import org.eclipse.ui.IExportWizard;
19
import org.eclipse.ui.IWorkbench;
20
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
21
import org.eclipse.ui.internal.wizards.refreshsnapshot.Messages;
22
23
/**
24
 * Wizard to create refresh snapshots
25
 *
26
 */
27
public class ProjectRefreshSnapshotExportWizard extends Wizard implements IExportWizard {
28
	private static final String DIALOG_SETTINGS_SECTION = "ProjectRefreshSnapshotExportWizard"; //$NON-NLS-1$
29
	private ProjectRefreshSnapshotExportWizardPage fMainPage;
30
	private IStructuredSelection fSelection;
31
32
	/**
33
	 * 
34
	 */
35
	public ProjectRefreshSnapshotExportWizard() {
36
        IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault().getDialogSettings();
37
        IDialogSettings section = workbenchSettings.getSection(DIALOG_SETTINGS_SECTION);
38
        if (section == null) {
39
			section = workbenchSettings.addNewSection(DIALOG_SETTINGS_SECTION);
40
		}
41
        setDialogSettings(section);
42
	}
43
44
    //@Override
45
	public void addPages() {
46
        super.addPages();
47
        fMainPage = new ProjectRefreshSnapshotExportWizardPage(fSelection);
48
        addPage(fMainPage);
49
    }
50
51
	//@Override
52
	public boolean performFinish() {
53
        return fMainPage.finish();
54
    }
55
56
	public void init(IWorkbench workbench, IStructuredSelection selection) {
57
        fSelection= selection;
58
        setWindowTitle(Messages.ProjectRefreshSnapshotExportWizard_exportTitle);
59
        setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/exportzip_wiz.png")); //$NON-NLS-1$
60
        setNeedsProgressMonitor(true);
61
	}
62
63
}
(-)src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizardPage.java (+499 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2010 Wind River Systems, Inc. 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
 *    Markus Schorn - initial API and implementation
10
 *    Francis Lynch (Wind River) - adapted from CDT TeamSharedExportWizardPage
11
 *******************************************************************************/ 
12
package org.eclipse.ui.internal.wizards.refreshsnapshot;
13
14
import java.io.File;
15
import java.net.URI;
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.HashSet;
19
import java.util.Iterator;
20
import java.util.List;
21
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.MultiStatus;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.jface.dialogs.ErrorDialog;
28
import org.eclipse.jface.dialogs.IDialogConstants;
29
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.viewers.CheckStateChangedEvent;
31
import org.eclipse.jface.viewers.CheckboxTableViewer;
32
import org.eclipse.jface.viewers.ICheckStateListener;
33
import org.eclipse.jface.viewers.IStructuredContentProvider;
34
import org.eclipse.jface.viewers.IStructuredSelection;
35
import org.eclipse.jface.viewers.Viewer;
36
import org.eclipse.osgi.util.NLS;
37
import org.eclipse.swt.SWT;
38
import org.eclipse.swt.events.FocusAdapter;
39
import org.eclipse.swt.events.SelectionAdapter;
40
import org.eclipse.swt.events.SelectionEvent;
41
import org.eclipse.swt.events.TraverseEvent;
42
import org.eclipse.swt.events.TraverseListener;
43
import org.eclipse.swt.layout.GridData;
44
import org.eclipse.swt.layout.GridLayout;
45
import org.eclipse.swt.widgets.Button;
46
import org.eclipse.swt.widgets.Composite;
47
import org.eclipse.swt.widgets.DirectoryDialog;
48
import org.eclipse.swt.widgets.Event;
49
import org.eclipse.swt.widgets.Label;
50
import org.eclipse.swt.widgets.Shell;
51
import org.eclipse.swt.widgets.Table;
52
import org.eclipse.swt.widgets.Text;
53
import org.eclipse.ui.dialogs.WizardDataTransferPage;
54
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
55
import org.eclipse.ui.model.WorkbenchLabelProvider;
56
import org.eclipse.ui.internal.wizards.refreshsnapshot.Messages;
57
 
58
/**
59
 * The wizard page for export refresh snapshot
60
 *
61
 */
62
public class ProjectRefreshSnapshotExportWizardPage extends  WizardDataTransferPage {
63
64
    private IStructuredSelection fInitialSelection;
65
	private CheckboxTableViewer fProjectViewer;
66
	private Text directorySnapshotPathField;
67
	private Button browseSnapshotDirectoryButton;
68
	// Keep track of the directory that we browsed to last time
69
	// the wizard was invoked.
70
	private static String previouslyBrowsedSnapshotDirectory = ""; //$NON-NLS-1$
71
72
73
    /**
74
     *	Create an instance of this class
75
     */
76
    protected ProjectRefreshSnapshotExportWizardPage(String name, IStructuredSelection selection) {
77
        super(name);
78
        fInitialSelection= selection;
79
    }
80
81
    /**
82
     * Create an instance of this class.
83
     *
84
     * @param selection the selection
85
     */
86
    public ProjectRefreshSnapshotExportWizardPage(IStructuredSelection selection) {
87
        this("refreshSnapshotExportPage", selection); //$NON-NLS-1$
88
		setTitle(Messages.ProjectRefreshSnapshotExportWizardPage_title);
89
		setDescription(Messages.ProjectRefreshSnapshotExportWizardPage_description);
90
    }
91
92
    public void createControl(Composite parent) {
93
        initializeDialogUnits(parent);
94
95
        Composite composite = new Composite(parent, SWT.NULL);
96
        composite.setLayout(new GridLayout());
97
        composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
98
                | GridData.HORIZONTAL_ALIGN_FILL));
99
        composite.setFont(parent.getFont());
100
101
        createResourcesGroup(composite);
102
        createSnapshotArea(composite);
103
104
        restoreWidgetValues(); 
105
        if (fInitialSelection != null) {
106
			setupBasedOnInitialSelections();
107
		}
108
109
        updateWidgetEnablements();
110
        setPageComplete(determinePageCompletion());
111
        setErrorMessage(null);	// should not initially have error message
112
        
113
        setControl(composite);
114
    }
115
116
	private void checkForComplete() {
117
		if (fProjectViewer.getCheckedElements().length > 0) {
118
			String path = directorySnapshotPathField.getText().trim();
119
			if (path.length() > 0) {
120
				File dirpath = new File(path);
121
				if (dirpath.exists()) {
122
					setPageComplete(true);
123
					return;
124
				}
125
			}
126
		}
127
128
		setPageComplete(false);
129
	}
130
131
    /**
132
     * Creates the checkbox tree and list for selecting resources.
133
     *
134
     * @param parent the parent control
135
     */
136
    private final void createResourcesGroup(Composite parent) {
137
        Composite resourcesGroup = new Composite(parent, SWT.NONE);
138
        resourcesGroup.setLayout(new GridLayout());
139
        resourcesGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
140
        resourcesGroup.setFont(parent.getFont());
141
142
        new Label(resourcesGroup, SWT.NONE).setText(Messages.ProjectRefreshSnapshotExportWizardPage_selectProjects);
143
        Table table= new Table(resourcesGroup, SWT.CHECK | SWT.BORDER);
144
        table.setLayoutData(new GridData(GridData.FILL_BOTH));
145
		fProjectViewer= new CheckboxTableViewer(table);
146
		fProjectViewer.setContentProvider(new IStructuredContentProvider() {
147
			List fContents;	
148
149
			public Object[] getElements(Object input) {
150
				if (fContents != null && fContents == input)
151
					return fContents.toArray();
152
				return new Object[0];
153
			}
154
155
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
156
				if (newInput instanceof List) 
157
					fContents= (List)newInput;
158
				else
159
					fContents= null;
160
				// we use a fixed set.
161
			}
162
163
			public void dispose() {
164
			}
165
			
166
167
		} );
168
		fProjectViewer.setLabelProvider(new WorkbenchLabelProvider());        
169
        ICheckStateListener checkListener = new ICheckStateListener() {
170
            public void checkStateChanged(CheckStateChangedEvent event) {
171
                updateWidgetEnablements();
172
            }
173
        };
174
        fProjectViewer.addCheckStateListener(checkListener);
175
        	
176
177
        // top level group
178
        Composite buttonComposite = new Composite(resourcesGroup, SWT.NONE);
179
        buttonComposite.setFont(parent.getFont());
180
181
        GridLayout layout = new GridLayout(2, true);
182
        layout.marginHeight= layout.marginWidth= 0;
183
        buttonComposite.setLayout(layout);
184
        buttonComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
185
                | GridData.HORIZONTAL_ALIGN_FILL));
186
187
188
        Button selectButton = createButton(buttonComposite,
189
                IDialogConstants.SELECT_ALL_ID, Messages.ProjectRefreshSnapshotExportWizardPage_selectAll, false);
190
191
        SelectionAdapter listener = new SelectionAdapter() {
192
            //@Override
193
			public void widgetSelected(SelectionEvent e) {
194
                fProjectViewer.setAllChecked(true);
195
                updateWidgetEnablements();
196
            }
197
        };
198
        selectButton.addSelectionListener(listener);
199
200
        Button deselectButton = createButton(buttonComposite,
201
				IDialogConstants.DESELECT_ALL_ID, Messages.ProjectRefreshSnapshotExportWizardPage_deselectAll, false);
202
203
        listener = new SelectionAdapter() {
204
            //@Override
205
			public void widgetSelected(SelectionEvent e) {
206
            	fProjectViewer.setAllChecked(false);
207
                updateWidgetEnablements();
208
            }
209
        };
210
        deselectButton.addSelectionListener(listener);
211
212
        initProjects();
213
    }
214
215
    private Button createButton(Composite parent, int id, String label,
216
            boolean defaultButton) {
217
        Button button = new Button(parent, SWT.PUSH);
218
219
        GridData buttonData = new GridData(GridData.FILL_HORIZONTAL);
220
        button.setLayoutData(buttonData);
221
222
        button.setData(new Integer(id));
223
        button.setText(label);
224
        button.setFont(parent.getFont());
225
226
        if (defaultButton) {
227
            Shell shell = parent.getShell();
228
            if (shell != null) {
229
                shell.setDefaultButton(button);
230
            }
231
            button.setFocus();
232
        }
233
        button.setFont(parent.getFont());
234
        setButtonLayoutData(button);
235
        return button;
236
    }
237
238
    private void initProjects() {
239
        ArrayList input = new ArrayList();
240
        IProject[] projects;
241
		projects = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getProjects();
242
			for (int i = 0; i < projects.length; i++) {
243
				if (projects[i].isOpen()) {
244
					input.add(projects[i]);
245
				}
246
	        }
247
		fProjectViewer.setInput(input);
248
	}
249
250
    private void setupBasedOnInitialSelections() {
251
    	HashSet names= new HashSet();
252
        Iterator it = fInitialSelection.iterator();
253
        while (it.hasNext()) {
254
            IProject project = (IProject) it.next();
255
            names.add(project.getName());
256
        }
257
        
258
        Collection prjsc= (Collection) fProjectViewer.getInput();
259
        Object[] prjs= prjsc.toArray();
260
        for (int i = 0; i < prjs.length; i++) {
261
        	Object element = prjs[i];
262
			IProject prj = (IProject) element;
263
			if (names.contains(prj.getName())) {
264
	            fProjectViewer.setChecked(prj, true);
265
			}
266
		}
267
    } 	
268
    
269
	/**
270
	 * Create the area to specify the snapshot directory.
271
	 * 
272
	 * @param workArea
273
	 */
274
	private void createSnapshotArea(Composite workArea) {
275
		// project specification group
276
		Composite snapshotGroup = new Composite(workArea, SWT.NONE);
277
		GridLayout layout = new GridLayout();
278
		layout.numColumns = 3;
279
		layout.makeColumnsEqualWidth = false;
280
		layout.marginWidth = 0;
281
		snapshotGroup.setLayout(layout);
282
		snapshotGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
283
284
		Label title = new Label(snapshotGroup, SWT.NONE);
285
		title.setText(Messages.ProjectRefreshSnapshotExportWizardPage_selectSnapshot);
286
287
		// refresh snapshot directory location entry field
288
		this.directorySnapshotPathField = new Text(snapshotGroup, SWT.BORDER);
289
290
		this.directorySnapshotPathField.setLayoutData(new GridData(
291
				GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
292
293
		// browse button
294
		browseSnapshotDirectoryButton = new Button(snapshotGroup, SWT.PUSH);
295
		browseSnapshotDirectoryButton
296
				.setText(Messages.ProjectRefreshSnapshotExportWizardPage_snapshotBrowse);
297
		setButtonLayoutData(browseSnapshotDirectoryButton);
298
299
		browseSnapshotDirectoryButton
300
				.addSelectionListener(new SelectionAdapter() {
301
					/*
302
					 * (non-Javadoc)
303
					 * 
304
					 * @see org.eclipse.swt.events.SelectionAdapter#widgetS
305
					 * elected(org.eclipse.swt.events.SelectionEvent)
306
					 */
307
					public void widgetSelected(SelectionEvent e) {
308
						handleLocationSnapshotDirectoryButtonPressed();
309
					}
310
				});
311
312
		directorySnapshotPathField
313
				.addTraverseListener(new TraverseListener() {
314
315
					/*
316
					 * (non-Javadoc)
317
					 * 
318
					 * @see
319
					 * org.eclipse.swt.events.TraverseListener#keyTraversed(
320
					 * org.eclipse.swt.events.TraverseEvent)
321
					 */
322
					public void keyTraversed(TraverseEvent e) {
323
						if (e.detail == SWT.TRAVERSE_RETURN) {
324
							e.doit = false;
325
							checkForComplete();
326
						}
327
					}
328
329
				});
330
331
		directorySnapshotPathField.addFocusListener(new FocusAdapter() {
332
333
			/*
334
			 * (non-Javadoc)
335
			 * 
336
			 * @see
337
			 * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
338
			 * .events.FocusEvent)
339
			 */
340
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
341
				checkForComplete();
342
			}
343
344
		});
345
346
	}
347
	/**
348
	 * The browse button has been selected. Select the location.
349
	 */
350
	protected void handleLocationSnapshotDirectoryButtonPressed() {
351
352
		DirectoryDialog dialog = new DirectoryDialog(
353
				directorySnapshotPathField.getShell());
354
		dialog
355
				.setMessage(Messages.ProjectRefreshSnapshotExportWizardPage_browseSnapshot);
356
357
		String dirName = directorySnapshotPathField.getText().trim();
358
		if (dirName.length() == 0) {
359
			dirName = previouslyBrowsedSnapshotDirectory;
360
		}
361
362
		if (dirName.length() == 0) {
363
			dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot()
364
					.getLocation().toOSString());
365
		} else {
366
			File path = new File(dirName);
367
			if (path.exists()) {
368
				dialog.setFilterPath(new Path(dirName).toOSString());
369
			}
370
		}
371
372
		String selectedDirectory = dialog.open();
373
		if (selectedDirectory != null) {
374
			previouslyBrowsedSnapshotDirectory = selectedDirectory;
375
			directorySnapshotPathField
376
					.setText(previouslyBrowsedSnapshotDirectory);
377
			checkForComplete();
378
		}
379
380
	}
381
382
383
	/**
384
	 * @return Return true to indicate that the operation was a success
385
	 * 
386
	 */
387
	public boolean finish() {
388
        IProject[] projectsToSnapshot= getCheckedElements();
389
390
        // about to invoke the operation so save our state
391
        saveWidgetValues();
392
        
393
        return executeSnapshotOperation(projectsToSnapshot);
394
    }
395
396
	private IProject[] getCheckedElements() {
397
		Object[] obj= fProjectViewer.getCheckedElements();
398
		IProject[] prjs= new IProject[obj.length];
399
		System.arraycopy(obj, 0, prjs, 0, obj.length);
400
		return prjs;
401
	}
402
403
    private boolean executeSnapshotOperation(final IProject[] projects) {
404
    	final MultiStatus status= new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, 
405
    			0, Messages.ProjectRefreshSnapshotExportWizardPage_errorsOccurred, null);
406
407
		final IPath snapshotPath = new Path(directorySnapshotPathField
408
				.getText().trim());
409
		for (int i = 0; i < projects.length; i++) {
410
			IProject project = projects[i];
411
			try {
412
				String projectName = project.getName();
413
				boolean cancelled = false;
414
				IPath zipPath = snapshotPath.append(projectName + "-index.zip");	//$NON-NLS-1$
415
				if (zipPath.toFile().exists()) {
416
		            String[] buttons = new String[] { IDialogConstants.YES_LABEL,
417
		                    IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
418
		            String question = NLS.bind(
419
		            		Messages.ProjectRefreshSnapshotExportWizardPage_overwrite, zipPath
420
									.toString());
421
					MessageDialog d = new MessageDialog(getShell(),
422
							Messages.ProjectRefreshSnapshotExportWizardPage_question,
423
		                    null, question, MessageDialog.QUESTION, buttons, 0) {
424
						protected int getShellStyle() {
425
							return super.getShellStyle() | SWT.SHEET;
426
						}
427
					};
428
		            int overwrite = d.open();
429
		            switch (overwrite) {
430
		            case 0: // Yes
431
		                break;
432
		            case 1: // No
433
		                continue;
434
		            case 2: // Cancel
435
		            default:
436
		            	cancelled = true;
437
		                break;
438
		            }
439
				}
440
				if (cancelled) break;
441
				URI snapshotLocation = org.eclipse.core.filesystem.URIUtil.toURI(zipPath);
442
				project.saveSnapshot(IProject.SNAPSHOT_TREE, snapshotLocation, null);
443
			}
444
			catch (CoreException e) {
445
				status.merge(e.getStatus());
446
			}
447
		}
448
        if (!status.isOK()) {
449
        	IDEWorkbenchPlugin.log("",status); //$NON-NLS-1$
450
            ErrorDialog.openError(getContainer().getShell(),
451
                    getErrorDialogTitle(),
452
                    null, // no special message
453
                    status);
454
            return false;
455
        }
456
457
        return true;
458
    }
459
460
 
461
    //@Override
462
	protected boolean validateSourceGroup() {
463
    	// there must be some resources selected for Export
464
    	boolean isValid = true;
465
        Object[] projectsToExport = getCheckedElements();
466
    	if (projectsToExport.length == 0){
467
			setErrorMessage(Messages.ProjectRefreshSnapshotExportWizardPage_needProjectSelected);
468
            isValid =  false;
469
    	} else {
470
			setErrorMessage(null);
471
		}
472
		return super.validateSourceGroup() && isValid;
473
	}
474
475
    //@Override
476
	protected void updateWidgetEnablements() {
477
        boolean pageComplete = determinePageCompletion();
478
        setPageComplete(pageComplete);
479
        if (pageComplete) {
480
			setMessage(null);
481
		}
482
        super.updateWidgetEnablements();
483
    }
484
    
485
486
	public void handleEvent(Event event) {
487
		updateWidgetEnablements();
488
	}
489
	
490
    //@Override
491
	protected String getErrorDialogTitle() {
492
		return Messages.ProjectRefreshSnapshotExportWizardPage_errorDialogTitle;
493
    }
494
495
	//@Override
496
	protected boolean allowNewContainerName() {
497
		return false;
498
	}
499
}
(-)src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizard.java (+87 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 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
 *     Francis Lynch (Wind River) - adapted from standard project import
11
 *******************************************************************************/
12
package org.eclipse.ui.internal.wizards.refreshsnapshot;
13
14
import org.eclipse.jface.dialogs.IDialogSettings;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.jface.wizard.Wizard;
17
import org.eclipse.ui.IImportWizard;
18
import org.eclipse.ui.IWorkbench;
19
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
20
21
/**
22
 * Wizard for importing projects with a refresh snapshot into the Eclipse
23
 * workspace. Allows specification of the URI for the project refresh snapshot.
24
 * Currently, that URI is assumed to contain a file named <projectName>-index.zip
25
 * that was created by the export refresh snapshot wizard.
26
 * <p>
27
 * This class may be instantiated and used without further configuration; this
28
 * class is not intended to be subclassed.
29
 * </p>
30
 */
31
32
public class ProjectRefreshSnapshotImportWizard extends Wizard implements
33
		IImportWizard {
34
	private static final String EXTERNAL_PROJECT_SECTION = "ProjectRefreshSnapshotImportWizard";//$NON-NLS-1$
35
	private ProjectRefreshSnapshotImportWizardPage mainPage;
36
37
	/**
38
	 * Constructor for ProjectRefreshSnapshotImportWizard.
39
	 */
40
	public ProjectRefreshSnapshotImportWizard() {
41
		super();
42
		setNeedsProgressMonitor(true);
43
		IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault()
44
				.getDialogSettings();
45
46
		IDialogSettings wizardSettings = workbenchSettings
47
				.getSection(EXTERNAL_PROJECT_SECTION);
48
		if (wizardSettings == null) {
49
			wizardSettings = workbenchSettings
50
					.addNewSection(EXTERNAL_PROJECT_SECTION);
51
		}
52
		setDialogSettings(wizardSettings);
53
	}
54
55
	/*
56
	 * (non-Javadoc) Method declared on IWizard.
57
	 */
58
	public void addPages() {
59
		super.addPages();
60
		mainPage = new ProjectRefreshSnapshotImportWizardPage();
61
		addPage(mainPage);
62
	}
63
64
	/*
65
	 * (non-Javadoc) Method declared on IWorkbenchWizard.
66
	 */
67
	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
68
		setWindowTitle(Messages.ProjectRefreshSnapshotImportWizard_importTitle);
69
		setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/importproj_wiz.png")); //$NON-NLS-1$
70
	}
71
72
	/*
73
	 * (non-Javadoc) Method declared on IWizard.
74
	 */
75
	public boolean performCancel() {
76
		mainPage.performCancel();
77
		return true;
78
	}
79
80
	/*
81
	 * (non-Javadoc) Method declared on IWizard.
82
	 */
83
	public boolean performFinish() {
84
		return mainPage.createProjects();
85
	}
86
87
}
(-)src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizardPage.java (+1184 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 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
 *     Red Hat, Inc - extensive changes to allow importing of Archive Files
11
 *     Philippe Ombredanne (pombredanne@nexb.com)
12
 *     		- Bug 101180 [Import/Export] Import Existing Project into Workspace default widget is back button , should be text field
13
 *     Martin Oberhuber (martin.oberhuber@windriver.com)
14
 *     		- Bug 187318[Wizards] "Import Existing Project" loops forever with cyclic symbolic links
15
 *     Remy Chi Jian Suen  (remy.suen@gmail.com)
16
 *     		- Bug 210568 [Import/Export] [Import/Export] - Refresh button does not update list of projects
17
 *     Francis Lynch (Wind River) - adapted from standard project import wizard
18
 *******************************************************************************/
19
package org.eclipse.ui.internal.wizards.refreshsnapshot;
20
21
import java.io.*;
22
import java.lang.reflect.InvocationTargetException;
23
import java.net.URI;
24
import java.util.ArrayList;
25
import java.util.Collection;
26
import java.util.HashSet;
27
import java.util.Iterator;
28
import java.util.List;
29
import java.util.Set;
30
31
import org.eclipse.core.resources.IProject;
32
import org.eclipse.core.resources.IProjectDescription;
33
import org.eclipse.core.resources.IResource;
34
import org.eclipse.core.resources.IWorkspace;
35
import org.eclipse.core.resources.ResourcesPlugin;
36
import org.eclipse.core.runtime.CoreException;
37
import org.eclipse.core.runtime.IPath;
38
import org.eclipse.core.runtime.IProgressMonitor;
39
import org.eclipse.core.runtime.IStatus;
40
import org.eclipse.core.runtime.OperationCanceledException;
41
import org.eclipse.core.runtime.Path;
42
import org.eclipse.core.runtime.Platform;
43
import org.eclipse.core.runtime.Status;
44
import org.eclipse.core.runtime.SubProgressMonitor;
45
import org.eclipse.jface.dialogs.Dialog;
46
import org.eclipse.jface.dialogs.ErrorDialog;
47
import org.eclipse.jface.dialogs.IDialogConstants;
48
import org.eclipse.jface.dialogs.IDialogSettings;
49
import org.eclipse.jface.dialogs.MessageDialog;
50
import org.eclipse.jface.operation.IRunnableWithProgress;
51
import org.eclipse.jface.viewers.CheckStateChangedEvent;
52
import org.eclipse.jface.viewers.CheckboxTreeViewer;
53
import org.eclipse.jface.viewers.ICheckStateListener;
54
import org.eclipse.jface.viewers.ITreeContentProvider;
55
import org.eclipse.jface.viewers.LabelProvider;
56
import org.eclipse.jface.viewers.Viewer;
57
import org.eclipse.jface.viewers.ViewerComparator;
58
import org.eclipse.jface.wizard.WizardPage;
59
import org.eclipse.osgi.util.NLS;
60
import org.eclipse.swt.SWT;
61
import org.eclipse.swt.events.FocusAdapter;
62
import org.eclipse.swt.events.SelectionAdapter;
63
import org.eclipse.swt.events.SelectionEvent;
64
import org.eclipse.swt.events.TraverseEvent;
65
import org.eclipse.swt.events.TraverseListener;
66
import org.eclipse.swt.layout.GridData;
67
import org.eclipse.swt.layout.GridLayout;
68
import org.eclipse.swt.widgets.Button;
69
import org.eclipse.swt.widgets.Composite;
70
import org.eclipse.swt.widgets.DirectoryDialog;
71
import org.eclipse.swt.widgets.Label;
72
import org.eclipse.swt.widgets.Text;
73
import org.eclipse.ui.actions.WorkspaceModifyOperation;
74
import org.eclipse.ui.dialogs.IOverwriteQuery;
75
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
76
import org.eclipse.ui.internal.ide.StatusUtil;
77
import org.eclipse.ui.statushandlers.StatusManager;
78
79
/**
80
 * The ProjectRefreshSnapshotImportWizardPage is the page that allows the user to import
81
 * projects from a particular location with refresh snapshots.
82
 */
83
public class ProjectRefreshSnapshotImportWizardPage extends WizardPage implements
84
		IOverwriteQuery {
85
86
	/**
87
	 * The name of the folder containing metadata information for the workspace.
88
	 */
89
	public static final String METADATA_FOLDER = ".metadata"; //$NON-NLS-1$
90
91
	/**
92
	 * Class declared public only for test suite.
93
	 * 
94
	 */
95
	public class ProjectRecord {
96
		File projectSystemFile;
97
98
		String projectName;
99
100
		Object parent;
101
102
		int level;
103
104
		IProjectDescription description;
105
106
		/**
107
		 * Create a record for a project based on the info in the file.
108
		 * 
109
		 * @param file
110
		 */
111
		ProjectRecord(File file) {
112
			projectSystemFile = file;
113
			setProjectName();
114
		}
115
116
		/**
117
		 * Set the name of the project based on the projectFile.
118
		 */
119
		private void setProjectName() {
120
			try {
121
122
				// If we don't have the project name try again
123
				if (projectName == null) {
124
					IPath path = new Path(projectSystemFile.getPath());
125
					// if the file is in the default location, use the directory
126
					// name as the project name
127
					if (isDefaultLocation(path)) {
128
						projectName = path.segment(path.segmentCount() - 2);
129
						description = IDEWorkbenchPlugin.getPluginWorkspace()
130
								.newProjectDescription(projectName);
131
					} else {
132
						description = IDEWorkbenchPlugin.getPluginWorkspace()
133
								.loadProjectDescription(path);
134
						projectName = description.getName();
135
					}
136
137
				}
138
			} catch (CoreException e) {
139
				// no good couldn't get the name
140
			}
141
		}
142
143
		/**
144
		 * Returns whether the given project description file path is in the
145
		 * default location for a project
146
		 * 
147
		 * @param path
148
		 *            The path to examine
149
		 * @return Whether the given path is the default location for a project
150
		 */
151
		private boolean isDefaultLocation(IPath path) {
152
			// The project description file must at least be within the project,
153
			// which is within the workspace location
154
			if (path.segmentCount() < 2)
155
				return false;
156
			return path.removeLastSegments(2).toFile().equals(
157
					Platform.getLocation().toFile());
158
		}
159
160
		/**
161
		 * Get the name of the project
162
		 * 
163
		 * @return String
164
		 */
165
		public String getProjectName() {
166
			return projectName;
167
		}
168
169
		/**
170
		 * Gets the label to be used when rendering this project record in the
171
		 * UI.
172
		 * 
173
		 * @return String the label
174
		 * @since 3.4
175
		 */
176
		public String getProjectLabel() {
177
			if (description == null)
178
				return projectName;
179
180
			String path = projectSystemFile.getParent();
181
182
			return NLS
183
					.bind(
184
							Messages.ProjectRefreshSnapshotImportWizardPage_projectLabel,
185
							projectName, path);
186
		}
187
	}
188
189
	// dialog store id constants
190
	private final static String STORE_RECURSE_SUBFOLDERS = "WizardProjectRefreshSnapshotImportPage.STORE__RECURSE_SUBFOLDERS_ID"; //$NON-NLS-1$
191
	
192
	private Text directoryPathField;
193
194
	private Text directorySnapshotPathField;
195
196
	private CheckboxTreeViewer projectsList;
197
	
198
	private Button recurseIntoSubFoldersCheckbox;
199
	
200
	private boolean recurseIntoSubFolders = false;
201
202
	private ProjectRecord[] selectedProjects = new ProjectRecord[0];
203
204
	// Keep track of the directory that we browsed to last time
205
	// the wizard was invoked.
206
	private static String previouslyBrowsedDirectory = ""; //$NON-NLS-1$
207
208
	private static String previouslyBrowsedSnapshotDirectory = ""; //$NON-NLS-1$
209
210
	private Button browseDirectoriesButton;
211
212
	private Button browseSnapshotDirectoryButton;
213
214
	private IProject[] wsProjects;
215
216
	// The last selected path to minimize searches
217
	private String lastPath;
218
219
	// The last time that the file or folder at the selected path was modified
220
	// to minimize searches
221
	private long lastModified;
222
223
	// The last selected snapshot directory path
224
	private String lastSnapshotPath;
225
	
226
	// The last time the snapshot folder was modified
227
	private long lastSnapshotModified;
228
	/**
229
	 * Creates a new project creation wizard page.
230
	 * 
231
	 */
232
	public ProjectRefreshSnapshotImportWizardPage() {
233
		this("refreshSnapshotImportPage"); //$NON-NLS-1$
234
	}
235
236
	/**
237
	 * Create a new instance of the receiver.
238
	 * 
239
	 * @param pageName
240
	 */
241
	public ProjectRefreshSnapshotImportWizardPage(String pageName) {
242
		super(pageName);
243
		setPageComplete(false);
244
		setTitle(Messages.ProjectRefreshSnapshotImportWizardPage_title);
245
		setDescription(Messages.ProjectRefreshSnapshotImportWizardPage_description);
246
	}
247
248
	/*
249
	 * (non-Javadoc)
250
	 * 
251
	 * @see
252
	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
253
	 * .Composite)
254
	 */
255
	public void createControl(Composite parent) {
256
257
		initializeDialogUnits(parent);
258
259
		Composite workArea = new Composite(parent, SWT.NONE);
260
		setControl(workArea);
261
262
		workArea.setLayout(new GridLayout());
263
		workArea.setLayoutData(new GridData(GridData.FILL_BOTH
264
				| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
265
266
		createProjectsRoot(workArea);
267
		createProjectsList(workArea);
268
		createOptionsArea(workArea);
269
		createSnapshotArea(workArea);
270
		restoreWidgetValues();
271
		Dialog.applyDialogFont(workArea);
272
273
	}
274
275
	private void checkForComplete() {
276
		if (projectsList.getCheckedElements().length > 0) {
277
			String path = directorySnapshotPathField.getText().trim();
278
			if (path.length() > 0) {
279
				File dirpath = new File(path);
280
				if (dirpath.exists()) {
281
					setPageComplete(true);
282
					return;
283
				}
284
			}
285
		}
286
287
		setPageComplete(false);
288
	}
289
290
	/**
291
	 * Create the checkbox list for the found projects.
292
	 * 
293
	 * @param workArea
294
	 */
295
	private void createProjectsList(Composite workArea) {
296
297
		Label title = new Label(workArea, SWT.NONE);
298
		title.setText(Messages.ProjectRefreshSnapshotImportWizardPage_selectProject);
299
300
		Composite listComposite = new Composite(workArea, SWT.NONE);
301
		GridLayout layout = new GridLayout();
302
		layout.numColumns = 2;
303
		layout.marginWidth = 0;
304
		layout.makeColumnsEqualWidth = false;
305
		listComposite.setLayout(layout);
306
307
		listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
308
				| GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
309
310
		projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER);
311
		GridData listData = new GridData(GridData.GRAB_HORIZONTAL
312
				| GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
313
		listData.heightHint = 100;
314
		projectsList.getControl().setLayoutData(listData);
315
316
		projectsList.setContentProvider(new ITreeContentProvider() {
317
318
			/*
319
			 * (non-Javadoc)
320
			 * 
321
			 * @see
322
			 * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java
323
			 * .lang.Object)
324
			 */
325
			public Object[] getChildren(Object parentElement) {
326
				return null;
327
			}
328
329
			/*
330
			 * (non-Javadoc)
331
			 * 
332
			 * @see
333
			 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements
334
			 * (java.lang.Object)
335
			 */
336
			public Object[] getElements(Object inputElement) {
337
				return getValidProjects();
338
			}
339
340
			/*
341
			 * (non-Javadoc)
342
			 * 
343
			 * @see
344
			 * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java
345
			 * .lang.Object)
346
			 */
347
			public boolean hasChildren(Object element) {
348
				return false;
349
			}
350
351
			/*
352
			 * (non-Javadoc)
353
			 * 
354
			 * @see
355
			 * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java
356
			 * .lang.Object)
357
			 */
358
			public Object getParent(Object element) {
359
				return null;
360
			}
361
362
			/*
363
			 * (non-Javadoc)
364
			 * 
365
			 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
366
			 */
367
			public void dispose() {
368
369
			}
370
371
			/*
372
			 * (non-Javadoc)
373
			 * 
374
			 * @see
375
			 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
376
			 * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
377
			 */
378
			public void inputChanged(Viewer viewer, Object oldInput,
379
					Object newInput) {
380
			}
381
382
		});
383
384
		projectsList.setLabelProvider(new LabelProvider() {
385
			/*
386
			 * (non-Javadoc)
387
			 * 
388
			 * @see
389
			 * org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
390
			 */
391
			public String getText(Object element) {
392
				return ((ProjectRecord) element).getProjectLabel();
393
			}
394
		});
395
396
		projectsList.addCheckStateListener(new ICheckStateListener() {
397
			/*
398
			 * (non-Javadoc)
399
			 * 
400
			 * @see
401
			 * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
402
			 * (org.eclipse.jface.viewers.CheckStateChangedEvent)
403
			 */
404
			public void checkStateChanged(CheckStateChangedEvent event) {
405
				checkForComplete();
406
			}
407
		});
408
409
		projectsList.setInput(this);
410
		projectsList.setComparator(new ViewerComparator());
411
	}
412
413
	/**
414
	 * Create the area to specify the snapshot directory.
415
	 * 
416
	 * @param workArea
417
	 */
418
	private void createSnapshotArea(Composite workArea) {
419
420
		// project specification group
421
		Composite projectGroup = new Composite(workArea, SWT.NONE);
422
		GridLayout layout = new GridLayout();
423
		layout.numColumns = 3;
424
		layout.makeColumnsEqualWidth = false;
425
		layout.marginWidth = 0;
426
		projectGroup.setLayout(layout);
427
		projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
428
429
		Label title = new Label(projectGroup, SWT.NONE);
430
		title.setText(Messages.ProjectRefreshSnapshotImportWizardPage_selectSnapshot);
431
432
		// refresh snapshot directory location entry field
433
		this.directorySnapshotPathField = new Text(projectGroup, SWT.BORDER);
434
435
		this.directorySnapshotPathField.setLayoutData(new GridData(
436
				GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
437
438
		// browse button
439
		browseSnapshotDirectoryButton = new Button(projectGroup, SWT.PUSH);
440
		browseSnapshotDirectoryButton
441
				.setText(Messages.ProjectRefreshSnapshotImportWizardPage_snapshotBrowse);
442
		setButtonLayoutData(browseSnapshotDirectoryButton);
443
444
		browseSnapshotDirectoryButton
445
				.addSelectionListener(new SelectionAdapter() {
446
					/*
447
					 * (non-Javadoc)
448
					 * 
449
					 * @see org.eclipse.swt.events.SelectionAdapter#widgetS
450
					 * elected(org.eclipse.swt.events.SelectionEvent)
451
					 */
452
					public void widgetSelected(SelectionEvent e) {
453
						handleLocationSnapshotDirectoryButtonPressed();
454
					}
455
				});
456
457
		directorySnapshotPathField
458
				.addTraverseListener(new TraverseListener() {
459
460
					/*
461
					 * (non-Javadoc)
462
					 * 
463
					 * @see
464
					 * org.eclipse.swt.events.TraverseListener#keyTraversed(
465
					 * org.eclipse.swt.events.TraverseEvent)
466
					 */
467
					public void keyTraversed(TraverseEvent e) {
468
						if (e.detail == SWT.TRAVERSE_RETURN) {
469
							e.doit = false;
470
							updateSnapshotPath(directorySnapshotPathField.getText().trim());
471
							checkForComplete();
472
						}
473
					}
474
475
				});
476
477
		directorySnapshotPathField.addFocusListener(new FocusAdapter() {
478
479
			/*
480
			 * (non-Javadoc)
481
			 * 
482
			 * @see
483
			 * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
484
			 * .events.FocusEvent)
485
			 */
486
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
487
				updateSnapshotPath(directorySnapshotPathField.getText().trim());
488
			}
489
490
		});
491
492
	}
493
494
	/**
495
	 * Create the area with the extra options.
496
	 * 
497
	 * @param workArea
498
	 */
499
	private void createOptionsArea(Composite workArea) {
500
		Composite optionsGroup = new Composite(workArea, SWT.NONE);
501
		optionsGroup.setLayout(new GridLayout());
502
		optionsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
503
504
		recurseIntoSubFoldersCheckbox = new Button(optionsGroup, SWT.CHECK);
505
		recurseIntoSubFoldersCheckbox.setText(
506
				Messages.ProjectRefreshSnapshotImportWizardPage_recurse);
507
		recurseIntoSubFoldersCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
508
		recurseIntoSubFoldersCheckbox.addSelectionListener(new SelectionAdapter() {
509
			public void widgetSelected(SelectionEvent e) {
510
				recurseIntoSubFolders = recurseIntoSubFoldersCheckbox.getSelection();
511
				lastPath = null;	// force update
512
				updateProjectsList(directoryPathField.getText().trim());
513
			}
514
		});
515
	}
516
	/**
517
	 * Create the area where you select the root directory for the projects.
518
	 * 
519
	 * @param workArea
520
	 *            Composite
521
	 */
522
	private void createProjectsRoot(Composite workArea) {
523
524
		// project specification group
525
		Composite projectGroup = new Composite(workArea, SWT.NONE);
526
		GridLayout layout = new GridLayout();
527
		layout.numColumns = 3;
528
		layout.makeColumnsEqualWidth = false;
529
		layout.marginWidth = 0;
530
		projectGroup.setLayout(layout);
531
		projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
532
533
		Label dirTitle = new Label(projectGroup, SWT.NONE);
534
		dirTitle.setText(Messages.ProjectRefreshSnapshotImportWizardPage_sourceDirectory);
535
536
		// project location entry field
537
		this.directoryPathField = new Text(projectGroup, SWT.BORDER);
538
539
		this.directoryPathField.setLayoutData(new GridData(
540
				GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
541
542
		// browse button
543
		browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);
544
		browseDirectoriesButton
545
				.setText(Messages.ProjectRefreshSnapshotImportWizardPage_sourceBrowse);
546
		setButtonLayoutData(browseDirectoriesButton);
547
548
		browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {
549
			/*
550
			 * (non-Javadoc)
551
			 * 
552
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetS
553
			 * elected(org.eclipse.swt.events.SelectionEvent)
554
			 */
555
			public void widgetSelected(SelectionEvent e) {
556
				handleLocationDirectoryButtonPressed();
557
			}
558
559
		});
560
561
		directoryPathField.addTraverseListener(new TraverseListener() {
562
563
			/*
564
			 * (non-Javadoc)
565
			 * 
566
			 * @see
567
			 * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse
568
			 * .swt.events.TraverseEvent)
569
			 */
570
			public void keyTraversed(TraverseEvent e) {
571
				if (e.detail == SWT.TRAVERSE_RETURN) {
572
					e.doit = false;
573
					updateProjectsList(directoryPathField.getText().trim());
574
				}
575
			}
576
577
		});
578
579
		directoryPathField.addFocusListener(new FocusAdapter() {
580
581
			/*
582
			 * (non-Javadoc)
583
			 * 
584
			 * @see
585
			 * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
586
			 * .events.FocusEvent)
587
			 */
588
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
589
				updateProjectsList(directoryPathField.getText().trim());
590
			}
591
592
		});
593
	}
594
595
	/*
596
	 * (non-Javadoc) Method declared on IDialogPage. Set the focus on path
597
	 * fields when page becomes visible.
598
	 */
599
	public void setVisible(boolean visible) {
600
		super.setVisible(visible);
601
		if (visible) {
602
			this.directoryPathField.setFocus();
603
		}
604
	}
605
606
	/**
607
	 * Update the list of projects based on path. Method declared public only
608
	 * for test suite.
609
	 * 
610
	 * @param path
611
	 */
612
	public void updateProjectsList(final String path) {
613
		// on an empty path empty selectedProjects
614
		if (path == null || path.length() == 0) {
615
			setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_selectProjects);
616
			selectedProjects = new ProjectRecord[0];
617
			projectsList.refresh(true);
618
			projectsList.setCheckedElements(selectedProjects);
619
			checkForComplete();
620
			lastPath = path;
621
			return;
622
		}
623
624
		final File directory = new File(path);
625
		long modified = directory.lastModified();
626
		if (path.equals(lastPath) && lastModified == modified) {
627
			// since the file/folder was not modified and the path did not
628
			// change, no refreshing is required
629
			return;
630
		}
631
632
		lastPath = path;
633
		lastModified = modified;
634
635
		try {
636
			getContainer().run(true, true, new IRunnableWithProgress() {
637
638
				/*
639
				 * (non-Javadoc)
640
				 * 
641
				 * @see
642
				 * org.eclipse.jface.operation.IRunnableWithProgress#run(org
643
				 * .eclipse.core.runtime.IProgressMonitor)
644
				 */
645
				public void run(IProgressMonitor monitor) {
646
647
					boolean dirSelected = true;
648
649
					monitor.beginTask(
650
									Messages.ProjectRefreshSnapshotImportWizardPage_searching,
651
									100);
652
					selectedProjects = new ProjectRecord[0];
653
					Collection files = new ArrayList();
654
					monitor.worked(10);
655
656
					File dirpath = new File(path);
657
					if (dirpath.exists()) {
658
						dirSelected = true;
659
					}
660
661
					if (dirSelected && directory.isDirectory()) {
662
663
						if (!collectProjectFilesFromDirectory(files, directory,
664
								null, monitor)) {
665
							return;
666
						}
667
						Iterator filesIterator = files.iterator();
668
						selectedProjects = new ProjectRecord[files.size()];
669
						int index = 0;
670
						monitor.worked(50);
671
						monitor.subTask(Messages.ProjectRefreshSnapshotImportWizardPage_processing);
672
						while (filesIterator.hasNext()) {
673
							File file = (File) filesIterator.next();
674
							selectedProjects[index] = new ProjectRecord(file);
675
							index++;
676
						}
677
					} else {
678
						monitor.worked(60);
679
					}
680
					monitor.done();
681
				}
682
683
			});
684
		} catch (InvocationTargetException e) {
685
			IDEWorkbenchPlugin.log(e.getMessage(), e);
686
		} catch (InterruptedException e) {
687
			// Nothing to do if the user interrupts.
688
		}
689
690
		projectsList.refresh(true);
691
		projectsList.setCheckedElements(getValidProjects());
692
		if (getValidProjects().length < selectedProjects.length) {
693
			setMessage(
694
					Messages.ProjectRefreshSnapshotImportWizardPage_hiddenProjects,
695
					WARNING);
696
		} else {
697
			setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_description);
698
		}
699
		checkForComplete();
700
	}
701
702
	/**
703
	 * Update the refresh snapshot directory if it has changed. Causes
704
	 * the projects list to be updated as well, if it has changed.
705
	 * 
706
	 * @param path
707
	 */
708
	private void updateSnapshotPath(final String path) {
709
		// on an empty path empty selectedProjects
710
		if (path == null || path.length() == 0) {
711
			setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_selectProjects);
712
			selectedProjects = new ProjectRecord[0];
713
			projectsList.refresh(true);
714
			projectsList.setCheckedElements(selectedProjects);
715
			checkForComplete();
716
			lastPath = path;
717
			return;
718
		}
719
720
		final File directory = new File(path);
721
		long modified = directory.lastModified();
722
		if (path.equals(lastSnapshotPath) && lastSnapshotModified == modified) {
723
			// since the file/folder was not modified and the path did not
724
			// change, no refreshing is required
725
			return;
726
		}
727
728
		lastSnapshotPath = path;
729
		lastSnapshotModified = modified;
730
		lastPath = null;	// force update of projects list
731
		updateProjectsList(directoryPathField.getText().trim());
732
		checkForComplete();
733
	}
734
735
	/**
736
	 * Display an error dialog with the specified message.
737
	 * 
738
	 * @param message
739
	 *            the error message
740
	 */
741
	protected void displayErrorDialog(String message) {
742
		MessageDialog.openError(getContainer().getShell(),
743
				getErrorDialogTitle(), message);
744
	}
745
746
	/**
747
	 * Get the title for an error dialog. Subclasses should override.
748
	 */
749
	protected String getErrorDialogTitle() {
750
		return Messages.ProjectRefreshSnapshotImportWizardPage_internalError;
751
	}
752
753
	/**
754
	 * Get the title for an error dialog. Subclasses should override.
755
	 */
756
	protected String getInformationDialogTitle() {
757
		return Messages.ProjectRefreshSnapshotImportWizardPage_snapshotError;
758
	}
759
760
	/**
761
	 * Collect the list of .project files that are under directory into files.
762
	 * To avoid potential performance degradation on slow file systems, by default
763
	 * only the files in this directory are collected; no recursion into
764
	 * sub-directories is performed unless the user checks the "recurse into
765
	 * subfolders" flag.
766
	 * 
767
	 * @param files
768
	 * @param directory
769
	 * @param monitor
770
	 *            The monitor to report to
771
	 * @return boolean <code>true</code> if the operation was completed.
772
	 */
773
	private boolean collectProjectFilesFromDirectory(Collection files,
774
			File directory, Set directoriesVisited, IProgressMonitor monitor) {
775
776
		if (monitor.isCanceled()) {
777
			return false;
778
		}
779
		monitor.subTask(NLS.bind(
780
				Messages.ProjectRefreshSnapshotImportWizardPage_checking,
781
				directory.getPath()));
782
		File[] contents = directory.listFiles();
783
		if (contents == null)
784
			return false;
785
786
		// Initialize recursion guard for recursive symbolic links
787
		if (directoriesVisited == null) {
788
			directoriesVisited = new HashSet();
789
			try {
790
				directoriesVisited.add(directory.getCanonicalPath());
791
			} catch (IOException exception) {
792
				StatusManager.getManager().handle(
793
						StatusUtil.newStatus(IStatus.ERROR, exception
794
								.getLocalizedMessage(), exception));
795
			}
796
		}
797
798
		// first look for project description files
799
		final String dotProject = IProjectDescription.DESCRIPTION_FILE_NAME;
800
		for (int i = 0; i < contents.length; i++) {
801
			File file = contents[i];
802
			if (file.isFile() && file.getName().equals(dotProject)) {
803
				files.add(file);
804
				// don't search sub-directories since we can't have nested
805
				// projects
806
				return true;
807
			}
808
		}
809
		if (!recurseIntoSubFolders)
810
			return true;
811
		// no project description found, so recurse into sub-directories
812
		for (int i = 0; i < contents.length; i++) {
813
			if (contents[i].isDirectory()) {
814
				if (!contents[i].getName().equals(METADATA_FOLDER)) {
815
					try {
816
						String canonicalPath = contents[i].getCanonicalPath();
817
						if (!directoriesVisited.add(canonicalPath)) {
818
							// already been here --> do not recurse
819
							continue;
820
						}
821
					} catch (IOException exception) {
822
						StatusManager.getManager().handle(
823
								StatusUtil.newStatus(IStatus.ERROR, exception
824
										.getLocalizedMessage(), exception));
825
826
					}
827
					collectProjectFilesFromDirectory(files, contents[i],
828
							directoriesVisited, monitor);
829
				}
830
			}
831
		}
832
		return true;
833
	}
834
835
	/**
836
	 * The browse button has been selected. Select the location.
837
	 */
838
	protected void handleLocationDirectoryButtonPressed() {
839
840
		DirectoryDialog dialog = new DirectoryDialog(directoryPathField
841
				.getShell());
842
		dialog
843
				.setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_browseSource);
844
845
		String dirName = directoryPathField.getText().trim();
846
		if (dirName.length() == 0) {
847
			dirName = previouslyBrowsedDirectory;
848
		}
849
850
		if (dirName.length() == 0) {
851
			dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot()
852
					.getLocation().toOSString());
853
		} else {
854
			File path = new File(dirName);
855
			if (path.exists()) {
856
				dialog.setFilterPath(new Path(dirName).toOSString());
857
			}
858
		}
859
860
		String selectedDirectory = dialog.open();
861
		if (selectedDirectory != null) {
862
			previouslyBrowsedDirectory = selectedDirectory;
863
			directoryPathField.setText(previouslyBrowsedDirectory);
864
			updateProjectsList(selectedDirectory);
865
		}
866
867
	}
868
869
	/**
870
	 * The browse button has been selected. Select the location.
871
	 */
872
	protected void handleLocationSnapshotDirectoryButtonPressed() {
873
874
		DirectoryDialog dialog = new DirectoryDialog(
875
				directorySnapshotPathField.getShell());
876
		dialog
877
				.setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_browseSnapshot);
878
879
		String dirName = directorySnapshotPathField.getText().trim();
880
		if (dirName.length() == 0) {
881
			dirName = previouslyBrowsedSnapshotDirectory;
882
		}
883
884
		if (dirName.length() == 0) {
885
			dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot()
886
					.getLocation().toOSString());
887
		} else {
888
			File path = new File(dirName);
889
			if (path.exists()) {
890
				dialog.setFilterPath(new Path(dirName).toOSString());
891
			}
892
		}
893
894
		String selectedDirectory = dialog.open();
895
		if (selectedDirectory != null) {
896
			previouslyBrowsedSnapshotDirectory = selectedDirectory;
897
			directorySnapshotPathField
898
					.setText(previouslyBrowsedSnapshotDirectory);
899
			updateSnapshotPath(selectedDirectory);
900
		}
901
902
	}
903
904
	/**
905
	 * Create the selected projects
906
	 * 
907
	 * @return boolean <code>true</code> if all project creations were
908
	 *         successful.
909
	 */
910
	public boolean createProjects() {
911
912
		saveWidgetValues();
913
914
		final Object[] selected = projectsList.getCheckedElements();
915
		final IPath snapshotPath = new Path(directorySnapshotPathField
916
				.getText().trim());
917
918
		WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
919
			protected void execute(IProgressMonitor monitor)
920
					throws InvocationTargetException, InterruptedException {
921
				try {
922
					monitor.beginTask("", selected.length); //$NON-NLS-1$
923
					if (monitor.isCanceled()) {
924
						throw new OperationCanceledException();
925
					}
926
					for (int i = 0; i < selected.length; i++) {
927
						createExistingProject((ProjectRecord) selected[i],
928
								snapshotPath, new SubProgressMonitor(monitor, 1));
929
					}
930
				} finally {
931
					monitor.done();
932
				}
933
			}
934
		};
935
		// run the new project creation operation
936
		try {
937
			getContainer().run(true, true, op);
938
		} catch (InterruptedException e) {
939
			return false;
940
		} catch (InvocationTargetException e) {
941
			// one of the steps resulted in a core exception
942
			Throwable t = e.getTargetException();
943
			String message = Messages.ProjectRefreshSnapshotImportWizardPage_creationProblems;
944
			IStatus status;
945
			if (t instanceof CoreException) {
946
				status = ((CoreException) t).getStatus();
947
			} else {
948
				status = new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
949
						message, t);
950
			}
951
			ErrorDialog.openError(getShell(), message, null, status);
952
			return false;
953
		}
954
		return true;
955
	}
956
957
	/**
958
	 * Performs clean-up if the user cancels the wizard without doing anything
959
	 */
960
	public void performCancel() {
961
	}
962
963
	/**
964
	 * Create the project described in record. If it is successful return true.
965
	 * 
966
	 * @param record
967
	 * @return boolean <code>true</code> if successful
968
	 * @throws InterruptedException
969
	 */
970
	private boolean createExistingProject(final ProjectRecord record,
971
			IPath snapshotPath, IProgressMonitor monitor) throws InvocationTargetException,
972
			InterruptedException
973
	{
974
		String projectName = record.getProjectName();
975
		final IWorkspace workspace = ResourcesPlugin.getWorkspace();
976
		final IProject project = workspace.getRoot().getProject(projectName);
977
		if (record.description == null)
978
		{
979
			// error case
980
			record.description = workspace.newProjectDescription(projectName);
981
			IPath locationPath = new Path(record.projectSystemFile
982
					.getAbsolutePath());
983
984
			// If it is under the root use the default location
985
			if (Platform.getLocation().isPrefixOf(locationPath))
986
			{
987
				record.description.setLocation(null);
988
			}
989
			else
990
			{
991
				record.description.setLocation(locationPath);
992
			}
993
		}
994
		else
995
		{
996
			record.description.setName(projectName);
997
		}
998
		// load snapshot and open project
999
		try
1000
		{
1001
			monitor
1002
					.beginTask(
1003
							Messages.ProjectRefreshSnapshotImportWizardPage_createProjectsTask,
1004
							100);
1005
			project.create(record.description, new SubProgressMonitor(monitor,
1006
					30));
1007
			IPath zipPath = snapshotPath.append(projectName + "-index.zip");	//$NON-NLS-1$
1008
			URI snapshotLocation = org.eclipse.core.filesystem.URIUtil.toURI(zipPath);
1009
			project.loadSnapshot(IProject.SNAPSHOT_TREE, snapshotLocation,
1010
				new SubProgressMonitor(monitor, 40));
1011
			project.open(IResource.NONE, new SubProgressMonitor(monitor, 30));
1012
		}
1013
		catch (CoreException e)
1014
		{
1015
			throw new InvocationTargetException(e);
1016
		}
1017
		finally
1018
		{
1019
			monitor.done();
1020
		}
1021
1022
		return true;
1023
	}
1024
1025
	/**
1026
	 * The <code>WizardDataTransfer</code> implementation of this
1027
	 * <code>IOverwriteQuery</code> method asks the user whether the existing
1028
	 * resource at the given path should be overwritten.
1029
	 * 
1030
	 * @param pathString
1031
	 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
1032
	 *         <code>"ALL"</code>, or <code>"CANCEL"</code>
1033
	 */
1034
	public String queryOverwrite(String pathString) {
1035
1036
		Path path = new Path(pathString);
1037
1038
		String messageString;
1039
		// Break the message up if there is a file name and a directory
1040
		// and there are at least 2 segments.
1041
		if (path.getFileExtension() == null || path.segmentCount() < 2) {
1042
			messageString = NLS.bind(
1043
					Messages.ProjectRefreshSnapshotImportWizardPage_overwrite,
1044
					pathString);
1045
		} else {
1046
			messageString = NLS
1047
					.bind(
1048
							Messages.ProjectRefreshSnapshotImportWizardPage_overwriteInFolder,
1049
							path.lastSegment(), path.removeLastSegments(1)
1050
									.toOSString());
1051
		}
1052
1053
		final MessageDialog dialog = new MessageDialog(getContainer()
1054
				.getShell(), Messages.ProjectRefreshSnapshotImportWizardPage_question, null,
1055
				messageString, MessageDialog.QUESTION, new String[] {
1056
						IDialogConstants.YES_LABEL,
1057
						IDialogConstants.YES_TO_ALL_LABEL,
1058
						IDialogConstants.NO_LABEL,
1059
						IDialogConstants.NO_TO_ALL_LABEL,
1060
						IDialogConstants.CANCEL_LABEL }, 0);
1061
		String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
1062
		// run in syncExec because callback is from an operation,
1063
		// which is probably not running in the UI thread.
1064
		getControl().getDisplay().syncExec(new Runnable() {
1065
			public void run() {
1066
				dialog.open();
1067
			}
1068
		});
1069
		return dialog.getReturnCode() < 0 ? CANCEL : response[dialog
1070
				.getReturnCode()];
1071
	}
1072
1073
	/**
1074
	 * Method used for test suite.
1075
	 * 
1076
	 * @return CheckboxTreeViewer the viewer containing all the projects found
1077
	 */
1078
	public CheckboxTreeViewer getProjectsList() {
1079
		return projectsList;
1080
	}
1081
1082
	/**
1083
	 * Retrieve all the projects in the current workspace.
1084
	 * 
1085
	 * @return IProject[] array of IProject in the current workspace
1086
	 */
1087
	private IProject[] getProjectsInWorkspace() {
1088
		if (wsProjects == null) {
1089
			wsProjects = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getProjects();
1090
		}
1091
		return wsProjects;
1092
	}
1093
1094
	/**
1095
	 * Get the array of valid project records that can be imported from the
1096
	 * source workspace or archive, selected by the user. If a project with the
1097
	 * same name exists in both the source workspace and the current workspace,
1098
	 * or if no refresh snapshot for the project is found in the snapshot folder,
1099
	 * it will not appear in the list of projects to import and thus cannot be
1100
	 * selected for import.
1101
	 * 
1102
	 * Method declared public for test suite.
1103
	 * 
1104
	 * @return ProjectRecord[] array of projects that can be imported into the
1105
	 *         workspace
1106
	 */
1107
	public ProjectRecord[] getValidProjects() {
1108
		List validProjects = new ArrayList();
1109
		for (int i = 0; i < selectedProjects.length; i++) {
1110
			String projectName = selectedProjects[i].getProjectName();
1111
			if (!isProjectInWorkspace(projectName)&& hasSnapshot(projectName)) {
1112
				validProjects.add(selectedProjects[i]);
1113
			}
1114
		}
1115
		return (ProjectRecord[]) validProjects
1116
				.toArray(new ProjectRecord[validProjects.size()]);
1117
	}
1118
1119
	/**
1120
	 * Determine if the project with the given name is in the current workspace.
1121
	 * 
1122
	 * @param projectName
1123
	 *            String the project name to check
1124
	 * @return boolean true if the project with the given name is in this
1125
	 *         workspace
1126
	 */
1127
	private boolean isProjectInWorkspace(String projectName) {
1128
		if (projectName == null) {
1129
			return false;
1130
		}
1131
		IProject[] workspaceProjects = getProjectsInWorkspace();
1132
		for (int i = 0; i < workspaceProjects.length; i++) {
1133
			if (projectName.equals(workspaceProjects[i].getName())) {
1134
				return true;
1135
			}
1136
		}
1137
		return false;
1138
	}
1139
1140
	/**
1141
	 * Determine if the named project has a refresh snapshot in the current
1142
	 * snapshot directory.
1143
	 * @param projectName
1144
	 *            String the project name to check
1145
	 * @return boolean true if the project with the given name has a refresh
1146
	 *         snapshot in the current snapshot directory
1147
	 */
1148
	private boolean hasSnapshot(String projectName) {
1149
		if (projectName == null) {
1150
			return false;
1151
		}
1152
 		final IPath snapshotPath = new Path(directorySnapshotPathField
1153
 				.getText().trim());
1154
		IPath zipPath = snapshotPath.append(projectName + "-index.zip");	//$NON-NLS-1$
1155
		return zipPath.toFile().exists();
1156
	}
1157
	/**
1158
	 * Use the dialog store to restore widget values to the values that they
1159
	 * held last time this wizard was used to completion.
1160
	 * 
1161
	 * Method declared public only for use of tests.
1162
	 */
1163
	public void restoreWidgetValues() {
1164
		IDialogSettings settings = getDialogSettings();
1165
		if (settings != null) {
1166
			recurseIntoSubFolders = settings.getBoolean(STORE_RECURSE_SUBFOLDERS);
1167
			recurseIntoSubFoldersCheckbox.setSelection(recurseIntoSubFolders);
1168
		}
1169
	}
1170
1171
	/**
1172
	 * Since Finish was pressed, write widget values to the dialog store so that
1173
	 * they will persist into the next invocation of this wizard page.
1174
	 * 
1175
	 * Method declared public only for use of tests.
1176
	 */
1177
	public void saveWidgetValues() {
1178
		IDialogSettings settings = getDialogSettings();
1179
		if (settings != null) {
1180
			settings.put(STORE_RECURSE_SUBFOLDERS, recurseIntoSubFolders);
1181
		}
1182
	}
1183
1184
}
(-)src/org/eclipse/ui/internal/wizards/refreshsnapshot/messages.properties (+50 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2010 Wind River Systems, Inc. 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
#     Francis Lynch (Wind River) - initial API and implementation
10
###############################################################################
11
12
ProjectRefreshSnapshotExportWizard_exportTitle=Export
13
ProjectRefreshSnapshotExportWizardPage_title=Export Refresh Snapshots
14
ProjectRefreshSnapshotExportWizardPage_description=Export a refresh snapshot from selected projects for trusted import in other workspaces
15
ProjectRefreshSnapshotExportWizardPage_selectProjects=Select &projects to snapshot:
16
ProjectRefreshSnapshotExportWizardPage_selectAll=&Select All
17
ProjectRefreshSnapshotExportWizardPage_deselectAll=&Deselect All
18
ProjectRefreshSnapshotExportWizardPage_errorsOccurred=Errors occurred while exporting project refresh snapshot
19
ProjectRefreshSnapshotExportWizardPage_needProjectSelected=At least one project must be selected.
20
ProjectRefreshSnapshotExportWizardPage_errorDialogTitle=Export Project Refresh Snapshot
21
ProjectRefreshSnapshotExportWizardPage_selectSnapshot=&Snapshot Directory:
22
ProjectRefreshSnapshotExportWizardPage_snapshotBrowse=B&rowse...
23
ProjectRefreshSnapshotExportWizardPage_browseSnapshot=Select destination directory for refresh snapshot
24
ProjectRefreshSnapshotExportWizardPage_overwrite=''{0}'' already exists. Would you like to overwrite it?
25
ProjectRefreshSnapshotExportWizardPage_question=Question
26
27
ProjectRefreshSnapshotImportWizard_importTitle=Import
28
ProjectRefreshSnapshotImportWizardPage_projectLabel={0} ({1})
29
ProjectRefreshSnapshotImportWizardPage_title=Import with refresh snapshot
30
ProjectRefreshSnapshotImportWizardPage_description=Select a directory to search for .project files and a directory with refresh snapshot(s)
31
ProjectRefreshSnapshotImportWizardPage_selectProject=&Project:
32
ProjectRefreshSnapshotImportWizardPage_selectSnapshot=&Snapshot Directory:
33
ProjectRefreshSnapshotImportWizardPage_sourceBrowse=B&rowse...
34
ProjectRefreshSnapshotImportWizardPage_sourceDirectory=Select &source directory:
35
ProjectRefreshSnapshotImportWizardPage_snapshotBrowse=B&rowse...
36
ProjectRefreshSnapshotImportWizardPage_selectProjects=Select a directory to search for .project files
37
ProjectRefreshSnapshotImportWizardPage_searching=Searching for projects
38
ProjectRefreshSnapshotImportWizardPage_processing=Processing results
39
ProjectRefreshSnapshotImportWizardPage_hiddenProjects=Some projects were hidden because they exist in the workspace or have no refresh snapshots
40
ProjectRefreshSnapshotImportWizardPage_internalError=Internal error
41
ProjectRefreshSnapshotImportWizardPage_snapshotError=Refresh snapshot error
42
ProjectRefreshSnapshotImportWizardPage_checking=Checking: {0}
43
ProjectRefreshSnapshotImportWizardPage_browseSource=Select source directory of the project to import
44
ProjectRefreshSnapshotImportWizardPage_browseSnapshot=Select directory containing refresh snapshot
45
ProjectRefreshSnapshotImportWizardPage_creationProblems=Creation problems
46
ProjectRefreshSnapshotImportWizardPage_createProjectsTask=Creating Projects
47
ProjectRefreshSnapshotImportWizardPage_overwrite=''{0}'' already exists. Would you like to overwrite it?
48
ProjectRefreshSnapshotImportWizardPage_overwriteInFolder=Overwrite ''{0}'' in folder ''{1}''?
49
ProjectRefreshSnapshotImportWizardPage_question=Question
50
ProjectRefreshSnapshotImportWizardPage_recurse=Scan sub-directories when searching for .project files

Return to bug 303751