use of org.eclipse.jface.viewers.ITreeContentProvider in project whole by wholeplatform.
the class BrowseListChooser method addControls.
private void addControls() {
Label title = new Label(this, SWT.NONE);
title.setText("&Classes");
Composite container = new Composite(this, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.makeColumnsEqualWidth = false;
container.setLayout(layout);
container.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
listChooser = new CheckboxTreeViewer(container, SWT.BORDER);
GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
listChooser.getControl().setLayoutData(listData);
listChooser.setContentProvider(new ITreeContentProvider() {
public Object[] getChildren(Object parentElement) {
return null;
}
public Object[] getElements(Object inputElement) {
return classList.toArray();
}
public boolean hasChildren(Object element) {
return false;
}
public Object getParent(Object element) {
return null;
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
listChooser.setLabelProvider(new LabelProvider() {
public String getText(Object element) {
return (((Class<?>) element).getSimpleName());
}
});
listChooser.setInput(this);
listChooser.setSorter(new ViewerSorter());
createSelectionButtons(container);
}
use of org.eclipse.jface.viewers.ITreeContentProvider 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