You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2009/09/16 15:03:54 UTC

svn commit: r815751 - in /incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor: core/model/ core/model/dotcorpus/ editor/ editor/contextmenu/

Author: joern
Date: Wed Sep 16 13:03:53 2009
New Revision: 815751

URL: http://svn.apache.org/viewvc?rev=815751&view=rev
Log:
UIMA-1576 The AnnotationEditor does not remember the shown annotations when the Cas Editor is restarted

Modified:
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java
    incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java?rev=815751&r1=815750&r2=815751&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java Wed Sep 16 13:03:53 2009
@@ -190,7 +190,20 @@
   public AnnotationStyle getAnnotation(Type type) {
     return mDotCorpus.getAnnotation(type);
   }
-
+  
+  
+  public Collection<String> getShownTypes() {
+    return mDotCorpus.getShownTypes();
+  }
+  
+  public void removeShownType(String type) {
+    mDotCorpus.removeShownType(type);
+  }
+  
+  public void addShownType(String type) {
+    mDotCorpus.setShownType(type);
+  }
+  
   /**
    * Retrieves the config folder name.
    * 

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java?rev=815751&r1=815750&r2=815751&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpus.java Wed Sep 16 13:03:53 2009
@@ -64,6 +64,11 @@
   private HashMap<String, AnnotationStyle> mStyleMap = new HashMap<String, AnnotationStyle>();
 
   /**
+   * Contains names of types which are visible/shown.
+   */
+  private Set<String> shownTypes = new HashSet<String>();
+  
+  /**
    * Retrieves type system name parameter.
    * 
    * @return type system name parameter
@@ -156,9 +161,21 @@
    * @return - the annotation styles
    */
   public Collection<AnnotationStyle> getAnnotationStyles() {
-    return mStyleMap.values();
+    return Collections.unmodifiableCollection(mStyleMap.values());
   }
-
+  
+  public Collection<String> getShownTypes() {
+    return Collections.unmodifiableCollection(shownTypes);
+  }
+  
+  public void setShownType(String type) {
+    shownTypes.add(type);
+  }
+  
+  public void removeShownType(String type) {
+    shownTypes.remove(type);
+  }
+  
   /**
    * Adds an AnnotationStyle. TODO: move style stuff to nlp project
    * 

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java?rev=815751&r1=815750&r2=815751&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/dotcorpus/DotCorpusSerializer.java Wed Sep 16 13:03:53 2009
@@ -74,6 +74,13 @@
 
   private static final String EDITOR_LINE_LENGTH_ATTRIBUTE = "line-length-hint";
 
+  private static final String SHOWN_ELEMENT = "shown";
+  
+  private static final String SHOWN_TYPE_ATTRIBUTE = "type";
+  
+  private static final String SHOWN_IS_VISISBLE_ATTRIBUTE = "visible";
+  
+  
   /**
    * Creates a {@link DotCorpus} object from a given {@link InputStream}.
    * 
@@ -175,7 +182,18 @@
         int lineLengthHint = Integer.parseInt(lineLengthHintString);
 
         dotCorpus.setEditorLineLength(lineLengthHint);
-      } else {
+      } else if (SHOWN_ELEMENT.equals(corporaChildElement.getNodeName())) {
+        String type = corporaChildElement.getAttribute(SHOWN_TYPE_ATTRIBUTE);
+        
+        String isVisisbleString = corporaChildElement.getAttribute(SHOWN_IS_VISISBLE_ATTRIBUTE);
+        
+        boolean isVisible = Boolean.parseBoolean(isVisisbleString);
+        
+        if (isVisible) {
+          dotCorpus.setShownType(type); 
+        }
+      }
+      else {
         String message = "Unexpected element: " + corporaChildElement.getNodeName();
 
         IStatus s = new Status(IStatus.ERROR, CasEditorPlugin.ID, IStatus.OK, message, null);
@@ -228,6 +246,16 @@
         xmlSerHandler.endElement("", STYLE_ELEMENT, STYLE_ELEMENT);
       }
 
+      for (String type : dotCorpus.getShownTypes()) {
+        
+        AttributesImpl shownAttributes = new AttributesImpl();
+        shownAttributes.addAttribute("", "", SHOWN_TYPE_ATTRIBUTE, "", type);
+        shownAttributes.addAttribute("", "", SHOWN_IS_VISISBLE_ATTRIBUTE, "", "true");
+        
+        xmlSerHandler.startElement("", SHOWN_ELEMENT, SHOWN_ELEMENT, shownAttributes);
+        xmlSerHandler.endElement("", SHOWN_ELEMENT, SHOWN_ELEMENT);
+      }
+      
       if (dotCorpus.getTypeSystemFileName() != null) {
         AttributesImpl typeSystemFileAttributes = new AttributesImpl();
         typeSystemFileAttributes.addAttribute("", "", TYPESYTEM_FILE_ATTRIBUTE, "", dotCorpus

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=815751&r1=815750&r2=815751&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Wed Sep 16 13:03:53 2009
@@ -23,6 +23,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -520,6 +521,8 @@
 
   private CloseEditorListener closeEditorListener;
 
+  private Collection<Type> shownAnnotationTypes = new HashSet<Type>();
+  
   /**
    * Creates an new AnnotationEditor object.
    */
