Author: schor
Date: Fri Apr 15 15:24:05 2016
New Revision: 1739318

URL: http://svn.apache.org/viewvc?rev=1739318&view=rev
Log:
[UIMA-4863] fix infinite recursion when changing sofas/views

Modified:
    
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java

Modified: 
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java
URL: 
http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java?rev=1739318&r1=1739317&r2=1739318&view=diff
==============================================================================
--- 
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java
 (original)
+++ 
uima/uimaj/trunk/uimaj-tools/src/main/java/org/apache/uima/tools/viewer/CasAnnotationViewer.java
 Fri Apr 15 15:24:05 2016
@@ -212,6 +212,7 @@ public class CasAnnotationViewer extends
   private JPanel sofaSelectionPanel;
   @SuppressWarnings("rawtypes")
   private JComboBox sofaSelectionComboBox;
+  private boolean disableSofaSelectionComboBoxStateChangeAction = false;
 
   private JTabbedPane tabbedChoicePane;
   private JScrollPane typeCheckBoxScrollPane;
@@ -353,7 +354,10 @@ public class CasAnnotationViewer extends
     this.sofaSelectionComboBox.addItemListener(new ItemListener() {
       @Override
       public void itemStateChanged(ItemEvent e) {
-        if (e.getSource() != sofaSelectionComboBox || cas == null) {
+        if (disableSofaSelectionComboBoxStateChangeAction) { // UIMA-4863
+          return;
+        }
+        if (e.getSource() != sofaSelectionComboBox || cas == null || 
e.getStateChange() != ItemEvent.SELECTED ) {
           return;
         }
         // a new sofa was selected. Switch to that view and update display
@@ -1043,6 +1047,7 @@ public class CasAnnotationViewer extends
     if (this.sofaSelectionComboBox == null) {
       return;
     }
+    this.disableSofaSelectionComboBoxStateChangeAction = true; // UIMA-4863
     this.sofaSelectionComboBox.removeAllItems();
     boolean hasNonDefaultSofa = false;
     Feature sofaIdFeature = 
this.typeSystem.getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFAID);
@@ -1058,12 +1063,14 @@ public class CasAnnotationViewer extends
       } else {
         hasNonDefaultSofa = true;
       }
+      
       this.sofaSelectionComboBox.addItem(sofaId);
       // if this sofa matches the view passed to this method, select it
       if (this.cas.getView(sofa) == this.cas) {
         
this.sofaSelectionComboBox.setSelectedIndex(this.sofaSelectionComboBox.getItemCount()
 - 1);
       }
     }
+    this.disableSofaSelectionComboBoxStateChangeAction = false; // UIMA-4863
     if (this.sofaSelectionComboBox.getItemCount() == 0) {
       throw new RuntimeException("This CAS contains no document to view.");
     }


Reply via email to