Search in sources :

Example 1 with ImportTypeDialog

use of org.eclipse.ui.ide.dialogs.ImportTypeDialog in project eclipse.platform.ui by eclipse-platform.

the class NavigatorDropAdapter method performResourceCopy.

/**
 * Performs a resource copy
 */
private IStatus performResourceCopy(Shell shell, IResource[] sources) {
    MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, ResourceNavigatorMessages.DropAdapter_problemsMoving, null);
    mergeStatus(problems, validateTarget(getCurrentTarget(), getCurrentTransfer()));
    IContainer target = getActualTarget((IResource) getCurrentTarget());
    boolean shouldLinkAutomatically = false;
    if (target.isVirtual()) {
        shouldLinkAutomatically = true;
        for (IResource source : sources) {
            if (source.getType() != IResource.FILE) {
                shouldLinkAutomatically = false;
                break;
            }
        }
    }
    CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
    // links
    if (shouldLinkAutomatically) {
        operation.setCreateLinks(true);
        operation.copyResources(sources, target);
    } else {
        boolean allSourceAreLinksOrGroups = true;
        for (IResource source : sources) {
            if (!source.isVirtual() && !source.isLinked()) {
                allSourceAreLinksOrGroups = false;
                break;
            }
        }
        // dialog
        if (!allSourceAreLinksOrGroups) {
            IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
            String dndPreference = store.getString(target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE);
            if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) {
                ImportTypeDialog dialog = new ImportTypeDialog(getShell(), getCurrentOperation(), sources, target);
                dialog.setResource(target);
                if (dialog.open() == Window.OK) {
                    if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS)
                        operation.setVirtualFolders(true);
                    if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK)
                        operation.setCreateLinks(true);
                    if (dialog.getVariable() != null)
                        operation.setRelativeVariable(dialog.getVariable());
                    operation.copyResources(sources, target);
                } else
                    return problems;
            } else
                operation.copyResources(sources, target);
        } else
            operation.copyResources(sources, target);
    }
    return problems;
}
Also used : ImportTypeDialog(org.eclipse.ui.ide.dialogs.ImportTypeDialog) MultiStatus(org.eclipse.core.runtime.MultiStatus) IContainer(org.eclipse.core.resources.IContainer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation) IResource(org.eclipse.core.resources.IResource)

Example 2 with ImportTypeDialog

use of org.eclipse.ui.ide.dialogs.ImportTypeDialog in project eclipse.platform.ui by eclipse-platform.

the class ResourceDropAdapterAssistant method performResourceCopy.

/**
 * Performs a resource copy
 */
private IStatus performResourceCopy(CommonDropAdapter dropAdapter, Shell shell, IResource[] sources) {
    MultiStatus problems = new MultiStatus(PlatformUI.PLUGIN_ID, 1, WorkbenchNavigatorMessages.DropAdapter_problemsMoving, null);
    mergeStatus(problems, validateTarget(dropAdapter.getCurrentTarget(), dropAdapter.getCurrentTransfer(), dropAdapter.getCurrentOperation()));
    IContainer target = getActualTarget((IResource) dropAdapter.getCurrentTarget());
    boolean shouldLinkAutomatically = false;
    if (target.isVirtual()) {
        shouldLinkAutomatically = true;
        for (IResource source : sources) {
            if ((source.getType() != IResource.FILE) && (source.getLocation() != null)) {
                // If the source is a folder, but the location is null (a
                // broken link, for example),
                // we still generate a link automatically (the best option).
                shouldLinkAutomatically = false;
                break;
            }
        }
    }
    CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(shell);
    // automatically create links
    if (shouldLinkAutomatically) {
        operation.setCreateLinks(true);
        operation.copyResources(sources, target);
    } else {
        boolean allSourceAreLinksOrVirtualFolders = true;
        for (IResource source : sources) {
            if (!source.isVirtual() && !source.isLinked()) {
                allSourceAreLinksOrVirtualFolders = false;
                break;
            }
        }
        // don't show the dialog
        if (!allSourceAreLinksOrVirtualFolders) {
            IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
            String dndPreference = store.getString(target.isVirtual() ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE);
            if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) {
                ImportTypeDialog dialog = new ImportTypeDialog(getShell(), dropAdapter.getCurrentOperation(), sources, target);
                dialog.setResource(target);
                if (dialog.open() == Window.OK) {
                    if (dialog.getSelection() == ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS)
                        operation.setVirtualFolders(true);
                    if (dialog.getSelection() == ImportTypeDialog.IMPORT_LINK)
                        operation.setCreateLinks(true);
                    if (dialog.getVariable() != null)
                        operation.setRelativeVariable(dialog.getVariable());
                    operation.copyResources(sources, target);
                } else
                    return problems;
            } else
                operation.copyResources(sources, target);
        } else
            operation.copyResources(sources, target);
    }
    return problems;
}
Also used : ImportTypeDialog(org.eclipse.ui.ide.dialogs.ImportTypeDialog) MultiStatus(org.eclipse.core.runtime.MultiStatus) IContainer(org.eclipse.core.resources.IContainer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) CopyFilesAndFoldersOperation(org.eclipse.ui.actions.CopyFilesAndFoldersOperation) IResource(org.eclipse.core.resources.IResource)

