use of org.eclipse.ui.model.WorkbenchContentProvider in project jbosstools-hibernate by jbosstools.
the class DialogSelectionHelper method chooseFileEntries.
/**
* Shows the UI to select new JAR or ZIP archive entries located in the workspace.
* The dialog returns the selected entries or <code>null</code> if the dialog has
* been cancelled. The dialog does not apply any changes.
* @param shell The parent shell for the dialog.
* @param initialSelection The path of the element (container or archive) to initially select or <code>null</code> to not select an entry.
* @param usedEntries An array of paths that are already on the classpath and therefore should not be
* selected again.
* @param fileExtensions An array of file extensions.
* @param allowMultiple allow multiple selections.
* @param allowFiles TODO
* @param acceptedTypes TODO
*
* @return Returns the new classpath container entry paths or <code>null</code> if the dialog has
* been cancelled by the user.
*
* Inspired by BuildPathDialogAccess.chooseJAREntries from jdt.ui.wizards
*/
public static IPath[] chooseFileEntries(Shell shell, IPath initialSelection, IPath[] usedEntries, String title, String description, String[] fileExtensions, boolean allowMultiple, boolean allowDirectories, boolean allowFiles) {
if (usedEntries == null) {
throw new IllegalArgumentException(HibernateConsoleMessages.DialogSelectionHelper_used_entries_must_be_notnull);
}
List<Class<?>> clazzes = new ArrayList<Class<?>>();
if (allowDirectories) {
clazzes.add(IFolder.class);
clazzes.add(IProject.class);
}
if (allowFiles) {
clazzes.add(IFile.class);
}
Class<?>[] acceptedClasses = clazzes.toArray(new Class[clazzes.size()]);
TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, true);
List<IResource> usedFiles = new ArrayList<IResource>(usedEntries.length);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
for (int i = 0; i < usedEntries.length; i++) {
IResource resource = root.findMember(usedEntries[i]);
if (resource instanceof IFile) {
usedFiles.add(resource);
}
}
IResource focus = initialSelection != null ? root.findMember(initialSelection) : null;
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setValidator(validator);
dialog.setAllowMultiple(allowMultiple);
dialog.setTitle(title);
dialog.setMessage(description);
dialog.addFilter(new FileFilter(fileExtensions, usedFiles, true, allowDirectories));
dialog.setInput(root);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setInitialSelection(focus);
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
IPath[] res = new IPath[elements.length];
for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i];
res[i] = elem.getFullPath();
}
return res;
}
return null;
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createWorkspaceFolderDialog.
private ElementTreeSelectionDialog createWorkspaceFolderDialog(Shell shell, String selectedFile) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle("Select a workspace folder");
dialog.setMessage("Select a workspace folder to deploy");
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (!(element instanceof IContainer)) {
return false;
}
IContainer container = (IContainer) element;
return container.isAccessible() && !ProjectUtils.isInternalPde(container.getName()) && !ProjectUtils.isInternalRSE(container.getName());
}
});
dialog.setAllowMultiple(false);
org.eclipse.core.resources.IResource res = model.getDeployProject();
if (org.apache.commons.lang.StringUtils.isNotBlank(selectedFile)) {
String path = VariablesHelper.getWorkspacePath(selectedFile);
org.eclipse.core.resources.IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
if (member != null) {
res = member;
}
}
if (res != null) {
dialog.setInitialSelection(res);
}
return dialog;
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project jbosstools-openshift by jbosstools.
the class UIUtils method createFileDialog.
/**
* Create a file selection dialog.
*
* @param selectedFile the initial selected file. May be null
* @param title the title of the dialog
* @param message the message of the dialog
* @param extension the extension to filter. If null or empty, all files are accepted
* @param initialSelection the initial selection resource (used if selectedFile is null)
* @return the dialog
*/
public static ElementTreeSelectionDialog createFileDialog(String selectedFile, String title, String message, String extension, IResource initialSelection) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return element instanceof IContainer || (element instanceof IFile && (StringUtils.isEmpty(extension) || extension.equals(((IFile) element).getFileExtension())));
}
});
dialog.setAllowMultiple(false);
if (StringUtils.isNotBlank(selectedFile)) {
String prefix = "${workspace_loc:";
String path = selectedFile;
if (selectedFile.startsWith(prefix) && selectedFile.endsWith("}")) {
path = path.substring(prefix.length(), path.length() - 1);
}
initialSelection = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
}
if (initialSelection != null) {
dialog.setInitialSelection(initialSelection);
}
return dialog;
}
Aggregations