use of org.knime.workbench.ui.navigator.KnimeResourceLabelProvider in project knime-core by knime.
the class WorkflowExportPage method createTreeViewer.
private void createTreeViewer(final Composite parent) {
m_treeViewer = new CheckboxTreeViewer(parent);
m_treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
m_treeViewer.setContentProvider(new ITreeContentProvider() {
// assume to have IContainers as input
@Override
public Object[] getChildren(final Object parentElement) {
if (parentElement instanceof IContainer) {
IContainer container = (IContainer) parentElement;
try {
// return only workflows and workflow groups
Collection<IContainer> children = new ArrayList<IContainer>();
for (IResource r : container.members(false)) {
if (KnimeResourceUtil.isWorkflow(r) || KnimeResourceUtil.isWorkflowGroup(r)) {
// if it is a workflow or workflow group
// it must be a container
children.add((IContainer) r);
}
}
return children.toArray();
} catch (CoreException e) {
return new Object[0];
}
}
return new Object[0];
}
@Override
public Object getParent(final Object element) {
if (element instanceof IResource) {
return ((IResource) element).getParent();
}
return null;
}
@Override
public boolean hasChildren(final Object element) {
if (element instanceof IWorkspaceRoot) {
return true;
}
if ((element instanceof IContainer) && KnimeResourceUtil.isWorkflowGroup((IContainer) element)) {
return true;
}
return false;
}
@Override
public Object[] getElements(final Object inputElement) {
return getChildren(inputElement);
}
@Override
public void dispose() {
// nothing to do
}
@Override
public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
// nothing to do
}
});
m_treeViewer.setLabelProvider(new KnimeResourceLabelProvider());
m_treeViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(final CheckStateChangedEvent event) {
Object o = event.getElement();
boolean isChecked = event.getChecked();
// first expand in order to be able to check children as well
m_treeViewer.expandToLevel(o, AbstractTreeViewer.ALL_LEVELS);
m_treeViewer.setSubtreeChecked(o, isChecked);
if (o instanceof IResource) {
IResource element = (IResource) o;
setParentTreeChecked(m_treeViewer, element, isChecked);
}
dialogChanged();
getWizard().getContainer().updateButtons();
}
});
m_treeViewer.getTree().setVisible(false);
}
Aggregations