### Eclipse Workspace Patch 1.0 #P org.eclipse.core.resources Index: src/org/eclipse/core/internal/resources/PathVariable.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/PathVariable.java,v retrieving revision 1.2 diff -u -r1.2 PathVariable.java --- src/org/eclipse/core/internal/resources/PathVariable.java 25 Jan 2010 14:08:43 -0000 1.2 +++ src/org/eclipse/core/internal/resources/PathVariable.java 12 Feb 2010 19:48:38 -0000 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.core.internal.resources; +import org.eclipse.core.internal.resources.projectvariables.*; + import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IPathVariable; @@ -42,4 +44,10 @@ ProjectVariableProviderManager.Descriptor descriptor = ProjectVariableProviderManager.getDefault().findDescriptor(variableName); return descriptor != null; } + + public boolean isPreferred() { + return !(variableName.equals(WorkspaceLocationVariableResolver.NAME) || + variableName.equals(WorkspaceParentLocationVariableResolver.NAME) || + variableName.equals(ParentVariableResolver.NAME)); + } } Index: src/org/eclipse/core/internal/resources/PathVariableUtil.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/PathVariableUtil.java,v retrieving revision 1.6 diff -u -r1.6 PathVariableUtil.java --- src/org/eclipse/core/internal/resources/PathVariableUtil.java 12 Feb 2010 12:24:44 -0000 1.6 +++ src/org/eclipse/core/internal/resources/PathVariableUtil.java 12 Feb 2010 19:48:38 -0000 @@ -236,7 +236,7 @@ } static public String buildParentPathVariable(String variable, int difference, boolean generateMacro) { - String newString = "PARENT-" + difference + "-" + variable; //$NON-NLS-1$//$NON-NLS-2$ + String newString = ParentVariableResolver.NAME + "-" + difference + "-" + variable; //$NON-NLS-1$//$NON-NLS-2$ if (!generateMacro) newString = "${" + newString + "}"; //$NON-NLS-1$//$NON-NLS-2$ Index: src/org/eclipse/core/internal/resources/Workspace.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java,v retrieving revision 1.230 diff -u -r1.230 Workspace.java --- src/org/eclipse/core/internal/resources/Workspace.java 12 Feb 2010 12:24:44 -0000 1.230 +++ src/org/eclipse/core/internal/resources/Workspace.java 12 Feb 2010 19:48:39 -0000 @@ -13,8 +13,6 @@ *******************************************************************************/ package org.eclipse.core.internal.resources; -import org.eclipse.core.internal.resources.projectvariables.WorkspaceParentLocationVariableResolver; - import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -25,8 +23,6 @@ import org.eclipse.core.internal.localstore.FileSystemResourceManager; import org.eclipse.core.internal.properties.IPropertyManager; import org.eclipse.core.internal.refresh.RefreshManager; -import org.eclipse.core.internal.resources.projectvariables.ParentVariableResolver; -import org.eclipse.core.internal.resources.projectvariables.WorkspaceLocationVariableResolver; import org.eclipse.core.internal.utils.*; import org.eclipse.core.internal.watson.*; import org.eclipse.core.resources.*; @@ -877,11 +873,8 @@ // look if one variable in the destination project matches String[] variables = destPathVariableManager.getPathVariableNames(dest); for (int i = 0; i < variables.length; i++) { - if (variables[i].equals(WorkspaceLocationVariableResolver.NAME)) - continue; - if (variables[i].equals(WorkspaceParentLocationVariableResolver.NAME)) - continue; - if (variables[i].equals(ParentVariableResolver.NAME)) + IPathVariable pathVariable = destPathVariableManager.getPathVariable(variables[i], dest); + if (!pathVariable.isPreferred()) continue; IPath resolveDestVariable = URIUtil.toPath(destPathVariableManager .resolveURI(destPathVariableManager.getValue(variables[i], dest), dest)); Index: src/org/eclipse/core/resources/IPathVariable.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/IPathVariable.java,v retrieving revision 1.2 diff -u -r1.2 IPathVariable.java --- src/org/eclipse/core/resources/IPathVariable.java 25 Jan 2010 14:08:44 -0000 1.2 +++ src/org/eclipse/core/resources/IPathVariable.java 12 Feb 2010 19:48:39 -0000 @@ -41,6 +41,16 @@ public boolean isReadOnly(); /** + * Returns whether a IPathVariable is a variable that is + * suited for programatically determining which variable is + * the most appropriate when create new linked resources. + * + * @return true if the path variable is preferred. + * @since 3.6 + */ + public boolean isPreferred(); + + /** * If the variable supports extensions (specified as * "${VARNAME-EXTENSIONNAME}"), this method can return the list of possible * extensions, or null if none are supported. #P org.eclipse.platform.doc.user Index: contexts_Workbench.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.platform.doc.user/contexts_Workbench.xml,v retrieving revision 1.93 diff -u -r1.93 contexts_Workbench.xml --- contexts_Workbench.xml 22 Oct 2009 09:24:22 -0000 1.93 +++ contexts_Workbench.xml 12 Feb 2010 19:48:44 -0000 @@ -1209,4 +1209,7 @@ This view allows you to display web pages. By default, it is used to display web pages when they are opened from the workbench. You can modify this setting in the Web Browser preferences available from the link below. + + This dialog allows you to customize how a file and folder hierarchy is recreated in a project. + #P org.eclipse.ui.ide Index: src/org/eclipse/ui/ide/dialogs/ImportTypeDialog.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/ide/dialogs/ImportTypeDialog.java,v retrieving revision 1.3 diff -u -r1.3 ImportTypeDialog.java --- src/org/eclipse/ui/ide/dialogs/ImportTypeDialog.java 25 Jan 2010 16:12:12 -0000 1.3 +++ src/org/eclipse/ui/ide/dialogs/ImportTypeDialog.java 12 Feb 2010 19:48:47 -0000 @@ -10,15 +10,30 @@ *******************************************************************************/ package org.eclipse.ui.ide.dialogs; +import java.io.File; +import java.net.URI; +import java.util.ArrayList; + +import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IPathVariable; import org.eclipse.core.resources.IPathVariableManager; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.TrayDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.CompositeImageDescriptor; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -27,36 +42,345 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.ide.IDEInternalPreferences; import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; +import org.eclipse.ui.internal.ide.IIDEHelpContextIds; +import org.eclipse.ui.internal.ide.misc.OverlayIcon; +import org.eclipse.ui.plugin.AbstractUIPlugin; /** + * Dialog to customize how files and resources are created in a project hierarchy * @since 3.6 * */ -public class ImportTypeDialog extends MessageDialog implements SelectionListener { +public class ImportTypeDialog extends TrayDialog implements SelectionListener { + + /** + * Do not perform an import operation + */ + public final static int IMPORT_NONE = 0; + /** + * Copy the files and folders to the destination + */ + public final static int IMPORT_COPY = 1; + /** + * Recreate the file and folder hierarchy using groups and links + */ + public final static int IMPORT_VIRTUAL_FOLDERS_AND_LINKS = 2; + /** + * Create linked resources for each file and folder + */ + public final static int IMPORT_LINK = 4; + /** + * Move the files and folders to the destination + */ + public final static int IMPORT_MOVE = 8; + /** + * Import only files + */ + public final static int IMPORT_FILES_ONLY = 16; + + /** + * @param shell + * @param dropOperation + * @param names + * @param target + */ + public ImportTypeDialog(Shell shell, int dropOperation, String[] names, IContainer target) { + this(shell, selectAppropriateMask(dropOperation, names, target), getPreferredVariable(names, target), target.isVirtual()); + } + + + /** + * @param shell + * @param dropOperation + * @param sources + * @param target + */ + public ImportTypeDialog(Shell shell, int dropOperation, + IResource[] sources, IContainer target) { + this(shell, selectAppropriateMask(dropOperation, sources, target), getPreferredVariable(sources, target), target.isVirtual()); + } + + /** + * @param names + * @param target + * @return the most appropriate path variable given the context + */ + private static String getPreferredVariable(String[] names, + IContainer target) { + IPath[] paths = new IPath[names.length]; + for (int i = 0; i < names.length; i++) { + paths[i] = Path.fromOSString(names[i]); + } + return getPreferredVariable(paths, target); + } + /** + * @param sources + * @param target + * @return the most appropriate path variable given the context + */ + private static String getPreferredVariable(IResource[] sources, + IContainer target) { + IPath[] paths = new IPath[sources.length]; + for (int i = 0; i < sources.length; i++) { + paths[i] = sources[i].getLocation(); + } + return getPreferredVariable(paths, target); + } + + /** + * Find the most appropriate path variable for a set of paths. + * The first thing is to find a common root for all the paths. + * So for the following paths: + * c:\foo\path\bar\dir1\file1.txt + * c:\foo\path\bar\dir2\file2.txt + * The following root will be selected: + * c:\foo\path\bar\ + * Then, given all the path variable locations, the variable + * who's distance (in segments) from the common root in the smallest + * will be chosen. + * A priority is given as to variables enclosing the root, as others + * only being enclosed by the root. + * + * So if there's two variables, being + * FOO - c:\foo\ + * DIR1 - c:\foo\path\bar\dir1 + * And the common root is: + * c:\foo\path\bar + * FOO will be selected over DIR1, even through the distance between + * the common root and DIR1 is (1), and the distance between the + * common root and FOO is (2). This is because selecting DIR1 would + * cause the location to be relative to its parent. + * @param paths + * @param target + * @return the most appropriate path variable given the context + */ + private static String getPreferredVariable(IPath[] paths, + IContainer target) { + IPath commonRoot = null; + for (int i = 0; i < paths.length; i++) { + if (paths[i] != null) { + if (commonRoot == null) + commonRoot = paths[i]; + else { + int count = commonRoot.matchingFirstSegments(paths[i]); + int remainingSegments = commonRoot.segmentCount() - count; + if (remainingSegments <= 0) + return null; + commonRoot = commonRoot.removeLastSegments(remainingSegments); + } + } + } + + String mostAppropriate = null; + String mostAppropriateToParent = null; + int mostAppropriateCount = Integer.MAX_VALUE; + int mostAppropriateCountToParent = Integer.MAX_VALUE; + IPathVariableManager pathVariableManager = target.getProject().getPathVariableManager(); + String [] variables = pathVariableManager.getPathVariableNames(target); + + for (int i = 0; i < variables.length; i++) { + IPathVariable var = pathVariableManager.getPathVariable(variables[i], target); + if (var.isPreferred()) { + URI value = pathVariableManager.getValue(variables[i], target); + if (value != null) { + IPath path = URIUtil.toPath(value); + if (path != null) { + int difference = path.matchingFirstSegments(commonRoot); + if (difference > 0) { + if (difference < mostAppropriateCount) { + mostAppropriateCount = difference; + mostAppropriate = variables[i]; + } + } + else { + // calculate if commonRoot could be relative to the parent of path + difference = commonRoot.matchingFirstSegments(path); + if (difference > 0) { + if (difference < mostAppropriateCountToParent) { + mostAppropriateCountToParent = difference; + mostAppropriateToParent = variables[i]; + } + } + } + } + } + } + } + + if (mostAppropriate == null) { + if (mostAppropriateToParent == null) + return "PROJECT_LOC"; //$NON-NLS-1$ + return mostAppropriateToParent; + } + return mostAppropriate; + } + + /** + * @param dropOperation + * @param names + * @param target + * @return the appropriate import mask given the files dropped on the target + */ + private static int selectAppropriateMask(int dropOperation, String[] names, IContainer target) { + int mask = ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS | ImportTypeDialog.IMPORT_LINK; + if (!target.isVirtual() && (dropOperation != DND.DROP_LINK)) + mask |= ImportTypeDialog.IMPORT_COPY; + if (areOnlyFiles(names)) + mask |= ImportTypeDialog.IMPORT_FILES_ONLY; + return mask; + } + + /** + * @param dropOperation + * @param resources + * @param target + * @return the appropriate import mask given the files dropped on the target + */ + private static int selectAppropriateMask(int dropOperation, IResource[] resources, IContainer target) { + int mask = ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS | ImportTypeDialog.IMPORT_LINK; + if (!target.isVirtual() && (dropOperation != DND.DROP_LINK)) + mask |= ImportTypeDialog.IMPORT_COPY; + if (areOnlyFiles(resources)) + mask |= ImportTypeDialog.IMPORT_FILES_ONLY; + return mask; + } + + private static boolean areOnlyFiles(String[] names) { + for (int i = 0; i < names.length; i++) { + File file = new File(names[i]); + if (file.exists() && !file.isFile()) + return false; + } + return true; + } + + private static boolean areOnlyFiles(IResource[] resources) { + for (int i = 0; i < resources.length; i++) { + if (resources[i].getType() != IResource.FILE) + return false; + } + return true; + } + + private Image fileImage; + private Image linkedFileImage; + private Image folderAndFileImage; + private Image virtualFolderAndFileImage; + private Image linkedFolderAndFileImage; + private int operationMask; + private int currentSelection; + private Button copyButton = null; + private Button shadowCopyButton = null; + private Button linkButton = null; + private Button moveButton = null; + private Combo variableCombo = null; + private Button alwaysPerformThisOperation = null; + private Button variableCheckbox = null; + private String variable = null; + private IResource receivingResource = null; + private boolean targetIsVirtual; + private String preferredVariable; /** * @param parentShell * @param operationMask */ - public ImportTypeDialog(Shell parentShell, int operationMask) { - super(parentShell, IDEWorkbenchMessages.ImportTypeDialog_title, null, IDEWorkbenchMessages.ImportTypeDialog_question, - MessageDialog.QUESTION, new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 0); + private ImportTypeDialog(Shell parentShell, int operationMask, String preferredVariable, boolean targetIsVirtual) { + super(parentShell); + this.preferredVariable = preferredVariable; this.operationMask = operationMask; + this.targetIsVirtual = targetIsVirtual; currentSelection = 0; String tmp = readContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_TYPE); if (tmp.length() > 0) currentSelection = Integer.parseInt(tmp); currentSelection = currentSelection & operationMask; if (currentSelection == 0) { - if ((operationMask & IMPORT_COPY) != 0) + if (hasFlag(IMPORT_COPY)) currentSelection = IMPORT_COPY; else currentSelection = IMPORT_MOVE; } + ImageDescriptor fileDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + ISharedImages.IMG_OBJ_FILE); + ImageDescriptor folderDescriptor = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( + ISharedImages.IMG_OBJ_FOLDER); + + ImageDescriptor[][] linkedResourceOverlayMap = new ImageDescriptor[4][1]; + linkedResourceOverlayMap[1]= new ImageDescriptor[] {AbstractUIPlugin.imageDescriptorFromPlugin( + IDEWorkbenchPlugin.IDE_WORKBENCH, + "$nl$/icons/full/ovr16/link_ovr.gif")}; //$NON-NLS-1$ + + CompositeImageDescriptor linkedFileDescriptor = new OverlayIcon(fileDescriptor, linkedResourceOverlayMap, new Point(16, 16)); + + CompositeImageDescriptor linkedFolderDescriptor = new OverlayIcon(folderDescriptor, linkedResourceOverlayMap, new Point(16, 16)); + + ImageDescriptor[][] virtualFolderOverlayMap = new ImageDescriptor[4][1]; + virtualFolderOverlayMap[1]= new ImageDescriptor[] {AbstractUIPlugin.imageDescriptorFromPlugin( + IDEWorkbenchPlugin.IDE_WORKBENCH, + "$nl$/icons/full/ovr16/virt_ovr.gif")}; //$NON-NLS-1$ + CompositeImageDescriptor virtualFolderDescriptor = new OverlayIcon(folderDescriptor, virtualFolderOverlayMap, new Point(16, 16)); + + fileImage = fileDescriptor.createImage(); + + linkedFileImage = linkedFileDescriptor.createImage(); + + CompositeImageDescriptor desc = new AlignedCompositeImageDescriptor(fileDescriptor, folderDescriptor); + folderAndFileImage = desc.createImage(); + + desc = new AlignedCompositeImageDescriptor(linkedFileDescriptor, virtualFolderDescriptor); + virtualFolderAndFileImage = desc.createImage(); + + desc = new AlignedCompositeImageDescriptor(linkedFileDescriptor, linkedFolderDescriptor); + linkedFolderAndFileImage = desc.createImage(); + + if (Boolean.valueOf(readContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_RELATIVE)).booleanValue()) + variable = preferredVariable; + } + + class AlignedCompositeImageDescriptor extends CompositeImageDescriptor { + + ImageDescriptor first, second; + + private int SPACE = 4; + AlignedCompositeImageDescriptor(ImageDescriptor first, ImageDescriptor second) { + this.first = first; + this.second = second; + } + /* (non-Javadoc) + * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int) + */ + protected void drawCompositeImage(int width, int height) { + drawImage(first.getImageData(), 0, 0); + drawImage(second.getImageData(), first.getImageData().width + SPACE, 0); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize() + */ + protected Point getSize() { + return new Point(first.getImageData().width + second.getImageData().width + SPACE, + Math.max(first.getImageData().height, second.getImageData().height)); + } + + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.TrayDialog#close() + */ + public boolean close() { + fileImage.dispose(); + linkedFileImage.dispose(); + folderAndFileImage.dispose(); + virtualFolderAndFileImage.dispose(); + linkedFolderAndFileImage.dispose(); + return super.close(); } // the format of the context is operationMask,value:operationMask,value:operationMask,value @@ -101,43 +425,12 @@ } /** - * Generate linked resources relative to their preferred variable (typically the PROJECT_LOC variable) - */ - public static final String AUTOMATIC = "PROJECT_LOC"; //$NON-NLS-1$ - /** - * Generate linked resources with absolute path locations. - */ - public static final String ABSOLUTE_PATH = "default"; //$NON-NLS-1$ - - /** * @return The currently selected variable, or AUTOMATIC or ABSOLUTE_PATH */ public String getVariable() { - if (variable == ABSOLUTE_PATH) - return null; return variable; } - /** - * Copy the files and folders to the destination - */ - public final static int IMPORT_COPY = 1; - /** - * Recreate the file and folder hierarchy using groups and links - */ - public final static int IMPORT_GROUPS_AND_LINKS = 2; - /** - * Create linked resources for each file and folder - */ - public final static int IMPORT_LINK = 4; - /** - * Move the files and folders to the destination - */ - public final static int IMPORT_MOVE = 8; - /** - * Do not perform an import operation - */ - public final static int IMPORT_NONE = 0; /** * @return The current selection (one of IMPORT_COPY, IMPORT_GROUPS_AND_LINKS, IMPORT_LINK and IMPORT_MOVE) @@ -146,89 +439,164 @@ return currentSelection; } - private int operationMask; - private int currentSelection; - private Button copyButton = null; - private Button shadowCopyButton = null; - private Button linkButton = null; - private Button moveButton = null; - private Combo variableCombo = null; - private Button alwaysPerformThisOperation = null; - private Label variableLabel = null; - private String variable = ABSOLUTE_PATH; - private IResource receivingResource = null; - /* (non-Javadoc) * @see org.eclipse.jface.dialogs.MessageDialog#open() */ public int open() { - String showDialogMap = readContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_SHOW_DIALOG); - if (showDialogMap.length() == 0 || !Boolean.valueOf(showDialogMap).booleanValue()) + IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); + + String mode = store.getString(targetIsVirtual? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE:IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE); + + if (mode.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) return super.open(); - return Window.OK; + if (mode.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_MOVE_COPY) && hasFlag(IMPORT_COPY)) { + this.currentSelection = IMPORT_COPY; + return Window.OK; + } + if (mode.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_MOVE_COPY) && hasFlag(IMPORT_MOVE)) { + this.currentSelection = IMPORT_MOVE; + return Window.OK; + } + if (mode.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK) && hasFlag(IMPORT_LINK)) { + this.currentSelection = IMPORT_LINK; + return Window.OK; + } + if (mode.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK_AND_VIRTUAL_FOLDER) && hasFlag(IMPORT_VIRTUAL_FOLDERS_AND_LINKS)) { + this.currentSelection = IMPORT_VIRTUAL_FOLDERS_AND_LINKS; + return Window.OK; + } + + return super.open(); } - protected Control createCustomArea(Composite parent) { + protected void configureShell(Shell shell) { + super.configureShell(shell); + String title = (operationMask & IMPORT_FILES_ONLY) != 0 ? IDEWorkbenchMessages.ImportTypeDialog_titleFilesOnly: + IDEWorkbenchMessages.ImportTypeDialog_title; + shell.setText(title); + PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, + IIDEHelpContextIds.IMPORT_TYPE_DIALOG); + } + + protected Control createMessageArea(Composite parent) { Composite composite = new Composite(parent, 0); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); composite.setLayoutData(gridData); - GridLayout layout = new GridLayout(); + + GridLayout layout = new GridLayout(); layout.numColumns = 1; - layout.verticalSpacing = 9; - layout.marginLeft = 32; - layout.marginTop = 0; + layout.marginTop= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); composite.setLayout(layout); - if ((operationMask & IMPORT_COPY) != 0) { + String message = (operationMask & IMPORT_FILES_ONLY) != 0 ? IDEWorkbenchMessages.ImportTypeDialog_questionFilesOnly: + IDEWorkbenchMessages.ImportTypeDialog_question; + + // create message + if (message != null) { + Label messageLabel = new Label(composite, SWT.WRAP); + messageLabel.setText(message); + gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + messageLabel.setLayoutData(gridData); + } + return composite; + } + + protected Control createDialogArea(Composite parent) { + boolean linkIsOnlyChoice = hasFlag(IMPORT_LINK) && !(hasFlag(IMPORT_COPY | IMPORT_MOVE) || (hasFlag(IMPORT_VIRTUAL_FOLDERS_AND_LINKS) && !hasFlag(IMPORT_FILES_ONLY))); + + if (!linkIsOnlyChoice) + createMessageArea(parent); + Composite composite = new Composite(parent, 0); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + composite.setLayoutData(gridData); + + + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + + int indent= linkIsOnlyChoice ? 0: convertWidthInCharsToPixels(3); + + layout.marginWidth += indent; + composite.setLayout(layout); + + if (hasFlag(IMPORT_COPY)) { copyButton = new Button(composite, SWT.RADIO); - copyButton.setText(IDEWorkbenchMessages.ImportTypeDialog_copyFilesAndDirectories); + copyButton.setText(hasFlag(IMPORT_FILES_ONLY) ? IDEWorkbenchMessages.ImportTypeDialog_copyFiles: IDEWorkbenchMessages.ImportTypeDialog_copyFilesAndDirectories); gridData = new GridData(GridData.FILL_HORIZONTAL); copyButton.setLayoutData(gridData); copyButton.setData(new Integer(IMPORT_COPY)); copyButton.addSelectionListener(this); + if (hasFlag(IMPORT_VIRTUAL_FOLDERS_AND_LINKS | IMPORT_LINK)) + copyButton.setImage(hasFlag(IMPORT_FILES_ONLY) ? fileImage:folderAndFileImage); } - if ((operationMask & IMPORT_MOVE) != 0) { + if (hasFlag(IMPORT_MOVE)) { moveButton = new Button(composite, SWT.RADIO); - moveButton.setText(IDEWorkbenchMessages.ImportTypeDialog_moveFilesAndDirectories); + moveButton.setText(hasFlag(IMPORT_FILES_ONLY) ? IDEWorkbenchMessages.ImportTypeDialog_moveFiles:IDEWorkbenchMessages.ImportTypeDialog_moveFilesAndDirectories); gridData = new GridData(GridData.FILL_HORIZONTAL); moveButton.setLayoutData(gridData); moveButton.setData(new Integer(IMPORT_MOVE)); moveButton.addSelectionListener(this); } - if ((operationMask & IMPORT_GROUPS_AND_LINKS) != 0) { - shadowCopyButton = new Button(composite, SWT.RADIO); - shadowCopyButton.setText(IDEWorkbenchMessages.ImportTypeDialog_recreateFilesAndDirectories); - gridData = new GridData(GridData.FILL_HORIZONTAL); - shadowCopyButton.setLayoutData(gridData); - shadowCopyButton.setData(new Integer(IMPORT_GROUPS_AND_LINKS)); - shadowCopyButton.addSelectionListener(this); - } - if ((operationMask & IMPORT_LINK) != 0) { + if (hasFlag(IMPORT_LINK) && !linkIsOnlyChoice) { linkButton = new Button(composite, SWT.RADIO); - linkButton.setText(IDEWorkbenchMessages.ImportTypeDialog_createLinks); + linkButton.setText(hasFlag(IMPORT_FILES_ONLY) ? IDEWorkbenchMessages.ImportTypeDialog_linkFiles:IDEWorkbenchMessages.ImportTypeDialog_createLinks); gridData = new GridData(GridData.FILL_HORIZONTAL); linkButton.setLayoutData(gridData); linkButton.setData(new Integer(IMPORT_LINK)); linkButton.addSelectionListener(this); + linkButton.setImage(hasFlag(IMPORT_FILES_ONLY) ? linkedFileImage:linkedFolderAndFileImage); } - if ((operationMask & (IMPORT_GROUPS_AND_LINKS | IMPORT_LINK)) != 0) { + if (hasFlag(IMPORT_VIRTUAL_FOLDERS_AND_LINKS) && !hasFlag(IMPORT_FILES_ONLY)) { + shadowCopyButton = new Button(composite, SWT.RADIO); + shadowCopyButton.setText(IDEWorkbenchMessages.ImportTypeDialog_recreateFilesAndDirectories); + gridData = new GridData(GridData.FILL_HORIZONTAL); + shadowCopyButton.setLayoutData(gridData); + shadowCopyButton.setData(new Integer(IMPORT_VIRTUAL_FOLDERS_AND_LINKS)); + shadowCopyButton.addSelectionListener(this); + shadowCopyButton.setImage(virtualFolderAndFileImage); + } + + if (hasFlag(IMPORT_VIRTUAL_FOLDERS_AND_LINKS | IMPORT_LINK)) { Composite variableGroup = new Composite(composite, 0); gridData = new GridData(SWT.FILL, SWT.FILL, true, true); variableGroup.setLayoutData(gridData); layout = new GridLayout(); layout.numColumns = 2; - layout.verticalSpacing = 9; + layout.marginWidth= 0; variableGroup.setLayout(layout); - variableLabel = new Label(variableGroup, 0); - variableLabel.setText(IDEWorkbenchMessages.ImportTypeDialog_importElementsAs); + variableCheckbox = new Button(variableGroup, SWT.CHECK); + variableCheckbox.setText(IDEWorkbenchMessages.ImportTypeDialog_importElementsAs); gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - variableLabel.setLayoutData(gridData); + variableCheckbox.setLayoutData(gridData); + variableCheckbox.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + selectRelativeCombo(); + } + public void widgetDefaultSelected(SelectionEvent e) { + selectRelativeCombo(); + } + private void selectRelativeCombo() { + if (variableCheckbox.getSelection()) { + variableCombo.setEnabled(true); + selectVariable(variableCombo.getItem(variableCombo.getSelectionIndex())); + } + else { + variableCombo.setEnabled(false); + variable = null; + } + + } + }); variableCombo = new Combo(variableGroup, SWT.DROP_DOWN | SWT.READ_ONLY); gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); // GridData.FILL_HORIZONTAL); @@ -248,84 +616,101 @@ } }); setupVariableContent(); - selectVariable(readContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VARIABLE)); + variableCheckbox.setSelection(variable != null); + if (variable != null) + selectVariable(variable); + else + selectVariable(preferredVariable); } - alwaysPerformThisOperation = new Button(composite, SWT.CHECK); - alwaysPerformThisOperation.setText(IDEWorkbenchMessages.ImportTypeDialog_alwaysPerformThisOperation); + if (linkIsOnlyChoice) { + currentSelection = IMPORT_LINK; + parent.getShell().setText(IDEWorkbenchMessages.ImportTypeDialog_titleFilesLinking); + } + alwaysPerformThisOperation = new Button(parent, SWT.CHECK); + alwaysPerformThisOperation.setText(linkIsOnlyChoice? IDEWorkbenchMessages.ImportTypeDialog_alwaysUseLocationWhenLinkingFiles: IDEWorkbenchMessages.ImportTypeDialog_alwaysPerformThisOperation); gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + gridData.horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); alwaysPerformThisOperation.setLayoutData(gridData); refreshSelection(); return composite; } + + private boolean hasFlag(int flag) { + return (operationMask & flag) != 0; + } private void editVariables() { + String selectedItem = variable; PathVariableEditDialog dialog = new PathVariableEditDialog(getShell()); dialog.setResource(receivingResource); if (dialog.open() == IDialogConstants.OK_ID) { String[] variableNames = (String[]) dialog.getResult(); if (variableNames != null && variableNames.length >= 1) { - variable = variableNames[0]; + selectedItem = variableNames[0]; } } setupVariableContent(); - selectVariable(variable); + if (selectedItem != null) { + selectVariable(selectedItem); + } } private void selectVariable(String var) { - if (var.equals(IDEWorkbenchMessages.ImportTypeDialog_automatic) || var.equals(AUTOMATIC)) { - variableCombo.select(0); - variable = var; - } - else - if (var.equals(IDEWorkbenchMessages.ImportTypeDialog_absolutePath) || var.equals(ABSOLUTE_PATH)) { - variableCombo.select(1); - variable = var; - } - else { - String[] items = variableCombo.getItems(); - for (int i = 0; i < items.length; i++) { - if (var.equals(items[i])) { - variableCombo.select(i); - if (i == 0) - variable = AUTOMATIC; - else - if (i == 1) - variable = ABSOLUTE_PATH; - else - variable = items[i]; - return; - } + String[] items = variableCombo.getItems(); + for (int i = 0; i < items.length; i++) { + if (var.equals(items[i])) { + variableCombo.select(i); + variable = items[i]; + return; } - variableCombo.select(0); - variable = AUTOMATIC; } + variableCombo.select(0); + variable = items[0]; } + private void setupVariableContent() { - String[] items; IPathVariableManager pathVariableManager; if (receivingResource != null) pathVariableManager = receivingResource.getProject().getPathVariableManager(); else pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); - String[] variables = pathVariableManager.getPathVariableNames(); - items = new String[variables.length + 3]; - items[0] = IDEWorkbenchMessages.ImportTypeDialog_automatic; - items[1] = IDEWorkbenchMessages.ImportTypeDialog_absolutePath; - for (int i = 0; i < variables.length; i++) - items[i + 2] = variables[i]; - items[items.length - 1] = IDEWorkbenchMessages.ImportTypeDialog_editVariables; - variableCombo.setItems(items); + String[] variables = pathVariableManager.getPathVariableNames(receivingResource); + + ArrayList items = new ArrayList(); + for (int i = 0; i < variables.length; i++) { + if (variables[i].equals("PARENT")) //$NON-NLS-1$ + continue; + items.add(variables[i]); + } + items.add(IDEWorkbenchMessages.ImportTypeDialog_editVariables); + variableCombo.setItems((String[]) items.toArray(new String[0])); super.getShell().layout(true); } protected void buttonPressed(int buttonId) { if (buttonId == IDialogConstants.OK_ID) { writeContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_TYPE, Integer.toString(currentSelection)); - String storageVariable = currentSelection == 0? AUTOMATIC: (currentSelection == 1 ? ABSOLUTE_PATH:variable); - writeContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VARIABLE, storageVariable); - writeContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_SHOW_DIALOG, Boolean.toString(alwaysPerformThisOperation.getSelection())); + writeContextPreference(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_RELATIVE, Boolean.toString(variable != null)); + + IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); + if (alwaysPerformThisOperation.getSelection()) { + String mode = IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT; + switch(currentSelection) { + case IMPORT_COPY: + case IMPORT_MOVE: + mode = IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_MOVE_COPY; + break; + case IMPORT_LINK: + mode = IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK; + break; + case IMPORT_VIRTUAL_FOLDERS_AND_LINKS: + mode = IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK_AND_VIRTUAL_FOLDER; + break; + } + store.putValue(targetIsVirtual? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE:IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE, mode); + } } super.buttonPressed(buttonId); } @@ -344,15 +729,15 @@ if (copyButton != null) copyButton.setSelection(currentSelection == IMPORT_COPY); if (shadowCopyButton != null) - shadowCopyButton.setSelection(currentSelection == IMPORT_GROUPS_AND_LINKS); + shadowCopyButton.setSelection(currentSelection == IMPORT_VIRTUAL_FOLDERS_AND_LINKS); if (linkButton != null) linkButton.setSelection(currentSelection == IMPORT_LINK); if (moveButton != null) moveButton.setSelection(currentSelection == IMPORT_MOVE); + if (variableCheckbox != null) + variableCheckbox.setEnabled((currentSelection & (IMPORT_VIRTUAL_FOLDERS_AND_LINKS | IMPORT_LINK)) != 0); if (variableCombo != null) - variableCombo.setEnabled((currentSelection & (IMPORT_GROUPS_AND_LINKS | IMPORT_LINK)) != 0); - if (variableLabel != null) - variableLabel.setEnabled((currentSelection & (IMPORT_GROUPS_AND_LINKS | IMPORT_LINK)) != 0); + variableCombo.setEnabled(variableCheckbox.getSelection() && variableCheckbox.isEnabled()); } /** Set the project that is the destination of the import operation Index: src/org/eclipse/ui/internal/ide/IDEInternalPreferences.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEInternalPreferences.java,v retrieving revision 1.23 diff -u -r1.23 IDEInternalPreferences.java --- src/org/eclipse/ui/internal/ide/IDEInternalPreferences.java 20 Nov 2009 19:57:32 -0000 1.23 +++ src/org/eclipse/ui/internal/ide/IDEInternalPreferences.java 12 Feb 2010 19:48:47 -0000 @@ -94,9 +94,21 @@ // Type of import public static final String IMPORT_FILES_AND_FOLDERS_TYPE = "IMPORT_FILES_AND_FOLDERS_TYPE"; //$NON-NLS-1$ - // Preferred variable for file and folder imports - public static final String IMPORT_FILES_AND_FOLDERS_VARIABLE = "IMPORT_FILES_AND_FOLDERS_VARIABLE"; //$NON-NLS-1$ + // (boolean) Using variable relative paths for the import file and folder dialog + public static final String IMPORT_FILES_AND_FOLDERS_RELATIVE = "IMPORT_FILES_AND_FOLDERS_RELATIVE"; //$NON-NLS-1$ + + // (string) Save all dirty editors before running a full or incremental build + public static final String IMPORT_FILES_AND_FOLDERS_MODE = "IMPORT_FILES_AND_FOLDERS_MODE"; //$NON-NLS-1$ + + // (string) Save all dirty editors before running a full or incremental build + public static final String IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE = "IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE"; //$NON-NLS-1$ + + public static final String IMPORT_FILES_AND_FOLDERS_MODE_PROMPT = MessageDialogWithToggle.PROMPT; + + public static final String IMPORT_FILES_AND_FOLDERS_MODE_MOVE_COPY = "MOVE_COPY"; //$NON-NLS-1$ + + public static final String IMPORT_FILES_AND_FOLDERS_MODE_LINK = "LINK"; //$NON-NLS-1$ + + public static final String IMPORT_FILES_AND_FOLDERS_MODE_LINK_AND_VIRTUAL_FOLDER = "LINK_AND_VIRTUAL_FOLDER"; //$NON-NLS-1$ - // Always show this import window - public static final String IMPORT_FILES_AND_FOLDERS_SHOW_DIALOG = "IMPORT_FILES_AND_FOLDERS_SHOW_DIALOG"; //$NON-NLS-1$ } Index: src/org/eclipse/ui/internal/ide/IDEPreferenceInitializer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEPreferenceInitializer.java,v retrieving revision 1.18 diff -u -r1.18 IDEPreferenceInitializer.java --- src/org/eclipse/ui/internal/ide/IDEPreferenceInitializer.java 20 Nov 2009 19:57:32 -0000 1.18 +++ src/org/eclipse/ui/internal/ide/IDEPreferenceInitializer.java 12 Feb 2010 19:48:47 -0000 @@ -78,13 +78,15 @@ node.putInt(IDEInternalPreferences.MARKER_LIMITS_VALUE, 100); node.put(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_TYPE, ""); //$NON-NLS-1$ - node.put(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VARIABLE, ""); //$NON-NLS-1$ - node.put(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_SHOW_DIALOG, ""); //$NON-NLS-1$ + node.putBoolean(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_RELATIVE, true); //Filter migration node.putBoolean(MarkerSupportInternalUtilities.MIGRATE_BOOKMARK_FILTERS, false); node.putBoolean(MarkerSupportInternalUtilities.MIGRATE_TASK_FILTERS, false); node.putBoolean(MarkerSupportInternalUtilities.MIGRATE_PROBLEM_FILTERS, false); + + node.put(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE, IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT); + node.put(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE, IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT); } private String getHelpSeparatorKey(String groupId) { Index: src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java,v retrieving revision 1.77 diff -u -r1.77 IDEWorkbenchMessages.java --- src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 10 Feb 2010 11:49:33 -0000 1.77 +++ src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 12 Feb 2010 19:48:48 -0000 @@ -482,6 +482,11 @@ public static String LinkedResourcesPreference_enableLinkedResources; public static String LinkedResourcesPreference_linkedResourcesWarningTitle; public static String LinkedResourcesPreference_linkedResourcesWarningMessage; + public static String LinkedResourcesPreference_dragAndDropHandlingMessage; + public static String LinkedResourcesPreference_dragAndDropVirtualFolderHandlingMessage; + public static String LinkedResourcesPreference_link; + public static String linkedResourcesPreference_copy; + public static String LinkedResourcesPreference_linkAndVirtualFolder; // The following six keys are marked as unused by the NLS search, but they are indirectly used // and should be removed. @@ -732,16 +737,21 @@ public static String PathVariableSelectionDialog_ExtensionDialog_description; public static String ImportTypeDialog_title; + public static String ImportTypeDialog_titleFilesOnly; + public static String ImportTypeDialog_titleFilesLinking; public static String ImportTypeDialog_question; + public static String ImportTypeDialog_questionFilesOnly; public static String ImportTypeDialog_moveFilesAndDirectories; public static String ImportTypeDialog_copyFilesAndDirectories; + public static String ImportTypeDialog_moveFiles; + public static String ImportTypeDialog_copyFiles; public static String ImportTypeDialog_recreateFilesAndDirectories; public static String ImportTypeDialog_createLinks; + public static String ImportTypeDialog_linkFiles; public static String ImportTypeDialog_importElementsAs; - public static String ImportTypeDialog_automatic; - public static String ImportTypeDialog_absolutePath; public static String ImportTypeDialog_editVariables; public static String ImportTypeDialog_alwaysPerformThisOperation; + public static String ImportTypeDialog_alwaysUseLocationWhenLinkingFiles; // ============================================================================== // Editor Framework Index: src/org/eclipse/ui/internal/ide/IIDEHelpContextIds.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IIDEHelpContextIds.java,v retrieving revision 1.11 diff -u -r1.11 IIDEHelpContextIds.java --- src/org/eclipse/ui/internal/ide/IIDEHelpContextIds.java 20 Nov 2009 19:57:32 -0000 1.11 +++ src/org/eclipse/ui/internal/ide/IIDEHelpContextIds.java 12 Feb 2010 19:48:48 -0000 @@ -148,6 +148,9 @@ public static final String PATH_VARIABLE_SELECTION_DIALOG = PREFIX + "path_variable_selection_dialog"; //$NON-NLS-1$ + public static final String IMPORT_TYPE_DIALOG = PREFIX + + "import_type_dialog"; //$NON-NLS-1$ + public static final String SAVE_AS_DIALOG = PREFIX + "save_as_dialog_context"; //$NON-NLS-1$ Index: src/org/eclipse/ui/internal/ide/ResourceDragAndDropEditor.java =================================================================== RCS file: src/org/eclipse/ui/internal/ide/ResourceDragAndDropEditor.java diff -N src/org/eclipse/ui/internal/ide/ResourceDragAndDropEditor.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/ui/internal/ide/ResourceDragAndDropEditor.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (c) 2005, 2007 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 + *******************************************************************************/ +package org.eclipse.ui.internal.ide; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +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.Group; + +/** + * A class to handle editing of the Line delimiter preferences in core. + * + * @since 3.1 + */ +public class ResourceDragAndDropEditor { + + class PreferenceGroup + { + String preferenceKey; + String title; + String[] labels; + String[] values; + Button[] buttons; + + public PreferenceGroup(String title, String pref, String[] labels, String[] values) { + this.preferenceKey = pref; + this.title = title; + this.labels = labels; + this.values = values; + } + + public void createControl(Composite parent) { + Font font = parent.getFont(); + Group group = new Group(parent, SWT.NONE); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + group.setLayoutData(data); + GridLayout layout = new GridLayout(); + layout.numColumns = labels.length; + group.setLayout(layout); + group.setText(title); + group.setFont(font); + + buttons = new Button[labels.length]; + for (int i = 0; i < labels.length; i++) { + buttons[i] = new Button(group, SWT.RADIO); + buttons[i].setText(labels[i]); + buttons[i].setData(values[i]); + buttons[i].setFont(font); + } + } + + /** + * + */ + public void doLoad() { + String resourcePreference = getStoredValue(false); + updateState(resourcePreference); + } + /** + * @param value + */ + private void updateState(String value) { + for (int i = 0; i < labels.length; i++) { + if (value.equals(buttons[i].getData())) + buttons[i].setSelection(true); + } + } + + /** + * + */ + public void loadDefault() { + String value = getStoredValue(true); + updateState(value); + } + /** + * Returns the value that is currently stored for the encoding. + * @param useDefault + * + * @return the currently stored encoding + */ + public String getStoredValue(boolean useDefault) { + IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); + if (useDefault) + return store.getDefaultString(preferenceKey); + return store.getString(preferenceKey); + } + + /** + * @return the current selection + */ + private String getSelection() { + for (int i = 0; i < labels.length; i++) { + if (buttons[i].getSelection()) + return (String) buttons[i].getData(); + } + return values[0]; + } + + /** + * + */ + public void store() { + IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); + store.putValue(preferenceKey, getSelection()); + } + } + + PreferenceGroup folderPref; + PreferenceGroup virtualFolderPref; + /** + * Creates a new drag and drop resource editor with the given preference name, label + * and parent. + * + * @param composite + * the parent of the field editor's control + */ + public ResourceDragAndDropEditor(Composite composite) { + folderPref = new PreferenceGroup(IDEWorkbenchMessages.LinkedResourcesPreference_dragAndDropHandlingMessage, + IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE, + new String[] { + IDEWorkbenchMessages.Prompt, + IDEWorkbenchMessages.linkedResourcesPreference_copy, + IDEWorkbenchMessages.LinkedResourcesPreference_link, + IDEWorkbenchMessages.LinkedResourcesPreference_linkAndVirtualFolder }, + new String[] {IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT, + IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_MOVE_COPY, + IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK, + IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK_AND_VIRTUAL_FOLDER}); + virtualFolderPref = new PreferenceGroup(IDEWorkbenchMessages.LinkedResourcesPreference_dragAndDropVirtualFolderHandlingMessage, + IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE, + new String[] { + IDEWorkbenchMessages.Prompt, + IDEWorkbenchMessages.LinkedResourcesPreference_link, + IDEWorkbenchMessages.LinkedResourcesPreference_linkAndVirtualFolder }, + new String[] {IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT, + IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK, + IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK_AND_VIRTUAL_FOLDER}); + createControl(composite); + } + + /** + * Creates this field editor's main control containing all of its basic + * controls. + * + * @param parent + * the parent control + */ + protected void createControl(Composite parent) { + folderPref.createControl(parent); + virtualFolderPref.createControl(parent); + } + + /** + * Load the list items from core and update the state of the buttons to + * match what the preference is currently set to. + */ + public void doLoad() { + folderPref.doLoad(); + virtualFolderPref.doLoad(); + } + + /** + * Initializes this field editor with the preference value from the + * preference store. + */ + public void loadDefault() { + folderPref.loadDefault(); + virtualFolderPref.loadDefault(); + } + + /** + * Store the currently selected line delimiter value in the preference + * store. + */ + public void store() { + folderPref.store(); + virtualFolderPref.store(); + } +} Index: src/org/eclipse/ui/internal/ide/dialogs/LinkedResourcesPreferencePage.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/LinkedResourcesPreferencePage.java,v retrieving revision 1.9 diff -u -r1.9 LinkedResourcesPreferencePage.java --- src/org/eclipse/ui/internal/ide/dialogs/LinkedResourcesPreferencePage.java 7 Mar 2005 19:17:39 -0000 1.9 +++ src/org/eclipse/ui/internal/ide/dialogs/LinkedResourcesPreferencePage.java 12 Feb 2010 19:48:54 -0000 @@ -31,6 +31,7 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; import org.eclipse.ui.internal.ide.IIDEHelpContextIds; +import org.eclipse.ui.internal.ide.ResourceDragAndDropEditor; /** * Preference page for linked resources. @@ -47,6 +48,8 @@ private PathVariablesGroup pathVariablesGroup; + private ResourceDragAndDropEditor dragAndDropHandlingEditor; + /** * Constructs a preference page of path variables. * Omits "Restore Defaults"/"Apply Changes" buttons. @@ -105,6 +108,7 @@ } }); + createLineSeparatorEditorControls(pageComponent); createSpace(pageComponent); topLabel = new Label(pageComponent, SWT.NONE); @@ -126,6 +130,33 @@ return pageComponent; } + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#performDefaults() + */ + protected void performDefaults() { + dragAndDropHandlingEditor.loadDefault(); + super.performDefaults(); + } + + /** + * Create a composite that contains the line delimiter controls + * + * @param parent + */ + private void createLineSeparatorEditorControls(Composite parent){ + Composite lineComposite = new Composite(parent,SWT.NONE); + final GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + lineComposite.setLayout(gridLayout); + + lineComposite.setLayoutData(new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL)); + + dragAndDropHandlingEditor = new ResourceDragAndDropEditor(lineComposite); + dragAndDropHandlingEditor.doLoad(); + } + /** * Creates a tab of one horizontal spans. * @@ -167,6 +198,7 @@ * @see PathVariablesGroup#performOk() */ public boolean performOk() { + dragAndDropHandlingEditor.store(); return pathVariablesGroup.performOk(); } Index: src/org/eclipse/ui/internal/ide/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties,v retrieving revision 1.189 diff -u -r1.189 messages.properties --- src/org/eclipse/ui/internal/ide/messages.properties 10 Feb 2010 18:09:23 -0000 1.189 +++ src/org/eclipse/ui/internal/ide/messages.properties 12 Feb 2010 19:48:54 -0000 @@ -482,6 +482,11 @@ LinkedResourcesPreference_enableLinkedResources = &Enable linked resources LinkedResourcesPreference_linkedResourcesWarningTitle = Enabled Linked Resources LinkedResourcesPreference_linkedResourcesWarningMessage = You have enabled a feature which may give rise to incompatibilities if projects are shared by users of different versions of the workbench. Please consult the documentation for further details. +LinkedResourcesPreference_dragAndDropHandlingMessage = Drag and drop files and folders on a folder or project +LinkedResourcesPreference_dragAndDropVirtualFolderHandlingMessage = Drag and drop files and folders on a virtual folder +LinkedResourcesPreference_link=&Link +linkedResourcesPreference_copy=&Copy +LinkedResourcesPreference_linkAndVirtualFolder=Link and create &virtual folders # The following six keys are marked as unused by the NLS search, but they are indirectly used # and should be removed. @@ -753,18 +758,24 @@ PathVariableSelectionDialog_ExtensionDialog_title = Variable Extension PathVariableSelectionDialog_ExtensionDialog_description = Choose extension to {0} -ImportTypeDialog_title=File and Folder Import +ImportTypeDialog_title=File and Folder Operation +ImportTypeDialog_titleFilesOnly= File Operation +ImportTypeDialog_titleFilesLinking= Link Files ImportTypeDialog_question=Select how files and folders should be imported in the project: -ImportTypeDialog_moveFilesAndDirectories=Move the files and directories -ImportTypeDialog_copyFilesAndDirectories=Copy the files and directories. -ImportTypeDialog_recreateFilesAndDirectories=Recreate the file and directory hierarchy with virtual folders and links. -ImportTypeDialog_createLinks=Create links for each file and directory. -ImportTypeDialog_importElementsAs=Create linked resources as relative to: -ImportTypeDialog_automatic= -ImportTypeDialog_absolutePath= +ImportTypeDialog_questionFilesOnly=Select how files should be imported in the project: +ImportTypeDialog_moveFilesAndDirectories=&Move files and folders +ImportTypeDialog_copyFilesAndDirectories=&Copy files and folders +ImportTypeDialog_moveFiles=&Move files +ImportTypeDialog_copyFiles=&Copy files +ImportTypeDialog_recreateFilesAndDirectories=Link to files and recreate folder structure with &virtual folders +ImportTypeDialog_createLinks=&Link to files and folders +ImportTypeDialog_linkFiles=&Link to files +ImportTypeDialog_importElementsAs=Create link locations as &relative to: +ImportTypeDialog_automatic=Default +ImportTypeDialog_absolutePath=Absolute Path ImportTypeDialog_editVariables=Edit Variables... -ImportTypeDialog_alwaysPerformThisOperation=Always perform the selected operation in this context - +ImportTypeDialog_alwaysPerformThisOperation=&Always perform the selected operation +ImportTypeDialog_alwaysUseLocationWhenLinkingFiles=&Always use the selected location # ============================================================================== # Editor Framework # ============================================================================== Index: src/org/eclipse/ui/views/navigator/NavigatorDropAdapter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/views/navigator/NavigatorDropAdapter.java,v retrieving revision 1.15 diff -u -r1.15 NavigatorDropAdapter.java --- src/org/eclipse/ui/views/navigator/NavigatorDropAdapter.java 25 Jan 2010 16:12:13 -0000 1.15 +++ src/org/eclipse/ui/views/navigator/NavigatorDropAdapter.java 12 Feb 2010 19:48:54 -0000 @@ -277,10 +277,7 @@ getShell()); // if the target is a group and all sources are files, then automatically create links int type; - int mask = ImportTypeDialog.IMPORT_GROUPS_AND_LINKS | ImportTypeDialog.IMPORT_LINK; - if (!target.isVirtual() && (getCurrentOperation() != DND.DROP_LINK)) - mask |= ImportTypeDialog.IMPORT_COPY; - ImportTypeDialog dialog = new ImportTypeDialog(getShell(), mask); + ImportTypeDialog dialog = new ImportTypeDialog(getShell(), getCurrentOperation(), names, target); dialog.setResource(target); if (dialog.open() == Window.OK) type = dialog.getSelection(); @@ -290,7 +287,7 @@ case ImportTypeDialog.IMPORT_COPY: operation.copyFiles(names, target); break; - case ImportTypeDialog.IMPORT_GROUPS_AND_LINKS: + case ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS: if (dialog.getVariable() != null) operation.setRelativeVariable(dialog.getVariable()); operation.createGroupAndLinks(names, target); @@ -308,7 +305,7 @@ return problems; } - /** + /** * Performs a resource copy */ private IStatus performResourceCopy(Shell shell, IResource[] sources) { @@ -348,13 +345,10 @@ } // if all sources are either links or groups, copy then normally, don't show the dialog if (!allSourceAreLinksOrGroups) { - int mask = ImportTypeDialog.IMPORT_GROUPS_AND_LINKS | ImportTypeDialog.IMPORT_LINK; - if (!target.isVirtual() && (getCurrentOperation() != DND.DROP_LINK)) - mask |= ImportTypeDialog.IMPORT_COPY; - ImportTypeDialog dialog = new ImportTypeDialog(getShell(), mask); + ImportTypeDialog dialog = new ImportTypeDialog(getShell(), getCurrentOperation(), sources, target); dialog.setResource(target); if (dialog.open() == Window.OK) { - if (dialog.getSelection() == ImportTypeDialog.IMPORT_GROUPS_AND_LINKS) + if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS) operation.setCreateGroups(true); if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK) operation.setCreateLinks(true); #P org.eclipse.ui.navigator.resources Index: src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.navigator.resources/src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java,v retrieving revision 1.11 diff -u -r1.11 ResourceDropAdapterAssistant.java --- src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java 25 Jan 2010 16:12:17 -0000 1.11 +++ src/org/eclipse/ui/navigator/resources/ResourceDropAdapterAssistant.java 12 Feb 2010 19:48:56 -0000 @@ -400,13 +400,10 @@ // if all sources are either links or groups, copy then normally, // don't show the dialog if (!allSourceAreLinksOrGroups) { - int mask = ImportTypeDialog.IMPORT_GROUPS_AND_LINKS | ImportTypeDialog.IMPORT_LINK; - if (!target.isVirtual() && (dropAdapter.getCurrentOperation() != DND.DROP_LINK)) - mask |= ImportTypeDialog.IMPORT_COPY; - ImportTypeDialog dialog = new ImportTypeDialog(getShell(), mask); + ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target); dialog.setResource(target); if (dialog.open() == Window.OK) { - if (dialog.getSelection() == ImportTypeDialog.IMPORT_GROUPS_AND_LINKS) + if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS) operation.setCreateGroups(true); if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK) operation.setCreateLinks(true); @@ -485,10 +482,7 @@ // if the target is a group and all sources are files, then // automatically create links int type; - int mask = ImportTypeDialog.IMPORT_GROUPS_AND_LINKS | ImportTypeDialog.IMPORT_LINK; - if (!target.isVirtual() && (finalAdapter.getCurrentOperation() != DND.DROP_LINK)) - mask |= ImportTypeDialog.IMPORT_COPY; - ImportTypeDialog dialog = new ImportTypeDialog(getShell(), mask); + ImportTypeDialog dialog = new ImportTypeDialog(getShell(), finalAdapter.getCurrentOperation(), names, target); dialog.setResource(target); if (dialog.open() == Window.OK) type = dialog.getSelection(); @@ -498,7 +492,7 @@ case ImportTypeDialog.IMPORT_COPY: operation.copyFiles(names, target); break; - case ImportTypeDialog.IMPORT_GROUPS_AND_LINKS: + case ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS: if (dialog.getVariable() != null) operation.setRelativeVariable(dialog.getVariable()); operation.createGroupAndLinks(names, target);