protected TypeNode insertForwardedReferenceNode()

in CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/core/internal/TypeTree.java [490:562]


    protected TypeNode insertForwardedReferenceNode (TypeNode parent, String typeName) 
    {
        TypeNode node = null;
        
		if ( typeName == null || typeName.trim().length() == 0 ) return null;

        // Same type may be forwarded ref MULTIPLE TIMES
        node = (TypeNode) _nodesHashtable.get(typeName);
        if (node != null) {
            // BUG !!! This FORWARD reference is already in tree since the caller
            // of this method ALREADY checked that this forward ref IS NOT in tree.
            
          TypeDescription meta = (TypeDescription) ((TypeNode)_nodesHashtable.get(typeName)).getObject();
            if ( meta != null ) {
                // Already defined
                node.setLabel(TypeSystemUtils2.getMyShortName(typeName)); // Use short name
                node.setObject(meta);
                _nodesHashtable.put (((TypeDescription)node.getObject()).getName(), node);
                Trace.err("??? BUG -- Already defined for " + typeName);
            }
        } else {
            // NEW forwarded ref
            node = new TypeNode(parent, UimaToolsUtil.getMyShortName(typeName));
            node.setObjectType(IItemTypeConstants.ITEM_TYPE_TYPE);            
            // Not yet defined (Forward reference)
            // Cannot use short name if no TypeDescription object (see TreeBaseNode.compare)
            // Trace.trace("Forward reference to " + typeName);
            // _nodesHashtable.put (node.getLabel(), node);
            _nodesHashtable.put (typeName, node);
            
            // Add to undefined type hashtable
            // _undefinedTypesHashtable.put (node.getLabel(), node);
            _undefinedTypesHashtable.put (typeName, node);
        }
        		
		// Insert "node" as child of "parent"
		TypeNode tempNode;
		if (parent == null) {
		    if (_rootSuper == null) {
		        _rootSuper = node;
		    } else {
				if ( (tempNode = _rootSuper.insertChild(node)) != null ) {
					if (tempNode != node) {				 
						// Duplicate Label
                        // Use full name as label
						Trace.trace(" 1 Duplicate (short name) Label:" + node.getLabel());
//						node.setShowFullName(true);
						if (node.getObject() != null) {
                            // Use full name as label
							node.setLabel(((TypeDescription)node.getObject()).getName());
						}				
						_rootSuper.insertChild(node);
					} else {
						
					}
				}
		    }
		} else {
			// parent.insertChild (node);
			if ( (tempNode = parent.insertChild(node)) != null && tempNode != node) {
				// Duplicate Label. Use full name as label.
                Trace.trace(" 2 Duplicate (short name) Label:" + node.getLabel());
//				node.setShowFullName(true);
				if (node.getObject() != null) {
                    // Use full name as label
					node.setLabel(((TypeDescription)node.getObject()).getName());
				}				
				parent.insertChild(node);
			}
		}
		
		return node;
	} // insertForwardedReferenceNode