Author: pkluegl Date: Fri Aug 26 12:14:00 2016 New Revision: 1757828 URL: http://svn.apache.org/viewvc?rev=1757828&view=rev Log: no jira - some refactoring preparing lazy tree nodes
Modified: uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainAbstractTreeNode.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AbstractTreeNode.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeNode.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSFeatureTreeNode.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSTreeNode.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/IRootTreeNode.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeOrderedRootTreeNode.java uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeTreeNode.java Modified: uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainAbstractTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainAbstractTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainAbstractTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-addons/src/main/java/org/apache/uima/ruta/explain/tree/ExplainAbstractTreeNode.java Fri Aug 26 12:14:00 2016 @@ -80,6 +80,7 @@ public abstract class ExplainAbstractTre return fs.toString(); } + @SuppressWarnings({ "unchecked", "rawtypes" }) public Object getAdapter(Class adapter) { if (FeatureStructure.class.equals(adapter)) { Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AbstractTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AbstractTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AbstractTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AbstractTreeNode.java Fri Aug 26 12:14:00 2016 @@ -22,32 +22,45 @@ package org.apache.uima.ruta.caseditor.v import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.List; + +import org.apache.uima.cas.CAS; public abstract class AbstractTreeNode implements ITreeNode { + private static final ITreeNode[] emptyArray = new ITreeNode[0]; + private ITreeNode parent; - private ArrayList<ITreeNode> children; + protected List<ITreeNode> children; - public AbstractTreeNode() { - this(null); + /** + * not used yet, may be null + */ + protected final CAS cas; + + public AbstractTreeNode(CAS cas) { + this(cas, null); } - public AbstractTreeNode(ITreeNode parent) { + public AbstractTreeNode(CAS cas, ITreeNode parent) { this.parent = parent; - children = new ArrayList<ITreeNode>(); + this.cas = cas; } @Override public void addChild(ITreeNode child) { + if(children == null) { + children = new ArrayList<>(); + } children.add(child); } @Override public ITreeNode[] getChildren() { - return children.toArray(new ITreeNode[] {}); + return children.toArray(emptyArray); } - + @Override public ITreeNode getParent() { return parent; @@ -55,6 +68,9 @@ public abstract class AbstractTreeNode i @Override public boolean hasChildren() { + if(children == null) { + return false; + } return children.size() > 0; } Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeNode.java Fri Aug 26 12:14:00 2016 @@ -21,6 +21,7 @@ package org.apache.uima.ruta.caseditor.v import java.util.Stack; +import org.apache.uima.cas.CAS; import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.Type; import org.apache.uima.cas.text.AnnotationFS; @@ -29,12 +30,12 @@ import org.eclipse.core.runtime.IAdaptab public class AnnotationTreeNode extends FSTreeNode implements IAnnotationNode, IAdaptable { - public AnnotationTreeNode(ITreeNode parent, AnnotationFS annotation) { - super(parent, annotation); + public AnnotationTreeNode(CAS cas, ITreeNode parent, AnnotationFS annotation) { + super(cas, parent, annotation); } - public AnnotationTreeNode(ITreeNode parent, AnnotationFS annotation, Stack<Type> parentTypes) { - super(parent, annotation, parentTypes); + public AnnotationTreeNode(CAS cas, ITreeNode parent, AnnotationFS annotation, Stack<Type> parentTypes) { + super(cas, parent, annotation, parentTypes); } @Override Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/AnnotationTreeViewPage.java Fri Aug 26 12:14:00 2016 @@ -581,12 +581,12 @@ public class AnnotationTreeViewPage exte } public IRootTreeNode getTypeOrderedTree(int pos, String manualTypeFilter, String manualTextFilter) { - TypeOrderedRootTreeNode root = new TypeOrderedRootTreeNode(); + CAS cas = editor.getDocument().getCAS(); + TypeOrderedRootTreeNode root = new TypeOrderedRootTreeNode(cas); IPreferenceStore preferenceStore = RutaCasEditorPlugin.getDefault().getPreferenceStore(); boolean withParents = preferenceStore .getBoolean(CasEditorViewsPreferenceConstants.SHOW_PARENT_TYPES); if (isTreeWithTypesWithoutAnnotations()) { - CAS cas = editor.getDocument().getCAS(); Type atype = cas.getAnnotationType(); TypeSystem ts = cas.getTypeSystem(); Iterator<Type> tit = ts.getProperlySubsumedTypes(atype).iterator(); @@ -595,7 +595,7 @@ public class AnnotationTreeViewPage exte boolean typeConstraint = StringUtils.isEmpty(manualTypeFilter) || type.getName().toLowerCase().indexOf(manualTypeFilter.toLowerCase()) != -1; if (typeConstraint) { - root.getTreeNode(type); // register type + root.getTreeNode(type, cas); // register type } } } @@ -610,7 +610,7 @@ public class AnnotationTreeViewPage exte || annotationFS.getCoveredText().toLowerCase() .indexOf(manualTextFilter.toLowerCase()) != -1; if (offsetConstraint && typeConstraint && textConstraint) { - root.insertFS(annotationFS, withParents); + root.insertFS(annotationFS, cas, withParents); } } @@ -654,7 +654,7 @@ public class AnnotationTreeViewPage exte Collection<Type> shownAnnotationTypes = editor.getShownAnnotationTypes(); List<TypeTreeNode> nodes = toNodes(shownAnnotationTypes); getTreeViewer().setCheckedElements(nodes.toArray()); - getTreeViewer().setGrayed(new TypeTreeNode(editor.getAnnotationMode()), true); + getTreeViewer().setGrayed(new TypeTreeNode(null, editor.getAnnotationMode()), true); // try to restore selection: if (selectedFS != null) { Type type = selectedFS.getType(); @@ -697,7 +697,7 @@ public class AnnotationTreeViewPage exte @Override public void annotationModeChanged(Type newMode) { - getTreeViewer().setGrayed(new TypeTreeNode(newMode), true); + getTreeViewer().setGrayed(new TypeTreeNode(null, newMode), true); } @Override @@ -709,7 +709,7 @@ public class AnnotationTreeViewPage exte private List<TypeTreeNode> toNodes(Collection<Type> shownAnnotationTypes) { List<TypeTreeNode> nodes = new ArrayList<TypeTreeNode>(); for (Type type : shownAnnotationTypes) { - nodes.add(new TypeTreeNode(type)); + nodes.add(new TypeTreeNode(null, type)); } return nodes; } Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSFeatureTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSFeatureTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSFeatureTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSFeatureTreeNode.java Fri Aug 26 12:14:00 2016 @@ -21,6 +21,7 @@ package org.apache.uima.ruta.caseditor.v import java.util.Stack; +import org.apache.uima.cas.CAS; import org.apache.uima.cas.Feature; import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.Type; @@ -31,14 +32,14 @@ public class FSFeatureTreeNode extends F private Feature feature; - public FSFeatureTreeNode(ITreeNode parent, Feature feature, FeatureStructure fs) { - super(parent, fs); + public FSFeatureTreeNode(CAS cas, ITreeNode parent, Feature feature, FeatureStructure fs) { + super(cas, parent, fs); this.feature = feature; } - public FSFeatureTreeNode(ITreeNode parent,Feature feature, FeatureStructure fs, + public FSFeatureTreeNode(CAS cas, ITreeNode parent,Feature feature, FeatureStructure fs, Stack<Type> parentTypes) { - super(parent, fs, parentTypes); + super(cas, parent, fs, parentTypes); this.feature = feature; } Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/FSTreeNode.java Fri Aug 26 12:14:00 2016 @@ -25,6 +25,7 @@ import java.util.Stack; import org.apache.commons.lang3.StringUtils; import org.apache.uima.cas.ArrayFS; +import org.apache.uima.cas.CAS; import org.apache.uima.cas.CommonArrayFS; import org.apache.uima.cas.Feature; import org.apache.uima.cas.FeatureStructure; @@ -36,16 +37,16 @@ public class FSTreeNode extends Abstract protected FeatureStructure fs; - public FSTreeNode(ITreeNode parent, FeatureStructure annotation) { - this(parent, annotation, new Stack<Type>()); + public FSTreeNode(CAS cas, ITreeNode parent, FeatureStructure annotation) { + this(cas, parent, annotation, new Stack<Type>()); } - public FSTreeNode(ITreeNode parent, FeatureStructure annotation, Stack<Type> parentTypes) { - super(parent); + public FSTreeNode(CAS cas, ITreeNode parent, FeatureStructure annotation, Stack<Type> parentTypes) { + super(cas, parent); this.fs = annotation; parentTypes.push(fs.getType()); for (Feature f : annotation.getType().getFeatures()) { - addFeatures(this, f, annotation, parentTypes); + addFeatures(this, f, annotation, cas, parentTypes); } parentTypes.pop(); } @@ -60,7 +61,7 @@ public class FSTreeNode extends Abstract return fs.getType(); } - public void addFeatures(ITreeNode parent, Feature f, FeatureStructure featureStructure, + public void addFeatures(ITreeNode parent, Feature f, FeatureStructure featureStructure, CAS cas, Stack<Type> parentTypes) { if (f.getRange().isArray()) { // handle all kinds of arrays @@ -81,9 +82,9 @@ public class FSTreeNode extends Abstract ITreeNode fsNode; if (fs instanceof AnnotationFS) { AnnotationFS faa = (AnnotationFS) fs; - fsNode = new AnnotationTreeNode(arrayNode, faa, parentTypes); + fsNode = new AnnotationTreeNode(cas, arrayNode, faa, parentTypes); } else { - fsNode = new TypeTreeNode(arrayNode, fsType); + fsNode = new TypeTreeNode(cas, arrayNode, fsType); } arrayNode.addChild(fsNode); } @@ -105,7 +106,7 @@ public class FSTreeNode extends Abstract } else if (f.getRange() instanceof Type) { FeatureStructure featureValue = featureStructure.getFeatureValue(f); if (featureValue instanceof AnnotationFS && expandable(featureValue.getType(), parentTypes)) { - parent.addChild(new FSFeatureTreeNode(this, f, featureValue, parentTypes)); + parent.addChild(new FSFeatureTreeNode(cas, this, f, featureValue, parentTypes)); } } } Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/IRootTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/IRootTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/IRootTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/IRootTreeNode.java Fri Aug 26 12:14:00 2016 @@ -19,11 +19,12 @@ package org.apache.uima.ruta.caseditor.view.tree; +import org.apache.uima.cas.CAS; import org.apache.uima.cas.FeatureStructure; public interface IRootTreeNode extends ITreeNode { - public void insertFS(FeatureStructure annotation, boolean withParents); + public void insertFS(FeatureStructure annotation, CAS cas, boolean withParents); public void sort(); } Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeOrderedRootTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeOrderedRootTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeOrderedRootTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeOrderedRootTreeNode.java Fri Aug 26 12:14:00 2016 @@ -23,6 +23,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Stack; +import org.apache.uima.cas.CAS; import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.Type; import org.apache.uima.cas.text.AnnotationFS; @@ -31,8 +32,8 @@ public class TypeOrderedRootTreeNode ext private Map<Type, TypeTreeNode> typeMap = new HashMap<Type, TypeTreeNode>(); - public TypeOrderedRootTreeNode() { - super(); + public TypeOrderedRootTreeNode(CAS cas) { + super(cas); } @Override @@ -45,10 +46,10 @@ public class TypeOrderedRootTreeNode ext return null; } - public TypeTreeNode getTreeNode(Type type) { + public TypeTreeNode getTreeNode(Type type, CAS cas) { TypeTreeNode typeTreeNode = typeMap.get(type); if (typeTreeNode == null) { - typeTreeNode = new TypeTreeNode(this, type); + typeTreeNode = new TypeTreeNode(cas, this, type); typeMap.put(type, typeTreeNode); addChild(typeTreeNode); } @@ -56,7 +57,7 @@ public class TypeOrderedRootTreeNode ext } @Override - public void insertFS(FeatureStructure fs, boolean withParents) { + public void insertFS(FeatureStructure fs, CAS cas, boolean withParents) { Type type = fs.getType(); if (type.getShortName().equals("RutaBasic") || type.getShortName().equals("DebugBlockApply") || type.getShortName().equals("DebugMatchedRuleMatch") @@ -66,27 +67,27 @@ public class TypeOrderedRootTreeNode ext || type.getShortName().equals("DebugRuleElementMatch")) { return; } - insertFS(fs, type, withParents); + insertFS(fs, type, cas, withParents); } - private void insertFS(FeatureStructure fs, Type type, boolean withParents) { - TypeTreeNode typeTreeNode = getTreeNode(type); + private void insertFS(FeatureStructure fs, Type type, CAS cas, boolean withParents) { + TypeTreeNode typeTreeNode = getTreeNode(type, cas); FSTreeNode node = createFSNode(typeTreeNode, fs); typeTreeNode.addChild(node); if (withParents) { Type parent = fs.getCAS().getTypeSystem().getParent(type); if (parent != null) { - insertFS(fs, parent, withParents); + insertFS(fs, parent, cas, withParents); } } } private FSTreeNode createFSNode(ITreeNode parent, FeatureStructure fs) { if (fs instanceof AnnotationFS) { - return new AnnotationTreeNode(parent, (AnnotationFS) fs, new Stack<Type>()); + return new AnnotationTreeNode(cas, parent, (AnnotationFS) fs, new Stack<Type>()); } - return new FSTreeNode(parent, fs); + return new FSTreeNode(cas, parent, fs); } @Override Modified: uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeTreeNode.java URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeTreeNode.java?rev=1757828&r1=1757827&r2=1757828&view=diff ============================================================================== --- uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeTreeNode.java (original) +++ uima/ruta/trunk/ruta-ep-caseditor/src/main/java/org/apache/uima/ruta/caseditor/view/tree/TypeTreeNode.java Fri Aug 26 12:14:00 2016 @@ -19,18 +19,19 @@ package org.apache.uima.ruta.caseditor.view.tree; +import org.apache.uima.cas.CAS; import org.apache.uima.cas.Type; public class TypeTreeNode extends AbstractTreeNode { private Type type; - public TypeTreeNode(Type type) { - this(null, type); + public TypeTreeNode(CAS cas, Type type) { + this(cas, null, type); } - public TypeTreeNode(ITreeNode parent, Type type) { - super(parent); + public TypeTreeNode(CAS cas, ITreeNode parent, Type type) { + super(cas, parent); this.type = type; }