Search in sources :

Example 21 with ContainerSelectionDialog

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

the class CopyResourceAction method queryDestinationResource.

/**
 * Asks the user for the destination of this action.
 *
 * @return the path on an existing or new resource container, or
 *  <code>null</code> if the operation should be abandoned
 */
IPath queryDestinationResource() {
    // start traversal at root resource, should probably start at a
    // better location in the tree
    ContainerSelectionDialog dialog = new ContainerSelectionDialog(shellProvider.getShell(), getInitialContainer(), true, IDEWorkbenchMessages.CopyResourceAction_selectDestination);
    dialog.setValidator(this);
    dialog.showClosedProjects(false);
    dialog.open();
    Object[] result = dialog.getResult();
    if (result != null && result.length == 1) {
        return (IPath) result[0];
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog)

Example 22 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project Pydev by fabioz.

the class WorkingDirectoryBlock method handleWorkspaceDirBrowseButtonSelected.

/**
 * Show a dialog that lets the user select a working directory from
 * the workspace
 */
private void handleWorkspaceDirBrowseButtonSelected() {
    IContainer currentContainer = getContainer();
    if (currentContainer == null) {
        currentContainer = ResourcesPlugin.getWorkspace().getRoot();
    }
    ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), currentContainer, false, "Select a workspace relative working directory");
    dialog.showClosedProjects(false);
    dialog.open();
    Object[] results = dialog.getResult();
    if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) {
        IPath path = (IPath) results[0];
        String containerName = path.makeRelative().toString();
        // $NON-NLS-1$ //$NON-NLS-2$
        setOtherWorkingDirectoryText("${workspace_loc:" + containerName + "}");
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) IContainer(org.eclipse.core.resources.IContainer)

Example 23 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project subclipse by subclipse.

the class CopyAction method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    final IResource[] resources = getSelectedResources();
    final IProject project = resources[0].getProject();
    ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), project, false, // $NON-NLS-1$
    Policy.bind("CopyAction.selectionLabel"));
    if (dialog.open() == ContainerSelectionDialog.CANCEL)
        return;
    Object[] result = dialog.getResult();
    if (result == null || result.length == 0)
        return;
    final Path path = (Path) result[0];
    IProject selectedProject;
    File target = null;
    if (path.segmentCount() == 1) {
        selectedProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.toString());
        target = selectedProject.getLocation().toFile();
    } else {
        IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        selectedProject = targetFile.getProject();
        target = targetFile.getLocation().toFile();
    }
    final IProject targetProject = selectedProject;
    final File destPath = target;
    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

        public void run() {
            ISVNClientAdapter client = null;
            ISVNRepositoryLocation repository = null;
            try {
                ISVNLocalResource svnTargetResource = SVNWorkspaceRoot.getSVNResourceFor(targetProject);
                for (int i = 0; i < resources.length; i++) {
                    final IResource resource = resources[i];
                    if (client == null) {
                        repository = SVNWorkspaceRoot.getSVNResourceFor(resources[i]).getRepository();
                        client = repository.getSVNClient();
                    }
                    File checkFile = new File(destPath.getPath() + File.separator + resource.getName());
                    File srcPath = new File(resource.getLocation().toString());
                    File newDestPath = new File(destPath.getPath() + File.separator + resource.getName());
                    if (checkFile.exists()) {
                        IInputValidator inputValidator = new IInputValidator() {

                            public String isValid(String newText) {
                                if (newText.equals(resource.getName()))
                                    // $NON-NLS-1$
                                    return Policy.bind("CopyAction.nameConflictSame");
                                return null;
                            }
                        };
                        InputDialog inputDialog = new InputDialog(getShell(), Policy.bind("CopyAction.nameConflictTitle"), Policy.bind("CopyAction.nameConflictMessage", resource.getName()), "Copy of " + resource.getName(), // $NON-NLS-1$
                        inputValidator);
                        if (inputDialog.open() == InputDialog.CANCEL)
                            return;
                        String newName = inputDialog.getValue();
                        if (newName == null || newName.trim().length() == 0)
                            return;
                        newDestPath = new File(destPath.getPath() + File.separator + newName);
                    }
                    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                    boolean sameRepository = svnTargetResource != null && svnTargetResource.getRepository() != null && svnTargetResource.getRepository().getLocation().equals(svnResource.getRepository().getLocation());
                    if (sameRepository)
                        client.copy(srcPath, newDestPath);
                    else
                        client.doExport(srcPath, newDestPath, true);
                    SVNUIPlugin.getPlugin().getRepositoryManager().resourceCreated(null, null);
                }
                targetProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
            } catch (Exception e) {
                MessageDialog.openError(getShell(), Policy.bind("CopyAction.copy"), // $NON-NLS-1$
                e.getMessage());
            } finally {
                if (repository != null) {
                    repository.returnSVNClient(client);
                }
            }
        }
    });
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) InputDialog(org.eclipse.jface.dialogs.InputDialog) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 24 with ContainerSelectionDialog

use of org.eclipse.ui.dialogs.ContainerSelectionDialog in project subclipse by subclipse.

