use of org.eclipse.ui.model.WorkbenchContentProvider in project generator by mybatis.
the class AbstractGeneratorComposite method chooseFileFromWorkspace.
protected IResource chooseFileFromWorkspace() {
ElementTreeSelectionDialog esd = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
esd.setTitle(getDialogTitle());
esd.setMessage(getDialogMessage());
esd.setAllowMultiple(false);
esd.setValidator(selectionStatusVerifier);
esd.addFilter(getViewerFilter());
esd.setInput(ResourcesPlugin.getWorkspace().getRoot());
esd.setInitialSelection(getWorkspaceResource());
int rc = esd.open();
if (rc == 0) {
Object[] elements = esd.getResult();
if (elements.length > 0) {
return (IResource) elements[0];
}
}
return null;
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project translationstudio8 by heartsome.
the class WizardExportResourcesPage2 method getResourceProvider.
/**
* Returns a content provider for <code>IResource</code>s that returns only children of the given resource type.
*/
private ITreeContentProvider getResourceProvider(final int resourceType) {
return new WorkbenchContentProvider() {
public Object[] getChildren(Object o) {
if (o instanceof IContainer) {
IResource[] members = null;
try {
members = ((IContainer) o).members();
} catch (CoreException e) {
// just return an empty set of children
return new Object[0];
}
// filter out the desired resource types
ArrayList results = new ArrayList();
for (int i = 0; i < members.length; i++) {
if (members[i].getName().equals(".config") || members[i].getName().equals(".project") || members[i].getName().equalsIgnoreCase(".temp")) {
defaultExportItems.add(members[i]);
continue;
}
// And the test bits with the resource types to see if they are what we want
if ((members[i].getType() & resourceType) > 0) {
results.add(members[i]);
}
}
return results.toArray();
}
// input element case
if (o instanceof ArrayList) {
return ((ArrayList) o).toArray();
}
return new Object[0];
}
};
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project xtext-eclipse by eclipse.
the class ProjectSelectionDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
Font font = parent.getFont();
composite.setFont(font);
createMessageArea(composite);
tableViewer = new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray());
}
});
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
okPressed();
}
});
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = SIZING_SELECTION_WIDGET_HEIGHT;
data.widthHint = SIZING_SELECTION_WIDGET_WIDTH;
tableViewer.getTable().setLayoutData(data);
tableViewer.setContentProvider(new WorkbenchContentProvider());
tableViewer.setLabelProvider(new WorkbenchLabelProvider());
tableViewer.setComparator(new ResourceComparator(ResourceComparator.NAME));
tableViewer.getControl().setFont(font);
Button checkbox = new Button(composite, SWT.CHECK);
checkbox.setText(Messages.ProjectSelectionDialog_filter);
checkbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false));
checkbox.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
updateFilter(((Button) e.widget).getSelection());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
updateFilter(((Button) e.widget).getSelection());
}
});
boolean doFilter = !dialogSettings.getBoolean(DIALOG_SETTINGS_SHOW_ALL) && !projectsWithSpecifics.isEmpty();
checkbox.setSelection(doFilter);
updateFilter(doFilter);
tableViewer.setInput(ResourcesPlugin.getWorkspace());
doSelectionChanged(new Object[0]);
Dialog.applyDialogFont(composite);
return composite;
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project linuxtools by eclipse.
the class BuildDockerImageLaunchConfigurationMainTab method onBrowseWorkspace.
/**
* Opens a dialog to browse the workspace
*
* @return
*/
private SelectionListener onBrowseWorkspace(final Text pathText, final Class<?> expectedType) {
return SelectionListener.widgetSelectedAdapter(e -> {
final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setTitle(LaunchMessages.getString(BROWSE_WORKSPACE_DIALOG_TITLE));
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setAllowMultiple(false);
dialog.setValidator(selection -> {
if (selection.length == 1 && expectedType.isAssignableFrom(selection[0].getClass())) {
return new Status(IStatus.OK, Activator.PLUGIN_ID, null);
}
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, null);
});
if (dialog.open() == IDialogConstants.OK_ID) {
final IResource selection = (IResource) dialog.getFirstResult();
pathText.setText(selection.getFullPath().toOSString());
buildContextPathWorkspaceRelative = true;
}
});
}
use of org.eclipse.ui.model.WorkbenchContentProvider in project linuxtools by eclipse.
the class DockerComposeUpLaunchConfigurationMainTab method onBrowseWorkspace.
/**
* Opens a dialog to browse the workspace
*
* @return
*/
private SelectionListener onBrowseWorkspace(final Text pathText, final Class<?> expectedType) {
return SelectionListener.widgetSelectedAdapter(e -> {
final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setTitle(LaunchMessages.getString(// $NON-NLS-1$
"DockerComposeUpLaunchConfigurationMainTab.dockerComposePath.browseworkspace.dialog.title"));
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setAllowMultiple(false);
dialog.setValidator(selection -> {
if (selection.length == 1 && expectedType.isAssignableFrom(selection[0].getClass())) {
return new Status(IStatus.OK, Activator.PLUGIN_ID, null);
}
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, null);
});
if (dialog.open() == IDialogConstants.OK_ID) {
final IResource selection = (IResource) dialog.getFirstResult();
pathText.setText(selection.getFullPath().toOSString());
dockerComposeFilePathWorkspaceRelative = true;
}
});
}
Aggregations