in CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexSectionPart.java [168:279]
public Section createContents ()
{
FormToolkit toolkit = managedForm.getToolkit();
Section section = getSection();
// Expand | Collapse
section.addExpansionListener(new ExpansionAdapter() {
public void expansionStateChanged(ExpansionEvent e) {
// parent.layout(true);
managedForm.reflow(true);
}
});
section.setExpanded(true);
///////////////////////////////////////////////////////////////////////
// Create ToolBar
Composite sectionToolbarComposite = FormSection.createGridLayoutContainer (toolkit, section,
3, 0, 0);
section.setTextClient(sectionToolbarComposite);
///////////////////////////////////////////////////////////////////////
// Create Composite
Composite client = FormSection.createGridLayoutContainer (toolkit, section,
1, 0, 0);
client.setLayoutData(new GridData(GridData.FILL_BOTH|GridData.VERTICAL_ALIGN_BEGINNING));
toolkit.paintBordersFor(client);
section.setClient(client);
/*********************************************************************/
// Create Tree for FSIndex
tree = toolkit.createTree(client, SWT.CHECK);
GridData gd = new GridData(GridData.FILL_BOTH|GridData.VERTICAL_ALIGN_BEGINNING);
gd.grabExcessVerticalSpace = true;
gd.grabExcessHorizontalSpace = true;
gd.heightHint = 160;
tree.setLayoutData(gd);
// Create Viewer for Tree
// treeViewer = new CheckboxTreeViewer(tree);
treeViewer = new ContainerCheckedTreeViewer(tree);
treeViewer.setUseHashlookup(true);
treeViewer.addCheckStateListener(new ICheckStateListener() {
/**
* Tree Structure:
* FS Index (root) --> model: TreeNode
* - FS[0] --> UFeatureStructure
* - FS[1]
* ...
*
* Note: The value of feature of a FS can be "another" FS....
* which can create a "cycle".
* Checking the tree node can create a stack overflow.
*
*/
public void checkStateChanged(CheckStateChangedEvent event) {
Object obj = event.getElement();
if (obj instanceof UFeature) {
return;
}
// Trace.err("Check obj:" + obj.getClass().getName());
// TODO Optimize by creating a list of "showed" AnnotationObjects
for (AnnotationObject annot: annotationObjectList) {
annot.show = false;
}
//
// Collect and set AnnotationObjects to show
//
// Prevent Stack Overflow by NOT using treeViewer.getCheckedElements()
TreeItem itemRoot = treeViewer.getTree().getItem(0); // get root
// Get all checked FS under root
TreeItem[] children = itemRoot.getItems();
for (int i=0; i<children.length; ++i) {
// Collect only "real" checked items (NOT grayed items)
if ( ! children[i].getGrayed() ) {
AnnotationObject annot = (AnnotationObject) ((UFeatureStructure)children[i].getData()).getUserData();
if (annot != null) {
annot.show = children[i].getChecked();
} else {
// FIXME Remove Trace.bug
Trace.bug("NO associated annotation");
}
}
}
casViewControl.showAnnotationsForView(AbstractAnnotatedTextSectionPart.TAB_VIEW_INDEX_REPO/*, fsDocumentAnnotList*/);
}
});
// Set Content/Label Provider
contentProvider = new FSIndexContentProvider(prefFlatLayout4Features);
labelProvider = new FSIndexLabelProvider(typesystemStyle);
contentProvider.hideNoValueFeature(hideNoValueFeature);
labelProvider.showOneLineView(prefFlatLayout4Features);
labelProvider.hideNoValueFeature(hideNoValueFeature);
treeViewer.setContentProvider(contentProvider);
treeViewer.setLabelProvider(labelProvider);
filter = new FeatureStructureViewerFilter();
treeViewer.addFilter(filter);
createSectionToolbar (toolkit, section, sectionToolbarComposite,
treeViewer);
return section;
}