@@ -645,18 +648,34 @@
     if (getDocument() != null) {
       mShowAnnotationsMenu = new ShowAnnotationsMenu(
               getDocumentProvider().getEditorAnnotationStatus(getEditorInput()),
-              getDocument().getCAS().getTypeSystem());
+              getDocument().getCAS().getTypeSystem(), shownAnnotationTypes);
       mShowAnnotationsMenu.addListener(new IShowAnnotationsListener() {
 
         public void selectionChanged(Collection<Type> selection) {
-          // TODO: only synchronize annotation which
-          // must be removed/added
-          syncAnnotations();
-
-          // TODO:
-          // get and set editor annotation status must
-          // be added to document provider
-
+          
+          // 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);
+            getDocumentProvider().addShownType(getEditorInput(), addedAnnotationType);
+          }
+          else if (selection.size() < shownAnnotationTypes.size()) {
+            List<Type> clonedCollection = new ArrayList<Type>(shownAnnotationTypes);
+            clonedCollection.removeAll(selection);
+            
+            Type removedAnnotationType = clonedCollection.get(0);
+            showAnnotationType(removedAnnotationType, false);
+            getDocumentProvider().removeShownType(getEditorInput(), removedAnnotationType);
+          }
+          
+          // Repaint after annotations are changed
+          mPainter.paint(IPainter.CONFIGURATION);
+          
           EditorAnnotationStatus status =
                   getDocumentProvider().getEditorAnnotationStatus(getEditorInput());
 
@@ -695,29 +714,40 @@
     super.doSetInput(input);
 
     mDocument = (ICasDocument) getDocumentProvider().getDocument(input);
-    
+
     if (mDocument != null) {
 
       closeEditorListener = new CloseEditorListener(this);
-      ResourcesPlugin.getWorkspace().addResourceChangeListener(
-              closeEditorListener, IResourceChangeEvent.POST_CHANGE);
+      ResourcesPlugin.getWorkspace().addResourceChangeListener(closeEditorListener,
+              IResourceChangeEvent.POST_CHANGE);
+
+      IAnnotationModel annotationModel = getDocumentProvider().getAnnotationModel(input);
 
-     IAnnotationModel annotationModel = getDocumentProvider().getAnnotationModel(input);
+      // copy annotations into annotation model
+      final Iterator<AnnotationFS> mAnnotations = mDocument.getCAS().getAnnotationIndex()
+              .iterator();
+
+      while (mAnnotations.hasNext()) {
+        AnnotationFS annotationFS = mAnnotations.next();
+        annotationModel.addAnnotation(new EclipseAnnotationPeer(annotationFS), new Position(
+                annotationFS.getBegin(), annotationFS.getEnd() - annotationFS.getBegin()));
+      }
 
-     // copy annotations into annotation model
-	  final Iterator<AnnotationFS> mAnnotations =
-		  mDocument.getCAS().getAnnotationIndex().iterator();
- 
-	 while (mAnnotations.hasNext()) {
-		  AnnotationFS annotationFS = mAnnotations.next();
-		  annotationModel.addAnnotation(new EclipseAnnotationPeer(annotationFS),
-				  new Position(annotationFS.getBegin(), annotationFS.getEnd()
-		          - annotationFS.getBegin()));
-	 }
-     
       mAnnotationSynchronizer = new DocumentListener();
 
       getDocument().addChangeListener(mAnnotationSynchronizer);
+
+      Collection<String> shownTypes = getDocumentProvider().getShownTypes(input);
+
+      for (String shownType : shownTypes) {
+        
+        // Types can be deleted from the type system but still be marked 
+        // as shown in the .dotCorpus file, in that case the type
+        // name cannot be mapped to a type and should be ignored.
+        Type type = getDocument().getType(shownType);
+        if (type != null)
+          shownAnnotationTypes.add(type);
+      }
     }
   }
 
@@ -816,14 +846,28 @@
     }
   }
 
