treeViewer = new CheckboxTreeViewer(comp);
treeViewer.setLabelProvider(new ValidationTreeLabelProvider());
treeViewer.setSorter(new WorkbenchViewerSorter());
contentProvider = new ValidationTreeContentProvider();
treeViewer.setContentProvider(contentProvider);
treeViewer.addCheckStateListener(new ICheckStateListener(){
public void checkStateChanged( CheckStateChangedEvent event ) {
Object element = event.getElement();
Object[] children = contentProvider.getChildren(element);
if (children != null && children.length > 0) {
// parent element was modified, adjust the children accordingly
for( int i = 0; i < children.length; i++ ) {
treeViewer.setChecked(children[i], event.getChecked());
}
// all children are in the same state, therefore the parent is not grayed
treeViewer.setGrayed(element, false);
}
Object parent = contentProvider.getParent(element);
if (parent != null) {
// child element was modified
Object[] siblings = contentProvider.getChildren(parent);
boolean oneSiblingChecked = false;
boolean allSiblingsChecked = true;
for (int i = 0; i < siblings.length; i++) {
if (treeViewer.getChecked(siblings[i])) {
oneSiblingChecked = true;
} else {
allSiblingsChecked = false;
}
}
if (allSiblingsChecked) { // mark parent checked and NOT grayed out
treeViewer.setGrayed(parent, false);
treeViewer.setChecked(parent, true);
} else {
if (oneSiblingChecked) { // mark parent checked and grayed out
treeViewer.setGrayChecked(parent, true);
} else { // mark parent NOT checked
treeViewer.setGrayChecked(parent, false);
}
}
}
}
});
// populate the tree
treeViewer.setInput(processor);
treeViewer.expandAll();
Control control = treeViewer.getControl();
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 250; // initial height of treeViewer (in pixels?)
gd.verticalSpan = 3;
control.setLayoutData(gd);
control.setFont(font);
// composite to hold the new/delete/save/... buttons
buttonComposite = new Composite(comp, SWT.NONE);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint = 200;
buttonComposite.setLayoutData(gd);
buttonComposite.setFont(comp.getFont());
GridLayout buttonLayout = new GridLayout(2, false);
buttonComposite.setLayout(buttonLayout);
// construct the new validation test button
newButton = new Button(buttonComposite, SWT.PUSH);
newButton.setFont(parent.getFont());
newButton.setText(Messages.ValidationDialog_new);
newButton.setEnabled(false);
newButton.addSelectionListener(new NewTestListener());
setButtonLayoutData(newButton);
// construct the delete validation test button
deleteButton = new Button(buttonComposite, SWT.PUSH);
deleteButton.setFont(parent.getFont());
deleteButton.setText(Messages.ValidationDialog_delete);
deleteButton.setEnabled(false);
deleteButton.addSelectionListener(new DeleteTestListener());
setButtonLayoutData(deleteButton);
// construct treeViewer listener
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged( SelectionChangedEvent event ) {
if (!event.getSelection().isEmpty()) {
StructuredSelection selection = (StructuredSelection) event.getSelection();
if (selection.size() == 1) {
Object element = selection.getFirstElement();
selectedTreeItem = element; //record the current selection so other events can figure out who is selected
if (element instanceof TestDTO) { //test instance was selected
newButton.setEnabled(false);
deleteButton.setEnabled(true);
nameText.setText(((TestDTO) element).getName());
nameText.setEditable(true);
descText.setText(((TestDTO) element).getDescription());
descText.setEditable(true);
tableViewer.setInput(element); // pass the args (inside the testDTO)
tableViewer.getControl().setEnabled(true);
resizeTable();
} else if (element instanceof PlugInDTO) { //validation parent (plugin) was selection
newButton.setEnabled(true);
deleteButton.setEnabled(false);
nameText.setText(((PlugInDTO) selection.getFirstElement()).getName());
nameText.setEditable(false);
descText.setText(((PlugInDTO) selection.getFirstElement()).getDescription());
descText.setEditable(false);
tableViewer.setInput(null); //hide arguments
tableViewer.getControl().setEnabled(false);
} else { // this shouldn't be called
newButton.setEnabled(false);
deleteButton.setEnabled(false);
nameText.setText(""); //$NON-NLS-1$
nameText.setEditable(false);
descText.setText(""); //$NON-NLS-1$
descText.setEditable(false);
tableViewer.setInput(null); //hide arguments
tableViewer.getControl().setEnabled(false);
}
} else { //more than one selection was made
selectedTreeItem = null;
newButton.setEnabled(false);
deleteButton.setEnabled(false);
nameText.setEditable(false);
descText.setEditable(false);
tableViewer.setInput(null); //hide arguments
tableViewer.getControl().setEnabled(false);
}
updateButtons();
}
}
});
treeViewer.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged( CheckStateChangedEvent event ) {
updateButtons();
if (event.getElement() instanceof PlugInDTO) {