Author: mtoepfer
Date: Wed Mar 12 08:41:35 2014
New Revision: 1576637

URL: http://svn.apache.org/r1576637
Log:
UIMA-3673
CAS Editor: set shown annotation types (collection of types)
- new public method in AnnotationEditor: 
setShownAnnotationTypes(Collection<Type> types) 
- adapted IShowAnnotationsListener in initiallySynchronizeUI()

Modified:
    
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java

Modified: 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=1576637&r1=1576636&r2=1576637&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
 Wed Mar 12 08:41:35 2014
@@ -948,23 +948,19 @@ public final class AnnotationEditor exte
       mShowAnnotationsMenu.addListener(new IShowAnnotationsListener() {
 
         public void selectionChanged(Collection<Type> selection) {
-          
-          // if changes selection is either larger, or smaller
-          // if larger an annotation type was added
-          // if smaller one was removed
-          if (shownAnnotationTypes.size() < selection.size()) {
-            List<Type> clonedCollection = new ArrayList<Type>(selection);
-            clonedCollection.removeAll(shownAnnotationTypes);
-            
-            Type addedAnnotationType = clonedCollection.get(0);
-            showAnnotationType(addedAnnotationType, true);
+          // compute change sets and apply changes:
+
+          Collection<Type> notShownAnymore = new 
HashSet<Type>(shownAnnotationTypes);
+          notShownAnymore.removeAll(selection);
+          for (Type type : notShownAnymore) {
+            showAnnotationType(type, false);
           }
-          else if (selection.size() < shownAnnotationTypes.size()) {
-            List<Type> clonedCollection = new 
ArrayList<Type>(shownAnnotationTypes);
-            clonedCollection.removeAll(selection);
-            
-            Type removedAnnotationType = clonedCollection.get(0);
-            showAnnotationType(removedAnnotationType, false);
+
+          Collection<Type> newShownTypes = new HashSet<Type>(selection);
+          newShownTypes.removeAll(shownAnnotationTypes);
+          for (Iterator<Type> iterator = newShownTypes.iterator(); 
iterator.hasNext();) {
+            Type type = iterator.next();
+            showAnnotationType(type, true);
           }
           
           // Repaint after annotations are changed
@@ -1125,6 +1121,10 @@ public final class AnnotationEditor exte
     mShowAnnotationsMenu.setSelectedType(type, isShown);
   }
 
+  public void setShownAnnotationTypes(Collection<Type> types) {
+    mShowAnnotationsMenu.setSelectedTypes(types);
+  }
+
   /**
    * @param type
    */


Reply via email to