-  private void showAnnotationType(Type type) {
-    AnnotationStyle style = getDocumentProvider().getAnnotationStyle(getEditorInput(), type);
-    mPainter.addDrawingStrategy(type.getName(),
-            DrawingStyle.valueOf(style.getStyle().name()).getStrategy());
-    mPainter.addAnnotationType(type.getName(), type.getName());
-    java.awt.Color color = style.getColor();
-    mPainter.setAnnotationTypeColor(type.getName(), new Color(null, color.getRed(),
-            color.getGreen(), color.getBlue()));
+  /**
+   * Set the shown annotation status of a type.
+   * 
+   * @param type
+   * @param isVisible if true the type is shown, if false the type
+   * it not shown
+   */
+  private void showAnnotationType(Type type, boolean isVisible) {
+    if (isVisible) {
+      AnnotationStyle style = getDocumentProvider().getAnnotationStyle(getEditorInput(), type);
+      mPainter.addDrawingStrategy(type.getName(),
+              DrawingStyle.valueOf(style.getStyle().name()).getStrategy());
+      mPainter.addAnnotationType(type.getName(), type.getName());
+      java.awt.Color color = style.getColor();
+      mPainter.setAnnotationTypeColor(type.getName(), new Color(null, color.getRed(),
+              color.getGreen(), color.getBlue()));
+      shownAnnotationTypes.add(type);
+    }
+    else {
+      mPainter.removeAnnotationType(type.getName());
+      shownAnnotationTypes.remove(type);
+    }
   }
 
   /**
@@ -832,13 +876,13 @@
   public void syncAnnotations() {
 
     mPainter.removeAllAnnotationTypes();
-
+    
     for (Type displayType : mShowAnnotationsMenu.getSelectedTypes()) {
-      showAnnotationType(displayType);
+      showAnnotationType(displayType, true);
     }
 
     if (!mShowAnnotationsMenu.getSelectedTypes().contains(getAnnotationMode())) {
-      showAnnotationType(getAnnotationMode());
+      showAnnotationType(getAnnotationMode(), true);
     }
 
     mPainter.paint(IPainter.CONFIGURATION);

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java?rev=815751&r1=815750&r2=815751&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/CasDocumentProvider.java Wed Sep 16 13:03:53 2009
@@ -19,6 +19,7 @@
 
 package org.apache.uima.caseditor.editor;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -80,6 +81,12 @@
 
   protected abstract AnnotationStyle getAnnotationStyle(Object element, Type type);
 
+  protected abstract Collection<String> getShownTypes(Object element);
+  
+  protected abstract void addShownType(Object elemtn, Type type);
+  
+  protected abstract void removeShownType(Object element, Type type);
+  
   protected abstract EditorAnnotationStatus getEditorAnnotationStatus(Object element);
 
   protected abstract void setEditorAnnotationStatus(Object element,

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java?rev=815751&r1=815750&r2=815751&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java Wed Sep 16 13:03:53 2009
@@ -1,5 +1,7 @@
 package org.apache.uima.caseditor.editor;
 
+import java.util.Collection;
+
 import org.apache.uima.cas.Type;
 import org.apache.uima.caseditor.CasEditorPlugin;
 import org.apache.uima.caseditor.core.model.DocumentElement;
@@ -111,6 +113,39 @@
   }
 
   @Override
+  protected Collection<String> getShownTypes(Object element) {
+    INlpElement nlpElement = getNlpElement(element);
+
+    return nlpElement.getNlpProject().getDotCorpus().getShownTypes();
+  }
+  
+  @Override
+  protected void addShownType(Object element, Type type) {
+    INlpElement nlpElement = getNlpElement(element);
+    
+    nlpElement.getNlpProject().getDotCorpus().addShownType(type.getName());
+    
+    try {
+      nlpElement.getNlpProject().getDotCorpus().serialize();
+    } catch (CoreException e) {
+      CasEditorPlugin.log(e);
+    }
+  }
+  
+  @Override
+  protected void removeShownType(Object element, Type type) {
+    INlpElement nlpElement = getNlpElement(element);
+
+    nlpElement.getNlpProject().getDotCorpus().removeShownType(type.getName());
+    
+    try {
+      nlpElement.getNlpProject().getDotCorpus().serialize();
+    } catch (CoreException e) {
+      CasEditorPlugin.log(e);
+    }
+  }
+  
+  @Override
   protected EditorAnnotationStatus getEditorAnnotationStatus(Object element) {
     INlpElement nlpElement = getNlpElement(element);
 

Modified: incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java?rev=815751&r1=815750&r2=815751&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/contextmenu/ShowAnnotationsMenu.java Wed Sep 16 13:03:53 2009
@@ -62,11 +62,11 @@
 	 * @param typeSystem
 	 */
 	public ShowAnnotationsMenu(EditorAnnotationStatus status,
-			TypeSystem typeSystem) {
+			TypeSystem typeSystem, Collection<Type> shownTypes) {
 		super(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION), typeSystem);
 
-		for (String typeName : status.getDisplayAnnotations()) {
-			typesToDisplay.add(typeSystem.getType(typeName));
+		for (Type type : shownTypes) {
+			typesToDisplay.add(type);
 		}
 	}