You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2008/07/02 16:46:38 UTC

svn commit: r673409 [6/10] - in /incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src: ./ main/ main/java/ main/java/org/ main/java/org/apache/ main/java/org/apache/uima/ main/java/org/apache/uima/casviewer/ main/java/org/apa...

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexContentProvider.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexContentProvider.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexContentProvider.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,420 @@
+package org.apache.uima.casviewer.ui.internal.index;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.cas.ArrayFS;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.FloatArrayFS;
+import org.apache.uima.cas.IntArrayFS;
+import org.apache.uima.cas.StringArrayFS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.impl.DebugFSLogicalStructure;
+import org.apache.uima.casviewer.core.internal.BaseNode;
+import org.apache.uima.casviewer.core.internal.CasIndexRepository;
+import org.apache.uima.casviewer.core.internal.IItemTypeConstants;
+import org.apache.uima.casviewer.core.internal.UFSIndex;
+import org.apache.uima.casviewer.core.internal.UFeature;
+import org.apache.uima.casviewer.core.internal.UFeatureStructure;
+import org.apache.uima.tools.debug.util.Trace;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class FSIndexContentProvider implements ITreeContentProvider 
+{
+    private static Object[] EMPTY_ARRAY = new Object[0];
+
+    private BaseNode               rootNode    = null;
+
+    // Preferences
+    private boolean hideNoValueFeature      =  false;    
+    private boolean showOneLine             = false;
+    
+    /*************************************************************************/
+    
+    public FSIndexContentProvider(boolean showOneLine) {
+        super();
+        this.showOneLine = showOneLine;
+    }
+
+    public void showOneLineView (boolean showOneLine) {
+        this.showOneLine = showOneLine;
+    }
+    
+    public void hideNoValueFeature (boolean hide)
+    {
+        hideNoValueFeature = hide;
+    }
+    
+    public void setViewerLayoutToFlatOrTree (boolean flat)
+    {
+        showOneLine = flat;
+    }
+
+    /*************************************************************************/
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+     */
+    public Object[] getChildren(Object parent) 
+    {
+        if (parent instanceof BaseNode) {
+            int kind = ((BaseNode)parent).getObjectType();
+            if (kind == IItemTypeConstants.ITEM_TYPE_U_FS_INDEX) {
+                UFSIndex index = (UFSIndex) ((BaseNode)parent).getObject();
+                if (index.size() == 0) {
+                    // May have other children 
+                    return ((BaseNode)parent).getChildren().toArray();
+                }
+                
+                // Add label "feature structures" node
+                BaseNode fNode = new BaseNode("FS [" + index.size() + "]", null, new ArrayList());
+                fNode.setObjectType(IItemTypeConstants.ITEM_TYPE_LABEL_U_FS_INDEX);
+                fNode.setObject(index);
+                
+                // Add children, if any
+                int count = 1;
+                if (((BaseNode)parent).getChildren() != null) {
+                    count += ((BaseNode)parent).getChildren().size();
+                }
+                Object[] objs = new Object[count];
+                objs[0] = fNode;
+                if (count > 1) {
+                    List<BaseNode> nodes = ((BaseNode)parent).getChildren();
+                    int i = 1;
+                    for (BaseNode node: nodes) {
+                        objs[i++] = node;
+                    }
+                }
+                
+                return objs;
+                
+            } else if (kind == IItemTypeConstants.ITEM_TYPE_LABEL_U_FS_INDEX) {
+//                Object[] objs = ((BaseNode)parent).getChildren();
+//                if (objs != null) {
+//                    return objs;
+//                }
+                
+                UFSIndex index = (UFSIndex) ((BaseNode)parent).getObject();
+                if (index.size() == 0) { 
+                    return null;
+                }
+//                FSIterator it = index.iterator();
+//                
+//                Object[] objs = new Object[index.size()];
+//                int i = 0;
+//                for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
+//                    // FeatureStructure fs = it.get();
+//                    objs[i] = new UFeatureStructure(it.get(), i);
+//                    ++i;
+//                }
+//                return objs;
+//                objs = index.getUFeatureStructures();
+//                ((BaseNode)parent).addChild()
+                return index.getUFeatureStructures();
+            }
+            
+        } else if (parent instanceof UFSIndex) {
+            UFSIndex index = (UFSIndex) parent;
+            if (index.size() == 0) { 
+                return null;
+            }
+//            FSIterator it = index.iterator();
+//            
+//            Object[] objs = new Object[index.size()];
+//            int i = 0;
+//            for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
+//                // FeatureStructure fs = it.get();
+//                objs[i] = new UFeatureStructure(it.get(), i);
+//                ++i;
+//            }
+//            return objs;
+            return index.getUFeatureStructures();
+            
+        } else if (parent instanceof UFeatureStructure
+                || parent instanceof FeatureStructure) {
+            if ( showOneLine ) {
+                return null;
+            }
+            
+            FeatureStructure fs;
+            if (parent instanceof UFeatureStructure) {
+                fs = ((UFeatureStructure)parent).getUimaFeatureStructure();
+            } else {
+                fs = (FeatureStructure) parent;
+            }
+            
+            List aFeatures = fs.getType().getAppropriateFeatures();
+            if (aFeatures.size() > 0) {
+                Object[] objs = new Object[aFeatures.size()];
+                for (int i=0; i<aFeatures.size(); ++i) {
+                    objs[i] = new UFeature(fs, (Feature) aFeatures.get(i));
+                }
+                return objs;
+            }            
+        } else if (parent instanceof UFeature) {
+            return getChildren ((UFeature)parent);
+        }
+        return null;
+    }
+        
+    public Object[] getChildren (UFeature uFeature)
+    {
+        // Non-primitive feature ONLY
+        if ( uFeature.isPrimitive() ) {
+            // Primitive feature
+            Trace.bug("SHOULD NOT BE primitive feature: feature name=" 
+                    + uFeature.getShortName() + " ; range type: " + uFeature.getRange().getName());
+            return null;
+        }
+        FeatureStructure fs = uFeature.getFeatureValue();
+        if (fs == null) {
+            // Trace.bug("No FeatureValue");
+            return null;
+        }
+        if (fs instanceof StringArrayFS) {
+            return ((StringArrayFS) fs).toArray();
+        }
+        if (fs instanceof IntArrayFS) {
+            int[] intArray = ((IntArrayFS) fs).toArray();
+            Object[] objs = new Object[intArray.length];
+            for (int i=0; i<intArray.length; ++i) {
+                objs[i] = new Integer(intArray[i]);
+            }
+            return objs;
+        }
+        if (fs instanceof FloatArrayFS) {
+            float[] floatArray = ((FloatArrayFS) fs).toArray();
+            Object[] objs = new Object[floatArray.length];
+            for (int i=0; i<floatArray.length; ++i) {
+                objs[i] = new Float(floatArray[i]);
+            }
+            return objs;
+        }
+        if (fs instanceof ArrayFS) {
+            // if ( ((ArrayFS) fs).size() == 0 ) {
+                Trace.trace(fs.getType().getShortName() + " is ArrayFS with length = " + ((ArrayFS) fs).size());
+            // }
+            return ((ArrayFS) fs).toArray();
+        }
+        
+        TypeSystem ts = fs.getCAS().getTypeSystem();
+        Type fsType   = fs.getType();
+        if (ts.subsumes(ts.getType("uima.cas.FloatList"), fsType)) {
+            return (Object[]) DebugFSLogicalStructure.floatListToArray(fs);
+        }
+        if (ts.subsumes(ts.getType("uima.cas.IntegerList"), fsType)) {
+            return (Object[]) DebugFSLogicalStructure.integerListToArray(fs);
+        }
+        if (ts.subsumes(ts.getType("uima.cas.StringList"), fsType)) {
+            return (Object[]) DebugFSLogicalStructure.stringListToArray(fs);
+        }
+        if (ts.subsumes(ts.getType("uima.cas.FSList"), fsType)) {
+            return (Object[]) DebugFSLogicalStructure.fsListToArray(fs);
+        }
+        
+        
+        List aFeatures = fs.getType().getAppropriateFeatures();
+        if (aFeatures.size() > 0) {
+            Object[] objs = new Object[aFeatures.size()];
+            for (int i=0; i<aFeatures.size(); ++i) {
+                objs[i] = new UFeature(fs, (Feature) aFeatures.get(i));
+            }
+            return objs;
+        }            
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+     */
+    public Object getParent(Object element) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+     */
+    public boolean hasChildren(Object element) 
+    {
+        if (element instanceof BaseNode) {
+            if ( ((BaseNode)element).getChildren().size() > 0 ) {
+                return true;
+            }
+            // Check item type
+            int kind = ((BaseNode)element).getObjectType();
+            if (kind == IItemTypeConstants.ITEM_TYPE_U_FS_INDEX
+                || kind == IItemTypeConstants.ITEM_TYPE_LABEL_U_FS_INDEX) {
+                if ( ((UFSIndex) ((BaseNode)element).getObject()).size() > 0 ) {
+                    // Index has annotations
+                    return true;
+                }
+            } else if (kind == IItemTypeConstants.ITEM_TYPE_U_FS) {
+                return true;
+            }
+        } else if (element instanceof UFSIndex) {
+            if ( ((UFSIndex) element).size() > 0 ) {
+                return true;
+            }
+        } else if (element instanceof UFeatureStructure
+                || element instanceof FeatureStructure) {
+            return !showOneLine;
+        } else if (element instanceof UFeature) {
+            if ( ! ((UFeature)element).isPrimitive() ) {
+                // Non-primitive feature
+                if ( ((UFeature)element).getFeatureValue() != null ) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+     */
+    public Object[] getElements(Object inputElement) 
+    {
+        if ( inputElement instanceof UFSIndex ) {
+            if (rootNode == null) {
+                rootNode = new BaseNode(((UFSIndex) inputElement).getUimaFSIndex().getType().getName(), null, new ArrayList());
+                rootNode.setObjectType(IItemTypeConstants.ITEM_TYPE_LABEL_U_FS_INDEX);
+                rootNode.setObject(inputElement);
+            }
+            
+            // Add label for FSIndex
+            Object[] objs = new Object[1];
+            objs[0] = rootNode;
+            return objs;
+        }
+        Trace.trace("Unknown inputElement: " + inputElement.getClass().getName());
+        return EMPTY_ARRAY;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+     */
+    public void dispose() {
+    }
+
+    // "newInput" will be UFSIndex
+    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+        if (newInput != null) {
+            if ( !(newInput instanceof UFSIndex) ) {
+                Trace.bug("Unknown input: " + newInput.getClass().getName());
+                return;
+            }
+            rootNode = null;
+        }
+    }
+
+    /*************************************************************************/
+    
+    public static void getFSValues (FeatureStructure aFS, CAS aTCAS, int aNestingLevel, 
+            PrintStream aOut)
+    {
+        Type stringType = CasIndexRepository.stringType;
+        
+        // printTabs(aNestingLevel, aOut);
+        aOut.println(aFS.getType().getName());
+        
+        //print all features
+        List aFeatures = aFS.getType().getAppropriateFeatures();
+        Iterator iter = aFeatures.iterator();
+        while (iter.hasNext())
+        {
+            Feature feat = (Feature)iter.next();
+            // printTabs(aNestingLevel + 1, aOut);
+            //print feature name
+            aOut.print(feat.getShortName());
+            aOut.print(" = ");
+            //prnt feature value (how we get this depends on feature's range type)
+            String rangeTypeName = feat.getRange().getName();
+            if (aTCAS.getTypeSystem().subsumes(stringType, feat.getRange())) {
+//              must check for subtypes of string
+                String str = aFS.getStringValue(feat);
+                if (str == null) {
+                    aOut.println("null");
+                } else {
+                    aOut.print("\"");
+                    if (str.length() > 64) {
+                        str = str.substring(0,64) + "...";
+                    }  
+                    aOut.print(str);
+                    aOut.println("\""); 
+                } 
+            } else if (CAS.TYPE_NAME_INTEGER.equals(rangeTypeName)) {
+                aOut.println(aFS.getIntValue(feat));        
+            } else if (CAS.TYPE_NAME_FLOAT.equals(rangeTypeName)) {
+                aOut.println(aFS.getFloatValue(feat));        
+            } else if (CAS.TYPE_NAME_STRING_ARRAY.equals(rangeTypeName)) {
+                StringArrayFS arrayFS = (StringArrayFS)aFS.getFeatureValue(feat);
+                if (arrayFS == null) {
+                    aOut.println("null");
+                } else {  
+                    String[] vals = arrayFS.toArray();
+                    aOut.print("[");
+                    for (int i=0; i < vals.length - 1; i++) {
+                        aOut.print(vals[i]);
+                        aOut.print(',');
+                    }
+                    if (vals.length > 0) {
+                        aOut.print(vals[vals.length - 1]);
+                    }
+                    aOut.println("]\"");
+                }  
+            } else if (CAS.TYPE_NAME_INTEGER_ARRAY.equals(rangeTypeName)) {
+                IntArrayFS arrayFS = (IntArrayFS)aFS.getFeatureValue(feat);
+                if (arrayFS == null) {
+                    aOut.println("null");
+                } else {  
+                    int[] vals = arrayFS.toArray();
+                    aOut.print("[");
+                    for (int i=0; i < vals.length - 1; i++)
+                    {
+                        aOut.print(vals[i]);
+                        aOut.print(',');
+                    }
+                    if (vals.length > 0)
+                    {
+                        aOut.print(vals[vals.length - 1]);
+                    }
+                    aOut.println("]\"");
+                }  
+            } else if (CAS.TYPE_NAME_FLOAT_ARRAY.equals(rangeTypeName)) {
+                FloatArrayFS arrayFS = (FloatArrayFS)aFS.getFeatureValue(feat);
+                if (arrayFS == null)
+                {
+                    aOut.println("null");
+                } else {  
+                    float[] vals = arrayFS.toArray();
+                    aOut.print("[");
+                    for (int i=0; i < vals.length - 1; i++)
+                    {
+                        aOut.print(vals[i]);
+                        aOut.print(',');
+                    }
+                    if (vals.length > 0) {
+                        aOut.print(vals[vals.length - 1]);
+                    }
+                    aOut.println("]\"");
+                }  
+            } else {
+                // non-primitive type
+                FeatureStructure val = aFS.getFeatureValue(feat);
+                if (val == null) {
+                    aOut.println("null");
+                } else {
+                    getFSValues(val, aTCAS, aNestingLevel + 1, aOut);
+                }    
+            }      
+        }   
+    } // getFSValues
+    
+}

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexContentProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexLabelProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexLabelProvider.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexLabelProvider.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexLabelProvider.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,220 @@
+package org.apache.uima.casviewer.ui.internal.index;
+
+import java.util.List;
+
+import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.casviewer.core.internal.AnnotationObject;
+import org.apache.uima.casviewer.core.internal.BaseNode;
+import org.apache.uima.casviewer.core.internal.IItemTypeConstants;
+import org.apache.uima.casviewer.core.internal.UFSIndex;
+import org.apache.uima.casviewer.core.internal.UFeature;
+import org.apache.uima.casviewer.core.internal.UFeatureStructure;
+import org.apache.uima.casviewer.ui.internal.style.TypeStyle;
+import org.apache.uima.casviewer.ui.internal.style.TypeSystemStyle;
+import org.apache.uima.tools.debug.util.Trace;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+
+public class FSIndexLabelProvider extends LabelProvider
+                                    implements IColorProvider { //, IFontProvider {
+
+    // Preferences
+    private boolean hideNoValueFeature      = true;    
+    private boolean showShortName           = true; // true: type's short name; false: full name
+    private boolean showOneLine             = false;
+    private TypeSystemStyle    typesystemStyle;
+    
+    public FSIndexLabelProvider(TypeSystemStyle tsStyle) {
+        super();
+        this.typesystemStyle = tsStyle;
+    }
+    
+    public FSIndexLabelProvider(TypeSystemStyle tsStyle, boolean showShortName) {
+        super();
+        this.typesystemStyle = tsStyle;
+        this.showShortName = showShortName;
+    }
+
+    public void showOneLineView (boolean showOneLine) {
+        this.showOneLine = showOneLine;
+    }
+    
+    public void hideNoValueFeature (boolean hide)
+    {
+        hideNoValueFeature = hide;
+    }
+    
+    public void setTypeSystemStyle (TypeSystemStyle style)
+    {
+        Trace.trace(style==null? "style==null":"");
+        this.typesystemStyle = style;
+    }
+
+    /*************************************************************************/
+    
+    public Image getImage(Object element) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    // 1st element to come: BaseNode ITEM_TYPE_LABEL_U_FS_INDEX
+    public String getText(Object element) {
+        if (element instanceof BaseNode) {
+            Object obj = ((BaseNode)element).getObject();
+            if (obj == null) {
+                return ((BaseNode) element).getLabel();
+            }
+            
+            int kind = ((BaseNode)element).getObjectType();
+            if (kind == IItemTypeConstants.ITEM_TYPE_U_FS_INDEX
+                || kind == IItemTypeConstants.ITEM_TYPE_LABEL_U_FS_INDEX) {
+                // Short Name ?
+                String  typeName;
+                if (showShortName) {
+                    typeName = ((UFSIndex) obj).getType().getShortName();
+                } else {
+                    typeName = ((UFSIndex) obj).getType().getName();
+                }
+                return ((UFSIndex) obj).getLabel() + " - " + typeName
+                        + "[" + ((UFSIndex) obj).size() + "]"; 
+                
+            } else if (kind == IItemTypeConstants.ITEM_TYPE_FS_INDEX) {
+                return ((BaseNode) element).getLabel() 
+                        + " [" + ((FSIndex) obj).size() + "]"; 
+            }
+            return ((BaseNode) element).getLabel();
+            
+        } else if (element instanceof FSIndex) {
+            FSIndex index = (FSIndex) element;
+            return index.getType() + "[" + index.size() + "]";
+            
+        } else if (element instanceof UFSIndex) {
+            UFSIndex index = (UFSIndex) element;
+            return index.getLabel() + " - " + index.getType() + "[" + index.size() + "]";
+            
+        } else if (element instanceof UFeatureStructure) {
+            int index = ((UFeatureStructure) element).getIndexInIterator();
+            String text = "";
+            if (index >= 0) {
+                text = "[" + index + "] - ";
+            }
+            
+            // Show feature values in ONE line with feature name
+            String values = "";
+            FeatureStructure fs = ((UFeatureStructure)element).getUimaFeatureStructure();
+            if (fs instanceof AnnotationFS) {
+                values = "- " + ((AnnotationFS)fs).getCoveredText() + " ";
+            }
+            if ( showOneLine ) {
+                List aFeatures = fs.getType().getFeatures();
+                if (aFeatures.size() > 0) {
+                    values += "(";
+                    for (int i=0; i<aFeatures.size(); ++i) {
+                        Feature f = (Feature) aFeatures.get(i);
+                        // Skip "sofa" ?
+                        if (f.getShortName().equalsIgnoreCase("sofa")) {
+                            continue;
+                        }
+                        String textFeature = "";
+                        if (f.getRange().isPrimitive()) {
+                            textFeature = ": " + fs.getFeatureValueAsString(f);
+                        } else {
+                            // Non-primitive feature
+                            String extra = "";
+                            if (fs.getFeatureValue(f) == null) {
+                                if (hideNoValueFeature) {
+                                    continue;
+                                }
+                                extra = " (no value)";
+                            }
+                            textFeature = " - " + f.getRange().getShortName() + extra;
+                        }
+                        // Display as "Short Name" {"Value" | "(no value)"}
+                        values += f.getShortName() + textFeature + " ; ";
+                    }  
+                    values += ")";
+                }            
+            } else {
+            }
+            return text + ((UFeatureStructure) element).getType().getShortName()
+                        + " " + values;
+            
+        } else if (element instanceof FeatureStructure) {
+            return ((FeatureStructure) element).getType().getShortName();
+            
+        } else if (element instanceof UFeature) {
+            String text = "";
+            if (((UFeature) element).isPrimitive()) {
+                text = ": " + ((UFeature) element).getValueAsString();
+            } else {
+                // Non-primitive feature
+                String extra = "";
+                if (((UFeature) element).getFeatureValue() == null) {
+                    extra = " (no value)";
+                }
+                text = " - " + ((UFeature) element).getRange().getShortName() + extra;
+            }
+            return ((UFeature) element).getShortName() + text;
+            
+        } else if (element instanceof Feature) {
+            return ((Feature) element).getShortName();
+            
+        } else if (element instanceof String) {
+            return (String) element;
+        } else if (element instanceof Integer) {
+            return "" + (Integer)element;
+        } else if (element instanceof Float) {
+            return "" + (Float) element;
+        } else if (element instanceof Boolean) {
+            return ((Boolean)element).toString();
+        }
+            
+        return "Unknown";
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.getObject())
+     */
+    public Color getBackground(Object element) {
+        if ( element instanceof UFeatureStructure ) {
+            return getTypeBackground(((UFeatureStructure) element).getType().getName());
+        } else {
+            // Trace.trace("Unknown " + element.getClass().getName());
+        }
+        return null; 
+    }
+
+    protected Color getTypeBackground (String typeName)
+    {
+        if (typesystemStyle != null) {   
+            TypeStyle style = typesystemStyle.getTypeStyle(typeName);
+            if (style != null) {
+                // Trace.trace("HAS bg for " + type.getName() + " " + style.bgColor);
+                return style.bgColor;
+            // } else {
+                // Trace.trace("NO bg for " + type.getName());
+            }
+        }
+        // Trace.trace("typesystemStyle == null");
+        return null;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.getObject())
+     */
+    public Font getFont(Object element) {
+        return null;
+    }
+    public Color getForeground(Object element) {
+        return null;
+    }       
+
+    
+}

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexLabelProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexSectionPart.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexSectionPart.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexSectionPart.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexSectionPart.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,434 @@
+package org.apache.uima.casviewer.ui.internal.index;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.FSIndexRepository;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.casviewer.core.internal.AnnotationObject;
+import org.apache.uima.casviewer.core.internal.CASObjectView;
+import org.apache.uima.casviewer.core.internal.UFSIndex;
+import org.apache.uima.casviewer.core.internal.UFeature;
+import org.apache.uima.casviewer.core.internal.UFeatureStructure;
+import org.apache.uima.casviewer.ui.internal.annotations.FeatureStructureViewerFilter;
+import org.apache.uima.casviewer.ui.internal.document.AbstractAnnotatedTextSectionPart;
+import org.apache.uima.casviewer.ui.internal.document.AnnotatedTextSectionPart;
+import org.apache.uima.casviewer.ui.internal.model.ICASViewControl;
+import org.apache.uima.casviewer.ui.internal.style.TypeSystemStyle;
+import org.apache.uima.casviewer.ui.internal.util.AbstractSectionPart;
+import org.apache.uima.casviewer.ui.internal.util.FormSection;
+import org.apache.uima.casviewer.ui.internal.util.TreeViewerHelper;
+import org.apache.uima.tools.common.internal.images.ImageLoader;
+import org.apache.uima.tools.debug.util.Trace;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.events.ExpansionAdapter;
+import org.eclipse.ui.forms.events.ExpansionEvent;
+import org.eclipse.ui.forms.events.HyperlinkAdapter;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ImageHyperlink;
+import org.eclipse.ui.forms.widgets.Section;
+
+/**
+ * Tree Structure:
+ *  FS Index (root) --> model: TreeNode
+ *    - FS[0]       --> UFeatureStructure
+ *    - FS[1]
+ *    ...
+ *
+ */
+public class FSIndexSectionPart extends AbstractSectionPart {
+
+    private ICASViewControl              casViewControl;
+    private FSIndexContentProvider  contentProvider;
+    private FSIndexLabelProvider    labelProvider;
+    private Tree                    tree = null;
+    private CheckboxTreeViewer      treeViewer = null;
+    private FeatureStructureViewerFilter filter;
+    private TypeSystemStyle    typesystemStyle;
+    
+    // List of AnnotationObject used for showing FS in document
+    private List<AnnotationObject> annotationObjectList = new ArrayList<AnnotationObject>();
+    
+    // Preferences
+    private boolean hideNoValueFeature =  false;
+    private boolean prefFlatLayout4Features = false;
+    
+    /*************************************************************************/
+    
+    protected FSIndexSectionPart(Section section) {
+        super(section);
+    }
+    
+    protected FSIndexSectionPart (ICASViewControl control,
+            IManagedForm managedForm, Composite parent,
+            Section section, int style, String title, String description,
+            boolean hide)
+    {
+        super(managedForm, parent, section, style, title, description);
+        this.hideNoValueFeature = hide;    
+        casViewControl = control;
+        managedForm.addPart(this);
+        initialize (managedForm);  // Need this code. Otherwise, exception in SectionPart !!!        
+    }
+    
+    /*************************************************************************/
+    
+    /**
+     * When the view is "Flat Structure", hide feature having no value.
+     * 
+     * @param hide
+     * @return void
+     */
+    public void hideNoValueFeature (boolean hide)
+    {
+        // Trace.err("Hide feature having no value");
+        if (hideNoValueFeature == hide) {
+            return;
+        }
+        hideNoValueFeature = hide;
+        if (contentProvider != null) {
+            contentProvider.hideNoValueFeature(hide);
+            labelProvider.hideNoValueFeature(hide);
+            TreeViewerHelper.refreshWithCheckedState(treeViewer, true);
+        }
+    }
+    
+    /**
+     * Hide all feature structures of types having the specified names
+     * 
+     * @param typeNames
+     * @return void
+     */
+    public void setHiddenTypeNames (List<String> typeNames) {
+        filter.setHiddenTypeNames(typeNames);
+        treeViewer.refresh();
+    }
+     
+    public void setViewerLayoutToFlatOrTree (boolean flat)
+    {
+        if (prefFlatLayout4Features == flat) {
+            return;
+        }
+        prefFlatLayout4Features = flat;
+        if (contentProvider != null) {
+            contentProvider.showOneLineView(flat);
+            labelProvider.showOneLineView(flat);
+            TreeViewerHelper.refreshWithCheckedState(treeViewer, true);
+        }
+    }
+
+    /*************************************************************************/
+    
+//    protected static IPreferenceStore store() {
+//        return CasViewerCorePlugin.getDefault().getPreferenceStore();
+//    }
+
+    static public FSIndexSectionPart createInstance (ICASViewControl control,
+            IManagedForm managedForm, 
+            Composite parent, int style, String title, String description,
+            boolean hide, TypeSystemStyle tsStyle)
+    {
+        FormToolkit toolkit = managedForm.getToolkit();
+        Section section = FormSection.createGridDataSection(toolkit, parent,
+                style, title, description, 5, 8,
+                GridData.FILL_BOTH|GridData.VERTICAL_ALIGN_BEGINNING,
+                1, 1);
+                
+        FSIndexSectionPart sectionPart = new FSIndexSectionPart (control,
+                managedForm, parent, section,
+                style, title, description, hide);
+        sectionPart.typesystemStyle = tsStyle;
+        sectionPart.createContents();
+                
+        return sectionPart;
+    }
+        
+    /*************************************************************************/
+    
+    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;
+    }    
+    
+    protected void createSectionToolbar (FormToolkit toolkit, Section section, 
+            Composite toolbarComposite, final CheckboxTreeViewer treeViewer)
+    {
+        AbstractSectionPart.createExpandAllMenu (toolkit, section, toolbarComposite, 
+                treeViewer);
+        AbstractSectionPart.createCollapseAllMenu(toolkit, section, toolbarComposite, 
+                treeViewer);
+        
+        // Create Menu
+        final Menu subMenu = new Menu (toolbarComposite); 
+        MenuItem item = new MenuItem(subMenu, SWT.NONE);
+        item.setText("Deselect All");
+        item.addSelectionListener(new SelectionListener () {
+            public void widgetSelected (SelectionEvent event) {
+                // TODO Optimize by creating a list of "showed" AnnotationObjects
+                for (AnnotationObject annot: annotationObjectList) {
+                    annot.show = false;
+                }
+                casViewControl.showAnnotationsForView(AbstractAnnotatedTextSectionPart.TAB_VIEW_INDEX_REPO/*, fsDocumentAnnotList*/);
+                treeViewer.setAllChecked(false);
+            }
+
+            public void widgetDefaultSelected(SelectionEvent e) {
+            }
+        });
+        new MenuItem(subMenu, SWT.SEPARATOR);
+
+        item = new MenuItem(subMenu, SWT.NONE);
+        item.setText("Show Flat Structure");
+        item.addSelectionListener(new SelectionListener () {
+            public void widgetSelected (SelectionEvent event) {
+                // Trace.trace("Show Input Types");
+//                _typeTreeViewerFiler.setFilterFlags(TypeSystemViewerFilter.FILTER_TYPE_SHOW_INPUT, true);
+                contentProvider.showOneLineView(true);
+                labelProvider.showOneLineView(true);
+                treeViewer.refresh(true);
+                treeViewer.expandToLevel(2);
+            }
+
+            public void widgetDefaultSelected(SelectionEvent e) {
+                // TODO Auto-generated method stub                
+            }
+        });
+        
+        item = new MenuItem(subMenu, SWT.NONE);
+        item.setText("Show Tree Structure");
+        item.setData(null);
+        item.addSelectionListener(new SelectionListener () {
+            public void widgetSelected (SelectionEvent event) {
+                // Trace.trace("Show Output Types");
+//                _typeTreeViewerFiler.setFilterFlags(TypeSystemViewerFilter.FILTER_TYPE_SHOW_OUTPUT, true);
+                contentProvider.showOneLineView(false);
+                labelProvider.showOneLineView(false);
+                // _typeTreeViewer.setInput(_typeHierarchy);
+                treeViewer.refresh(true);
+                treeViewer.expandToLevel(2);
+            }
+
+            public void widgetDefaultSelected(SelectionEvent e) {
+            }
+        });
+        
+        ImageHyperlink info = new ImageHyperlink(toolbarComposite, SWT.NULL);
+        toolkit.adapt(info, true, true);
+        info.setImage(ImageLoader.getInstance().getImage(ImageLoader.ICON_UI_VIEW_MENU));
+        info.setToolTipText("Flat or Tree...");
+        info.setBackground(section.getTitleBarGradientBackground());
+        info.addHyperlinkListener(new HyperlinkAdapter() {
+            public void linkActivated(HyperlinkEvent e) {
+                subMenu.setVisible(true);
+            }
+        });        
+                
+    }
+       
+    /*************************************************************************/
+
+    /* (non-Javadoc)
+     * 
+     * Called from IndexRepositorySectionPart.setSelectedTreeNode when an index
+     * is selected
+     */
+    public void setInput(Object model, String title) {
+        // "model" will be UFSIndex
+        if (model == null || !(model instanceof UFSIndex)) {
+            return;
+        }
+        // Set Show/Hide attributes of AnnotationObject
+        AnnotationObject   annot;
+        annotationObjectList.clear();
+        UFeatureStructure[] uFSs = ((UFSIndex) model).getUFeatureStructures();
+        for (int i=0; i<uFSs.length; ++i) {
+            // Is it sub-type of AnnotationFS
+            if (uFSs[i].getUimaFeatureStructure() instanceof AnnotationFS) {
+                // Lazily creating AnnotationObject
+                // Currently, UFeatureStructure.UserData is used to refer to FSNode
+                // Used by "FSIndexSectionPart.setInput" to refer to "AnnotationObject"
+                if (uFSs[i].getUserData() == null) {
+                    annot = CASObjectView.createAnnotationObjectFromFS(uFSs[i].getUimaFeatureStructure(), false);
+                    uFSs[i].setUserData(annot);
+                } else {
+                    annot = (AnnotationObject) uFSs[i].getUserData();
+                    annot.setShow(false); // Hide 
+                }
+                annotationObjectList.add(annot);
+            }
+        }
+        casViewControl.setAnnotationObjectListForView(AnnotatedTextSectionPart.TAB_VIEW_INDEX_REPO, 
+                annotationObjectList);
+        treeViewer.setInput(model);
+        treeViewer.expandToLevel(2);        
+    }
+    
+    /*************************************************************************/
+
+    static protected void createRootIndexTree(CAS aCas) {
+        if (aCas != null) {
+            FSIndexRepository ir = aCas.getIndexRepository();
+            Iterator<String> it = ir.getLabels();
+            while (it.hasNext()) {
+                String label = it.next();
+                FSIndex index1 = ir.getIndex(label);
+//                Trace.trace("label: " + label + " ; type: " + index1.getType()
+//                        + " ; size: " + index1.size());
+                createIndexSubTree(index1.getType(), aCas.getTypeSystem(),
+                         label, ir, 1);
+            }
+        }
+    }
+    
+    static private void createIndexSubTree(Type type, TypeSystem ts,
+                                String label, FSIndexRepository ir, int level) 
+    {
+//        for (int i=0; i<level; ++i) {
+//            System.out.print( "    ");
+//        }
+//        int size = ir.getIndex(label, type).size();
+//        System.out.println( "type: " + type + " ; label: " + label + " ; size:" + size);
+
+        Vector types = ts.getDirectlySubsumedTypes(type);
+        final int max = types.size();
+        for (int i = 0; i < max; i++) {
+            createIndexSubTree((Type) types.get(i), ts, label, ir, level+1);            
+        }        
+    }
+
+    /*************************************************************************/
+    
+    public void refreshTypeSystemStyle ()
+    {
+        TreeViewerHelper.refreshWithCheckedState(treeViewer, true);
+    }
+     
+} // FSIndexSectionPart

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/index/FSIndexSectionPart.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewControl.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewControl.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewControl.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewControl.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,62 @@
+package org.apache.uima.casviewer.ui.internal.model;
+
+import java.util.List;
+
+import org.apache.uima.casviewer.core.internal.AnnotationObject;
+import org.apache.uima.casviewer.core.internal.ICASObjectView;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IStatusLineManager;
+
+/**
+ * 
+ *
+ */
+public interface ICASViewControl {
+    
+    static final public int     PREF_HIDE_FEATURES_IN_TYPE_SYSTEM   = 1;
+    static final public int     PREF_HIDE_FEATURE_NO_VALUE          = 2;
+    static final public int     PREF_STYLE_FILE_EXTENSION           = 3;
+    static final public int     PREF_DEFAULT_COLORS_FILE            = 4;
+    static final public int     PREF_DEFAULT_FOREGROUND             = 5;
+    static final public int     PREF_DEFAULT_BACKGROUND             = 6;
+    static final public int     PREF_FLAT_LAYOUT_FOR_TYPES          = 7;
+    static final public int     PREF_FLAT_LAYOUT_FOR_FS             = 8;
+    public void setPreference (int attribute, boolean value);
+    public void setPreference (int attribute, String value);
+    
+    static final public int     ACTION_SELECT_ALL           = 1;
+    static final public int     ACTION_DESELECT_ALL         = 2;
+    static final public int     ACTION_SET_FILTERS          = 3;
+    
+    public void createContents();
+    public void setStatusLineManager(IStatusLineManager statusLine);
+    public void dispose();
+    public IAction getGlobalAction(String id);
+    
+    public void setTypeSelectionByName(List<String> types, boolean selection);
+    public List getSelectedTypeNames();
+    public void refreshTypeSystemStyle();
+    public void setInput(ICASObjectView icasViewObject, String title);
+    
+    public void onActionInvocation (Object source, int flags, Object obj);
+        
+    /**
+     * Set the annotation object list for the specified view
+     */
+    public void setAnnotationObjectListForView (int viewIndex, List<AnnotationObject> list);
+    
+    public void showAnnotationsForView (int forView);
+    
+    /**
+     * Show the annotations of the specified list of type names 
+     * and the specified view
+     * 
+     * @param typeNames
+     * @param forView
+     * @return void
+     */
+    public void showAnnotationsByTypenameForView (List<String> typeNames, int forView);
+
+    public void showMoreAnnotationObjects (int viewIndex, List<AnnotationObject> list);
+    public void enableTypes (boolean enable, List<String> typeNames);
+}

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewControl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewer.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewer.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewer.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewer.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,90 @@
+package org.apache.uima.casviewer.ui.internal.model;
+
+import java.util.List;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FeatureStructure;
+
+public interface ICASViewer {
+    
+    /**
+     * Editor ID of the generic CAS Viewer.
+     * 
+     * Example of usage:
+     *  ICASViewer casViewer = page.openEditor(new FileEditorInput(xcas), 
+     *                                 ICASViewer.GENERIC_CASVIEWER_ID);
+     *
+     */
+    static public String GENERIC_CASVIEWER_ID = "com.ibm.uima.casviewer.GenericCasViewer";
+  
+    /**
+     *  Set the input to this CAS Viewer from an xcas/xmi file.
+     *  The viewer will open this file and display the deserialized CAS.
+     * 
+     * @param xcasOrxmiFileName Full path name of xcas/xmi file
+     * @param title             Title to be shown in each page (can be null)
+     * @return void
+     */
+    public void setInput(String xcasOrxmiFileName, String title);
+    
+    /**
+     *  Set the input to this CAS Viewer from a CAS object.
+     *  The viewer will display the specified CAS object.
+     * 
+     * @param aCAS      CAS object to be displayed (can be multi-sofa enable CAS)
+     * @param title     Title to be shown in each page (can be null)
+     * @return void
+     */
+    public void setInput(CAS aCAS, String title);
+    
+    /**
+     * Refresh current input file
+     * 
+     * @return void
+     */
+    public void refreshInput ();
+        
+    /**
+     * Get CAS which is deserialized from xcas/xmi file. 
+     * 
+     * @return CAS      CAS object which can contains multiple sofa
+     */
+    public CAS getCAS ();
+    
+    /**
+     * Get currently selected type names from the Type System tree
+     * 
+     * @return List List of type full names. Return null if no selection
+     */
+    public List getSelectedTypeNames ();
+    
+    /**
+     * Select types in the Type System tree.
+     * The associated annotations of the specified types will be shown in the document.
+     * 
+     * @param typeNames List of type full names. If typeNames is null, all types will be assumed
+     * @return void
+     */
+    public void selectTypesByName (List typeNames);
+    
+    
+    /**
+     * Deselect types in the Type System tree.
+     * The associated annotations of the specified types will be removed from the document.
+     * 
+     * @param typeNames List of type full names. If typeNames is null, all types will be assumed
+     * @return void
+     */
+    public void deselectTypesByName (List typeNames);
+    
+    // highlight some annotation in the CAS Viewer and make sure it's visible 
+    // (i.e. scroll to it)
+    // Note: This method might NOT consistent withh CAS Viewer user-interface.
+    // THIS API IS NOT YET IMPLEMENTED
+    public void selectAndReveal(FeatureStructure featureStructure);
+    
+    public void setSelectedAnnotation (Object annotation);
+    
+    public String getImportedStyleFileName ();
+    
+}

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewerListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewerListener.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewerListener.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewerListener.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,15 @@
+package org.apache.uima.casviewer.ui.internal.model;
+
+public interface ICASViewerListener {
+    
+    static final public int         PAGE_EVENT_REFRESH_INPUT            = 1;
+    // Notify when a style file is imported
+    static final public int         PAGE_EVENT_REFRESH_STYLE            = 2;
+    static final public int         PAGE_EVENT_RESTORE_DEFAULT_STYLE    = 3;
+    
+    // Type's style (color) is update
+    static final public int         PAGE_EVENT_UPDATE_TYPE_STYLE        = 10;
+    
+    public void onActionInvocation (Object source, int flags, Object obj);
+
+}

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/model/ICASViewerListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColorManager.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColorManager.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColorManager.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColorManager.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,82 @@
+package org.apache.uima.casviewer.ui.internal.style;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Generic color manager.
+ */
+public class ColorManager { // implements ISharedTextColors {   
+    
+    private static int colorManager = 0;
+    
+    private ColorManager() {
+    }
+    
+    public static ColorManager createColorManager() {
+        ++colorManager;
+        return new ColorManager();
+    }
+        
+    protected Map fColorTable= new HashMap(10);
+    
+    public Color getColor(int hexColorValue) {
+        Color color= (Color) fColorTable.get(hexColorValue);
+        if (color == null) {
+            RGB rgb = new RGB((hexColorValue >> 16) & 0xFF, (hexColorValue >> 8) & 0xFF, hexColorValue & 0xFF);
+            color = new Color(Display.getCurrent(), rgb);
+            fColorTable.put(hexColorValue, color);
+            // Trace.err("rgb: " + rgb.toString());
+        }
+        return color;
+    }
+    
+    public Color getColor(RGB rgb) {
+        Color color= (Color) fColorTable.get(rgb);
+        if (color == null) {
+            color= new Color(Display.getCurrent(), rgb);
+            fColorTable.put(rgb, color);
+        }
+        return color;
+    }
+    
+//    static private RGB hexToRBG (String number)
+//    {
+//        int i = Integer.decode(number.toLowerCase()).intValue();
+//        return new RGB((i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF);
+//    }
+
+    public void dispose() 
+    {
+        // Trace.err("Dispose " + fColorTable.values().size() + " colors");
+//        if (--colorManager > 0) {
+//            Trace.bug(colorManager + " ColorManager instances remained");
+//        }
+        Iterator e = fColorTable.values().iterator();
+        while (e.hasNext()) {
+            Color c = (Color) e.next();
+            // Trace.trace("   " + c);
+            c.dispose();
+        }
+    }
+    
+    protected void finalize() throws Throwable
+    {
+        System.out.println("ColorManager.finalize");
+        Iterator e= fColorTable.values().iterator();
+        // Trace.err("Dispose " + fColorTable.values().size() + " colors");
+        while (e.hasNext()) {
+            Color c = (Color) e.next();
+            // Trace.trace("   " + c);
+            c.dispose();
+        }
+    }
+   
+}
+
+

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColorManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeContentProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeContentProvider.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeContentProvider.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeContentProvider.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,359 @@
+package org.apache.uima.casviewer.ui.internal.style;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.casviewer.core.internal.IItemTypeConstants;
+import org.apache.uima.casviewer.core.internal.TypeNode;
+import org.apache.uima.casviewer.core.internal.TypeTree;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.tools.debug.util.Trace;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+
+
+public class ColoredTypeTreeContentProvider implements ITreeContentProvider {
+    
+    private static final int ITEM_TYPE_COLORED_TYPE          = 1000;
+    private static final int ITEM_TYPE_TYPECOLOR             = 1010;
+    private static final int ITEM_TYPE_TYPESTYLE             = 1020;
+    
+	private static Object[] EMPTY_ARRAY = new Object[0];
+    private boolean         _includeFeature = true; 
+    private boolean         _isTableTree    = true; // viewer is a table tree
+    
+    /*************************************************************************/
+    public ColoredTypeTreeContentProvider () {
+        super();
+    }
+    
+    public ColoredTypeTreeContentProvider (boolean isTableTree) {
+        super();
+        _isTableTree = isTableTree;
+    }
+    
+    public void includeFeature (boolean includeFeature) {
+        _includeFeature = includeFeature;
+    }
+    
+    public void setViewerType (boolean isTableTree)
+    {
+        _isTableTree = isTableTree;
+    }
+    /*************************************************************************/
+    
+    // With Java 5, use Formatter (or String.format)
+    static private String toHexString (int i)
+    {
+        String hex = Integer.toHexString(i).toUpperCase();
+        return hex.length()==1? "0"+hex : hex;
+    }
+
+    static private String toHexString (RGB rgb)
+    {
+        String r = Integer.toHexString(rgb.red).toUpperCase();
+        r = r.length()==1? "0"+r : r;
+        String g = Integer.toHexString(rgb.green).toUpperCase();
+        g = g.length()==1? "0"+g : g;
+        String b = Integer.toHexString(rgb.blue).toUpperCase();
+        b = b.length()==1? "0"+b : b;
+        
+        return r+g+b;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+     */
+    public Object[] getChildren (Object parent) 
+    {
+	    if (parent instanceof List) {
+            // List<TypeStyle> of default colors
+            List list = (List) parent;
+            if (list == null || list.size() == 0) {
+                return EMPTY_ARRAY;
+            }
+            Object[] objs = new Object[list.size()];
+            
+            String      text = "";
+            NumberFormat formatter = new DecimalFormat("00");
+            for (int i=0; i<list.size(); ++i) {
+                Color   bgColor = null;
+                int     kind;
+                if (list.get(i) instanceof TypeStyle) {
+                    kind = ITEM_TYPE_TYPESTYLE;
+                    text = ((TypeStyle) list.get(i)).getTypeName();
+                    bgColor = ((TypeStyle) list.get(i)).getBackground();
+                    
+//                } else if (list.get(i) instanceof TypeColor) {
+//                    TypeColor typeColor = (TypeColor) list.get(i);
+//                    kind = ITEM_TYPE_TYPECOLOR;
+//                    text = toHexString(typeColor.rgbForeground) + "  " 
+//                         + toHexString(typeColor.rgbBackground);
+//                    bgColor = typeColor.bgColor;
+//                } else if (list.get(i) instanceof ColoredType) {
+//                    kind = ITEM_TYPE_COLORED_TYPE;
+//                    text = ((ColoredType) list.get(i)).getTypeName();
+//                    if (((ColoredType) list.get(i)).getColor() != null) {
+//                        bgColor = ((ColoredType) list.get(i)).getColor().bgColor;
+//                    }
+                } else {
+                    continue;
+                }
+                TypeNode node = new TypeNode (null, text);
+                node.setObjectType(kind);
+                node.setObject(list.get(i));
+                node.setBgColor(bgColor);
+                objs[i] = node;
+            }
+            return objs;
+            
+        } else if (parent instanceof TypeSystemStyle) {
+            Map map = ((TypeSystemStyle) parent).getStyledTypeMap();
+            if (map == null || map.size() == 0) {
+                Trace.err("getStyledTypeMap() == null");
+                return EMPTY_ARRAY;
+            }
+            Object[] objs = new Object[map.size()];
+            Iterator iter = map.entrySet().iterator();
+            int i = 0;
+            while (iter.hasNext()) {
+                Map.Entry e = (Map.Entry) iter.next();
+                TypeNode node = new TypeNode (null, (String) e.getKey());
+                node.setObjectType(ITEM_TYPE_TYPESTYLE);
+                node.setObject(e.getValue());
+                node.setBgColor(((TypeStyle) e.getValue()).getBackground());
+                objs[i++] = node;
+            }
+            return objs;
+            
+            
+        } else if (parent instanceof TypeNode) {
+	        if ( ((TypeNode)parent).getObjectType() == IItemTypeConstants.ITEM_TYPE_TYPE 
+	          || ((TypeNode)parent).getObjectType() == IItemTypeConstants.ITEM_TYPE_UNKNOW ) {
+                TypeDescription t = (TypeDescription)((TypeNode)parent).getObject();
+                // Trace.trace("TypeDescription.name: " + t.getName());
+               
+	            int		count = 0;
+            	TypeNode fNode = null;
+	            // Add "Features" or "Allowed values" Node
+                	            
+                // Count the number of types having annotations
+                Object[] childrenArray = null;
+                if ( !_isTableTree && ((TypeNode)parent).getChildren() != null ) {
+                    childrenArray = ((TypeNode)parent).getChildrenArray();
+                    for (int j=0; j<childrenArray.length ; ++j) {
+                        TypeNode node = (TypeNode) childrenArray[j];
+                        if ( ((TypeDescription) node.getObject()).getName().endsWith("AnnotationBase") ) {
+                            // "uima.cas.AnnotationBase"
+                            if ( node.getChildren() != null ) {
+                                 if ( ((TypeNode) node.getChildrenArray()[0]).getFsTotal() > 0 ) {
+                                     count++;
+                                 }
+                            }
+                        } else {
+                            if (node.getFsTotal() > 0 ) {
+                                count++;
+                            }                            
+                        }
+                    }
+                    // count += childrenArray.length;
+                } 
+                // Trace.trace("TypeDescription.name: " + t.getName() + " has " + count + " children");
+	            Object[] objs = new Object[count];
+	            int index = 0;
+	            if ( fNode != null ) {
+	                objs[index++] = fNode;
+	            }
+	            
+                if ( childrenArray != null ) {
+                    for (int j=0; j<childrenArray.length ; ++j) {
+//                        if ( ((TypeNode) childrenArray[j]).getFsTotal() > 0 ) {
+//                            objs[index++] = (TypeNode) childrenArray[j];
+//                        }
+                        TypeNode node = (TypeNode) childrenArray[j];
+                        if ( ((TypeDescription) node.getObject()).getName().endsWith("AnnotationBase") ) {
+                            // "uima.cas.AnnotationBase"
+                            if ( node.getChildren() != null ) {
+                                 if ( ((TypeNode) node.getChildrenArray()[0]).getFsTotal() > 0 ) {
+                                     objs[index++] = (TypeNode) node.getChildrenArray()[0];
+                                 }
+                            }
+                        } else {
+                            if (node.getFsTotal() > 0 ) {
+                                objs[index++] = node;                            }                            
+                        }
+                    }                   
+                }
+	            return objs;
+	        } else if ( ((TypeNode)parent).getObjectType() == IItemTypeConstants.ITEM_TYPE_LABEL_FEATURES ) {
+//	            List 	featureList = ((TypeDescription)((TypeNode)parent).getObject()).getFeatureList();
+//                ArrayList featureNodeList = (ArrayList) ((TypeNode)parent).getChildren();
+//                if (featureNodeList == null) {
+//                    FeatureMetadata f;
+//                    featureNodeList = new ArrayList();
+//    	            for (int i=0; i<featureList.size(); ++i ) {
+//    	                f = (FeatureMetadata) featureList.get(i);
+//    	                // System.out.println("feature2:" + f.getShortName());
+//                        TypeNode fNode = new TypeNode((TypeNode)parent, f.getName());
+//    		            fNode.setObjectType(IItemTypeConstants.ITEM_TYPE_FEATURE);
+//    		            fNode.setObject(f);
+//    		            featureNodeList.add(fNode);
+//    	            }
+//                    ((TypeNode)parent).setChildren(featureNodeList);
+//                }
+//	            return featureNodeList.toArray(new TypeNode[featureNodeList.size()]);
+
+            // } else if ( ((TypeNode)parent).getObjectType() == IItemTypeConstants.ITEM_TYPE_CATEGORY ) {
+                
+            } else {
+	            // System.out.println("getChildren - Unknown Type: " + ((TreeElementNode)parent).getObjectType());                
+	            if ( ((TypeNode)parent).getChildren() != null ) {
+                    return ((TypeNode)parent).getChildrenArray();
+	            }
+	        }            
+        } else if ( parent instanceof TypeDescription ) {
+            if (((TypeDescription) parent).getFeatures() != null) {
+                return ((TypeDescription) parent).getFeatures();
+            }            
+        } else if (parent instanceof TypeTree) {
+            Object[] objs = new Object[1];
+            objs[0] = ((TypeTree)parent).getRoot ();
+            return objs;
+            
+        } else {
+            Trace.err("Unknow parent: " + parent.getClass().getName());
+	    }
+	    
+        return EMPTY_ARRAY;
+    } // getChildren
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+     */
+    public Object getParent(Object element) 
+    {
+        // Trace.trace();
+        if (element instanceof TypeNode) {
+            return ((TypeNode)element).getParent();
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+     */
+    public boolean hasChildren(Object element) 
+    {
+        if ( element instanceof TypeSystemStyle
+                || element instanceof List ) {
+            return true;
+            
+        } else if (element instanceof TypeNode
+           || element instanceof TypeDescription) {
+            if ( element instanceof TypeDescription
+                    || ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_TYPE 
+                    || ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_UNKNOW) {
+                TypeDescription t;
+                if ( element instanceof TypeDescription ) {
+                    t = (TypeDescription) element;
+                } else {
+                    // Check if the type has "type" children
+                    if ( ((TypeNode)element).getChildren() != null ) {
+                        return true;
+                    }
+                    t = (TypeDescription)((TypeNode)element).getObject();
+                }
+                // Check if the type has "features"
+//                if ( _includeFeature && t != null ) {
+//                    List    featureList = t.getFeatureList();
+//                    if ( featureList != null && featureList.size() > 0 ) {
+//                        return true;
+//                    }
+//                }
+            } else if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_LABEL_FEATURES ) {
+                return true;
+                // For Category
+//            } else if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_CATEGORY ) {
+//                if ( ((TypeNode)element).getChildren() != null ) {
+//                    return true;
+//                }
+//                
+//            // For View Mapping
+//            } else if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_VIEWMAPPING ) {
+//                if ( ((TypeNode)element).getChildren() != null ) {
+//                    return true;
+//                }
+            }
+        } else if ( element instanceof TypeTree ) {
+        	return true;
+        } else {
+            Trace.err("Unknow element: " + element.getClass().getName());
+        }
+        
+        return false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+     */
+    public Object[] getElements(Object inputElement) 
+    {
+        if ( inputElement instanceof TypeSystemStyle
+                || inputElement instanceof List ) {
+            return getChildren(inputElement);
+            
+        } else if ( inputElement instanceof TypeTree ) {
+            if ( _isTableTree ) {
+                // Trace.trace("_isTableTree");
+                List<TypeNode> list = ((TypeTree) inputElement).getNodeListFromHierarchy(true, true);
+                
+                // Return ONLY types having annotations
+                List<TypeNode>   typesHavingAnnotations = new ArrayList<TypeNode>();
+                for (int i=0; i<list.size(); ++i) {
+                    // Has annotations ?
+                    if ( list.get(i).getFsTotal() > 0 ) {
+                        typesHavingAnnotations.add(list.get(i));
+                    }                    
+                }
+                return typesHavingAnnotations.toArray();
+            } else {
+                // TreeViewer
+                // Trace.trace("getRoot().getLabel: " + ((TypeTree)inputElement).getRoot().getLabel());
+                if ( TypeTree.isTypeSystemRootName(((TypeTree)inputElement).getRoot().getLabel()) ) {             
+                    return getChildren(((TypeTree)inputElement).getRoot().getChildrenArray()[0]);
+                    // return getChildren(((TypeTree)inputElement).getRoot());
+                } else {
+                    return getChildren(inputElement);
+                }
+            }
+        } else {
+            Trace.err("Unknow input: " + inputElement.getClass().getName());
+        }
+        return EMPTY_ARRAY;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+     */
+    public void dispose() {
+        // TODO Auto-generated method stub        
+    }
+
+
+    /**
+     * 
+     *  newInput    List<TypeStyle>
+     */                  
+    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+//        if (newInput != null) {
+//            Trace.trace("newInput: " + newInput.getClass().getName());
+//        }        
+    }
+
+} // 

Propchange: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeContentProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeLabelProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeLabelProvider.java?rev=673409&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeLabelProvider.java (added)
+++ incubator/uima/sandbox/trunk/CasViewerEclipsePlugin/uimaj-ep-casviewer-core/src/main/java/org/apache/uima/casviewer/ui/internal/style/ColoredTypeTreeLabelProvider.java Wed Jul  2 07:46:35 2008
@@ -0,0 +1,307 @@
+package org.apache.uima.casviewer.ui.internal.style;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.uima.casviewer.core.internal.IItemTypeConstants;
+import org.apache.uima.casviewer.core.internal.TypeNode;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.tools.common.internal.images.ImageLoader;
+import org.apache.uima.tools.debug.util.Trace;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+
+public class ColoredTypeTreeLabelProvider extends LabelProvider 
+									 implements ITableLabelProvider, ITableColorProvider, IFontProvider  
+{
+    final static int COLUMN_PRE_SELECTED        = 5;
+    final static int COLUMN_HIDDEN              = 6;
+    
+	private StructuredViewer	_viewer          = null;
+	private Map 			    imageCache      = new HashMap(11);
+	private boolean             _showFullName 	= false; // If true, will show "full name"
+	
+	protected ColoredTypeTreeLabelProvider () {
+	}
+	
+	public ColoredTypeTreeLabelProvider (StructuredViewer viewer) {
+		super();
+		_viewer = viewer;
+	}
+
+	public ColoredTypeTreeLabelProvider (StructuredViewer viewer, boolean showFullName) {
+		super();
+		_viewer = viewer;
+		_showFullName = showFullName;
+	}
+        	
+    /*************************************************************************/
+        
+    /**
+     * 
+     * @return true if Full Name View
+     */
+    public boolean switchNameView (boolean refresh) 
+    {
+        Trace.trace();
+        _showFullName = !_showFullName;
+        if (refresh) {
+            _viewer.refresh();
+        }
+        return _showFullName;
+    }
+    
+    /*************************************************************************/
+    
+    
+	/*
+	 * @see ILabelProvider#getImage(Object)
+	 */
+	public Image getImage(Object element) 
+    {
+        String imageFile = null;
+        
+		ImageDescriptor descriptor = null;
+	    if (element instanceof TypeNode
+            || element instanceof TypeDescription) {
+            
+            // Object object = ((TypeNode)element).getObject();
+	        if ( element instanceof TypeDescription
+                || ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_TYPE ) {
+                TypeDescription t;
+                if (element instanceof TypeDescription) {
+                    t = (TypeDescription) element;
+                } else {
+                    t = (TypeDescription)((TypeNode)element).getObject();
+                }
+                imageFile = "type.gif";
+                descriptor = ImageLoader.getInstance().getImageDescriptor(imageFile);
+                
+	        } else if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_LABEL_FEATURES ) {
+//				return PlatformUI.getWorkbench().getSharedImages().getImage(
+//				        		ISharedImages.IMG_OBJ_FOLDER);
+                
+            } else if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_FEATURE ) {
+                descriptor = ImageLoader.getInstance().getImageDescriptor("final_co.gif");
+
+            } else {
+				// throw unknownElement(element);
+                // Trace.err("unknownElement");
+			    return null;
+			}           
+	    } else {
+			// throw unknownElement(element);
+		    return null;
+	    }
+		//obtain the cached image corresponding to the descriptor
+        if (descriptor != null) {
+    		Image image = (Image)imageCache.get(descriptor);
+    		if (image == null) {
+    			image = descriptor.createImage();
+                if (image != null) {
+                    imageCache.put(descriptor, image);
+                }
+    		}
+    		return image;
+        } else {
+            return null;
+        }
+	}
+
+	public String getText (Object element) 
+	{
+	    if (element instanceof TypeNode) {
+	        if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_TYPE ) {
+                if (((TypeNode)element).getObject() != null) {
+                    String ioText = "";
+                    if (_showFullName) {
+                        return ((TypeDescription)((TypeNode)element).getObject()).getName()+ioText
+                                + " [" + ((TypeNode)element).getFsTotal() + " : "
+                                + ((TypeNode)element).getFsCount() + "]";
+                    } else {
+                        // System.out.println(((TypeDescription)((TypeNode)element).getObject()).getShortName());
+                        return ((TypeDescription)((TypeNode)element).getObject()).getName()+ioText
+                        + " [" + ((TypeNode)element).getFsTotal() + " : "
+                        + ((TypeNode)element).getFsCount() + "]";
+                    }
+                } else {
+                    return ((TypeNode)element).getLabel();
+                }
+	        } else if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_LABEL_FEATURES ) {
+		        return ((TypeNode)element).getLabel(); // new String("features");
+		        
+	        } else if ( ((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_FEATURE ) {
+	        	// return ((TreeFeatureNode)element).getLabel();
+//                if (_showFullName) {
+//                    // System.err.println("[_showFullName]");
+//                    return ((FeatureMetadata)((TypeNode)element).getObject()).getFullName();
+//                } else {
+//                    return ((FeatureMetadata)((TypeNode)element).getObject()).getName();
+//                }
+
+			} else {
+//			    Trace.err("Unknown element.getObjectType() (= " 
+//			    		+ ((TypeNode)element).getObjectType()
+//			            + ") for label: " + ((TypeNode)element).getLabel());
+			    return ((TypeNode)element).getLabel(); // "Unknow element.getObjectType()";
+		    } 
+	        	        
+	    } else if (element instanceof TypeDescription) {
+	        return ((TypeDescription)element).getName();
+	        
+//	    } else if (element instanceof FeatureMetadata) {
+//            // System.err.println("[0 FeatureMetadata _showFullName]");
+//	    	if (_showFullName) {
+//                // System.err.println("[FeatureMetadata _showFullName]");
+//	    		return ((FeatureMetadata)element).getFullName();
+//	    	} else {
+//	    		return ((FeatureMetadata)element).getName();
+//	    	}
+
+	    } else if (element instanceof String) {
+	        return (String) element;
+	    }
+	    System.out.println("Unknown element: " + element.getClass().getName());
+	    return "Unknow";
+	} // getText
+    
+    public String getColumnText(Object element, int index) 
+    {
+        if (element instanceof TypeNode) {
+            Object obj = ((TypeNode) element).getObject();
+            if ( obj instanceof TypeStyle ) {
+                if (index == 0) {
+                    // Display type's name from node's label
+                    return ((TypeNode)element).getLabel();
+                    
+                } else if (index == COLUMN_PRE_SELECTED) {
+                    if ( ((TypeStyle) obj).isChecked() ) {
+                        return "selected";
+                    }
+                    return "";
+                } else if (index == COLUMN_HIDDEN) {
+                    if ( ((TypeStyle) obj).isHidden() ) {
+                        return "hidden";
+                    }
+                    return "";
+                } else {
+                    return "";
+                }
+            }
+            // return getText(element);
+            
+        }
+        Trace.trace("Unknown element: " + element.getClass().getName());
+        return "???";
+    }
+    
+
+	public void dispose() {
+		for (Iterator i = imageCache.values().iterator(); i.hasNext();) {
+			((Image) i.next()).dispose();
+		}
+		imageCache.clear();
+	}
+
+	protected RuntimeException unknownElement(Object element) {
+		return new RuntimeException("Unknown type of element in tree of type " + element.getClass().getName());
+	}	
+	
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.getObject())
+     */
+    public Color getForeground (Object element) {
+        if ( element instanceof TypeNode ) {
+            int color = -1;
+        	if (((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_LABEL_FEATURES) {
+                color = SWT.COLOR_BLUE;
+        		
+        	} else if (((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_TYPE)  {
+//                if (((TypeNode)element).getObject() != null) {
+//            		int status = ((TypeDescription)((TypeNode)element).getObject()).getModificationAttribut();
+//            		if (((TypeDescription)((TypeNode)element).getObject()).getValidityAttribut() != ItemAttributes.STATUS_VALID) { 
+//                        color = SWT.COLOR_RED;
+//                    } else if (status == ItemAttributes.MODIFICATION_UPDATE) {
+//    	        		System.out.println("getForeground: COLOR_GREEN");
+//                        color = SWT.COLOR_GREEN;
+//    	        	}
+//                }
+            } else if (((TypeNode)element).getObjectType() == IItemTypeConstants.ITEM_TYPE_FEATURE)  {
+                
+        	}
+            if (color != -1) {
+                return _viewer.getControl().getDisplay().getSystemColor(color);
+            }
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.getObject())
+     */
+    public Color getBackground(Object element) {
+        // System.out.println("getBackground: ");
+        if ( element instanceof TypeNode ) {
+            if ( ((TypeNode) element).getBgColor() != null ) {
+                return (Color) ((TypeNode) element).getBgColor();
+            }
+        } else {
+            // ((TreeViewer)_viewer).getTree().tes
+        }
+        return null; 
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.getObject())
+     */
+    public Font getFont(Object element) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Color getBackground(Object element, int columnIndex) {
+        if ( element instanceof TypeNode ) {
+            Object obj = ((TypeNode) element).getObject();
+            if ( (obj instanceof TypeStyle) /* || (obj instanceof ColoredType)*/ ) {
+                if (columnIndex == 0 || columnIndex == 4) {
+                    return (Color) ((TypeNode) element).getBgColor();
+                } else if (columnIndex == 2) {
+                    if ( obj instanceof TypeStyle ) {
+                        TypeStyle typeColor = (TypeStyle) obj;
+                        if (typeColor != null) {
+                            return (Color) typeColor.fgColor;
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    public Color getForeground(Object element, int columnIndex) {
+        if ( element instanceof TypeNode ) {
+            if (columnIndex == 0) {
+                Object obj = ((TypeNode) element).getObject();
+                if ( obj instanceof TypeStyle ) {
+                    return ((TypeStyle) obj).fgColor;
+                }            
+            }
+        }
+        return null;
+    }
+
+    public Image getColumnImage(Object element, int columnIndex) {
+        // TODO Auto-generated method stub
+        return null;
+    }		
+    
+}