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;
}
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 + "}");
}
}
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);
}
}
}
});
}
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;
}
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);
}
Aggregations