static public void visitTreeAndAddAnnotations()

in CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/core/internal/CASObjectView.java [278:327]


    static public void visitTreeAndAddAnnotations (TypeNode fromNode, CAS casView)
    {        
        // Get "Type" object to work with FSIndex when retrieving FS from index
        String typeName = ((TypeDescription) fromNode.getObject()).getName();
        Type type = casView.getTypeSystem().getType(typeName);

        // Is sub-type of AnnotationBase ?
        Type annotationBase = casView.getTypeSystem().getType("uima.cas.AnnotationBase");
        if (!typeName.equals("uima.cas.TOP") &&
                !casView.getTypeSystem().subsumes(annotationBase, type)) {
            return;
        }
        FSIndex fsIndex = CasHelper.getIndexForType(casView, typeName);
        if  (!typeName.equals("uima.cas.TOP") && !typeName.equals("uima.cas.AnnotationBase") 
                && (fsIndex == null || fsIndex.size() == 0)) {
            // Skip Type having NO Annotation
            return;
        }

        // Add FeatureStructures as children of fromNode
        if (fsIndex != null) {
            FSIterator iter = fsIndex.iterator();
            List<AnnotationObject> selfAnnotations = new ArrayList<AnnotationObject>();
            while (iter.isValid()) {
                FeatureStructure fs = iter.get();
                if (fs.getType() == type) {
                    // Create new object for this type's annotation
                    String coveredText = null;
                    if (fs instanceof AnnotationFS) {
                        coveredText = ((AnnotationFS)fs).getCoveredText();
                    }
                    selfAnnotations.add(new AnnotationObject (fs, coveredText));
                }
                iter.moveToNext();
            }
            if (selfAnnotations.size() > 0) {
                AnnotationObjectsNode n = new AnnotationObjectsNode(selfAnnotations);
                fromNode.setAnnotationNode(n);
            }
        }
        
        // Visit Children Types 
        if ( fromNode.getChildren() != null ) {
            // Collection c = fromNode.getChildren().values();
            Iterator<TypeNode> iter = fromNode.getChildrenIterator();                
            while (iter.hasNext()) {
                visitTreeAndAddAnnotations (iter.next(), casView);
            }                  
        }        
    }