use of org.eclipse.jface.viewers.IElementComparer 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);
}
});
}
Aggregations