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 (+1149 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
	/**
224
	 * Creates a new project creation wizard page.
225
	 * 
226
	 */
227
	public ProjectRefreshSnapshotImportWizardPage() {
228
		this("refreshSnapshotImportPage"); //$NON-NLS-1$
229
	}
230
231
	/**
232
	 * Create a new instance of the receiver.
233
	 * 
234
	 * @param pageName
235
	 */
236
	public ProjectRefreshSnapshotImportWizardPage(String pageName) {
237
		super(pageName);
238
		setPageComplete(false);
239
		setTitle(Messages.ProjectRefreshSnapshotImportWizardPage_title);
240
		setDescription(Messages.ProjectRefreshSnapshotImportWizardPage_description);
241
	}
242
243
	/*
244
	 * (non-Javadoc)
245
	 * 
246
	 * @see
247
	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
248
	 * .Composite)
249
	 */
250
	public void createControl(Composite parent) {
251
252
		initializeDialogUnits(parent);
253
254
		Composite workArea = new Composite(parent, SWT.NONE);
255
		setControl(workArea);
256
257
		workArea.setLayout(new GridLayout());
258
		workArea.setLayoutData(new GridData(GridData.FILL_BOTH
259
				| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
260
261
		createProjectsRoot(workArea);
262
		createProjectsList(workArea);
263
		createOptionsArea(workArea);
264
		createSnapshotArea(workArea);
265
		restoreWidgetValues();
266
		Dialog.applyDialogFont(workArea);
267
268
	}
269
270
	private void checkForComplete() {
271
		if (projectsList.getCheckedElements().length > 0) {
272
			String path = directorySnapshotPathField.getText().trim();
273
			if (path.length() > 0) {
274
				File dirpath = new File(path);
275
				if (dirpath.exists()) {
276
					setPageComplete(true);
277
					return;
278
				}
279
			}
280
		}
281
282
		setPageComplete(false);
283
	}
284
285
	/**
286
	 * Create the checkbox list for the found projects.
287
	 * 
288
	 * @param workArea
289
	 */
290
	private void createProjectsList(Composite workArea) {
291
292
		Label title = new Label(workArea, SWT.NONE);
293
		title.setText(Messages.ProjectRefreshSnapshotImportWizardPage_selectProject);
294
295
		Composite listComposite = new Composite(workArea, SWT.NONE);
296
		GridLayout layout = new GridLayout();
297
		layout.numColumns = 2;
298
		layout.marginWidth = 0;
299
		layout.makeColumnsEqualWidth = false;
300
		listComposite.setLayout(layout);
301
302
		listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
303
				| GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
304
305
		projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER);
306
		GridData listData = new GridData(GridData.GRAB_HORIZONTAL
307
				| GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
308
		listData.heightHint = 100;
309
		projectsList.getControl().setLayoutData(listData);
310
311
		projectsList.setContentProvider(new ITreeContentProvider() {
312
313
			/*
314
			 * (non-Javadoc)
315
			 * 
316
			 * @see
317
			 * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java
318
			 * .lang.Object)
319
			 */
320
			public Object[] getChildren(Object parentElement) {
321
				return null;
322
			}
323
324
			/*
325
			 * (non-Javadoc)
326
			 * 
327
			 * @see
328
			 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements
329
			 * (java.lang.Object)
330
			 */
331
			public Object[] getElements(Object inputElement) {
332
				return getValidProjects();
333
			}
334
335
			/*
336
			 * (non-Javadoc)
337
			 * 
338
			 * @see
339
			 * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java
340
			 * .lang.Object)
341
			 */
342
			public boolean hasChildren(Object element) {
343
				return false;
344
			}
345
346
			/*
347
			 * (non-Javadoc)
348
			 * 
349
			 * @see
350
			 * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java
351
			 * .lang.Object)
352
			 */
353
			public Object getParent(Object element) {
354
				return null;
355
			}
356
357
			/*
358
			 * (non-Javadoc)
359
			 * 
360
			 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
361
			 */
362
			public void dispose() {
363
364
			}
365
366
			/*
367
			 * (non-Javadoc)
368
			 * 
369
			 * @see
370
			 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
371
			 * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
372
			 */
373
			public void inputChanged(Viewer viewer, Object oldInput,
374
					Object newInput) {
375
			}
376
377
		});
378
379
		projectsList.setLabelProvider(new LabelProvider() {
380
			/*
381
			 * (non-Javadoc)
382
			 * 
383
			 * @see
384
			 * org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
385
			 */
386
			public String getText(Object element) {
387
				return ((ProjectRecord) element).getProjectLabel();
388
			}
389
		});
390
391
		projectsList.addCheckStateListener(new ICheckStateListener() {
392
			/*
393
			 * (non-Javadoc)
394
			 * 
395
			 * @see
396
			 * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
397
			 * (org.eclipse.jface.viewers.CheckStateChangedEvent)
398
			 */
399
			public void checkStateChanged(CheckStateChangedEvent event) {
400
				checkForComplete();
401
			}
402
		});
403
404
		projectsList.setInput(this);
405
		projectsList.setComparator(new ViewerComparator());
406
	}
407
408
	/**
409
	 * Create the area to specify the snapshot directory.
410
	 * 
411
	 * @param workArea
412
	 */
413
	private void createSnapshotArea(Composite workArea) {
414
415
		// project specification group
416
		Composite projectGroup = new Composite(workArea, SWT.NONE);
417
		GridLayout layout = new GridLayout();
418
		layout.numColumns = 3;
419
		layout.makeColumnsEqualWidth = false;
420
		layout.marginWidth = 0;
421
		projectGroup.setLayout(layout);
422
		projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
423
424
		Label title = new Label(projectGroup, SWT.NONE);
425
		title.setText(Messages.ProjectRefreshSnapshotImportWizardPage_selectSnapshot);
426
427
		// refresh snapshot directory location entry field
428
		this.directorySnapshotPathField = new Text(projectGroup, SWT.BORDER);
429
430
		this.directorySnapshotPathField.setLayoutData(new GridData(
431
				GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
432
433
		// browse button
434
		browseSnapshotDirectoryButton = new Button(projectGroup, SWT.PUSH);
435
		browseSnapshotDirectoryButton
436
				.setText(Messages.ProjectRefreshSnapshotImportWizardPage_snapshotBrowse);
437
		setButtonLayoutData(browseSnapshotDirectoryButton);
438
439
		browseSnapshotDirectoryButton
440
				.addSelectionListener(new SelectionAdapter() {
441
					/*
442
					 * (non-Javadoc)
443
					 * 
444
					 * @see org.eclipse.swt.events.SelectionAdapter#widgetS
445
					 * elected(org.eclipse.swt.events.SelectionEvent)
446
					 */
447
					public void widgetSelected(SelectionEvent e) {
448
						handleLocationSnapshotDirectoryButtonPressed();
449
					}
450
				});
451
452
		directorySnapshotPathField
453
				.addTraverseListener(new TraverseListener() {
454
455
					/*
456
					 * (non-Javadoc)
457
					 * 
458
					 * @see
459
					 * org.eclipse.swt.events.TraverseListener#keyTraversed(
460
					 * org.eclipse.swt.events.TraverseEvent)
461
					 */
462
					public void keyTraversed(TraverseEvent e) {
463
						if (e.detail == SWT.TRAVERSE_RETURN) {
464
							e.doit = false;
465
							updateProjectsList(directoryPathField.getText().trim());
466
							checkForComplete();
467
						}
468
					}
469
470
				});
471
472
		directorySnapshotPathField.addFocusListener(new FocusAdapter() {
473
474
			/*
475
			 * (non-Javadoc)
476
			 * 
477
			 * @see
478
			 * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
479
			 * .events.FocusEvent)
480
			 */
481
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
482
				updateProjectsList(directoryPathField.getText().trim());
483
				checkForComplete();
484
			}
485
486
		});
487
488
	}
489
490
	/**
491
	 * Create the area with the extra options.
492
	 * 
493
	 * @param workArea
494
	 */
495
	private void createOptionsArea(Composite workArea) {
496
		Composite optionsGroup = new Composite(workArea, SWT.NONE);
497
		optionsGroup.setLayout(new GridLayout());
498
		optionsGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
499
500
		recurseIntoSubFoldersCheckbox = new Button(optionsGroup, SWT.CHECK);
501
		recurseIntoSubFoldersCheckbox.setText(
502
				Messages.ProjectRefreshSnapshotImportWizardPage_recurse);
503
		recurseIntoSubFoldersCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
504
		recurseIntoSubFoldersCheckbox.addSelectionListener(new SelectionAdapter() {
505
			public void widgetSelected(SelectionEvent e) {
506
				recurseIntoSubFolders = recurseIntoSubFoldersCheckbox.getSelection();
507
				lastPath = null;	// force update
508
				updateProjectsList(directoryPathField.getText().trim());
509
			}
510
		});
511
	}
512
	/**
513
	 * Create the area where you select the root directory for the projects.
514
	 * 
515
	 * @param workArea
516
	 *            Composite
517
	 */
518
	private void createProjectsRoot(Composite workArea) {
519
520
		// project specification group
521
		Composite projectGroup = new Composite(workArea, SWT.NONE);
522
		GridLayout layout = new GridLayout();
523
		layout.numColumns = 3;
524
		layout.makeColumnsEqualWidth = false;
525
		layout.marginWidth = 0;
526
		projectGroup.setLayout(layout);
527
		projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
528
529
		Label dirTitle = new Label(projectGroup, SWT.NONE);
530
		dirTitle.setText(Messages.ProjectRefreshSnapshotImportWizardPage_sourceDirectory);
531
532
		// project location entry field
533
		this.directoryPathField = new Text(projectGroup, SWT.BORDER);
534
535
		this.directoryPathField.setLayoutData(new GridData(
536
				GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
537
538
		// browse button
539
		browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);
540
		browseDirectoriesButton
541
				.setText(Messages.ProjectRefreshSnapshotImportWizardPage_sourceBrowse);
542
		setButtonLayoutData(browseDirectoriesButton);
543
544
		browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {
545
			/*
546
			 * (non-Javadoc)
547
			 * 
548
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetS
549
			 * elected(org.eclipse.swt.events.SelectionEvent)
550
			 */
551
			public void widgetSelected(SelectionEvent e) {
552
				handleLocationDirectoryButtonPressed();
553
			}
554
555
		});
556
557
		directoryPathField.addTraverseListener(new TraverseListener() {
558
559
			/*
560
			 * (non-Javadoc)
561
			 * 
562
			 * @see
563
			 * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse
564
			 * .swt.events.TraverseEvent)
565
			 */
566
			public void keyTraversed(TraverseEvent e) {
567
				if (e.detail == SWT.TRAVERSE_RETURN) {
568
					e.doit = false;
569
					updateProjectsList(directoryPathField.getText().trim());
570
				}
571
			}
572
573
		});
574
575
		directoryPathField.addFocusListener(new FocusAdapter() {
576
577
			/*
578
			 * (non-Javadoc)
579
			 * 
580
			 * @see
581
			 * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt
582
			 * .events.FocusEvent)
583
			 */
584
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
585
				updateProjectsList(directoryPathField.getText().trim());
586
			}
587
588
		});
589
	}
590
591
	/*
592
	 * (non-Javadoc) Method declared on IDialogPage. Set the focus on path
593
	 * fields when page becomes visible.
594
	 */
595
	public void setVisible(boolean visible) {
596
		super.setVisible(visible);
597
		if (visible) {
598
			this.directoryPathField.setFocus();
599
		}
600
	}
601
602
	/**
603
	 * Update the list of projects based on path. Method declared public only
604
	 * for test suite.
605
	 * 
606
	 * @param path
607
	 */
608
	public void updateProjectsList(final String path) {
609
		// on an empty path empty selectedProjects
610
		if (path == null || path.length() == 0) {
611
			setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_selectProjects);
612
			selectedProjects = new ProjectRecord[0];
613
			projectsList.refresh(true);
614
			projectsList.setCheckedElements(selectedProjects);
615
			checkForComplete();
616
			lastPath = path;
617
			return;
618
		}
619
620
		final File directory = new File(path);
621
		long modified = directory.lastModified();
622
		if (path.equals(lastPath) && lastModified == modified) {
623
			// since the file/folder was not modified and the path did not
624
			// change, no refreshing is required
625
			return;
626
		}
627
628
		lastPath = path;
629
		lastModified = modified;
630
631
		try {
632
			getContainer().run(true, true, new IRunnableWithProgress() {
633
634
				/*
635
				 * (non-Javadoc)
636
				 * 
637
				 * @see
638
				 * org.eclipse.jface.operation.IRunnableWithProgress#run(org
639
				 * .eclipse.core.runtime.IProgressMonitor)
640
				 */
641
				public void run(IProgressMonitor monitor) {
642
643
					boolean dirSelected = true;
644
645
					monitor.beginTask(
646
									Messages.ProjectRefreshSnapshotImportWizardPage_searching,
647
									100);
648
					selectedProjects = new ProjectRecord[0];
649
					Collection files = new ArrayList();
650
					monitor.worked(10);
651
652
					File dirpath = new File(path);
653
					if (dirpath.exists()) {
654
						dirSelected = true;
655
					}
656
657
					if (dirSelected && directory.isDirectory()) {
658
659
						if (!collectProjectFilesFromDirectory(files, directory,
660
								null, monitor)) {
661
							return;
662
						}
663
						Iterator filesIterator = files.iterator();
664
						selectedProjects = new ProjectRecord[files.size()];
665
						int index = 0;
666
						monitor.worked(50);
667
						monitor.subTask(Messages.ProjectRefreshSnapshotImportWizardPage_processing);
668
						while (filesIterator.hasNext()) {
669
							File file = (File) filesIterator.next();
670
							selectedProjects[index] = new ProjectRecord(file);
671
							index++;
672
						}
673
					} else {
674
						monitor.worked(60);
675
					}
676
					monitor.done();
677
				}
678
679
			});
680
		} catch (InvocationTargetException e) {
681
			IDEWorkbenchPlugin.log(e.getMessage(), e);
682
		} catch (InterruptedException e) {
683
			// Nothing to do if the user interrupts.
684
		}
685
686
		projectsList.refresh(true);
687
		projectsList.setCheckedElements(getValidProjects());
688
		if (getValidProjects().length < selectedProjects.length) {
689
			setMessage(
690
					Messages.ProjectRefreshSnapshotImportWizardPage_hiddenProjects,
691
					WARNING);
692
		} else {
693
			setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_description);
694
		}
695
		checkForComplete();
696
	}
697
698
	/**
699
	 * Display an error dialog with the specified message.
700
	 * 
701
	 * @param message
702
	 *            the error message
703
	 */
704
	protected void displayErrorDialog(String message) {
705
		MessageDialog.openError(getContainer().getShell(),
706
				getErrorDialogTitle(), message);
707
	}
708
709
	/**
710
	 * Get the title for an error dialog. Subclasses should override.
711
	 */
712
	protected String getErrorDialogTitle() {
713
		return Messages.ProjectRefreshSnapshotImportWizardPage_internalError;
714
	}
715
716
	/**
717
	 * Get the title for an error dialog. Subclasses should override.
718
	 */
719
	protected String getInformationDialogTitle() {
720
		return Messages.ProjectRefreshSnapshotImportWizardPage_snapshotError;
721
	}
722
723
	/**
724
	 * Collect the list of .project files that are under directory into files.
725
	 * To avoid potential performance degradation on slow file systems, by default
726
	 * only the files in this directory are collected; no recursion into
727
	 * sub-directories is performed unless the user checks the "recurse into
728
	 * subfolders" flag.
729
	 * 
730
	 * @param files
731
	 * @param directory
732
	 * @param monitor
733
	 *            The monitor to report to
734
	 * @return boolean <code>true</code> if the operation was completed.
735
	 */
736
	private boolean collectProjectFilesFromDirectory(Collection files,
737
			File directory, Set directoriesVisited, IProgressMonitor monitor) {
738
739
		if (monitor.isCanceled()) {
740
			return false;
741
		}
742
		monitor.subTask(NLS.bind(
743
				Messages.ProjectRefreshSnapshotImportWizardPage_checking,
744
				directory.getPath()));
745
		File[] contents = directory.listFiles();
746
		if (contents == null)
747
			return false;
748
749
		// Initialize recursion guard for recursive symbolic links
750
		if (directoriesVisited == null) {
751
			directoriesVisited = new HashSet();
752
			try {
753
				directoriesVisited.add(directory.getCanonicalPath());
754
			} catch (IOException exception) {
755
				StatusManager.getManager().handle(
756
						StatusUtil.newStatus(IStatus.ERROR, exception
757
								.getLocalizedMessage(), exception));
758
			}
759
		}
760
761
		// first look for project description files
762
		final String dotProject = IProjectDescription.DESCRIPTION_FILE_NAME;
763
		for (int i = 0; i < contents.length; i++) {
764
			File file = contents[i];
765
			if (file.isFile() && file.getName().equals(dotProject)) {
766
				files.add(file);
767
				// don't search sub-directories since we can't have nested
768
				// projects
769
				return true;
770
			}
771
		}
772
		if (!recurseIntoSubFolders)
773
			return true;
774
		// no project description found, so recurse into sub-directories
775
		for (int i = 0; i < contents.length; i++) {
776
			if (contents[i].isDirectory()) {
777
				if (!contents[i].getName().equals(METADATA_FOLDER)) {
778
					try {
779
						String canonicalPath = contents[i].getCanonicalPath();
780
						if (!directoriesVisited.add(canonicalPath)) {
781
							// already been here --> do not recurse
782
							continue;
783
						}
784
					} catch (IOException exception) {
785
						StatusManager.getManager().handle(
786
								StatusUtil.newStatus(IStatus.ERROR, exception
787
										.getLocalizedMessage(), exception));
788
789
					}
790
					collectProjectFilesFromDirectory(files, contents[i],
791
							directoriesVisited, monitor);
792
				}
793
			}
794
		}
795
		return true;
796
	}
797
798
	/**
799
	 * The browse button has been selected. Select the location.
800
	 */
801
	protected void handleLocationDirectoryButtonPressed() {
802
803
		DirectoryDialog dialog = new DirectoryDialog(directoryPathField
804
				.getShell());
805
		dialog
806
				.setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_browseSource);
807
808
		String dirName = directoryPathField.getText().trim();
809
		if (dirName.length() == 0) {
810
			dirName = previouslyBrowsedDirectory;
811
		}
812
813
		if (dirName.length() == 0) {
814
			dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot()
815
					.getLocation().toOSString());
816
		} else {
817
			File path = new File(dirName);
818
			if (path.exists()) {
819
				dialog.setFilterPath(new Path(dirName).toOSString());
820
			}
821
		}
