### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.ide Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/META-INF/MANIFEST.MF,v retrieving revision 1.51 diff -u -r1.51 MANIFEST.MF --- META-INF/MANIFEST.MF 13 Jan 2010 18:45:45 -0000 1.51 +++ META-INF/MANIFEST.MF 14 Apr 2010 21:53:14 -0000 @@ -34,6 +34,7 @@ org.eclipse.ui.internal.views.tasklist;x-internal:=true, org.eclipse.ui.internal.wizards.datatransfer;x-internal:=true, org.eclipse.ui.internal.wizards.newresource;x-internal:=true, + org.eclipse.ui.internal.wizards.refreshsnapshot;x-internal:=true, org.eclipse.ui.model, org.eclipse.ui.part, org.eclipse.ui.views.bookmarkexplorer, Index: plugin.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.properties,v retrieving revision 1.155 diff -u -r1.155 plugin.properties --- plugin.properties 4 Feb 2010 19:44:08 -0000 1.155 +++ plugin.properties 14 Apr 2010 21:53:13 -0000 @@ -28,9 +28,11 @@ ExportWizards.FileSystem = File System ExportWizards.Preferences = Preferences ExportWizards.ZipFile = Archive File +ExportWizards.ProjectRefreshSnapshot = Project Refresh Snapshot ExportWizards.FileSystemDescription = Export resources to the local file system. ExportWizards.PreferencesDescription = Export preferences to the local file system. ExportWizards.ZipFileDescription = Export resources to an archive file on the local file system. +ExportWizards.ProjectRefreshSnapshotDescription = Export a refresh snapshot from selected projects for trusted import in other workspaces. ImportWizards.FileSystem = File System ImportWizards.Preferences = Preferences ImportWizards.ZipFile = Archive File @@ -38,7 +40,9 @@ ImportWizards.FileSystemDescription = Import resources from the local file system into an existing project. ImportWizards.PreferencesDescription = Import preferences from the local file system. ImportWizards.ZipFileDescription = Import resources from an archive file into an existing project. -ImportWizards.ExternalProjectDescription = Create new projects from an archive file or directory. +ImportWizards.ExternalProjectDescription = Create new projects from an archive file or directory. +ImportWizards.ProjectRefreshSnapshot = Project Refresh Snapshot +ImportWizards.ProjectRefreshSnapshotDescription = Import project with refresh snapshot NewWizards.Category.Examples = Examples NewWizards.Category.Basic = General NewWizards.project = Project Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.xml,v retrieving revision 1.302 diff -u -r1.302 plugin.xml --- plugin.xml 8 Mar 2010 21:48:22 -0000 1.302 +++ plugin.xml 14 Apr 2010 21:53:14 -0000 @@ -75,6 +75,16 @@ id="org.eclipse.ui.ide.archive"> + + + %ImportWizards.ProjectRefreshSnapshotDescription + + @@ -132,6 +142,19 @@ id="org.eclipse.ui.ide.project"> + + + + + %ExportWizards.ProjectRefreshSnapshotDescription + + Index: src/org/eclipse/ui/internal/wizards/refreshsnapshot/Messages.java =================================================================== RCS file: src/org/eclipse/ui/internal/wizards/refreshsnapshot/Messages.java diff -N src/org/eclipse/ui/internal/wizards/refreshsnapshot/Messages.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/wizards/refreshsnapshot/Messages.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2010 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Francis Lynch (Wind River) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui.internal.wizards.refreshsnapshot; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages for refresh snapshot wizards + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.ui.internal.wizards.refreshsnapshot.messages"; //$NON-NLS-1$ + + // + public static String ProjectRefreshSnapshotExportWizard_exportTitle; + public static String ProjectRefreshSnapshotExportWizardPage_title; + public static String ProjectRefreshSnapshotExportWizardPage_description; + public static String ProjectRefreshSnapshotExportWizardPage_selectProjects; + public static String ProjectRefreshSnapshotExportWizardPage_selectAll; + public static String ProjectRefreshSnapshotExportWizardPage_deselectAll; + public static String ProjectRefreshSnapshotExportWizardPage_errorsOccurred; + public static String ProjectRefreshSnapshotExportWizardPage_needProjectSelected; + public static String ProjectRefreshSnapshotExportWizardPage_errorDialogTitle; + public static String ProjectRefreshSnapshotExportWizardPage_selectSnapshot; + public static String ProjectRefreshSnapshotExportWizardPage_snapshotBrowse; + public static String ProjectRefreshSnapshotExportWizardPage_browseSnapshot; + public static String ProjectRefreshSnapshotExportWizardPage_overwrite; + public static String ProjectRefreshSnapshotExportWizardPage_question; + + public static String ProjectRefreshSnapshotImportWizard_importTitle; + public static String ProjectRefreshSnapshotImportWizardPage_projectLabel; + public static String ProjectRefreshSnapshotImportWizardPage_title; + public static String ProjectRefreshSnapshotImportWizardPage_description; + public static String ProjectRefreshSnapshotImportWizardPage_selectProject; + public static String ProjectRefreshSnapshotImportWizardPage_selectSnapshot; + public static String ProjectRefreshSnapshotImportWizardPage_sourceBrowse; + public static String ProjectRefreshSnapshotImportWizardPage_sourceDirectory; + public static String ProjectRefreshSnapshotImportWizardPage_snapshotBrowse; + public static String ProjectRefreshSnapshotImportWizardPage_selectProjects; + public static String ProjectRefreshSnapshotImportWizardPage_searching; + public static String ProjectRefreshSnapshotImportWizardPage_processing; + public static String ProjectRefreshSnapshotImportWizardPage_hiddenProjects; + public static String ProjectRefreshSnapshotImportWizardPage_internalError; + public static String ProjectRefreshSnapshotImportWizardPage_snapshotError; + public static String ProjectRefreshSnapshotImportWizardPage_checking; + public static String ProjectRefreshSnapshotImportWizardPage_browseSource; + public static String ProjectRefreshSnapshotImportWizardPage_browseSnapshot; + public static String ProjectRefreshSnapshotImportWizardPage_creationProblems; + public static String ProjectRefreshSnapshotImportWizardPage_createProjectsTask; + public static String ProjectRefreshSnapshotImportWizardPage_overwrite; + public static String ProjectRefreshSnapshotImportWizardPage_overwriteInFolder; + public static String ProjectRefreshSnapshotImportWizardPage_question; + public static String ProjectRefreshSnapshotImportWizardPage_noSnapshotFound; + + static { + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + +} Index: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizard.java =================================================================== RCS file: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizard.java diff -N src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizard.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizard.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + * Francis Lynch (Wind River) - adapted from CDT TeamSharedExportWizard + *******************************************************************************/ + +package org.eclipse.ui.internal.wizards.refreshsnapshot; + +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IExportWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; +import org.eclipse.ui.internal.wizards.refreshsnapshot.Messages; + +/** + * Wizard to create refresh snapshots + * + */ +public class ProjectRefreshSnapshotExportWizard extends Wizard implements IExportWizard { + private static final String DIALOG_SETTINGS_SECTION = "ProjectRefreshSnapshotExportWizard"; //$NON-NLS-1$ + private ProjectRefreshSnapshotExportWizardPage fMainPage; + private IStructuredSelection fSelection; + + /** + * + */ + public ProjectRefreshSnapshotExportWizard() { + IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault().getDialogSettings(); + IDialogSettings section = workbenchSettings.getSection(DIALOG_SETTINGS_SECTION); + if (section == null) { + section = workbenchSettings.addNewSection(DIALOG_SETTINGS_SECTION); + } + setDialogSettings(section); + } + + //@Override + public void addPages() { + super.addPages(); + fMainPage = new ProjectRefreshSnapshotExportWizardPage(fSelection); + addPage(fMainPage); + } + + //@Override + public boolean performFinish() { + return fMainPage.finish(); + } + + public void init(IWorkbench workbench, IStructuredSelection selection) { + fSelection= selection; + setWindowTitle(Messages.ProjectRefreshSnapshotExportWizard_exportTitle); + setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/exportzip_wiz.png")); //$NON-NLS-1$ + setNeedsProgressMonitor(true); + } + +} Index: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizardPage.java =================================================================== RCS file: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizardPage.java diff -N src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizardPage.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotExportWizardPage.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,499 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + * Francis Lynch (Wind River) - adapted from CDT TeamSharedExportWizardPage + *******************************************************************************/ +package org.eclipse.ui.internal.wizards.refreshsnapshot; + +import java.io.File; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.WizardDataTransferPage; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.internal.wizards.refreshsnapshot.Messages; + +/** + * The wizard page for export refresh snapshot + * + */ +public class ProjectRefreshSnapshotExportWizardPage extends WizardDataTransferPage { + + private IStructuredSelection fInitialSelection; + private CheckboxTableViewer fProjectViewer; + private Text directorySnapshotPathField; + private Button browseSnapshotDirectoryButton; + // Keep track of the directory that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedSnapshotDirectory = ""; //$NON-NLS-1$ + + + /** + * Create an instance of this class + */ + protected ProjectRefreshSnapshotExportWizardPage(String name, IStructuredSelection selection) { + super(name); + fInitialSelection= selection; + } + + /** + * Create an instance of this class. + * + * @param selection the selection + */ + public ProjectRefreshSnapshotExportWizardPage(IStructuredSelection selection) { + this("refreshSnapshotExportPage", selection); //$NON-NLS-1$ + setTitle(Messages.ProjectRefreshSnapshotExportWizardPage_title); + setDescription(Messages.ProjectRefreshSnapshotExportWizardPage_description); + } + + public void createControl(Composite parent) { + initializeDialogUnits(parent); + + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL + | GridData.HORIZONTAL_ALIGN_FILL)); + composite.setFont(parent.getFont()); + + createResourcesGroup(composite); + createSnapshotArea(composite); + + restoreWidgetValues(); + if (fInitialSelection != null) { + setupBasedOnInitialSelections(); + } + + updateWidgetEnablements(); + setPageComplete(determinePageCompletion()); + setErrorMessage(null); // should not initially have error message + + setControl(composite); + } + + private void checkForComplete() { + if (fProjectViewer.getCheckedElements().length > 0) { + String path = directorySnapshotPathField.getText().trim(); + if (path.length() > 0) { + File dirpath = new File(path); + if (dirpath.exists()) { + setPageComplete(true); + return; + } + } + } + + setPageComplete(false); + } + + /** + * Creates the checkbox tree and list for selecting resources. + * + * @param parent the parent control + */ + private final void createResourcesGroup(Composite parent) { + Composite resourcesGroup = new Composite(parent, SWT.NONE); + resourcesGroup.setLayout(new GridLayout()); + resourcesGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + resourcesGroup.setFont(parent.getFont()); + + new Label(resourcesGroup, SWT.NONE).setText(Messages.ProjectRefreshSnapshotExportWizardPage_selectProjects); + Table table= new Table(resourcesGroup, SWT.CHECK | SWT.BORDER); + table.setLayoutData(new GridData(GridData.FILL_BOTH)); + fProjectViewer= new CheckboxTableViewer(table); + fProjectViewer.setContentProvider(new IStructuredContentProvider() { + List fContents; + + public Object[] getElements(Object input) { + if (fContents != null && fContents == input) + return fContents.toArray(); + return new Object[0]; + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput instanceof List) + fContents= (List)newInput; + else + fContents= null; + // we use a fixed set. + } + + public void dispose() { + } + + + } ); + fProjectViewer.setLabelProvider(new WorkbenchLabelProvider()); + ICheckStateListener checkListener = new ICheckStateListener() { + public void checkStateChanged(CheckStateChangedEvent event) { + updateWidgetEnablements(); + } + }; + fProjectViewer.addCheckStateListener(checkListener); + + + // top level group + Composite buttonComposite = new Composite(resourcesGroup, SWT.NONE); + buttonComposite.setFont(parent.getFont()); + + GridLayout layout = new GridLayout(2, true); + layout.marginHeight= layout.marginWidth= 0; + buttonComposite.setLayout(layout); + buttonComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL + | GridData.HORIZONTAL_ALIGN_FILL)); + + + Button selectButton = createButton(buttonComposite, + IDialogConstants.SELECT_ALL_ID, Messages.ProjectRefreshSnapshotExportWizardPage_selectAll, false); + + SelectionAdapter listener = new SelectionAdapter() { + //@Override + public void widgetSelected(SelectionEvent e) { + fProjectViewer.setAllChecked(true); + updateWidgetEnablements(); + } + }; + selectButton.addSelectionListener(listener); + + Button deselectButton = createButton(buttonComposite, + IDialogConstants.DESELECT_ALL_ID, Messages.ProjectRefreshSnapshotExportWizardPage_deselectAll, false); + + listener = new SelectionAdapter() { + //@Override + public void widgetSelected(SelectionEvent e) { + fProjectViewer.setAllChecked(false); + updateWidgetEnablements(); + } + }; + deselectButton.addSelectionListener(listener); + + initProjects(); + } + + private Button createButton(Composite parent, int id, String label, + boolean defaultButton) { + Button button = new Button(parent, SWT.PUSH); + + GridData buttonData = new GridData(GridData.FILL_HORIZONTAL); + button.setLayoutData(buttonData); + + button.setData(new Integer(id)); + button.setText(label); + button.setFont(parent.getFont()); + + if (defaultButton) { + Shell shell = parent.getShell(); + if (shell != null) { + shell.setDefaultButton(button); + } + button.setFocus(); + } + button.setFont(parent.getFont()); + setButtonLayoutData(button); + return button; + } + + private void initProjects() { + ArrayList input = new ArrayList(); + IProject[] projects; + projects = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getProjects(); + for (int i = 0; i < projects.length; i++) { + if (projects[i].isOpen()) { + input.add(projects[i]); + } + } + fProjectViewer.setInput(input); + } + + private void setupBasedOnInitialSelections() { + HashSet names= new HashSet(); + Iterator it = fInitialSelection.iterator(); + while (it.hasNext()) { + IProject project = (IProject) it.next(); + names.add(project.getName()); + } + + Collection prjsc= (Collection) fProjectViewer.getInput(); + Object[] prjs= prjsc.toArray(); + for (int i = 0; i < prjs.length; i++) { + Object element = prjs[i]; + IProject prj = (IProject) element; + if (names.contains(prj.getName())) { + fProjectViewer.setChecked(prj, true); + } + } + } + + /** + * Create the area to specify the snapshot directory. + * + * @param workArea + */ + private void createSnapshotArea(Composite workArea) { + // project specification group + Composite snapshotGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + snapshotGroup.setLayout(layout); + snapshotGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label title = new Label(snapshotGroup, SWT.NONE); + title.setText(Messages.ProjectRefreshSnapshotExportWizardPage_selectSnapshot); + + // refresh snapshot directory location entry field + this.directorySnapshotPathField = new Text(snapshotGroup, SWT.BORDER); + + this.directorySnapshotPathField.setLayoutData(new GridData( + GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); + + // browse button + browseSnapshotDirectoryButton = new Button(snapshotGroup, SWT.PUSH); + browseSnapshotDirectoryButton + .setText(Messages.ProjectRefreshSnapshotExportWizardPage_snapshotBrowse); + setButtonLayoutData(browseSnapshotDirectoryButton); + + browseSnapshotDirectoryButton + .addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationSnapshotDirectoryButtonPressed(); + } + }); + + directorySnapshotPathField + .addTraverseListener(new TraverseListener() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.TraverseListener#keyTraversed( + * org.eclipse.swt.events.TraverseEvent) + */ + public void keyTraversed(TraverseEvent e) { + if (e.detail == SWT.TRAVERSE_RETURN) { + e.doit = false; + checkForComplete(); + } + } + + }); + + directorySnapshotPathField.addFocusListener(new FocusAdapter() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt + * .events.FocusEvent) + */ + public void focusLost(org.eclipse.swt.events.FocusEvent e) { + checkForComplete(); + } + + }); + + } + /** + * The browse button has been selected. Select the location. + */ + protected void handleLocationSnapshotDirectoryButtonPressed() { + + DirectoryDialog dialog = new DirectoryDialog( + directorySnapshotPathField.getShell()); + dialog + .setMessage(Messages.ProjectRefreshSnapshotExportWizardPage_browseSnapshot); + + String dirName = directorySnapshotPathField.getText().trim(); + if (dirName.length() == 0) { + dirName = previouslyBrowsedSnapshotDirectory; + } + + if (dirName.length() == 0) { + dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot() + .getLocation().toOSString()); + } else { + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + } + + String selectedDirectory = dialog.open(); + if (selectedDirectory != null) { + previouslyBrowsedSnapshotDirectory = selectedDirectory; + directorySnapshotPathField + .setText(previouslyBrowsedSnapshotDirectory); + checkForComplete(); + } + + } + + + /** + * @return Return true to indicate that the operation was a success + * + */ + public boolean finish() { + IProject[] projectsToSnapshot= getCheckedElements(); + + // about to invoke the operation so save our state + saveWidgetValues(); + + return executeSnapshotOperation(projectsToSnapshot); + } + + private IProject[] getCheckedElements() { + Object[] obj= fProjectViewer.getCheckedElements(); + IProject[] prjs= new IProject[obj.length]; + System.arraycopy(obj, 0, prjs, 0, obj.length); + return prjs; + } + + private boolean executeSnapshotOperation(final IProject[] projects) { + final MultiStatus status= new MultiStatus(IDEWorkbenchPlugin.IDE_WORKBENCH, + 0, Messages.ProjectRefreshSnapshotExportWizardPage_errorsOccurred, null); + + final IPath snapshotPath = new Path(directorySnapshotPathField + .getText().trim()); + for (int i = 0; i < projects.length; i++) { + IProject project = projects[i]; + try { + String projectName = project.getName(); + boolean cancelled = false; + IPath zipPath = snapshotPath.append(projectName + "-index.zip"); //$NON-NLS-1$ + if (zipPath.toFile().exists()) { + String[] buttons = new String[] { IDialogConstants.YES_LABEL, + IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; + String question = NLS.bind( + Messages.ProjectRefreshSnapshotExportWizardPage_overwrite, zipPath + .toString()); + MessageDialog d = new MessageDialog(getShell(), + Messages.ProjectRefreshSnapshotExportWizardPage_question, + null, question, MessageDialog.QUESTION, buttons, 0) { + protected int getShellStyle() { + return super.getShellStyle() | SWT.SHEET; + } + }; + int overwrite = d.open(); + switch (overwrite) { + case 0: // Yes + break; + case 1: // No + continue; + case 2: // Cancel + default: + cancelled = true; + break; + } + } + if (cancelled) break; + URI snapshotLocation = org.eclipse.core.filesystem.URIUtil.toURI(zipPath); + project.saveSnapshot(IProject.SNAPSHOT_TREE, snapshotLocation, null); + } + catch (CoreException e) { + status.merge(e.getStatus()); + } + } + if (!status.isOK()) { + IDEWorkbenchPlugin.log("",status); //$NON-NLS-1$ + ErrorDialog.openError(getContainer().getShell(), + getErrorDialogTitle(), + null, // no special message + status); + return false; + } + + return true; + } + + + //@Override + protected boolean validateSourceGroup() { + // there must be some resources selected for Export + boolean isValid = true; + Object[] projectsToExport = getCheckedElements(); + if (projectsToExport.length == 0){ + setErrorMessage(Messages.ProjectRefreshSnapshotExportWizardPage_needProjectSelected); + isValid = false; + } else { + setErrorMessage(null); + } + return super.validateSourceGroup() && isValid; + } + + //@Override + protected void updateWidgetEnablements() { + boolean pageComplete = determinePageCompletion(); + setPageComplete(pageComplete); + if (pageComplete) { + setMessage(null); + } + super.updateWidgetEnablements(); + } + + + public void handleEvent(Event event) { + updateWidgetEnablements(); + } + + //@Override + protected String getErrorDialogTitle() { + return Messages.ProjectRefreshSnapshotExportWizardPage_errorDialogTitle; + } + + //@Override + protected boolean allowNewContainerName() { + return false; + } +} Index: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizard.java =================================================================== RCS file: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizard.java diff -N src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizard.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizard.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Francis Lynch (Wind River) - adapted from standard project import + *******************************************************************************/ +package org.eclipse.ui.internal.wizards.refreshsnapshot; + +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; + +/** + * Wizard for importing projects with a refresh snapshot into the Eclipse + * workspace. Allows specification of the URI for the project refresh snapshot. + * Currently, that URI is assumed to contain a file named -index.zip + * that was created by the export refresh snapshot wizard. + *

