use of org.eclipse.ui.model.WorkbenchContentProvider in project InformationSystem by ObeoNetwork.
the class SpecificWorkspaceResourceDialog method openFolderOrFileSelection.
public static IResource openFolderOrFileSelection(Shell parent, String title, String message, IPath suggestedPath, List<ViewerFilter> viewerFilters) {
final SpecificWorkspaceResourceDialog dialog = new SpecificWorkspaceResourceDialog(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setAllowMultiple(false);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setShowNewFolderControl(true);
dialog.setShowFileControl(false);
dialog.addFilter(dialog.createDefaultViewerFilter(false));
if (viewerFilters != null) {
for (ViewerFilter viewerFilter : viewerFilters) {
dialog.addFilter(viewerFilter);
}
}
if (suggestedPath != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(suggestedPath);
if (resource != null && resource.isAccessible()) {
if (resource instanceof IContainer) {
dialog.setInitialSelection(resource);
} else {
dialog.setInitialSelection(resource.getParent());
dialog.setFileText(resource.getName());
}
} else {
if (suggestedPath.segmentCount() > 1) {
if (resource == null) {
resource = root.getFile(suggestedPath);
}
if (resource.getProject().isAccessible()) {
IContainer container = resource.getParent();
for (; !container.isAccessible() && container != resource.getProject(); container = container.getParent()) {
// Do nothing
}
dialog.setInitialSelection(container);
suggestedPath = suggestedPath.removeFirstSegments(container.getFullPath().segmentCount());
dialog.setFileText(suggestedPath.toString());
suggestedPath = null;
}
}
if (suggestedPath != null) {
String fileText = suggestedPath.isAbsolute() ? suggestedPath.removeFirstSegments(1).toString() : suggestedPath.toString();
dialog.setFileText(fileText);
}
}
}
dialog.loadContents();
return dialog.open() == Window.OK ? dialog.getSelectedContainers()[0] : null;
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project bndtools by bndtools.
the class JarListWizardPage method createControl.
@Override
public void createControl(final Composite parent) {
setTitle("Select JARs");
final Composite composite = new Composite(parent, SWT.NONE);
Label lblHint = new Label(composite, SWT.WRAP);
lblHint.setText("Selected files (hint: drag files from an external application into this list):");
final Table table = new Table(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ClassPathLabelProvider());
btnAdd = new Button(composite, SWT.PUSH);
btnAdd.setText("Add");
btnAddExternal = new Button(composite, SWT.PUSH);
btnAddExternal.setText("Add External");
btnRemove = new Button(composite, SWT.PUSH);
btnRemove.setText("Remove");
viewer.setInput(paths);
update();
// Listeners
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
return true;
}
@Override
public boolean performDrop(Object data) {
if (data instanceof String[]) {
String[] newPaths = (String[]) data;
List<IPath> added = new ArrayList<IPath>(newPaths.length);
for (String path : newPaths) {
added.add(new Path(path));
}
if (!added.isEmpty()) {
addToPaths(added);
viewer.add(added.toArray());
update();
}
}
return true;
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setSelectionFeedbackEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { FileTransfer.getInstance() }, dropAdapter);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
update();
}
});
btnAdd.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// IResource newFile = ResourcesPlugin.getWorkspace().getRoot();
// if(newFile != null) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setValidator(new ISelectionStatusValidator() {
@Override
public IStatus validate(Object[] selection) {
if (selection.length > 0 && selection[0] instanceof IFile) {
// $NON-NLS-1$
return new Status(IStatus.OK, Plugin.PLUGIN_ID, IStatus.OK, "", null);
}
// $NON-NLS-1$
return new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.ERROR, "", null);
}
});
dialog.setAllowMultiple(true);
dialog.setTitle("JAR File Selection");
dialog.setMessage("Select one or more JAR files.");
// $NON-NLS-1$
dialog.addFilter(new FileExtensionFilter("jar"));
dialog.setInput(ResourcesPlugin.getWorkspace());
if (dialog.open() == Window.OK) {
Object[] files = dialog.getResult();
List<IPath> added = new ArrayList<IPath>(files.length);
for (Object file : files) {
added.add(((IResource) file).getFullPath().makeRelative());
}
if (!added.isEmpty()) {
addToPaths(added);
viewer.add(added.toArray());
}
}
// }
update();
}
});
btnAddExternal.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.MULTI);
dialog.setFilterExtensions(new String[] { // $NON-NLS-1$
"*.jar" });
String res = dialog.open();
if (res != null) {
IPath filterPath = new Path(dialog.getFilterPath());
String[] fileNames = dialog.getFileNames();
List<IPath> added = new ArrayList<IPath>(fileNames.length);
for (String fileName : fileNames) {
added.add(filterPath.append(fileName));
}
if (!added.isEmpty()) {
addToPaths(added);
viewer.add(added.toArray());
}
}
update();
}
});
btnRemove.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent e) {
removeFromPaths(((IStructuredSelection) viewer.getSelection()).toList());
viewer.remove(((IStructuredSelection) viewer.getSelection()).toArray());
update();
}
});
// Layout
composite.setLayout(new GridLayout(2, false));
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3));
btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
btnAddExternal.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
lblHint.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1));
setControl(composite);
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project bndtools by bndtools.
the class WizardBndFileSelector method setupTree.
private void setupTree(final List<IResource> bndFiles) {
checkboxTreeViewer.setContentProvider(new WorkbenchContentProvider() {
@Override
public Object[] getChildren(Object element) {
Object[] children = super.getChildren(element);
List<IResource> resources = new ArrayList<IResource>();
for (Object o : children) {
IPath child = ((IResource) o).getProjectRelativePath();
for (IResource bndFile : bndFiles) {
if (child.isPrefixOf(bndFile.getProjectRelativePath()) || child.equals(bndFile.getProjectRelativePath())) {
resources.add((IResource) o);
break;
}
}
}
return resources.toArray();
}
});
checkboxTreeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
checkboxTreeViewer.expandAll();
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project mechanoid by robotoworks.
the class PackageBrowserField method onBrowseButtonPressed.
@Override
protected void onBrowseButtonPressed() {
Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
ListDialog dialog = new ListDialog(shell);
dialog.setContentProvider(new WorkbenchContentProvider());
dialog.setInput("hi");
dialog.setLabelProvider(new WorkbenchLabelProvider());
dialog.setBlockOnOpen(true);
if (dialog.open() == Window.OK) {
// TODO
}
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project jbosstools-hibernate by jbosstools.
the class DialogSelectionHelper method chooseFolderEntries.
public static IPath[] chooseFolderEntries(Shell shell, IPath initialSelection, String title, String description, boolean allowMultiple) {
List<Class<?>> clazzes = new ArrayList<Class<?>>();
clazzes.add(IFolder.class);
clazzes.add(IProject.class);
Class<?>[] acceptedClasses = clazzes.toArray(new Class[clazzes.size()]);
TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, true);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource focus = initialSelection != null ? root.findMember(initialSelection) : null;
ElementTreeSelectionDialog dialog = null;
dialog = new FolderSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setValidator(validator);
dialog.setAllowMultiple(allowMultiple);
dialog.setTitle(title);
dialog.setMessage(description);
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;
}
Aggregations