822
823
		String selectedDirectory = dialog.open();
824
		if (selectedDirectory != null) {
825
			previouslyBrowsedDirectory = selectedDirectory;
826
			directoryPathField.setText(previouslyBrowsedDirectory);
827
			updateProjectsList(selectedDirectory);
828
		}
829
830
	}
831
832
	/**
833
	 * The browse button has been selected. Select the location.
834
	 */
835
	protected void handleLocationSnapshotDirectoryButtonPressed() {
836
837
		DirectoryDialog dialog = new DirectoryDialog(
838
				directorySnapshotPathField.getShell());
839
		dialog
840
				.setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_browseSnapshot);
841
842
		String dirName = directorySnapshotPathField.getText().trim();
843
		if (dirName.length() == 0) {
844
			dirName = previouslyBrowsedSnapshotDirectory;
845
		}
846
847
		if (dirName.length() == 0) {
848
			dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot()
849
					.getLocation().toOSString());
850
		} else {
851
			File path = new File(dirName);
852
			if (path.exists()) {
853
				dialog.setFilterPath(new Path(dirName).toOSString());
854
			}
855
		}
856
857
		String selectedDirectory = dialog.open();
858
		if (selectedDirectory != null) {
859
			previouslyBrowsedSnapshotDirectory = selectedDirectory;
860
			directorySnapshotPathField
861
					.setText(previouslyBrowsedSnapshotDirectory);
862
			lastPath = null;	// force update
863
			updateProjectsList(directoryPathField.getText().trim());
864
			checkForComplete();
865
		}
