You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/07/20 15:04:13 UTC

svn commit: r557989 - in /incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor: editor/AnnotationEditor.java editor/outline/AnnotationOutline.java ui/action/AnnotatorActionRunnable.java

Author: twgoetz
Date: Fri Jul 20 06:04:12 2007
New Revision: 557989

URL: http://svn.apache.org/viewvc?view=rev&rev=557989
Log:
Jira UIMA-504: apply UIMA-504-2.patch.

https://issues.apache.org/jira/browse/UIMA-504

Modified:
    incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
    incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/outline/AnnotationOutline.java
    incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java

Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?view=diff&rev=557989&r1=557988&r2=557989
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Fri Jul 20 06:04:12 2007
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -50,6 +50,7 @@
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.text.IPainter;
 import org.eclipse.jface.text.information.InformationPresenter;
 import org.eclipse.jface.text.source.Annotation;
 import org.eclipse.jface.text.source.AnnotationPainter;
@@ -91,11 +92,11 @@
 
 /**
  * An editor to annotate text.
- * 
- * TODO: 
- * add an action to increase left side of an annotation 
- * add an action to increase right side of an annotation 
- * add an action to decrease left side on an annotation 
+ *
+ * TODO:
+ * add an action to increase left side of an annotation
+ * add an action to increase right side of an annotation
+ * add an action to decrease left side on an annotation
  * add an action to decrease right side on an annotation
  */
 public final class AnnotationEditor extends StatusTextEditor implements ISelectionListener {
@@ -107,7 +108,7 @@
 
     /**
      * Initializes a new instance.
-     * 
+     *
      * @param textWidget
      */
     AnnotateAction(StyledText textWidget) {
@@ -206,22 +207,22 @@
   private class DocumentListener extends AbstractAnnotationDocumentListener {
     /**
      * Adds a collection of annotations.
-     * 
+     *
      * @param annotations
      */
     @Override
-    public void addedAnnotation(Collection<AnnotationFS> annotations) {    	
-    	mPainter.paint(AnnotationPainter.CONFIGURATION);
+    public void addedAnnotation(Collection<AnnotationFS> annotations) {
+    	mPainter.paint(IPainter.CONFIGURATION);
     }
 
     /**
      * Removes a collection of annotations.
-     * 
+     *
      * @param deletedAnnotations
      */
     @Override
     public void removedAnnotation(Collection<AnnotationFS> deletedAnnotations) {
-    	
+
       if (getSite().getPage().getActivePart() == AnnotationEditor.this) {
         mFeatureStructureSelectionProvider.clearSelection();
       } else {
@@ -229,35 +230,31 @@
       }
 
       highlight(0, 0); // TODO: only if removed annotation was selected
-      
-      mPainter.paint(AnnotationPainter.CONFIGURATION);
+
+      mPainter.paint(IPainter.CONFIGURATION);
     }
 
     /**
-     * 
+     *
      * @param annotations
      */
     @Override
     public void updatedAnnotation(Collection<AnnotationFS> annotations) {
-      
+
       removedAnnotation(annotations);
       addedAnnotation(annotations);
-      
+
       List<ModelFeatureStructure> structures = new LinkedList<ModelFeatureStructure>();
-      
+
       for (AnnotationFS annotation : annotations) {
         structures.add((new ModelFeatureStructure(getDocument(), annotation)));
       }
-      
+
       selectionChanged(getSite().getPage().getActivePart(), new StructuredSelection(structures));
     }
-    
+
     public void changed() {
-      Display.getDefault().syncExec(new Runnable() {
-        public void run() {
-          syncAnnotations();
-        }
-      });
+      syncAnnotations();
     }
   }
 
@@ -270,7 +267,7 @@
 
     /**
      * Initializes a new instance.
-     * 
+     *
      * @param parentType
      * @param typeSystem
      */
@@ -281,7 +278,7 @@
 
     /**
      * Fills the menu with type entries.
-     * 
+     *
      * @param menu
      * @param index
      */
@@ -329,7 +326,7 @@
   private class ModeMenu extends TypeMenu {
     /**
      * Initializes a new instance.
-     * 
+     *
      * @param type
      * @param typeSystem
      */
@@ -353,23 +350,23 @@
       });
     }
   }
