### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.ide Index: src/org/eclipse/ui/internal/wizards/datatransfer/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/messages.properties,v retrieving revision 1.19 diff -u -r1.19 messages.properties --- src/org/eclipse/ui/internal/wizards/datatransfer/messages.properties 7 Nov 2005 22:18:16 -0000 1.19 +++ src/org/eclipse/ui/internal/wizards/datatransfer/messages.properties 2 May 2006 09:36:56 -0000 @@ -50,12 +50,14 @@ FileImport_fromDirectory = From director&y: FileImport_importFileSystem = Import resources from the local file system. FileImport_overwriteExisting = &Overwrite existing resources without warning +FileImport_configuredProject = Check out as a project &configured using the New Project Wizard FileImport_createComplete = &Create complete folder structure FileImport_createSelectedFolders = Create s&elected folders only FileImport_noneSelected = There are no resources currently selected for import. FileImport_invalidSource = Source directory is not valid or has not been specified. FileImport_sourceEmpty = Source must not be empty. FileImport_importProblems = Import Problems +FileImport_needCreateProject = New project wizard didn't return a new project. ZipImport_description = Import the contents of a Zip file from the local file system. ZipImport_couldNotClose = Could not close file {0} Index: src/org/eclipse/ui/internal/wizards/datatransfer/WizardFileSystemResourceImportPage1.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardFileSystemResourceImportPage1.java,v retrieving revision 1.8 diff -u -r1.8 WizardFileSystemResourceImportPage1.java --- src/org/eclipse/ui/internal/wizards/datatransfer/WizardFileSystemResourceImportPage1.java 24 Feb 2006 17:45:41 -0000 1.8 +++ src/org/eclipse/ui/internal/wizards/datatransfer/WizardFileSystemResourceImportPage1.java 2 May 2006 09:36:56 -0000 @@ -20,6 +20,12 @@ import java.util.Map; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -54,8 +60,11 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.NewProjectAction; import org.eclipse.ui.dialogs.FileSystemElement; import org.eclipse.ui.dialogs.WizardResourceImportPage; +import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; import org.eclipse.ui.internal.ide.dialogs.IElementFilter; import org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog; import org.eclipse.ui.model.WorkbenchContentProvider; @@ -73,6 +82,8 @@ protected Button overwriteExistingResourcesCheckbox; + protected Button importAsConfiguredProjectCheckbox; + protected Button createContainerStructureButton; protected Button createOnlySelectedButton; @@ -93,6 +104,8 @@ private final static String STORE_OVERWRITE_EXISTING_RESOURCES_ID = "WizardFileSystemResourceImportPage1.STORE_OVERWRITE_EXISTING_RESOURCES_ID";//$NON-NLS-1$ + private final static String STORE_IMPORT_CONFIGURED_PROJECT = "WizardFileSystemResourceImportPage1.STORE_IMPORT_CONFIGURED_PROJECT"; //$NON-NLS-1$ + private final static String STORE_CREATE_CONTAINER_STRUCTURE_ID = "WizardFileSystemResourceImportPage1.STORE_CREATE_CONTAINER_STRUCTURE_ID";//$NON-NLS-1$ private static final String SELECT_TYPES_TITLE = DataTransferMessages.DataTransfer_selectTypes; @@ -106,7 +119,35 @@ private static final String SELECT_SOURCE_MESSAGE = DataTransferMessages.FileImport_selectSource; protected static final String SOURCE_EMPTY_MESSAGE = DataTransferMessages.FileImport_sourceEmpty; - + + /** + * This is copied from {@link org.eclipse.team.internal.ccvs.ui.wizards.CheckoutAsWizard} + */ + class NewProjectListener implements IResourceChangeListener { + private IProject newProject = null; + /** + * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) + */ + public void resourceChanged(IResourceChangeEvent event) { + IResourceDelta root = event.getDelta(); + IResourceDelta[] projectDeltas = root.getAffectedChildren(); + for (int i = 0; i < projectDeltas.length; i++) { + IResourceDelta delta = projectDeltas[i]; + IResource resource = delta.getResource(); + if (delta.getKind() == IResourceDelta.ADDED) { + newProject = (IProject)resource; + } + } + } + /** + * Gets the newProject. + * @return Returns a IProject + */ + public IProject getNewProject() { + return newProject; + } + } + /** * Creates an instance of this class */ @@ -239,32 +280,68 @@ } /** - * Create the import options specification widgets. - */ - protected void createOptionsGroupButtons(Group optionsGroup) { - - // overwrite... checkbox - overwriteExistingResourcesCheckbox = new Button(optionsGroup, SWT.CHECK); - overwriteExistingResourcesCheckbox.setFont(optionsGroup.getFont()); - overwriteExistingResourcesCheckbox.setText(DataTransferMessages.FileImport_overwriteExisting); - - // create containers radio - createContainerStructureButton = new Button(optionsGroup, SWT.RADIO); - createContainerStructureButton.setFont(optionsGroup.getFont()); - createContainerStructureButton.setText(DataTransferMessages.FileImport_createComplete); - createContainerStructureButton.setSelection(false); + * These buttons will be used by both WizardFileSystemResourceImportPage1 + * and its subclasses + * + * @param parent + * org.eclipse.swt.widgets.Composite + */ + protected void createBaseOptionsGroup(Composite parent) { + + // create import as configured project checkbox + importAsConfiguredProjectCheckbox = new Button(parent, SWT.CHECK); + importAsConfiguredProjectCheckbox + .setText(DataTransferMessages.FileImport_configuredProject); + importAsConfiguredProjectCheckbox.setFont(parent.getFont()); + importAsConfiguredProjectCheckbox + .addSelectionListener(new SelectionAdapter() { + // if the configured project checkbox is checked the name + // field and browse button should be disabled, and + // vice-versa + + public void widgetSelected(SelectionEvent e) { + boolean newState = importAsConfiguredProjectCheckbox + .getSelection(); + containerNameField.setEnabled(!newState); + containerBrowseButton.setEnabled(!newState); + updateWidgetEnablements(); + } + }); - // create selection only radio - createOnlySelectedButton = new Button(optionsGroup, SWT.RADIO); - createOnlySelectedButton.setFont(optionsGroup.getFont()); - createOnlySelectedButton.setText(DataTransferMessages.FileImport_createSelectedFolders); - createOnlySelectedButton.setSelection(true); + // overwrite... checkbox + overwriteExistingResourcesCheckbox = new Button(parent, SWT.CHECK); + overwriteExistingResourcesCheckbox + .setText(DataTransferMessages.FileImport_overwriteExisting); + overwriteExistingResourcesCheckbox.setFont(parent.getFont()); + } + + /** + * Create the specification widgets that are specific to import from file + * system. + */ + protected void createOptionsGroupButtons(Group optionsGroup) { + + createBaseOptionsGroup(optionsGroup); + + // create containers radio + createContainerStructureButton = new Button(optionsGroup, SWT.RADIO); + createContainerStructureButton.setFont(optionsGroup.getFont()); + createContainerStructureButton + .setText(DataTransferMessages.FileImport_createComplete); + createContainerStructureButton.setSelection(false); + + // create selection only radio + createOnlySelectedButton = new Button(optionsGroup, SWT.RADIO); + createOnlySelectedButton.setFont(optionsGroup.getFont()); + createOnlySelectedButton + .setText(DataTransferMessages.FileImport_createSelectedFolders); + createOnlySelectedButton.setSelection(true); - } + } /** - * Create the group for creating the root directory - */ + * Create the group for creating the root directory + */ protected void createRootDirectoryGroup(Composite parent) { Composite sourceContainerGroup = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); @@ -435,6 +512,33 @@ return true; } + /* + * @see WizardDataTransferPage.determinePageCompletion. + */ + protected boolean determinePageCompletion() { + //Check for valid projects before making the user do anything + if (noOpenProjects() && !importAsConfiguredProjectCheckbox.getSelection()) { + setErrorMessage(IDEWorkbenchMessages.WizardImportPage_noOpenProjects); + return false; + } + return super.determinePageCompletion(); + } + + /** + * Returns whether or not the passed workspace has any + * open projects + * @return boolean + */ + protected boolean noOpenProjects() { + IProject[] projects = IDEWorkbenchPlugin.getPluginWorkspace().getRoot() + .getProjects(); + for (int i = 0; i < projects.length; i++) { + if (projects[i].isOpen()) + return false; + } + return true; + } + /** * The Finish button was pressed. Try to do the required work now and answer * a boolean indicating success. If false is returned then the wizard will @@ -639,20 +743,37 @@ } /** - * Import the resources with extensions as specified by the user - */ - protected boolean importResources(List fileSystemObjects) { - ImportOperation operation = new ImportOperation(getContainerFullPath(), - getSourceDirectory(), FileSystemStructureProvider.INSTANCE, - this, fileSystemObjects); - - operation.setContext(getShell()); - return executeImportOperation(operation); - } + * Import the resources with extensions as specified by the user + */ + protected boolean importResources(List fileSystemObjects) { + IPath containerPath = getDestinationPath(); + if (containerPath == null) + return false; // getDestinationPath should have already set an + // error message + ImportOperation operation = new ImportOperation(containerPath, + getSourceDirectory(), FileSystemStructureProvider.INSTANCE, + this, fileSystemObjects); + + operation.setContext(getShell()); + return executeImportOperation(operation); + } + + /** + * Get a new project that is configured by the new project wizard. + * This is currently the only way to do this. + */ + protected IProject getNewProject() { + NewProjectListener listener = new NewProjectListener(); + ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE); + (new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow())).run(); + ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener); + IProject project = listener.getNewProject(); + return project; + } /** - * Initializes the specified operation appropriately. - */ + * Initializes the specified operation appropriately. + */ protected void initializeOperation(ImportOperation op) { op.setCreateContainerStructure(createContainerStructureButton .getSelection()); @@ -718,6 +839,10 @@ .getBoolean(STORE_CREATE_CONTAINER_STRUCTURE_ID); createContainerStructureButton.setSelection(createStructure); createOnlySelectedButton.setSelection(!createStructure); + boolean configureSelection = settings.getBoolean(STORE_IMPORT_CONFIGURED_PROJECT); + importAsConfiguredProjectCheckbox.setSelection(configureSelection); + containerBrowseButton.setEnabled(!configureSelection); + containerNameField.setEnabled(!configureSelection); } } @@ -744,7 +869,8 @@ settings.put(STORE_CREATE_CONTAINER_STRUCTURE_ID, createContainerStructureButton.getSelection()); - + settings.put(STORE_IMPORT_CONFIGURED_PROJECT, + importAsConfiguredProjectCheckbox.getSelection()); } } @@ -922,7 +1048,13 @@ super.updateWidgetEnablements(); } - + + protected boolean validateDestinationGroup() { + if (importAsConfiguredProjectCheckbox.getSelection()) + return true; + return super.validateDestinationGroup(); + } + /** * Answer a boolean indicating whether self's source specification * widgets currently all contain valid values. @@ -975,5 +1107,20 @@ // WizardResourceImportPage return false; } - + + protected IPath getDestinationPath() { + if (importAsConfiguredProjectCheckbox.getSelection()) { // Create a new + // configured + // project than + // import into + // there + IProject newProject = getNewProject(); + if (newProject == null) { + displayErrorDialog(DataTransferMessages.FileImport_needCreateProject); + return null; + } + return newProject.getFullPath(); + } + return getContainerFullPath(); + } } Index: src/org/eclipse/ui/internal/wizards/datatransfer/WizardArchiveFileResourceImportPage1.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/WizardArchiveFileResourceImportPage1.java,v retrieving revision 1.8 diff -u -r1.8 WizardArchiveFileResourceImportPage1.java --- src/org/eclipse/ui/internal/wizards/datatransfer/WizardArchiveFileResourceImportPage1.java 24 Feb 2006 17:45:41 -0000 1.8 +++ src/org/eclipse/ui/internal/wizards/datatransfer/WizardArchiveFileResourceImportPage1.java 2 May 2006 09:36:55 -0000 @@ -17,12 +17,12 @@ import java.util.zip.ZipException; import java.util.zip.ZipFile; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Listener; @@ -56,6 +56,8 @@ private final static String STORE_OVERWRITE_EXISTING_RESOURCES_ID = "WizardZipFileResourceImportPage1.STORE_OVERWRITE_EXISTING_RESOURCES_ID"; //$NON-NLS-1$ + private final static String STORE_IMPORT_CONFIGURED_PROJECT = "WizardZipFileResourceImportPage1.STORE_IMPORT_CONFIGURED_PROJECT"; //$NON-NLS-1$ + private final static String STORE_SELECTED_TYPES_ID = "WizardZipFileResourceImportPage1.STORE_SELECTED_TYPES_ID"; //$NON-NLS-1$ /** @@ -113,18 +115,15 @@ } /** - * Create the options specification widgets. There is only one - * in this case so create no group. - * - * @param parent org.eclipse.swt.widgets.Composite - */ - protected void createOptionsGroup(Composite parent) { - - // overwrite... checkbox - overwriteExistingResourcesCheckbox = new Button(parent, SWT.CHECK); - overwriteExistingResourcesCheckbox.setText(DataTransferMessages.FileImport_overwriteExisting); - overwriteExistingResourcesCheckbox.setFont(parent.getFont()); - } + * We don't want all the buttons used by file system import so just use the + * base group. + * + * @param parent + * org.eclipse.swt.widgets.Composite + */ + protected void createOptionsGroupButtons(Composite parent) { + super.createBaseOptionsGroup(parent); + } private boolean validateSourceFile(String fileName) { if(ArchiveFileManipulations.isTarFile(fileName)) { @@ -370,14 +369,18 @@ */ protected boolean importResources(List fileSystemObjects) { boolean result = false; - + + IPath containerPath = getDestinationPath(); + if (containerPath == null) + return false; // getDestinationPath should have already set an + // error message + if (ArchiveFileManipulations.isTarFile(sourceNameField.getText())) { if( ensureTarSourceIsValid()) { TarFile tarFile = getSpecifiedTarSourceFile(); TarLeveledStructureProvider structureProvider = ArchiveFileManipulations - .getTarStructureProvider(tarFile, getContainer() - .getShell()); - ImportOperation operation = new ImportOperation(getContainerFullPath(), + .getTarStructureProvider(tarFile, getContainer().getShell()); + ImportOperation operation = new ImportOperation(containerPath, structureProvider.getRoot(), structureProvider, this, fileSystemObjects); @@ -390,9 +393,8 @@ ZipFile zipFile = getSpecifiedZipSourceFile(); ZipLeveledStructureProvider structureProvider = ArchiveFileManipulations .getZipStructureProvider(zipFile, getContainer().getShell()); - ImportOperation operation = new ImportOperation( - getContainerFullPath(), structureProvider.getRoot(), - structureProvider, this, fileSystemObjects); + ImportOperation operation = new ImportOperation(containerPath, + structureProvider.getRoot(),structureProvider, this, fileSystemObjects); operation.setContext(getShell()); result = executeImportOperation(operation); @@ -459,6 +461,11 @@ // radio buttons and checkboxes overwriteExistingResourcesCheckbox.setSelection(settings .getBoolean(STORE_OVERWRITE_EXISTING_RESOURCES_ID)); + boolean configureSelection = settings.getBoolean(STORE_IMPORT_CONFIGURED_PROJECT); + importAsConfiguredProjectCheckbox.setSelection(configureSelection); + containerBrowseButton.setEnabled(!configureSelection); + containerNameField.setEnabled(!configureSelection); + } } @@ -490,6 +497,8 @@ settings.put(STORE_OVERWRITE_EXISTING_RESOURCES_ID, overwriteExistingResourcesCheckbox.getSelection()); + settings.put(STORE_IMPORT_CONFIGURED_PROJECT, + importAsConfiguredProjectCheckbox.getSelection()); } } Index: src/org/eclipse/ui/internal/wizards/datatransfer/DataTransferMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/wizards/datatransfer/DataTransferMessages.java,v retrieving revision 1.8 diff -u -r1.8 DataTransferMessages.java --- src/org/eclipse/ui/internal/wizards/datatransfer/DataTransferMessages.java 25 Oct 2005 20:38:39 -0000 1.8 +++ src/org/eclipse/ui/internal/wizards/datatransfer/DataTransferMessages.java 2 May 2006 09:36:55 -0000 @@ -51,12 +51,14 @@ public static String FileImport_fromDirectory; public static String FileImport_importFileSystem; public static String FileImport_overwriteExisting; + public static String FileImport_configuredProject; public static String FileImport_createComplete; public static String FileImport_createSelectedFolders; public static String FileImport_noneSelected; public static String FileImport_invalidSource; public static String FileImport_sourceEmpty; public static String FileImport_importProblems; + public static String FileImport_needCreateProject; public static String ZipImport_description; public static String ZipImport_couldNotClose; public static String ZipImport_badFormat; Index: extensions/org/eclipse/ui/dialogs/WizardResourceImportPage.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/WizardResourceImportPage.java,v retrieving revision 1.10 diff -u -r1.10 WizardResourceImportPage.java --- extensions/org/eclipse/ui/dialogs/WizardResourceImportPage.java 24 Feb 2006 17:45:45 -0000 1.10 +++ extensions/org/eclipse/ui/dialogs/WizardResourceImportPage.java 2 May 2006 09:36:54 -0000 @@ -78,9 +78,9 @@ protected java.util.List selectedTypes = new ArrayList(); // widgets - private Text containerNameField; + protected Text containerNameField; - private Button containerBrowseButton; + protected Button containerBrowseButton; protected ResourceTreeAndListGroup selectionGroup; @@ -480,7 +480,7 @@ /* (non-Javadoc) * Method declared on WizardDataTransferPage. */ - protected final boolean validateDestinationGroup() { + protected boolean validateDestinationGroup() { IPath containerPath = getContainerFullPath(); if (containerPath == null) {