866
867
	}
868
869
	/**
870
	 * Create the selected projects
871
	 * 
872
	 * @return boolean <code>true</code> if all project creations were
873
	 *         successful.
874
	 */
875
	public boolean createProjects() {
876
877
		saveWidgetValues();
878
879
		final Object[] selected = projectsList.getCheckedElements();
880
		final IPath snapshotPath = new Path(directorySnapshotPathField
881
				.getText().trim());
882
883
		WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
884
			protected void execute(IProgressMonitor monitor)
885
					throws InvocationTargetException, InterruptedException {
886
				try {
887
					monitor.beginTask("", selected.length); //$NON-NLS-1$
888
					if (monitor.isCanceled()) {
889
						throw new OperationCanceledException();
890
					}
891
					for (int i = 0; i < selected.length; i++) {
892
						createExistingProject((ProjectRecord) selected[i],
893
								snapshotPath, new SubProgressMonitor(monitor, 1));
894
					}
895
				} finally {
896
					monitor.done();
897
				}
898
			}
899
		};
900
		// run the new project creation operation
901
		try {
902
			getContainer().run(true, true, op);
903
		} catch (InterruptedException e) {
904
			return false;
905
		} catch (InvocationTargetException e) {
906
			// one of the steps resulted in a core exception
907
			Throwable t = e.getTargetException();
908
			String message = Messages.ProjectRefreshSnapshotImportWizardPage_creationProblems;
909
			IStatus status;
910
			if (t instanceof CoreException) {
911
				status = ((CoreException) t).getStatus();
912
			} else {
913
				status = new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1,
914
						message, t);
915
			}