the class SVNHistoryPage method getCopyChangedPathAction.

private IAction getCopyChangedPathAction() {
    if (copyChangedPathAction == null) {
        copyChangedPathAction = new // $NON-NLS-1$
        Action(// $NON-NLS-1$
        Policy.bind("HistoryView.copyChangedPath")) {

            public void run() {
                ContainerSelectionDialog dialog = new ContainerSelectionDialog(Display.getDefault().getActiveShell(), null, false, // $NON-NLS-1$
                Policy.bind("CopyAction.selectionLabel"));
                if (dialog.open() == ContainerSelectionDialog.OK) {
                    Object[] result = dialog.getResult();
                    if (result == null || result.length == 0)
                        return;
                    final Path path = (Path) result[0];
                    IProject selectedProject;
                    File target = null;
                    if (path.segmentCount() == 1) {
                        selectedProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.toString());
                        target = selectedProject.getLocation().toFile();
                    } else {
                        IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
                        selectedProject = targetFile.getProject();
                        target = targetFile.getLocation().toFile();
                    }
                    final IProject targetProject = selectedProject;
                    final File destPath = target;
                    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                        public void run() {
                            ISVNClientAdapter client = null;
                            try {
                                IStructuredSelection sel = (IStructuredSelection) changePathsViewer.getSelection();
                                if (sel.getFirstElement() instanceof LogEntryChangePath) {
                                    LogEntryChangePath changePath = (LogEntryChangePath) sel.getFirstElement();
                                    SVNRevision revision = changePath.getRevision();
                                    if (changePath.getAction() == 'D') {
                                        long rev = Long.parseLong(revision.toString());
                                        rev--;
                                        revision = new SVNRevision.Number(rev);
                                    }
                                    client = SVNProviderPlugin.getPlugin().getSVNClient();
                                    client.copy(changePath.getUrl(), destPath, revision, revision, true, false);
                                    targetProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                                    SVNUIPlugin.getPlugin().getRepositoryManager().resourceCreated(null, null);
                                }
                            } catch (Exception e) {
                                MessageDialog.openError(Display.getDefault().getActiveShell(), Policy.bind("HistoryView.copyError"), // $NON-NLS-1$
                                e.getMessage());
                            } finally {
                                SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
                            }
                        }
                    });
                }
            }
        };
    }
    return copyChangedPathAction;
}
Also used : LogEntryChangePath(org.tigris.subversion.subclipse.core.history.LogEntryChangePath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) LogEntryChangePath(org.tigris.subversion.subclipse.core.history.LogEntryChangePath) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) ParseException(java.text.ParseException) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) IFile(org.eclipse.core.resources.IFile) ISVNLocalFile(org.tigris.subversion.subclipse.core.ISVNLocalFile) File(java.io.File) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 25 with ContainerSelectionDialog

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

the class UIDialogs method testCopyMoveResource.

@Test
public void testCopyMoveResource() {
    Dialog dialog = new ContainerSelectionDialog(getShell(), null, true, "Select Destination");
    DialogCheck.assertDialog(dialog);
}
Also used : SelectPerspectiveDialog(org.eclipse.ui.internal.dialogs.SelectPerspectiveDialog) ProjectLocationSelectionDialog(org.eclipse.ui.dialogs.ProjectLocationSelectionDialog) TypeFilteringDialog(org.eclipse.ui.dialogs.TypeFilteringDialog) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) FileExtensionDialog(org.eclipse.ui.internal.dialogs.FileExtensionDialog) EditorSelectionDialog(org.eclipse.ui.dialogs.EditorSelectionDialog) AboutDialog(org.eclipse.ui.internal.dialogs.AboutDialog) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) SavePerspectiveDialog(org.eclipse.ui.internal.dialogs.SavePerspectiveDialog) Dialog(org.eclipse.jface.dialogs.Dialog) ListSelectionDialog(org.eclipse.ui.dialogs.ListSelectionDialog) ShowViewDialog(org.eclipse.ui.internal.dialogs.ShowViewDialog) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) Test(org.junit.Test)

Aggregations

ContainerSelectionDialog (org.eclipse.ui.dialogs.ContainerSelectionDialog)30 IPath (org.eclipse.core.runtime.IPath)15 GridData (org.eclipse.swt.layout.GridData)11 IProject (org.eclipse.core.resources.IProject)8 File (java.io.File)7 Path (org.eclipse.core.runtime.Path)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 GridLayout (org.eclipse.swt.layout.GridLayout)7 Button (org.eclipse.swt.widgets.Button)7 IResource (org.eclipse.core.resources.IResource)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 Label (org.eclipse.swt.widgets.Label)6 Text (org.eclipse.swt.widgets.Text)6 IContainer (org.eclipse.core.resources.IContainer)5 Composite (org.eclipse.swt.widgets.Composite)5 IFolder (org.eclipse.core.resources.IFolder)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)4 ModifyListener (org.eclipse.swt.events.ModifyListener)4 Group (org.eclipse.swt.widgets.Group)4