-  
+
   /**
    * Creates the show annotations context submenu.
    */
   private class ShowAnnotationsMenu extends TypeMenu {
-	 
+
     private Collection<Type> mTypesToDisplay = new HashSet<Type>();
- 
+
     /**
      * Initializes a new instance.
-     * 
+     *
      * @param type
      * @param typeSystem
      */
     ShowAnnotationsMenu(EditorAnnotationStatus status, TypeSystem typeSystem) {
       super(typeSystem.getType(CAS.TYPE_NAME_ANNOTATION), typeSystem);
-      
+
       mTypesToDisplay.addAll(status.getDisplayAnnotations());
     }
 
@@ -396,19 +393,19 @@
           // TODO: only synchronize annotation which
           // must be removed/addeded
           syncAnnotations();
-          
+
           EditorAnnotationStatus status = mDocument.getProject().getEditorAnnotationStatus();
-          
+
           mDocument.getProject().setEditorAnnotationStatus(
                   new EditorAnnotationStatus(status.getMode(), getSelectedTypes()));
         }
       });
     }
-    
+
     Collection<Type> getSelectedTypes() {
     	return Collections.unmodifiableCollection(mTypesToDisplay);
     }
-    
+
     void setSelectedTypes(Collection<Type> types) {
       mTypesToDisplay = new HashSet<Type>();
       mTypesToDisplay.addAll(types);
@@ -477,7 +474,7 @@
     public void dragFinished(DragSourceEvent event) {
     }
   }
-  
+
   private Type mAnnotationMode;
 
   /**
@@ -507,7 +504,7 @@
   private ShowAnnotationsMenu mShowAnnotationsMenu;
 
 private DocumentListener mAnnotationSynchronizer;
-  
+
   /**
    * Creates an new AnnotationEditor object.
    */
@@ -517,7 +514,7 @@
 
   /**
    * Retrives annotation editor adapters.
-   * 
+   *
    * @param adapter
    * @return an adapter or null
    */