916
			ErrorDialog.openError(getShell(), message, null, status);
917
			return false;
918
		}
919
		return true;
920
	}
921
922
	/**
923
	 * Performs clean-up if the user cancels the wizard without doing anything
924
	 */
925
	public void performCancel() {
926
	}
927
928
	/**
929
	 * Create the project described in record. If it is successful return true.
930
	 * 
931
	 * @param record
932
	 * @return boolean <code>true</code> if successful
933
	 * @throws InterruptedException
934
	 */
935
	private boolean createExistingProject(final ProjectRecord record,
936
			IPath snapshotPath, IProgressMonitor monitor) throws InvocationTargetException,
937
			InterruptedException
938
	{
939
		String projectName = record.getProjectName();
940
		final IWorkspace workspace = ResourcesPlugin.getWorkspace();
941
		final IProject project = workspace.getRoot().getProject(projectName);
942
		if (record.description == null)
943
		{
944
			// error case
945
			record.description = workspace.newProjectDescription(projectName);
946
			IPath locationPath = new Path(record.projectSystemFile
947
					.getAbsolutePath());
948
949
			// If it is under the root use the default location
950
			if (Platform.getLocation().isPrefixOf(locationPath))
951
			{
952
				record.description.setLocation(null);
953
			}
954
			else
955
			{
956
				record.description.setLocation(locationPath);
957
			}
958
		}
959
		else
960
		{
961
			record.description.setName(projectName);
962
		}
963
		// load snapshot and open project
964
		try
965
		{
966
			monitor
967
					.beginTask(
968
							Messages.ProjectRefreshSnapshotImportWizardPage_createProjectsTask,
969
							100);
970
			project.create(record.description, new SubProgressMonitor(monitor,
971
					30));
972
			IPath zipPath = snapshotPath.append(projectName + "-index.zip");	//$NON-NLS-1$
973
			URI snapshotLocation = org.eclipse.core.filesystem.URIUtil.toURI(zipPath);
974
			project.loadSnapshot(IProject.SNAPSHOT_TREE, snapshotLocation,
975
				new SubProgressMonitor(monitor, 40));
976
			project.open(IResource.NONE, new SubProgressMonitor(monitor, 30));
977
		}
978
		catch (CoreException e)
979
		{
980
			throw new InvocationTargetException(e);
981
		}
982
		finally
983
		{
984
			monitor.done();
985
		}
986
987
		return true;
988
	}