Example 3 with ImportTypeDialog

use of org.eclipse.ui.ide.dialogs.ImportTypeDialog in project eclipse.platform.ui by eclipse-platform.

the class CopyFilesAndFoldersOperation method copyOrLinkFiles.

/**
 * Depending on the 'Linked Resources' preferences it copies the given files and folders to the
 * destination or creates links or shows a dialog that lets the user choose. The current thread
 * is halted while the resources are copied using a {@link WorkspaceModifyOperation}. This
 * method should be called from the UI Thread.
 *
 * @param fileNames names of the files to copy
 * @param destination destination to which files will be copied
 * @param dropOperation the drop operation ({@link DND#DROP_NONE}, {@link DND#DROP_MOVE}
 *            {@link DND#DROP_COPY}, {@link DND#DROP_LINK}, {@link DND#DROP_DEFAULT})
 * @see WorkspaceModifyOperation
 * @see Display#getThread()
 * @see Thread#currentThread()
 * @since 3.6
 */
public void copyOrLinkFiles(final String[] fileNames, IContainer destination, int dropOperation) {
    IPreferenceStore store = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
    boolean targetIsVirtual = destination.isVirtual();
    String dndPreference = store.getString(targetIsVirtual ? IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_VIRTUAL_FOLDER_MODE : IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE);
    int mode = ImportTypeDialog.IMPORT_NONE;
    String variable = null;
    // check if resource linking is disabled
    if (ResourcesPlugin.getPlugin().getPluginPreferences().getBoolean(ResourcesPlugin.PREF_DISABLE_LINKING))
        mode = ImportTypeDialog.IMPORT_COPY;
    else if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_PROMPT)) {
        ImportTypeDialog dialog = new ImportTypeDialog(messageShell, dropOperation, fileNames, destination);
        dialog.setResource(destination);
        if (dialog.open() == Window.OK) {
            mode = dialog.getSelection();
            variable = dialog.getVariable();
        }
    } else if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_MOVE_COPY)) {
        mode = ImportTypeDialog.IMPORT_COPY;
    } else if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK)) {
        mode = ImportTypeDialog.IMPORT_LINK;
    } else if (dndPreference.equals(IDEInternalPreferences.IMPORT_FILES_AND_FOLDERS_MODE_LINK_AND_VIRTUAL_FOLDER)) {
        mode = ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS;
    }
    switch(mode) {
        case ImportTypeDialog.IMPORT_COPY:
            copyFiles(fileNames, destination);
            break;
        case ImportTypeDialog.IMPORT_VIRTUAL_FOLDERS_AND_LINKS:
            if (variable != null)
                setRelativeVariable(variable);
            createVirtualFoldersAndLinks(fileNames, destination);
            break;
        case ImportTypeDialog.IMPORT_LINK:
            if (variable != null)
                setRelativeVariable(variable);
            linkFiles(fileNames, destination);
            break;
        case ImportTypeDialog.IMPORT_NONE:
            break;
    }
}
Also used : ImportTypeDialog(org.eclipse.ui.ide.dialogs.ImportTypeDialog) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 ImportTypeDialog (org.eclipse.ui.ide.dialogs.ImportTypeDialog)3 IContainer (org.eclipse.core.resources.IContainer)2 IResource (org.eclipse.core.resources.IResource)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 CopyFilesAndFoldersOperation (org.eclipse.ui.actions.CopyFilesAndFoldersOperation)2