@@ -540,9 +537,9 @@
   protected ISourceViewer createSourceViewer(Composite parent,
           org.eclipse.jface.text.source.IVerticalRuler ruler, int styles) {
 	  SourceViewer sourceViewer = new SourceViewer(parent, ruler, styles);
-    
+
     sourceViewer.setEditable(false);
-    
+
     mPainter = new AnnotationPainter(sourceViewer, new IAnnotationAccess() {
 
 		public Object getType(Annotation annotation) {
@@ -556,24 +553,22 @@
 		public boolean isTemporary(Annotation annotation) {
 			return false;
 		}
-		
+
 	});
-	sourceViewer.addPainter(mPainter);
-    
-	// mPainter.modelChanged(mAnnotationModel); // realy nessesary ?
-	
+    sourceViewer.addPainter(mPainter);
+
     return sourceViewer;
   }
 
   /**
    * Configures the editor.
-   * 
+   *
    * @param parent
    */
   @Override
   public void createPartControl(Composite parent) {
     super.createPartControl(parent);
-    
+
     /*
      * this is a workaround for the quickdiff assertion if nothing was changed, how to do this
      * better ? is this the right way ?
@@ -630,15 +625,15 @@
     getSourceViewer().setEditable(false);
 
     getSite().setSelectionProvider(mFeatureStructureSelectionProvider);
-    
+
     if (mDocument != null) {
 	    mShowAnnotationsMenu = new ShowAnnotationsMenu(
-	    		mDocument.getProject().getEditorAnnotationStatus(), 
+	    		mDocument.getProject().getEditorAnnotationStatus(),
 	    		getDocument().getCAS().getTypeSystem());
-	    
+
 	    EditorAnnotationStatus status = mDocument.getProject().getEditorAnnotationStatus();
-      
-      
+
+
 	    setAnnotationMode(status.getMode());
     }
   }
@@ -650,7 +645,7 @@
 
   /**
    * Checks if the current instance is editable.
-   * 
+   *
    * @return false
    */
   @Override
@@ -666,9 +661,9 @@
 
     if (mDocument != null) {
     	// mAnnotationModel = getDocumentProvider().getAnnotationModel(input);
-    	
+
       mAnnotationSynchronizer = new DocumentListener();
-      
+
     	getDocument().addChangeListener(mAnnotationSynchronizer);
     }
   }
@@ -705,7 +700,7 @@
 
   /**
    * Returns the current <code>AnnotationDocument</code> of this editor.
-   * 
+   *
    * @return current <code>AnnotationDocument</code>
    */
   public AnnotationDocument getDocument() {
@@ -714,7 +709,7 @@
 
   /**
    * Returns the current annotation type.
-   * 
+   *
    * @return - current annotation type
    */
   public Type getAnnotationMode() {
@@ -723,7 +718,7 @@
 
   /**
    * Sets the new annotation type.
-   * 
+   *
    * @param type
    */
   protected void setAnnotationMode(Type type) {
@@ -732,7 +727,7 @@
     mAnnotationMode = type;
 
     highlight(0, 0);
-    
+
     setProjectEditorStatus();
 
     updateStatusLineModeItem();
@@ -755,21 +750,21 @@
 
   private void showAnnotationType(Type type) {
 		AnnotationStyle style = mDocument.getProject().getDotCorpus().getAnnotation(type);
-		mPainter.addDrawingStrategy(type.getName(), 
+		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(), 
+		mPainter.setAnnotationTypeColor(type.getName(), new Color(null, color.getRed(),
             color.getGreen(), color.getBlue()));
   }
-  
+
   /**
-   * 
+   *
    */
   private void syncAnnotations() {
 
 	mPainter.removeAllAnnotationTypes();
-	
+
 	for (Type displayType : mShowAnnotationsMenu.getSelectedTypes()) {
 		showAnnotationType(displayType);
 	}
@@ -779,7 +774,7 @@
     	showAnnotationType(mAnnotationMode);
     }
 
-	mPainter.paint(AnnotationPainter.CONFIGURATION);
+	mPainter.paint(IPainter.CONFIGURATION);
   }
 
   /**
@@ -791,7 +786,7 @@
 
   /**
    * Returns the selection.
-   * 
+   *
    * @return - the selection
    */
   public Point getSelection() {
@@ -800,7 +795,7 @@
 
   /**
    * Hightligts the given range in the editor.
-   * 
+   *
    * @param start
    * @param length
    */
@@ -829,9 +824,9 @@
 
   /**
    * Retrives the currently selected annotation.
-   * 
+   *
    * TODO: make this private ??? clients can use selections for this ...
-   * 
+   *
    * @return the selected anotation or null if none
    */
   public List<AnnotationFS> getSelectedAnnotations() {
@@ -870,7 +865,7 @@
   /**
    * Text is not editable, cause of the nature of the annotation editor. This does not mean, that
    * the annotations are not editable.
-   * 
+   *
    * @return false
    */
   @Override
@@ -880,7 +875,7 @@
 
   /**
    * Notifies the current instance about selection changes in the workbench.
-   * 
+   *
    * @param part
    * @param selection
    */
@@ -890,7 +885,7 @@
 
       // only process these selection if the annotations belong
       // to the current editor instance
-      if (getSite().getPage().getActiveEditor() == this && !annotations.isEmpty() 
+      if (getSite().getPage().getActiveEditor() == this && !annotations.isEmpty()
               && annotations.getFirst().getType() == mAnnotationMode) {
         highlight(annotations.getFirst().getBegin(), annotations.getLast().getEnd()
                 - annotations.getFirst().getBegin());
@@ -913,7 +908,7 @@
 
   private void setProjectEditorStatus() {
     // TODO: do not replace if equal ... check this
-    EditorAnnotationStatus status = new EditorAnnotationStatus(getAnnotationMode(), 
+    EditorAnnotationStatus status = new EditorAnnotationStatus(getAnnotationMode(),
             mShowAnnotationsMenu.getSelectedTypes());
     getDocument().getProject().setEditorAnnotationStatus(status);
   }
@@ -924,8 +919,8 @@
   @Override
   protected void createActions() {
     super.createActions();
-    
-    
+
+
     mFeatureStructureSelectionProvider = new FeatureStructureSelectionProvider();
     getSite().setSelectionProvider(mFeatureStructureSelectionProvider);
 
@@ -941,35 +936,35 @@
     // create delete action
     DeleteFeatureStructureAction deleteAnnotationAction = new DeleteFeatureStructureAction(
             getDocument());
-    
+
     getSite().getSelectionProvider().addSelectionChangedListener(deleteAnnotationAction);
-    
+
     deleteAnnotationAction.setActionDefinitionId(IWorkbenchActionDefinitionIds.DELETE);
 
     setAction(IWorkbenchActionDefinitionIds.DELETE, deleteAnnotationAction);
     setActionActivationCode(IWorkbenchActionDefinitionIds.DELETE, (char) 0, SWT.CR, SWT.NONE);
 
     // create show annotation context editing action
-    ShowAnnotationContextEditAction annotationContextEditAction = 
+    ShowAnnotationContextEditAction annotationContextEditAction =
             new ShowAnnotationContextEditAction();
 
     annotationContextEditAction.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICK_ASSIST);
 
     setAction(ITextEditorActionDefinitionIds.QUICK_ASSIST, annotationContextEditAction);
   }
-  
+
   @Override
   public void dispose() {
     // remove selection listener
     getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this);
-    
+
     IDocument document = getDocument();
-    
+
     if (document != null) {
       document.removeChangeListener(mAnnotationSynchronizer);
     }
   }
-  
+
   public void setDirty() {
     getDocument().fireDocumentChanged();
   }

Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/outline/AnnotationOutline.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/outline/AnnotationOutline.java?view=diff&rev=557989&r1=557988&r2=557989
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/outline/AnnotationOutline.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/editor/outline/AnnotationOutline.java Fri Jul 20 06:04:12 2007
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -85,8 +85,8 @@
    */
   protected class EditorListener implements IAnnotationEditorModifyListener {
     /**
-     * Called if the editor annoation mode was changed.
-     * 
+     * Called if the editor annotation mode was changed.
+     *
      * @param newMode
      */
     public void annotationModeChanged(Type newMode) {
@@ -104,7 +104,7 @@
 
     private AnnotationTreeNodeList mAnnotationNodeList;
 
-    private Map<AnnotationFS, AnnotationTreeNode> mParentNodeLookup = 
+    private Map<AnnotationFS, AnnotationTreeNode> mParentNodeLookup =
       new HashMap<AnnotationFS, AnnotationTreeNode>();
 
     /**
@@ -117,7 +117,7 @@
     /**
      * Gets called if the viewer input was changed. In this case, this only happens once if the
      * {@link AnnotationOutline} is initialized.
-     * 
+     *
      * @param viewer
      * @param oldInput
      * @param newInput
@@ -143,19 +143,14 @@
         // TODO:
         // create a recursive method to fill the parent lookup table
 
-        Display.getDefault().syncExec(new Runnable() {
-          public void run() {
-            mTableViewer.refresh();
-          }
-        });
+        mTableViewer.refresh();
       }
-
     }
 
     /**
      * Retrieves all children of the {@link NlpModel}. That are the {@link NlpProject}s and
      * {@link IProject}s.
-     * 
+     *
      * @param inputElement
      *          the {@link NlpModel}
      * @return the nlp-projects and non-nlp projects
@@ -170,7 +165,7 @@
 
     /**
      * Adds the added annotations to the viewer.
-     * 
+     *
      * @param annotations
      */
     @Override
@@ -197,7 +192,7 @@
 
     /**
      * Removes the removed annoations from the viewer.
-     * 
+     *
      * @param deletedAnnotations
      */
     @Override
@@ -214,7 +209,7 @@
         i++;
       }
 
-      
+
       Display.getDefault().syncExec(new Runnable() {
         public void run() {
           mTableViewer.remove(items);
@@ -224,7 +219,7 @@
 
     /**
      * Updates the given annoation in the viewer.
-     * 
+     *
      * @param annotations
      */
     @Override
@@ -259,7 +254,7 @@
     }
 
     public void changed() {
-      
+
       Collection<AnnotationFS> annotations = mEditor.getDocument().getAnnotations(
               mEditor.getAnnotationMode());
 
@@ -267,14 +262,14 @@
               .getDocument(), annotations) : null;
 
       mParentNodeLookup.clear();
-      
+
       Display.getDefault().syncExec(new Runnable() {
         public void run() {
           mTableViewer.refresh();
         }
       });
     }
-    
+
     public Object[] getChildren(Object parentElement) {
       AnnotationTreeNode node = (AnnotationTreeNode) parentElement;
 
@@ -319,7 +314,7 @@
 
   /**
    * Creates a new <code>AnnotationOutline</code> object.
-   * 
+   *
    * @param editor -
    *          the editor to bind
    */
@@ -335,7 +330,7 @@
 
   /**
    * Creates the outline table control.
-   * 
+   *
    * @param parent
    */
   @Override
@@ -388,7 +383,7 @@
 
   /**
    * Adds the actions to the tool bar.
-   * 
+   *
    * @param menuManager
    * @param toolBarManager
    * @param statusLineManager
@@ -419,7 +414,7 @@
     toolBarManager.add(lowerLeftAnnotationSideAction);
 
     // lower right annotation side action
-    LowerRightAnnotationSideAction lowerRightAnnotionSideAction = 
+    LowerRightAnnotationSideAction lowerRightAnnotionSideAction =
       new LowerRightAnnotationSideAction(mEditor.getDocument());
     lowerRightAnnotionSideAction.setText("Lowers the right annotation side");
     lowerRightAnnotionSideAction.setImageDescriptor(CasEditorPlugin
@@ -454,7 +449,7 @@
 
   /**
    * Retrives the control.
-   * 
+   *
    * @return the control
    */
   @Override
@@ -465,7 +460,7 @@
   /**
    * Adds the these actions to the global action handler: {@link DeleteFeatureStructureAction}
    * SelectAllAction
-   * 
+   *
    * @param actionBars
    */
   @Override

Modified: incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java?view=diff&rev=557989&r1=557988&r2=557989
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java (original)
+++ incubator/uima/sandbox/trunk/CasEditor/src/main/java/org/apache/uima/caseditor/ui/action/AnnotatorActionRunnable.java Fri Jul 20 06:04:12 2007
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -35,6 +35,7 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
@@ -49,7 +50,7 @@
 
   /**
    * Initializes a new instance.
-   * 
+   *
    * @param annotator
    * @param documents
    * @param shell
@@ -65,7 +66,7 @@
    */
   private AnnotationEditor[] getAnnotationEditors() {
 
-    ArrayList dirtyParts = new ArrayList();
+    ArrayList<AnnotationEditor> dirtyParts = new ArrayList<AnnotationEditor>();
     IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
     for (IWorkbenchWindow element : windows) {
       IWorkbenchPage pages[] = element.getPages();
@@ -81,7 +82,7 @@
       }
     }
 
-    return (AnnotationEditor[]) dirtyParts.toArray(new AnnotationEditor[dirtyParts.size()]);
+    return dirtyParts.toArray(new AnnotationEditor[dirtyParts.size()]);
   }
 
   /**
@@ -102,20 +103,20 @@
 
     monitor.subTask("Tagging, please stand by.");
 
-    Map<DocumentElement, AnnotationEditor> editorMap = 
+    Map<DocumentElement, AnnotationEditor> editorMap =
         new HashMap<DocumentElement, AnnotationEditor>();
 
     for (AnnotationEditor annotationEditor : getAnnotationEditors()) {
       editorMap.put(annotationEditor.getDocument().getDocumentElement(), annotationEditor);
     }
-    
+
     for (DocumentElement element : mDocuments) {
 
-      IDocument document = null;
+      final IDocument document;
       try {
         document = element.getDocument(); // retrieve the working copy
       } catch (CoreException e1) {
-        e1.printStackTrace();
+        throw new InvocationTargetException(e1);
       }
 
       try {
@@ -124,7 +125,14 @@
         throw new InvocationTargetException(e);
       }
 
-      document.changed();
+      // currently all updates are made from the ui thread, just post this call to change
+      // to the ui job queue
+
+      Display.getDefault().syncExec(new Runnable() {
+        public void run() {
+          document.changed();
+        }
+      });
 
       try {