989
990
	/**
991
	 * The <code>WizardDataTransfer</code> implementation of this
992
	 * <code>IOverwriteQuery</code> method asks the user whether the existing
993
	 * resource at the given path should be overwritten.
994
	 * 
995
	 * @param pathString
996
	 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
997
	 *         <code>"ALL"</code>, or <code>"CANCEL"</code>
998
	 */
999
	public String queryOverwrite(String pathString) {
1000
1001
		Path path = new Path(pathString);
1002
1003
		String messageString;
1004
		// Break the message up if there is a file name and a directory
1005
		// and there are at least 2 segments.
1006
		if (path.getFileExtension() == null || path.segmentCount() < 2) {
1007
			messageString = NLS.bind(
1008
					Messages.ProjectRefreshSnapshotImportWizardPage_overwrite,
1009
					pathString);
1010
		} else {
1011
			messageString = NLS
1012
					.bind(
1013
							Messages.ProjectRefreshSnapshotImportWizardPage_overwriteInFolder,
1014
							path.lastSegment(), path.removeLastSegments(1)
1015
									.toOSString());
1016
		}
1017
1018
		final MessageDialog dialog = new MessageDialog(getContainer()
1019
				.getShell(), Messages.ProjectRefreshSnapshotImportWizardPage_question, null,
1020
				messageString, MessageDialog.QUESTION, new String[] {
1021
						IDialogConstants.YES_LABEL,
1022
						IDialogConstants.YES_TO_ALL_LABEL,
1023
						IDialogConstants.NO_LABEL,
1024
						IDialogConstants.NO_TO_ALL_LABEL,
1025
						IDialogConstants.CANCEL_LABEL }, 0);
1026
		String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
1027
		// run in syncExec because callback is from an operation,
1028
		// which is probably not running in the UI thread.
1029
		getControl().getDisplay().syncExec(new Runnable() {
1030
			public void run() {
1031
				dialog.open();
1032
			}
1033
		});
1034
		return dialog.getReturnCode() < 0 ? CANCEL : response[dialog
1035
				.getReturnCode()];
1036
	}
