use of org.eclipse.jface.viewers.ViewerFilter in project tdi-studio-se by Talend.
the class AbstractVersionManagementProjectSettingPage method addRepositoryTreeViewer.
/**
* repository tree viewer.
*/
private void addRepositoryTreeViewer(Composite leftComposite) {
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.widthHint = 210;
gridData.heightHint = 400;
leftComposite.setLayoutData(gridData);
RepoCommonViewerProvider provider = RepoCommonViewerProvider.CHECKBOX;
treeViewer = (CheckboxRepositoryTreeViewer) provider.createViewer(leftComposite);
IProjectRepositoryNode projectRepositoryNode = provider.getProjectRepositoryNode();
processItems(versionObjects, (RepositoryNode) projectRepositoryNode);
addMenuAction(treeViewer.getTree());
// filter
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
RepositoryNode node = (RepositoryNode) element;
return filterRepositoryNode(node);
}
});
// event
treeViewer.addCheckStateListener(checkStateListener);
treeViewer.addTreeListener(new ITreeViewerListener() {
@Override
public void treeCollapsed(TreeExpansionEvent event) {
//
}
@Override
public void treeExpanded(TreeExpansionEvent event) {
// refreshCheckedTreeView();
}
});
expandSomeNodes(projectRepositoryNode);
}
use of org.eclipse.jface.viewers.ViewerFilter in project sling by apache.
the class ConvertToContentProjectHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IProject project = (IProject) ((IStructuredSelection) selection).getFirstElement();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getDisplay().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
dialog.setMessage("Select content sync root location (containing the jcr root)");
dialog.setTitle("Content Sync Root");
IContainer initialContainer = ProjectHelper.getInferredContentProjectContentRoot(project);
if (initialContainer != null) {
dialog.setInitialElementSelections(Arrays.asList(initialContainer));
}
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IProject) {
return ((IProject) element).equals(project);
}
// display folders only
return element instanceof IContainer;
}
});
dialog.setInput(new IWorkbenchAdapter() {
@Override
public Object getParent(Object o) {
return null;
}
@Override
public String getLabel(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
return null;
}
@Override
public Object[] getChildren(Object o) {
return new Object[] { project };
}
});
// this is the root element
dialog.setAllowMultiple(false);
dialog.setValidator(new ISelectionStatusValidator() {
@Override
public IStatus validate(Object[] selection) {
if (selection.length > 0) {
final Object item = selection[0];
if (item instanceof IContainer) {
IContainer selectedContainer = (IContainer) item;
String errorMsg = ProjectHelper.validateContentPackageStructure(selectedContainer);
if (errorMsg != null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMsg);
} else {
return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
}
}
}
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "");
}
});
if (dialog.open() == ContainerSelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result != null && result.length > 0) {
final IContainer container = (IContainer) result[0];
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
IResource jcrRoot = container.findMember("jcr_root");
if (jcrRoot == null || !(jcrRoot instanceof IFolder)) {
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", "jcr_root not found under " + container + " (or not a Folder)");
return;
}
ConfigurationHelper.convertToContentPackageProject(project, monitor, jcrRoot.getProjectRelativePath());
} catch (CoreException e) {
Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
} catch (Exception e) {
Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
}
}
}
}
return null;
}
use of org.eclipse.jface.viewers.ViewerFilter in project bndtools by bndtools.
the class ResolutionView method createPartControl.
@Override
public void createPartControl(Composite parent) {
this.display = parent.getDisplay();
SashForm splitPanel = new SashForm(parent, SWT.HORIZONTAL);
splitPanel.setLayout(new FillLayout());
Composite reqsPanel = new Composite(splitPanel, SWT.NONE);
reqsPanel.setBackground(parent.getBackground());
GridLayout reqsLayout = new GridLayout(1, false);
reqsLayout.marginWidth = 0;
reqsLayout.marginHeight = 0;
reqsLayout.verticalSpacing = 2;
reqsPanel.setLayout(reqsLayout);
new Label(reqsPanel, SWT.NONE).setText("Requirements:");
reqsTree = new Tree(reqsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
reqsTree.setHeaderVisible(false);
reqsTree.setLinesVisible(false);
reqsTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
reqsViewer = new TreeViewer(reqsTree);
ColumnViewerToolTipSupport.enableFor(reqsViewer);
reqsViewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
reqsViewer.setContentProvider(new CapReqMapContentProvider());
Composite capsPanel = new Composite(splitPanel, SWT.NONE);
capsPanel.setBackground(parent.getBackground());
GridLayout capsLayout = new GridLayout(1, false);
capsLayout.marginWidth = 0;
capsLayout.marginHeight = 0;
capsLayout.verticalSpacing = 2;
capsPanel.setLayout(capsLayout);
new Label(capsPanel, SWT.NONE).setText("Capabilities:");
capsTable = new Table(capsPanel, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
capsTable.setHeaderVisible(false);
capsTable.setLinesVisible(false);
capsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
capsViewer = new TableViewer(capsTable);
ColumnViewerToolTipSupport.enableFor(capsViewer);
capsViewer.setLabelProvider(new CapabilityLabelProvider(true));
capsViewer.setContentProvider(new CapReqMapContentProvider());
capsViewer.setFilters(new ViewerFilter[] { new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
return !filteredCapabilityNamespaces.contains(((Capability) element).getNamespace());
}
} });
hideSelfImportsFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof RequirementWrapper) {
RequirementWrapper rw = (RequirementWrapper) element;
return !rw.resolved;
}
return true;
}
};
reqsViewer.setFilters(new ViewerFilter[] { hideSelfImportsFilter });
reqsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(reqsViewer));
capsViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new LocalTransferDragListener(capsViewer));
reqsViewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
Object item = iter.next();
if (item instanceof Clazz) {
Clazz clazz = (Clazz) item;
String className = clazz.getFQN();
IType type = null;
if (!loaders.isEmpty()) {
IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
for (CapReqLoader loader : loaders) {
if (loader instanceof BndBuilderCapReqLoader) {
File loaderFile = ((BndBuilderCapReqLoader) loader).getFile();
IFile[] wsfiles = wsroot.findFilesForLocationURI(loaderFile.toURI());
for (IFile wsfile : wsfiles) {
IJavaProject javaProject = JavaCore.create(wsfile.getProject());
try {
type = javaProject.findType(className);
if (type != null)
break;
} catch (JavaModelException e) {
ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
}
}
}
}
}
try {
if (type != null)
JavaUI.openInEditor(type, true, true);
} catch (PartInitException e) {
ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java editor for class '{0}'.", className), e));
} catch (JavaModelException e) {
ErrorDialog.openError(getSite().getShell(), "Error", "", new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening Java class '{0}'.", className), e));
}
}
}
}
});
fillActionBars();
getSite().getPage().addPostSelectionListener(this);
getSite().getPage().addPartListener(partAdapter);
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
// Current selection & part
IWorkbenchPart activePart = getSite().getPage().getActivePart();
ISelection activeSelection = getSite().getWorkbenchWindow().getSelectionService().getSelection();
selectionChanged(activePart, activeSelection);
}
use of org.eclipse.jface.viewers.ViewerFilter in project bndtools by bndtools.
the class BundleCalculatedImportsPart method createSection.
private void createSection(Section section, FormToolkit toolkit) {
// CREATE COMPONENTS
section.setText(Messages.BundleCalculatedImportsPart_title);
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
final ToolItem showSelfImportsItem = new ToolItem(toolbar, SWT.CHECK);
showSelfImportsItem.setImage(imgShowSelfImports);
showSelfImportsItem.setToolTipText(Messages.BundleCalculatedImportsPart_tooltipShowSelfImports);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
// toolkit.createLabel(composite,
// Messages.BundleCalculatedImportsPart_description, SWT.WRAP);
tree = toolkit.createTree(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
viewer = new TreeViewer(tree);
viewer.setContentProvider(new CapReqMapContentProvider());
viewer.setLabelProvider(new RequirementWrapperLabelProvider(true));
ColumnViewerToolTipSupport.enableFor(viewer);
nonPkgFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof RequirementWrapper)
return PackageNamespace.PACKAGE_NAMESPACE.equals(((RequirementWrapper) element).requirement.getNamespace());
return true;
}
};
hideSelfImportsFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof RequirementWrapper)
return !((RequirementWrapper) element).resolved;
return true;
}
};
viewer.setFilters(new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter });
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
getManagedForm().fireSelectionChanged(BundleCalculatedImportsPart.this, event.getSelection());
}
});
viewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceAdapter() {
@Override
public void dragSetData(DragSourceEvent event) {
LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
if (transfer.isSupportedType(event.dataType))
transfer.setSelection(viewer.getSelection());
}
});
viewer.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
Object item = iter.next();
if (item instanceof Clazz) {
Clazz importUsedBy = (Clazz) item;
String className = importUsedBy.getFQN();
IType type = null;
IFile file = getEditorFile();
if (file != null) {
IJavaProject javaProject = JavaCore.create(file.getProject());
try {
type = javaProject.findType(className);
} catch (JavaModelException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, Messages.BundleCalculatedImportsPart_errorFindingType, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
}
}
try {
if (type != null)
JavaUI.openInEditor(type, true, true);
} catch (PartInitException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningJavaEditor, className), e));
} catch (JavaModelException e) {
ErrorDialog.openError(tree.getShell(), Messages.BundleCalculatedImportsPart_error, null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format(Messages.BundleCalculatedImportsPart_errorOpeningClass, className), e));
}
}
}
}
});
// LISTENERS
showSelfImportsItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean showSelfImports = showSelfImportsItem.getSelection();
ViewerFilter[] filters = showSelfImports ? new ViewerFilter[] { nonPkgFilter } : new ViewerFilter[] { nonPkgFilter, hideSelfImportsFilter };
viewer.setFilters(filters);
}
});
// LAYOUT
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 2;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 75;
gd.widthHint = 75;
tree.setLayoutData(gd);
}
Aggregations