use of org.eclipse.jface.viewers.CheckboxTreeViewer in project tdi-studio-se by Talend.
the class ImportItemWizardPage method createTreeViewer.
private TreeViewer createTreeViewer(Composite listComposite) {
filteredCheckboxTree = new FilteredCheckboxTree(listComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
CheckboxTreeViewer viewer = filteredCheckboxTree.getViewer();
viewer.setContentProvider(new ITreeContentProvider() {
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof IContainerNode) {
return ((IContainerNode) parentElement).getChildren().toArray();
}
return null;
}
@Override
public Object[] getElements(Object inputElement) {
// return getValidItems();
return repositoryUtil.getTreeViewInput().toArray();
}
@Override
public boolean hasChildren(Object element) {
if (element instanceof IContainerNode) {
return ((IContainerNode) element).hasChildren();
}
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
viewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof IContainerNode) {
if (element instanceof ProjectNode) {
Project project = ((ProjectNode) element).getProject();
return ProjectManager.getProjectDisplayLabel(project);
}
return ((IContainerNode) element).getLabel();
} else if (element instanceof ItemRecord) {
return ((ItemRecord) element).getLabel();
}
return super.getText(element);
}
@Override
public Image getImage(Object element) {
if (element instanceof IContainerNode) {
return ((IContainerNode) element).getImage();
} else if (element instanceof ItemRecord) {
return ((ItemRecord) element).getImage();
}
return super.getImage(element);
}
});
viewer.setSorter(TreeBuilder.createSorter());
viewer.setInput(this);
viewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
filteredCheckboxTree.calculateCheckedLeafNodes();
updateFinishStatus();
}
});
filteredCheckboxTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return selectRepositoryNode(viewer, element);
}
});
return viewer;
}
use of org.eclipse.jface.viewers.CheckboxTreeViewer in project tdi-studio-se by Talend.
the class UseDynamicJobSelectionDialog method createTreeViewer.
private void createTreeViewer(Composite itemComposite) {
filteredCheckboxTree = new FilteredCheckboxTree(itemComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI) {
@Override
protected CheckboxTreeViewer doCreateTreeViewer(Composite parent, int style) {
return (CheckboxTreeViewer) RepoCommonViewerProvider.CHECKBOX.createViewer(parent);
}
@Override
protected void refreshCompleted() {
restoreCheckedElements();
}
};
CheckboxTreeViewer viewer = filteredCheckboxTree.getViewer();
viewer.setComparer(new IElementComparer() {
private String getElementUniqueString(Object element) {
if (element instanceof RepositoryNode && getSupportType() != null && getSupportType().equals(((RepositoryNode) element).getContentType())) {
final RepositoryNode node = (RepositoryNode) element;
StringBuffer sb = new StringBuffer();
boolean validElem = false;
ENodeType type = node.getType();
if (ENodeType.REPOSITORY_ELEMENT.equals(type)) {
sb.append(node.getId());
validElem = true;
} else if (ENodeType.SIMPLE_FOLDER.equals(type)) {
final IRepositoryViewObject object = node.getObject();
// path
if (object instanceof Folder) {
sb.append(((Folder) object).getPath());
sb.append('/');
}
sb.append(node.getLabel());
validElem = true;
}
if (validElem) {
sb.append('|');
// add project
if (node.getRoot() != null && node.getRoot().getProject() != null) {
sb.append(node.getRoot().getProject().getTechnicalLabel());
}
sb.append('|');
sb.append(node.getContentType().getType());
sb.append('|');
sb.append(type);
return sb.toString();
}
}
return null;
}
@Override
public int hashCode(Object element) {
final String elementUniqueString = getElementUniqueString(element);
if (elementUniqueString != null) {
return elementUniqueString.hashCode();
}
return element.hashCode();
}
@Override
public boolean equals(Object a, Object b) {
String aStr = getElementUniqueString(a);
String bStr = getElementUniqueString(b);
return aStr != null && bStr != null ? aStr.equals(bStr) : a.equals(b);
}
});
viewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
RepositoryNode node = (RepositoryNode) element;
return filterRepositoryNode(node);
}
});
}
use of org.eclipse.jface.viewers.CheckboxTreeViewer in project tdi-studio-se by Talend.
the class UseDynamicJobSelectionDialog method removeCheckStateListener.
public void removeCheckStateListener(ICheckStateListener listener) {
CheckboxTreeViewer exportItemsTreeViewer = getItemsTreeViewer();
exportItemsTreeViewer.removeCheckStateListener(listener);
}
use of org.eclipse.jface.viewers.CheckboxTreeViewer in project tdi-studio-se by Talend.
the class UseDynamicJobSelectionDialog method collectCheckedNodes.
private void collectCheckedNodes() {
repositoryNodes.clear();
CheckboxTreeViewer exportItemsTreeViewer = getItemsTreeViewer();
for (int i = 0; i < exportItemsTreeViewer.getCheckedElements().length; i++) {
RepositoryNode node = (RepositoryNode) exportItemsTreeViewer.getCheckedElements()[i];
if (node.getType() == ENodeType.REPOSITORY_ELEMENT) {
repositoryNodes.add(node);
}
}
}
use of org.eclipse.jface.viewers.CheckboxTreeViewer in project bndtools by bndtools.
the class WizardBndFileSelector method createControl.
@Override
public void createControl(Composite composite) {
checkboxTreeViewer = new CheckboxTreeViewer(composite);
checkboxTreeViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
Object element = event.getElement();
ITreeContentProvider contentProvider = (ITreeContentProvider) checkboxTreeViewer.getContentProvider();
alterChildren(element, contentProvider, event.getChecked());
alterParents(element, contentProvider);
}
private void alterChildren(Object element, ITreeContentProvider contentProvider, boolean checked) {
Queue<Object> toRecurse = new LinkedList<Object>();
toRecurse.offer(element);
while (!toRecurse.isEmpty()) {
Object o = toRecurse.poll();
for (Object child : contentProvider.getChildren(o)) {
if (contentProvider.hasChildren(child))
toRecurse.offer(child);
checkboxTreeViewer.setChecked(child, checked);
checkboxTreeViewer.setGrayed(child, false);
}
}
}
private void alterParents(Object element, ITreeContentProvider contentProvider) {
Object parent = contentProvider.getParent(element);
while (parent != null) {
boolean allChecked = true;
boolean noneChecked = true;
for (Object child : contentProvider.getChildren(parent)) {
boolean checked = checkboxTreeViewer.getChecked(child);
boolean grayed = checkboxTreeViewer.getGrayed(child);
allChecked &= checked & !grayed;
noneChecked &= !checked;
}
if (allChecked) {
checkboxTreeViewer.setChecked(parent, true);
checkboxTreeViewer.setGrayed(parent, false);
} else if (noneChecked) {
checkboxTreeViewer.setGrayChecked(parent, false);
} else {
checkboxTreeViewer.setGrayChecked(parent, true);
}
parent = contentProvider.getParent(parent);
}
}
});
setControl(checkboxTreeViewer.getControl());
}
Aggregations