1037
1038
	/**
1039
	 * Method used for test suite.
1040
	 * 
1041
	 * @return CheckboxTreeViewer the viewer containing all the projects found
1042
	 */
1043
	public CheckboxTreeViewer getProjectsList() {
1044
		return projectsList;
1045
	}
1046
1047
	/**
1048
	 * Retrieve all the projects in the current workspace.
1049
	 * 
1050
	 * @return IProject[] array of IProject in the current workspace
1051
	 */
1052
	private IProject[] getProjectsInWorkspace() {
1053
		if (wsProjects == null) {
1054
			wsProjects = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getProjects();
1055
		}
1056
		return wsProjects;
1057
	}
1058
1059
	/**
1060
	 * Get the array of valid project records that can be imported from the
1061
	 * source workspace or archive, selected by the user. If a project with the
1062
	 * same name exists in both the source workspace and the current workspace,
1063
	 * or if no refresh snapshot for the project is found in the snapshot folder,
1064
	 * it will not appear in the list of projects to import and thus cannot be
1065
	 * selected for import.
1066
	 * 
1067
	 * Method declared public for test suite.
1068
	 * 
1069
	 * @return ProjectRecord[] array of projects that can be imported into the
1070
	 *         workspace
1071
	 */
1072
	public ProjectRecord[] getValidProjects() {
1073
		List validProjects = new ArrayList();
1074
		for (int i = 0; i < selectedProjects.length; i++) {
1075
			String projectName = selectedProjects[i].getProjectName();
1076
			if (!isProjectInWorkspace(projectName)&& hasSnapshot(projectName)) {
1077
				validProjects.add(selectedProjects[i]);
1078
			}
1079
		}
1080
		return (ProjectRecord[]) validProjects
1081
				.toArray(new ProjectRecord[validProjects.size()]);
1082
	}