+ * This class may be instantiated and used without further configuration; this + * class is not intended to be subclassed. + *

+ */ + +public class ProjectRefreshSnapshotImportWizard extends Wizard implements + IImportWizard { + private static final String EXTERNAL_PROJECT_SECTION = "ProjectRefreshSnapshotImportWizard";//$NON-NLS-1$ + private ProjectRefreshSnapshotImportWizardPage mainPage; + + /** + * Constructor for ProjectRefreshSnapshotImportWizard. + */ + public ProjectRefreshSnapshotImportWizard() { + super(); + setNeedsProgressMonitor(true); + IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault() + .getDialogSettings(); + + IDialogSettings wizardSettings = workbenchSettings + .getSection(EXTERNAL_PROJECT_SECTION); + if (wizardSettings == null) { + wizardSettings = workbenchSettings + .addNewSection(EXTERNAL_PROJECT_SECTION); + } + setDialogSettings(wizardSettings); + } + + /* + * (non-Javadoc) Method declared on IWizard. + */ + public void addPages() { + super.addPages(); + mainPage = new ProjectRefreshSnapshotImportWizardPage(); + addPage(mainPage); + } + + /* + * (non-Javadoc) Method declared on IWorkbenchWizard. + */ + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + setWindowTitle(Messages.ProjectRefreshSnapshotImportWizard_importTitle); + setDefaultPageImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("wizban/importproj_wiz.png")); //$NON-NLS-1$ + } + + /* + * (non-Javadoc) Method declared on IWizard. + */ + public boolean performCancel() { + mainPage.performCancel(); + return true; + } + + /* + * (non-Javadoc) Method declared on IWizard. + */ + public boolean performFinish() { + return mainPage.createProjects(); + } + +} Index: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizardPage.java =================================================================== RCS file: src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizardPage.java diff -N src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizardPage.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/wizards/refreshsnapshot/ProjectRefreshSnapshotImportWizardPage.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1088 @@ +/******************************************************************************* + * Copyright (c) 2004, 2010 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Red Hat, Inc - extensive changes to allow importing of Archive Files + * Philippe Ombredanne (pombredanne@nexb.com) + * - Bug 101180 [Import/Export] Import Existing Project into Workspace default widget is back button , should be text field + * Martin Oberhuber (martin.oberhuber@windriver.com) + * - Bug 187318[Wizards] "Import Existing Project" loops forever with cyclic symbolic links + * Remy Chi Jian Suen (remy.suen@gmail.com) + * - Bug 210568 [Import/Export] [Import/Export] - Refresh button does not update list of projects + * Francis Lynch (Wind River) - adapted from standard project import wizard + *******************************************************************************/ +package org.eclipse.ui.internal.wizards.refreshsnapshot; + +import java.io.*; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.OperationCanceledException; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +//import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.actions.WorkspaceModifyOperation; +import org.eclipse.ui.dialogs.IOverwriteQuery; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; + +/** + * The ProjectRefreshSnapshotImportWizardPage is the page that allows the user to import + * projects from a particular location with refresh snapshots. + */ +public class ProjectRefreshSnapshotImportWizardPage extends WizardPage implements + IOverwriteQuery { + + /** + * Class declared public only for test suite. + * + */ + public class ProjectRecord { + File projectSystemFile; + + String projectName; + + Object parent; + + int level; + + IProjectDescription description; + + /** + * Create a record for a project based on the info in the file. + * + * @param file + */ + ProjectRecord(File file) { + projectSystemFile = file; + setProjectName(); + } + + /** + * Set the name of the project based on the projectFile. + */ + private void setProjectName() { + try { + + // If we don't have the project name try again + if (projectName == null) { + IPath path = new Path(projectSystemFile.getPath()); + // if the file is in the default location, use the directory + // name as the project name + if (isDefaultLocation(path)) { + projectName = path.segment(path.segmentCount() - 2); + description = IDEWorkbenchPlugin.getPluginWorkspace() + .newProjectDescription(projectName); + } else { + description = IDEWorkbenchPlugin.getPluginWorkspace() + .loadProjectDescription(path); + projectName = description.getName(); + } + + } + } catch (CoreException e) { + // no good couldn't get the name + } + } + + /** + * Returns whether the given project description file path is in the + * default location for a project + * + * @param path + * The path to examine + * @return Whether the given path is the default location for a project + */ + private boolean isDefaultLocation(IPath path) { + // The project description file must at least be within the project, + // which is within the workspace location + if (path.segmentCount() < 2) + return false; + return path.removeLastSegments(2).toFile().equals( + Platform.getLocation().toFile()); + } + + /** + * Get the name of the project + * + * @return String + */ + public String getProjectName() { + return projectName; + } + + /** + * Gets the label to be used when rendering this project record in the + * UI. + * + * @return String the label + * @since 3.4 + */ + public String getProjectLabel() { + if (description == null) + return projectName; + + String path = projectSystemFile.getParent(); + + return NLS + .bind( + Messages.ProjectRefreshSnapshotImportWizardPage_projectLabel, + projectName, path); + } + } + + // dialog store id constants + private Text directoryPathField; + + private Text directorySnapshotPathField; + + private CheckboxTreeViewer projectsList; + + private ProjectRecord[] selectedProjects = new ProjectRecord[0]; + + // Keep track of the directory that we browsed to last time + // the wizard was invoked. + private static String previouslyBrowsedDirectory = ""; //$NON-NLS-1$ + + private static String previouslyBrowsedSnapshotDirectory = ""; //$NON-NLS-1$ + + private Button browseDirectoriesButton; + + private Button browseSnapshotDirectoryButton; + + private IProject[] wsProjects; + + // The last selected path to minimize searches + private String lastPath; + + // The last time that the file or folder at the selected path was modified + // to minimize searches + private long lastModified; + + /** + * Creates a new project creation wizard page. + * + */ + public ProjectRefreshSnapshotImportWizardPage() { + this("refreshSnapshotImportPage"); //$NON-NLS-1$ + } + + /** + * Create a new instance of the receiver. + * + * @param pageName + */ + public ProjectRefreshSnapshotImportWizardPage(String pageName) { + super(pageName); + setPageComplete(false); + setTitle(Messages.ProjectRefreshSnapshotImportWizardPage_title); + setDescription(Messages.ProjectRefreshSnapshotImportWizardPage_description); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets + * .Composite) + */ + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite workArea = new Composite(parent, SWT.NONE); + setControl(workArea); + + workArea.setLayout(new GridLayout()); + workArea.setLayoutData(new GridData(GridData.FILL_BOTH + | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL)); + + createProjectsRoot(workArea); + createProjectsList(workArea); + createSnapshotArea(workArea); + restoreWidgetValues(); + Dialog.applyDialogFont(workArea); + + } + + private void checkForComplete() { + if (projectsList.getCheckedElements().length == 1) { + String path = directorySnapshotPathField.getText().trim(); + if (path.length() > 0) { + File dirpath = new File(path); + if (dirpath.exists()) { + setPageComplete(true); + return; + } + } + } + + setPageComplete(false); + } + + /** + * Create the checkbox list for the found projects. + * + * @param workArea + */ + private void createProjectsList(Composite workArea) { + + Label title = new Label(workArea, SWT.NONE); + title.setText(Messages.ProjectRefreshSnapshotImportWizardPage_selectProject); + + Composite listComposite = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginWidth = 0; + layout.makeColumnsEqualWidth = false; + listComposite.setLayout(layout); + + listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL + | GridData.GRAB_VERTICAL | GridData.FILL_BOTH)); + + projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER); + GridData listData = new GridData(GridData.GRAB_HORIZONTAL + | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); + listData.heightHint = 100; + projectsList.getControl().setLayoutData(listData); + + projectsList.setContentProvider(new ITreeContentProvider() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java + * .lang.Object) + */ + public Object[] getChildren(Object parentElement) { + return null; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.IStructuredContentProvider#getElements + * (java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + return getValidProjects(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java + * .lang.Object) + */ + public boolean hasChildren(Object element) { + return false; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java + * .lang.Object) + */ + public Object getParent(Object element) { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse + * .jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, + Object newInput) { + } + + }); + + projectsList.setLabelProvider(new LabelProvider() { + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + return ((ProjectRecord) element).getProjectLabel(); + } + }); + + projectsList.addCheckStateListener(new ICheckStateListener() { + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged + * (org.eclipse.jface.viewers.CheckStateChangedEvent) + */ + public void checkStateChanged(CheckStateChangedEvent event) { + checkForComplete(); + } + }); + + projectsList.setInput(this); + projectsList.setComparator(new ViewerComparator()); + } + + /** + * Create the area to specify the snapshot directory. + * + * @param workArea + */ + private void createSnapshotArea(Composite workArea) { + + // project specification group + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label title = new Label(projectGroup, SWT.NONE); + title.setText(Messages.ProjectRefreshSnapshotImportWizardPage_selectSnapshot); + + // refresh snapshot directory location entry field + this.directorySnapshotPathField = new Text(projectGroup, SWT.BORDER); + + this.directorySnapshotPathField.setLayoutData(new GridData( + GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); + + // browse button + browseSnapshotDirectoryButton = new Button(projectGroup, SWT.PUSH); + browseSnapshotDirectoryButton + .setText(Messages.ProjectRefreshSnapshotImportWizardPage_snapshotBrowse); + setButtonLayoutData(browseSnapshotDirectoryButton); + + browseSnapshotDirectoryButton + .addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationSnapshotDirectoryButtonPressed(); + } + }); + + directorySnapshotPathField + .addTraverseListener(new TraverseListener() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.TraverseListener#keyTraversed( + * org.eclipse.swt.events.TraverseEvent) + */ + public void keyTraversed(TraverseEvent e) { + if (e.detail == SWT.TRAVERSE_RETURN) { + e.doit = false; + checkForComplete(); + } + } + + }); + + directorySnapshotPathField.addFocusListener(new FocusAdapter() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt + * .events.FocusEvent) + */ + public void focusLost(org.eclipse.swt.events.FocusEvent e) { + checkForComplete(); + } + + }); + + } + + /** + * Create the area where you select the root directory for the projects. + * + * @param workArea + * Composite + */ + private void createProjectsRoot(Composite workArea) { + + // project specification group + Composite projectGroup = new Composite(workArea, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + layout.makeColumnsEqualWidth = false; + layout.marginWidth = 0; + projectGroup.setLayout(layout); + projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label dirTitle = new Label(projectGroup, SWT.NONE); + dirTitle.setText(Messages.ProjectRefreshSnapshotImportWizardPage_sourceDirectory); + + // project location entry field + this.directoryPathField = new Text(projectGroup, SWT.BORDER); + + this.directoryPathField.setLayoutData(new GridData( + GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL)); + + // browse button + browseDirectoriesButton = new Button(projectGroup, SWT.PUSH); + browseDirectoriesButton + .setText(Messages.ProjectRefreshSnapshotImportWizardPage_sourceBrowse); + setButtonLayoutData(browseDirectoriesButton); + + browseDirectoriesButton.addSelectionListener(new SelectionAdapter() { + /* + * (non-Javadoc) + * + * @see org.eclipse.swt.events.SelectionAdapter#widgetS + * elected(org.eclipse.swt.events.SelectionEvent) + */ + public void widgetSelected(SelectionEvent e) { + handleLocationDirectoryButtonPressed(); + } + + }); + + directoryPathField.addTraverseListener(new TraverseListener() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse + * .swt.events.TraverseEvent) + */ + public void keyTraversed(TraverseEvent e) { + if (e.detail == SWT.TRAVERSE_RETURN) { + e.doit = false; + updateProjectsList(directoryPathField.getText().trim()); + } + } + + }); + + directoryPathField.addFocusListener(new FocusAdapter() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt + * .events.FocusEvent) + */ + public void focusLost(org.eclipse.swt.events.FocusEvent e) { + updateProjectsList(directoryPathField.getText().trim()); + } + + }); + } + + /* + * (non-Javadoc) Method declared on IDialogPage. Set the focus on path + * fields when page becomes visible. + */ + public void setVisible(boolean visible) { + super.setVisible(visible); + if (visible) { + this.directoryPathField.setFocus(); + } + } + + /** + * Update the list of projects based on path. Method declared public only + * for test suite. + * + * @param path + */ + public void updateProjectsList(final String path) { + // on an empty path empty selectedProjects + if (path == null || path.length() == 0) { + setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_selectProjects); + selectedProjects = new ProjectRecord[0]; + projectsList.refresh(true); + projectsList.setCheckedElements(selectedProjects); + checkForComplete(); + lastPath = path; + return; + } + + final File directory = new File(path); + long modified = directory.lastModified(); + if (path.equals(lastPath) && lastModified == modified) { + // since the file/folder was not modified and the path did not + // change, no refreshing is required + return; + } + + lastPath = path; + lastModified = modified; + + try { + getContainer().run(true, true, new IRunnableWithProgress() { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.operation.IRunnableWithProgress#run(org + * .eclipse.core.runtime.IProgressMonitor) + */ + public void run(IProgressMonitor monitor) { + + boolean dirSelected = true; + + monitor.beginTask( + Messages.ProjectRefreshSnapshotImportWizardPage_searching, + 100); + selectedProjects = new ProjectRecord[0]; + Collection files = new ArrayList(); + monitor.worked(10); + + File dirpath = new File(path); + if (dirpath.exists()) { + dirSelected = true; + } + + if (dirSelected && directory.isDirectory()) { + + if (!collectProjectFilesFromDirectory(files, directory, + monitor)) { + return; + } + Iterator filesIterator = files.iterator(); + selectedProjects = new ProjectRecord[files.size()]; + int index = 0; + monitor.worked(50); + monitor.subTask(Messages.ProjectRefreshSnapshotImportWizardPage_processing); + while (filesIterator.hasNext()) { + File file = (File) filesIterator.next(); + selectedProjects[index] = new ProjectRecord(file); + index++; + } + } else { + monitor.worked(60); + } + monitor.done(); + } + + }); + } catch (InvocationTargetException e) { + IDEWorkbenchPlugin.log(e.getMessage(), e); + } catch (InterruptedException e) { + // Nothing to do if the user interrupts. + } + + projectsList.refresh(true); + projectsList.setCheckedElements(getValidProjects()); + if (getValidProjects().length < selectedProjects.length) { + setMessage( + Messages.ProjectRefreshSnapshotImportWizardPage_hiddenProjects, + WARNING); + } else { + setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_description); + } + checkForComplete(); + } + + /** + * Display an error dialog with the specified message. + * + * @param message + * the error message + */ + protected void displayErrorDialog(String message) { + MessageDialog.openError(getContainer().getShell(), + getErrorDialogTitle(), message); + } + + /** + * Get the title for an error dialog. Subclasses should override. + */ + protected String getErrorDialogTitle() { + return Messages.ProjectRefreshSnapshotImportWizardPage_internalError; + } + + /** + * Get the title for an error dialog. Subclasses should override. + */ + protected String getInformationDialogTitle() { + return Messages.ProjectRefreshSnapshotImportWizardPage_snapshotError; + } + + /** + * Collect the list of .project files that are under directory into files. + * To avoid potential performance degradation on slow file systems, only + * the files in this directory are collected; no recursion into subdirectories + * is performed. + * + * @param files + * @param directory + * @param monitor + * The monitor to report to + * @return boolean true if the operation was completed. + */ + private boolean collectProjectFilesFromDirectory(Collection files, + File directory, IProgressMonitor monitor) { + + if (monitor.isCanceled()) { + return false; + } + monitor.subTask(NLS.bind( + Messages.ProjectRefreshSnapshotImportWizardPage_checking, + directory.getPath())); + File[] contents = directory.listFiles(); + if (contents == null) + return false; + + // first look for project description files + final String dotProject = IProjectDescription.DESCRIPTION_FILE_NAME; + for (int i = 0; i < contents.length; i++) { + File file = contents[i]; + if (file.isFile() && file.getName().equals(dotProject)) { + files.add(file); + // don't search sub-directories since we can't have nested + // projects + return true; + } + } + return true; + + } + + /** + * The browse button has been selected. Select the location. + */ + protected void handleLocationDirectoryButtonPressed() { + + DirectoryDialog dialog = new DirectoryDialog(directoryPathField + .getShell()); + dialog + .setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_browseSource); + + String dirName = directoryPathField.getText().trim(); + if (dirName.length() == 0) { + dirName = previouslyBrowsedDirectory; + } + + if (dirName.length() == 0) { + dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot() + .getLocation().toOSString()); + } else { + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + } + + String selectedDirectory = dialog.open(); + if (selectedDirectory != null) { + previouslyBrowsedDirectory = selectedDirectory; + directoryPathField.setText(previouslyBrowsedDirectory); + updateProjectsList(selectedDirectory); + } + + } + + /** + * The browse button has been selected. Select the location. + */ + protected void handleLocationSnapshotDirectoryButtonPressed() { + + DirectoryDialog dialog = new DirectoryDialog( + directorySnapshotPathField.getShell()); + dialog + .setMessage(Messages.ProjectRefreshSnapshotImportWizardPage_browseSnapshot); + + String dirName = directorySnapshotPathField.getText().trim(); + if (dirName.length() == 0) { + dirName = previouslyBrowsedSnapshotDirectory; + } + + if (dirName.length() == 0) { + dialog.setFilterPath(IDEWorkbenchPlugin.getPluginWorkspace().getRoot() + .getLocation().toOSString()); + } else { + File path = new File(dirName); + if (path.exists()) { + dialog.setFilterPath(new Path(dirName).toOSString()); + } + } + + String selectedDirectory = dialog.open(); + if (selectedDirectory != null) { + previouslyBrowsedSnapshotDirectory = selectedDirectory; + directorySnapshotPathField + .setText(previouslyBrowsedSnapshotDirectory); + checkForComplete(); + } + + } + + /** + * Create the selected projects + * + * @return boolean true if all project creations were + * successful. + */ + public boolean createProjects() { + + saveWidgetValues(); + + final Object[] selected = projectsList.getCheckedElements(); + final IPath snapshotPath = new Path(directorySnapshotPathField + .getText().trim()); + /* verify that the projects selected have snapshots in the specified directory */ + boolean cancelled = false; + final ProjectRecord[] projects = new ProjectRecord[selected.length]; + int j = 0; + for (int i = 0; i < selected.length; i++) { + ProjectRecord project = (ProjectRecord) selected[i]; + IPath zipPath = snapshotPath.append(project.getProjectName() + "-index.zip"); //$NON-NLS-1$ + if (!zipPath.toFile().exists()) { + String[] buttons = new String[] { IDialogConstants.YES_LABEL, + IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; + String question = Messages.ProjectRefreshSnapshotImportWizardPage_noSnapshotFound; + MessageDialog d = new MessageDialog(getShell(), + Messages.ProjectRefreshSnapshotImportWizardPage_question, + null, question, MessageDialog.QUESTION, buttons, 0) { + protected int getShellStyle() { + return super.getShellStyle() | SWT.SHEET; + } + }; + int option = d.open(); + switch (option) { + case 0: // Yes + break; + case 1: // No + continue; + case 2: // Cancel + default: + cancelled = true; + break; + } + } + if (cancelled) break; + projects[j++] = project; + } + + if (cancelled || j == 0) { + return true; + } + WorkspaceModifyOperation op = new WorkspaceModifyOperation() { + protected void execute(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + try { + monitor.beginTask("", selected.length); //$NON-NLS-1$ + if (monitor.isCanceled()) { + throw new OperationCanceledException(); + } + for (int i = 0; i < projects.length; i++) { + ProjectRecord project = projects[i]; + if (project != null) { + createExistingProject(project, snapshotPath, new SubProgressMonitor(monitor, 1)); + } + } + } finally { + monitor.done(); + } + } + }; + // run the new project creation operation + try { + getContainer().run(true, true, op); + } catch (InterruptedException e) { + return false; + } catch (InvocationTargetException e) { + // one of the steps resulted in a core exception + Throwable t = e.getTargetException(); + String message = Messages.ProjectRefreshSnapshotImportWizardPage_creationProblems; + IStatus status; + if (t instanceof CoreException) { + status = ((CoreException) t).getStatus(); + } else { + status = new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, 1, + message, t); + } + ErrorDialog.openError(getShell(), message, null, status); + return false; + } + return true; + } + + /** + * Performs clean-up if the user cancels the wizard without doing anything + */ + public void performCancel() { + } + + /** + * Create the project described in record. If it is successful return true. + * + * @param record + * @return boolean true if successful + * @throws InterruptedException + */ + private boolean createExistingProject(final ProjectRecord record, + IPath snapshotPath, IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException + { + String projectName = record.getProjectName(); + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final IProject project = workspace.getRoot().getProject(projectName); + if (record.description == null) + { + // error case + record.description = workspace.newProjectDescription(projectName); + IPath locationPath = new Path(record.projectSystemFile + .getAbsolutePath()); + + // If it is under the root use the default location + if (Platform.getLocation().isPrefixOf(locationPath)) + { + record.description.setLocation(null); + } + else + { + record.description.setLocation(locationPath); + } + } + else + { + record.description.setName(projectName); + } + // load snapshot and open project + try + { + monitor + .beginTask( + Messages.ProjectRefreshSnapshotImportWizardPage_createProjectsTask, + 100); + project.create(record.description, new SubProgressMonitor(monitor, + 30)); + IPath zipPath = snapshotPath.append(projectName + "-index.zip"); //$NON-NLS-1$ + URI snapshotLocation = org.eclipse.core.filesystem.URIUtil.toURI(zipPath); + project.loadSnapshot(IProject.SNAPSHOT_TREE, snapshotLocation, + new SubProgressMonitor(monitor, 40)); + project.open(IResource.NONE, new SubProgressMonitor(monitor, 30)); + } + catch (CoreException e) + { + throw new InvocationTargetException(e); + } + finally + { + monitor.done(); + } + + return true; + } + + /** + * The WizardDataTransfer implementation of this + * IOverwriteQuery method asks the user whether the existing + * resource at the given path should be overwritten. + * + * @param pathString + * @return the user's reply: one of "YES", "NO", + * "ALL", or "CANCEL" + */ + public String queryOverwrite(String pathString) { + + Path path = new Path(pathString); + + String messageString; + // Break the message up if there is a file name and a directory + // and there are at least 2 segments. + if (path.getFileExtension() == null || path.segmentCount() < 2) { + messageString = NLS.bind( + Messages.ProjectRefreshSnapshotImportWizardPage_overwrite, + pathString); + } else { + messageString = NLS + .bind( + Messages.ProjectRefreshSnapshotImportWizardPage_overwriteInFolder, + path.lastSegment(), path.removeLastSegments(1) + .toOSString()); + } + + final MessageDialog dialog = new MessageDialog(getContainer() + .getShell(), Messages.ProjectRefreshSnapshotImportWizardPage_question, null, + messageString, MessageDialog.QUESTION, new String[] { + IDialogConstants.YES_LABEL, + IDialogConstants.YES_TO_ALL_LABEL, + IDialogConstants.NO_LABEL, + IDialogConstants.NO_TO_ALL_LABEL, + IDialogConstants.CANCEL_LABEL }, 0); + String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL }; + // run in syncExec because callback is from an operation, + // which is probably not running in the UI thread. + getControl().getDisplay().syncExec(new Runnable() { + public void run() { + dialog.open(); + } + }); + return dialog.getReturnCode() < 0 ? CANCEL : response[dialog + .getReturnCode()]; + } + + /** + * Method used for test suite. + * + * @return CheckboxTreeViewer the viewer containing all the projects found + */ + public CheckboxTreeViewer getProjectsList() { + return projectsList; + } + + /** + * Retrieve all the projects in the current workspace. + * + * @return IProject[] array of IProject in the current workspace + */ + private IProject[] getProjectsInWorkspace() { + if (wsProjects == null) { + wsProjects = IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getProjects(); + } + return wsProjects; + } + + /** + * Get the array of valid project records that can be imported from the + * source workspace or archive, selected by the user. If a project with the + * same name exists in both the source workspace and the current workspace, + * it will not appear in the list of projects to import and thus cannot be + * selected for import. + * + * Method declared public for test suite. + * + * @return ProjectRecord[] array of projects that can be imported into the + * workspace + */ + public ProjectRecord[] getValidProjects() { + List validProjects = new ArrayList(); + for (int i = 0; i < selectedProjects.length; i++) { + if (!isProjectInWorkspace(selectedProjects[i].getProjectName())) { + validProjects.add(selectedProjects[i]); + } + } + return (ProjectRecord[]) validProjects + .toArray(new ProjectRecord[validProjects.size()]); + } + + /** + * Determine if the project with the given name is in the current workspace. + * + * @param projectName + * String the project name to check + * @return boolean true if the project with the given name is in this + * workspace + */ + private boolean isProjectInWorkspace(String projectName) { + if (projectName == null) { + return false; + } + IProject[] workspaceProjects = getProjectsInWorkspace(); + for (int i = 0; i < workspaceProjects.length; i++) { + if (projectName.equals(workspaceProjects[i].getName())) { + return true; + } + } + return false; + } + + /** + * Use the dialog store to restore widget values to the values that they + * held last time this wizard was used to completion. + * + * Method declared public only for use of tests. + */ + public void restoreWidgetValues() { +// IDialogSettings settings = getDialogSettings(); +// if (settings != null) { +// } + } + + /** + * Since Finish was pressed, write widget values to the dialog store so that + * they will persist into the next invocation of this wizard page. + * + * Method declared public only for use of tests. + */ + public void saveWidgetValues() { +// IDialogSettings settings = getDialogSettings(); +// if (settings != null) { +// } + } + +} Index: src/org/eclipse/ui/internal/wizards/refreshsnapshot/messages.properties =================================================================== RCS file: src/org/eclipse/ui/internal/wizards/refreshsnapshot/messages.properties diff -N src/org/eclipse/ui/internal/wizards/refreshsnapshot/messages.properties --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/wizards/refreshsnapshot/messages.properties 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,50 @@ +############################################################################### +# Copyright (c) 2010 Wind River Systems, Inc. and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Francis Lynch (Wind River) - initial API and implementation +############################################################################### + +ProjectRefreshSnapshotExportWizard_exportTitle=Export +ProjectRefreshSnapshotExportWizardPage_title=Export Refresh Snapshots +ProjectRefreshSnapshotExportWizardPage_description=Export a refresh snapshot from selected projects for trusted import in other workspaces +ProjectRefreshSnapshotExportWizardPage_selectProjects=Select &projects to snapshot: +ProjectRefreshSnapshotExportWizardPage_selectAll=&Select All +ProjectRefreshSnapshotExportWizardPage_deselectAll=&Deselect All +ProjectRefreshSnapshotExportWizardPage_errorsOccurred=Errors occurred while exporting project refresh snapshot +ProjectRefreshSnapshotExportWizardPage_needProjectSelected=At least one project must be selected. +ProjectRefreshSnapshotExportWizardPage_errorDialogTitle=Export Project Refresh Snapshot +ProjectRefreshSnapshotExportWizardPage_selectSnapshot=&Snapshot Directory: +ProjectRefreshSnapshotExportWizardPage_snapshotBrowse=B&rowse... +ProjectRefreshSnapshotExportWizardPage_browseSnapshot=Select destination directory for refresh snapshot +ProjectRefreshSnapshotExportWizardPage_overwrite=''{0}'' already exists. Would you like to overwrite it? +ProjectRefreshSnapshotExportWizardPage_question=Question + +ProjectRefreshSnapshotImportWizard_importTitle=Import +ProjectRefreshSnapshotImportWizardPage_projectLabel={0} ({1}) +ProjectRefreshSnapshotImportWizardPage_title=Import with refresh snapshot +ProjectRefreshSnapshotImportWizardPage_description=Select a directory to search for .project files and a directory with refresh snapshot(s) +ProjectRefreshSnapshotImportWizardPage_selectProject=&Project: +ProjectRefreshSnapshotImportWizardPage_selectSnapshot=&Snapshot Directory: +ProjectRefreshSnapshotImportWizardPage_sourceBrowse=B&rowse... +ProjectRefreshSnapshotImportWizardPage_sourceDirectory=Select &source directory: +ProjectRefreshSnapshotImportWizardPage_snapshotBrowse=B&rowse... +ProjectRefreshSnapshotImportWizardPage_selectProjects=Select a directory to search for .project files +ProjectRefreshSnapshotImportWizardPage_searching=Searching for projects +ProjectRefreshSnapshotImportWizardPage_processing=Processing results +ProjectRefreshSnapshotImportWizardPage_hiddenProjects=Some projects were hidden because they exist in the workspace directory +ProjectRefreshSnapshotImportWizardPage_internalError=Internal error +ProjectRefreshSnapshotImportWizardPage_snapshotError=Refresh snapshot error +ProjectRefreshSnapshotImportWizardPage_checking=Checking: {0} +ProjectRefreshSnapshotImportWizardPage_browseSource=Select source directory of the project to import +ProjectRefreshSnapshotImportWizardPage_browseSnapshot=Select directory containing refresh snapshot +ProjectRefreshSnapshotImportWizardPage_creationProblems=Creation problems +ProjectRefreshSnapshotImportWizardPage_createProjectsTask=Creating Projects +ProjectRefreshSnapshotImportWizardPage_overwrite=''{0}'' already exists. Would you like to overwrite it? +ProjectRefreshSnapshotImportWizardPage_overwriteInFolder=Overwrite ''{0}'' in folder ''{1}''? +ProjectRefreshSnapshotImportWizardPage_question=Question +ProjectRefreshSnapshotImportWizardPage_noSnapshotFound=No refresh snapshot found. Import project anyway?