private void chooseWebappDir() { IProject project = ResourcesPlugin.getWorkspace().getRoot() .getProject(fProjText.getText()); ContainerSelectionDialog dialog = new ContainerSelectionDialog( getShell(), project, false, "Select Web Application Directory"); dialog.setTitle("Folder Selection"); if (project != null) { IPath path = project.getFullPath(); dialog.setInitialSelections(new Object[] { path }); } dialog.showClosedProjects(false); dialog.open(); Object[] results = dialog.getResult(); if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) { IPath path = (IPath) results[0]; path = path.removeFirstSegments(1); String containerName = path.makeRelative().toString(); fWebAppDirText.setText(containerName); } }
/** * Creates a resource container selection dialog rooted at the given resource. * All selections are considered valid. * * @param parentShell the parent shell * @param initialRoot the initial selection in the tree * @param allowNewContainerName <code>true</code> to enable the user to type in * a new container name, and <code>false</code> to restrict the user to just * selecting from existing ones * @param message the message to be displayed at the top of this dialog, or * <code>null</code> to display a default message */ public ContainerSelectionDialog(Shell parentShell, IContainer initialRoot, boolean allowNewContainerName, String message) { super(parentShell); setTitle(IDEWorkbenchMessages.ContainerSelectionDialog_title); this.initialSelection = initialRoot; this.allowNewContainerName = allowNewContainerName; if (message != null) { setMessage(message); } else { setMessage(IDEWorkbenchMessages.ContainerSelectionDialog_message); } setShellStyle(getShellStyle() | SWT.SHEET); }
/** * Shows a dialog to select a folder from the workspace * * @param project the project * @param shell the shell * @param title the title * @param message the message * @param path the initial path * @return the result, null if canceled */ public static String chooseWorkspaceDirectory(Shell shell, IProject project, String title, String message, String path) { path = JettyPluginUtils.resolveVariables(path); ContainerSelectionDialog dialog = new ContainerSelectionDialog(shell, project, false, message); dialog.setTitle(title); if (project != null) { dialog.setInitialSelections(new Object[]{path}); } dialog.showClosedProjects(false); dialog.open(); Object[] results = dialog.getResult(); if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) { IPath folder = (IPath) results[0]; return JettyPluginUtils.toRelativePath(project, folder.toString()); } return null; }
/** * Queries the user to supply a container resource. * * @return the path to an existing or new container, or <code>null</code> if the * user cancelled the dialog */ protected IPath queryForContainer(IContainer initialSelection, String msg, String title) { ContainerSelectionDialog dialog = new ContainerSelectionDialog( getControl().getShell(), initialSelection, allowNewContainerName(), msg); if (title != null) { dialog.setTitle(title); } dialog.showClosedProjects(false); dialog.open(); Object[] result = dialog.getResult(); if (result != null && result.length == 1) { return (IPath) result[0]; } return null; }