1083
1084
	/**
1085
	 * Determine if the project with the given name is in the current workspace.
1086
	 * 
1087
	 * @param projectName
1088
	 *            String the project name to check
1089
	 * @return boolean true if the project with the given name is in this
1090
	 *         workspace
1091
	 */
1092
	private boolean isProjectInWorkspace(String projectName) {
1093
		if (projectName == null) {
1094
			return false;
1095
		}
1096
		IProject[] workspaceProjects = getProjectsInWorkspace();
1097
		for (int i = 0; i < workspaceProjects.length; i++) {
1098
			if (projectName.equals(workspaceProjects[i].getName())) {
1099
				return true;
1100
			}
1101
		}
1102
		return false;
1103
	}
1104
1105
	/**
1106
	 * Determine if the named project has a refresh snapshot in the current
1107
	 * snapshot directory.
1108
	 * @param projectName
1109
	 *            String the project name to check
1110
	 * @return boolean true if the project with the given name has a refresh
1111
	 *         snapshot in the current snapshot directory
1112
	 */
1113
	private boolean hasSnapshot(String projectName) {
1114
		if (projectName == null) {
1115
			return false;
1116
		}
1117
 		final IPath snapshotPath = new Path(directorySnapshotPathField
1118
 				.getText().trim());
1119
		IPath zipPath = snapshotPath.append(projectName + "-index.zip");	//$NON-NLS-1$
1120
		return zipPath.toFile().exists();
1121
	}
1122
	/**
1123
	 * Use the dialog store to restore widget values to the values that they
1124
	 * held last time this wizard was used to completion.
1125
	 * 
1126
	 * Method declared public only for use of tests.
1127
	 */
1128
	public void restoreWidgetValues() {
1129
		IDialogSettings settings = getDialogSettings();
1130
		if (settings != null) {
1131
			recurseIntoSubFolders = settings.getBoolean(STORE_RECURSE_SUBFOLDERS);
1132
			recurseIntoSubFoldersCheckbox.setSelection(recurseIntoSubFolders);
1133
		}
1134
	}
1135
1136
	/**
1137
	 * Since Finish was pressed, write widget values to the dialog store so that
1138
	 * they will persist into the next invocation of this wizard page.
1139
	 * 
1140
	 * Method declared public only for use of tests.
1141
	 */
1142
	public void saveWidgetValues() {
1143
		IDialogSettings settings = getDialogSettings();
1144
		if (settings != null) {
1145
			settings.put(STORE_RECURSE_SUBFOLDERS, recurseIntoSubFolders);
1146
		}
1147
	}
1148
1149
}
(-)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