performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-bulkeditor / src / main / java / eu / etaxonomy / taxeditor / annotatedlineeditor / AnnotatedLineDocumentProvider.java
index 42e33bfa4608fe99556023414be0a61787019a35..866938b236d703f2885bfbc27b32c3bfec3267b0 100644 (file)
-// $Id$\r
-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-package eu.etaxonomy.taxeditor.annotatedlineeditor;\r
-\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.runtime.Assert;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.jface.operation.IRunnableContext;\r
-import org.eclipse.jface.text.BadLocationException;\r
-import org.eclipse.jface.text.Document;\r
-import org.eclipse.jface.text.IDocument;\r
-import org.eclipse.jface.text.Position;\r
-import org.eclipse.jface.text.source.Annotation;\r
-import org.eclipse.jface.text.source.IAnnotationModel;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.texteditor.AbstractDocumentProvider;\r
-\r
-import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;\r
-import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;\r
-\r
-\r
-\r
-/**\r
- * Using an <code>IEditorPart</code>, creates a document where each line is associated\r
- * with an entity. Mapping between document positions and entities is stored in\r
- * <code>LineAnnotation</code>s in a <code>LineAnnotationModel</code>.  \r
- * <p>\r
- * Requires:\r
- * <ul>\r
- * <li>an <code>IEntityCreator</code> to create entities for new lines;\r
- * <li>an <code>IEntityPersistenceService</code> for interacting with the persistence layer; and\r
- * <li>an <code>ILineDisplayStrategy</code> for various visual manifestations of the domain object. \r
- * </ul> \r
- * \r
- * @author p.ciardelli\r
- * @created 25.06.2009\r
- * @version 1.0\r
- * @author n.hoffmann\r
- */\r
-public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {\r
-\r
-       private IDocument document;\r
-\r
-       private LineAnnotationModel annotationModel;\r
-\r
-       private IEntityCreator entityCreator;\r
-       \r
-       private ILineDisplayStrategy lineDisplayStrategy;\r
-\r
-       private IEditorInput input;\r
-       \r
-       public AnnotatedLineDocumentProvider(IEditorInput input){\r
-               this.input = input;\r
-       }\r
-       \r
-       @Override\r
-       public IAnnotationModel getAnnotationModel(Object element) {\r
-               if (element == input) {\r
-                       \r
-                       // Create model as necessary\r
-                       if (annotationModel == null) {\r
-                               annotationModel = new LineAnnotationModel(getLineDisplayStrategy(element));\r
-                               annotationModel.setEntityCreator(getEntityCreator(element));\r
-                       }\r
-                       return annotationModel;\r
-               }\r
-               \r
-               return null;\r
-       }\r
-       \r
-       @Override\r
-       protected IAnnotationModel createAnnotationModel(Object element)\r
-                       throws CoreException {\r
-               return getAnnotationModel(element);\r
-       }\r
-\r
-       @Override\r
-       public IDocument getDocument(Object element) {\r
-               return document;\r
-       }\r
-       \r
-       @Override\r
-       protected IDocument createDocument(Object element) throws CoreException {\r
-               \r
-               if (element instanceof IEditorInput) {\r
-                       IEditorInput input = (IEditorInput) element;\r
-                       document = new Document("");\r
-//                     IAnnotationModel model = getAnnotationModel(element);\r
-                                       \r
-                       List<?> entityList = getEntityList(element);\r
-                       \r
-                       if(entityList != null){\r
-                               for (Object entity : entityList) {\r
-                                       try {\r
-                                               createAnnotatedLine(input, entity);\r
-                                       } catch (BadLocationException e) {\r
-                                               BulkEditorUtil.error(getClass(), "Problems creating annotated line: ", e);\r
-                                       }\r
-                               }       \r
-                       }\r
-                       \r
-                       return document;\r
-               }\r
-               return null;\r
-       }\r
-\r
-       /**\r
-        * Creates an annotated line at the end of the document associated with the element\r
-        * @return \r
-        * @throws BadLocationException \r
-        */\r
-       protected LineAnnotation createAnnotatedLine(Object element, Object entity) throws BadLocationException {\r
-               \r
-               Document document = (Document) getDocument(element);\r
-               ILineDisplayStrategy lineDisplayStrategy = getLineDisplayStrategy(element);\r
-               \r
-               LineAnnotation annotation = new LineAnnotation(entity, lineDisplayStrategy);\r
-                               \r
-               // Is document zero length, or is last char in document line delimiter?\r
-               int docLength = document.getLength();\r
-               boolean useDelimiter = false;\r
-               if (docLength > 0) {\r
-                       if (docLength > 1 && !document.get(docLength - 2, 2).equals(document.getDefaultLineDelimiter())) {\r
-                               useDelimiter = true;\r
-                       }\r
-               }\r
-               if (useDelimiter) {\r
-                       document.replace(docLength, 0, document.getDefaultLineDelimiter());\r
-               }\r
-               \r
-               String text;\r
-               if (lineDisplayStrategy.isEntityCacheEmpty(entity)) {\r
-                       text = lineDisplayStrategy.getEmptyCacheMessage(entity);\r
-               } else {\r
-                       text = lineDisplayStrategy.getText(entity);\r
-               }\r
-               text += lineDisplayStrategy.getSupplementalText(entity);\r
-               docLength = document.getLength();\r
-               document.replace(docLength, 0, text);\r
-               \r
-               Position position = new Position(docLength, text.length());\r
-               \r
-               IAnnotationModel model = getAnnotationModel(element);\r
-               model.addAnnotation(annotation, position);\r
-                                                       \r
-//             lineDisplayStrategy.addDisplayListener(entity, \r
-//                                             new EntityListenerImpl((LineAnnotation) annotation, element));\r
-//                             \r
-               return annotation;\r
-       }\r
-       \r
-       \r
-       public void updateLineFromAnnotation(LineAnnotation annotation) {\r
-                               \r
-               IAnnotationModel model = getAnnotationModel(input);\r
-               IDocument document = getDocument(input);\r
-               ILineDisplayStrategy lineDisplay = getLineDisplayStrategy(input);\r
-               \r
-               Object entity = annotation.getEntity();\r
-               String text = "";\r
-               if (getLineDisplayStrategy(input).isEntityCacheEmpty(entity)) {\r
-                       text = lineDisplay.getEmptyCacheMessage(entity);\r
-               } else {\r
-                       text = lineDisplay.getText(entity);\r
-               }               \r
-               text += lineDisplay.getSupplementalText(entity);\r
-               \r
-               try {\r
-                       if (model.getPosition(annotation) == null) {\r
-                               return;\r
-                       }\r
-                       int offset = model.getPosition(annotation).getOffset();                 \r
-                       int line = document.getLineOfOffset(offset);\r
-                       int lineLength = document.getLineLength(document.getLineOfOffset(offset));\r
-                       if (document.getLineDelimiter(line) != null) {\r
-                               lineLength -= document.getLineDelimiter(line).length();\r
-                       }\r
-                       document.replace(offset, lineLength, text);\r
-               } catch (BadLocationException e) {\r
-                       BulkEditorUtil.error(getClass(), "Problem updating annotated line: " ,e);\r
-               }\r
-       }\r
-\r
-//     class EntityListenerImpl extends EntityListener {\r
-//\r
-//             private LineAnnotation lineAnnotation;\r
-//             private Object element;\r
-//\r
-//             EntityListenerImpl(LineAnnotation lineAnnotation, Object element) {\r
-//                     this.lineAnnotation = lineAnnotation;\r
-//                     this.element = element;\r
-//             }\r
-//             /* (non-Javadoc)\r
-//              * @see eu.etaxonomy.taxeditor.annotatedlineeditor.EntityDisplayListener#updateDisplay()\r
-//              */\r
-//             @Override\r
-//             protected void updateEntity() {\r
-//                     lineAnnotation.setDirty(true);\r
-//                     updateLineFromAnnotation(element, lineAnnotation);\r
-//             }\r
-//     }\r
-       \r
-       /**\r
-        * @param element \r
-        * @return\r
-        */\r
-       private List<?> getEntityList(Object element) {\r
-               if (element instanceof AbstractBulkEditorInput) {\r
-                       return ((AbstractBulkEditorInput)element).listEntities();\r
-               }\r
-               return null;\r
-       }\r
-\r
-       @Override\r
-       protected void doSaveDocument(IProgressMonitor monitor, Object element,\r
-                       IDocument document, boolean overwrite) throws CoreException {\r
-               if (element instanceof AbstractBulkEditorInput) {\r
-                       \r
-                       IEntityPersistenceService persistenceService = (AbstractBulkEditorInput) element;\r
-                       \r
-                       // Get new containers from annotation model\r
-                       LineAnnotationModel model = (LineAnnotationModel) getAnnotationModel(element);\r
-                       Iterator iterator = model.getAnnotationIterator();\r
-                       while (iterator.hasNext()) {\r
-                               Annotation annotation = (Annotation) iterator.next();\r
-                               if (annotation instanceof IEntityContainer<?>) {\r
-                                       IEntityContainer<?> container = (IEntityContainer<?>) annotation;\r
-                                       if (container.isMarkedAsNew() || container.isDirty()) {\r
-                                               persistenceService.save(container.getEntity()); // save\r
-                                               container.setDirty(false);\r
-                                               container.markAsNew(false);\r
-                                       }\r
-                               }\r
-                       }\r
-                       for (LineAnnotation annotation : model.getDeletedAnnotations()) {\r
-                               if (annotation.isMarkedAsNew()) {\r
-                                       continue;\r
-                               }\r
-                               if (annotation.isMarkedAsMerged()) {\r
-                                       persistenceService.merge(annotation.getEntity(), annotation.getMergeTarget()); //  merge                                        \r
-                               } else {\r
-                                       // TODO clarify w AM whether this needs to be executed on merged objects\r
-                                       persistenceService.delete(annotation.getEntity()); // delete\r
-                               }\r
-                       }\r
-                       model.clearDeletedAnnotations();\r
-               }\r
-       }\r
-\r
-       @Override\r
-       protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {\r
-               return null;\r
-       }\r
-       \r
-       @Override\r
-       public boolean isModifiable(Object element) {\r
-               return true;\r
-       }\r
-       \r
-       @Override\r
-       public boolean isReadOnly(Object element) {\r
-               // enables copy & paste\r
-               return false;\r
-       }\r
-\r
-       /**\r
-        * @param entityCreator\r
-        * @param element\r
-        */\r
-       public void setEntityCreator(IEntityCreator<?> entityCreator, Object element) {\r
-               if (element instanceof IEditorInput) {\r
-                       this.entityCreator = entityCreator;\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * @param element\r
-        * @return\r
-        */\r
-       public IEntityCreator<?> getEntityCreator(Object element) {\r
-               if (element instanceof IEditorInput) {\r
-//                     Assert.isNotNull(entityCreator, "No IEntityCreator set for this element.");\r
-                       return entityCreator;\r
-               }\r
-               return null;\r
-       }\r
-\r
-       /**\r
-        * @param lineDisplayStrategy\r
-        * @param input\r
-        */\r
-       public void setLineDisplayStrategy(\r
-                       ILineDisplayStrategy lineDisplayStrategy, Object element) {\r
-               if (element instanceof IEditorInput) {\r
-                       this.lineDisplayStrategy = lineDisplayStrategy;\r
-               }       \r
-       }\r
-       \r
-       /**\r
-        * @param element\r
-        * @return\r
-        */\r
-       protected ILineDisplayStrategy getLineDisplayStrategy(Object element) {\r
-               if (element instanceof IEditorInput) {\r
-                       Assert.isNotNull(lineDisplayStrategy, "No ILineDisplayStrategy set for this element.");\r
-                       return lineDisplayStrategy;\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       public void removeAnnotatedLine(Object entity){\r
-               LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotation(entity);\r
-               removeAnnotatedLine(annotation);\r
-       }\r
-       \r
-       /**\r
-        * @param editorInput\r
-        * @param lineno\r
-        */\r
-       public void removeAnnotatedLine(Object element, int lineno) {\r
-               LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotationAtLine(lineno, document);\r
-               removeAnnotatedLine(annotation);\r
-       }\r
-       \r
-       public void removeAnnotatedLine(LineAnnotation annotation) {\r
-               if (annotation != null) {\r
-                       Document document = (Document) getDocument(input);\r
-                       LineAnnotationModel model = (LineAnnotationModel) getAnnotationModel(input);\r
-                       \r
-                       Position position = model.getPosition(annotation);\r
-                       int offset = position.getOffset();\r
-                       int length = position.getLength();\r
-                       \r
-                       Object entity = annotation.getEntity();\r
-                       annotation.markAsDeleted();\r
-                       model.removeAnnotation(annotation);\r
-                       \r
-                       // Immediately followed by a delimiter?\r
-                       int annotationEnd = offset + length;\r
-                       try {\r
-                               if (document.getLength() > annotationEnd + 1 && document.get(annotationEnd, 2).equals(document.getDefaultLineDelimiter())) {\r
-                                       length += 2;\r
-                               }\r
-                       } catch (BadLocationException e1) {\r
-                               BulkEditorUtil.error(getClass(), "Problems removing annotated line", e1);\r
-                       }\r
-                       \r
-                       try {\r
-                               document.replace(offset, length, "");\r
-                       } catch (BadLocationException e) {\r
-                               BulkEditorUtil.error(getClass(), "Problems removing annotated line", e);\r
-                       }\r
-               }               \r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#changed(java.lang.Object)\r
-        */\r
-       @Override\r
-       public void changed(Object entity) {\r
-               LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotation(entity);\r
-               if(annotation != null){\r
-                       annotation.setDirty(true);\r
-                       updateLineFromAnnotation(annotation);\r
-               }\r
-       }\r
-}
\ No newline at end of file
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.annotatedlineeditor;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.texteditor.AbstractDocumentProvider;
+
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
+import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
+
+
+
+/**
+ * Using an <code>IEditorPart</code>, creates a document where each line is associated
+ * with an entity. Mapping between document positions and entities is stored in
+ * <code>LineAnnotation</code>s in a <code>LineAnnotationModel</code>.
+ * <p>
+ * Requires:
+ * <ul>
+ * <li>an <code>IEntityCreator</code> to create entities for new lines;
+ * <li>an <code>IEntityPersistenceService</code> for interacting with the persistence layer; and
+ * <li>an <code>ILineDisplayStrategy</code> for various visual manifestations of the domain object.
+ * </ul>
+ *
+ * @author p.ciardelli
+ * @author n.hoffmann
+ * @created 25.06.2009
+ * @version 1.0
+ */
+public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
+
+       private IDocument document;
+
+       private LineAnnotationModel annotationModel;
+
+       private IEntityCreator entityCreator;
+       
+       private ILineDisplayStrategy lineDisplayStrategy;
+
+       private IEditorInput input;
+       
+       /**
+        * <p>Constructor for AnnotatedLineDocumentProvider.</p>
+        *
+        * @param input a {@link org.eclipse.ui.IEditorInput} object.
+        */
+       public AnnotatedLineDocumentProvider(IEditorInput input){
+               this.input = input;
+       }
+       
+       /** {@inheritDoc} */
+       @Override
+       public IAnnotationModel getAnnotationModel(Object element) {
+               if (element == input) {
+                       
+                       // Create model as necessary
+                       if (annotationModel == null) {
+                               annotationModel = new LineAnnotationModel(getLineDisplayStrategy(element));
+                               annotationModel.setEntityCreator(getEntityCreator(element));
+                       }
+                       return annotationModel;
+               }
+               
+               return null;
+       }
+       
+       /** {@inheritDoc} */
+       @Override
+       protected IAnnotationModel createAnnotationModel(Object element)
+                       throws CoreException {
+               return getAnnotationModel(element);
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       public IDocument getDocument(Object element) {
+               return document;
+       }
+       
+       /** {@inheritDoc} */
+       @Override
+       protected IDocument createDocument(Object element) throws CoreException {
+               
+               if (element instanceof IEditorInput) {
+                       IEditorInput input = (IEditorInput) element;
+                       document = new Document("");
+//                     IAnnotationModel model = getAnnotationModel(element);
+                                       
+                       List<?> entityList = getEntityList(element);
+                       
+                       if(entityList != null){
+                               for (Object entity : entityList) {
+                                       try {
+                                               createAnnotatedLine(input, entity);
+                                       } catch (BadLocationException e) {
+                                               BulkEditorUtil.error(getClass(), "Problems creating annotated line: ", e);
+                                       }
+                               }       
+                       }
+                       
+                       return document;
+               }
+               return null;
+       }
+
+       /**
+        * Creates an annotated line at the end of the document associated with the element
+        *
+        * @throws org.eclipse.jface.text.BadLocationException if any.
+        * @param element a {@link java.lang.Object} object.
+        * @param entity a {@link java.lang.Object} object.
+        * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation} object.
+        */
+       protected LineAnnotation createAnnotatedLine(Object element, Object entity) throws BadLocationException {
+               
+               Document document = (Document) getDocument(element);
+               ILineDisplayStrategy lineDisplayStrategy = getLineDisplayStrategy(element);
+               
+               LineAnnotation annotation = new LineAnnotation(entity, lineDisplayStrategy);
+                               
+               // Is document zero length, or is last char in document line delimiter?
+               int docLength = document.getLength();
+               boolean useDelimiter = false;
+               if (docLength > 0) {
+                       if (docLength > 1 && !document.get(docLength - 2, 2).equals(document.getDefaultLineDelimiter())) {
+                               useDelimiter = true;
+                       }
+               }
+               if (useDelimiter) {
+                       document.replace(docLength, 0, document.getDefaultLineDelimiter());
+               }
+               
+               String text;
+               if (lineDisplayStrategy.isEntityCacheEmpty(entity)) {
+                       text = lineDisplayStrategy.getEmptyCacheMessage(entity);
+               } else {
+                       text = lineDisplayStrategy.getText(entity);
+               }
+               text += lineDisplayStrategy.getSupplementalText(entity);
+               docLength = document.getLength();
+               document.replace(docLength, 0, text);
+               
+               Position position = new Position(docLength, text.length());
+               
+               IAnnotationModel model = getAnnotationModel(element);
+               model.addAnnotation(annotation, position);
+                                                       
+//             lineDisplayStrategy.addDisplayListener(entity, 
+//                                             new EntityListenerImpl((LineAnnotation) annotation, element));
+//                             
+               return annotation;
+       }
+       
+       
+       /**
+        * <p>updateLineFromAnnotation</p>
+        *
+        * @param annotation a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation} object.
+        */
+       public void updateLineFromAnnotation(LineAnnotation annotation) {
+                               
+               IAnnotationModel model = getAnnotationModel(input);
+               IDocument document = getDocument(input);
+               ILineDisplayStrategy lineDisplay = getLineDisplayStrategy(input);
+               
+               Object entity = annotation.getEntity();
+               String text = "";
+               if (getLineDisplayStrategy(input).isEntityCacheEmpty(entity)) {
+                       text = lineDisplay.getEmptyCacheMessage(entity);
+               } else {
+                       text = lineDisplay.getText(entity);
+               }               
+               text += lineDisplay.getSupplementalText(entity);
+               
+               try {
+                       if (model.getPosition(annotation) == null) {
+                               return;
+                       }
+                       int offset = model.getPosition(annotation).getOffset();                 
+                       int line = document.getLineOfOffset(offset);
+                       int lineLength = document.getLineLength(document.getLineOfOffset(offset));
+                       if (document.getLineDelimiter(line) != null) {
+                               lineLength -= document.getLineDelimiter(line).length();
+                       }
+                       document.replace(offset, lineLength, text);
+               } catch (BadLocationException e) {
+                       BulkEditorUtil.error(getClass(), "Problem updating annotated line: " ,e);
+               }
+       }
+
+//     class EntityListenerImpl extends EntityListener {
+//
+//             private LineAnnotation lineAnnotation;
+//             private Object element;
+//
+//             EntityListenerImpl(LineAnnotation lineAnnotation, Object element) {
+//                     this.lineAnnotation = lineAnnotation;
+//                     this.element = element;
+//             }
+//             /* (non-Javadoc)
+//              * @see eu.etaxonomy.taxeditor.annotatedlineeditor.EntityDisplayListener#updateDisplay()
+//              */
+//             @Override
+//             protected void updateEntity() {
+//                     lineAnnotation.setDirty(true);
+//                     updateLineFromAnnotation(element, lineAnnotation);
+//             }
+//     }
+       
+       /**
+        * @param element 
+        * @return
+        */
+       private List<?> getEntityList(Object element) {
+               if (element instanceof AbstractBulkEditorInput) {
+                       return ((AbstractBulkEditorInput)element).listEntities();
+               }
+               return null;
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected void doSaveDocument(IProgressMonitor monitor, Object element,
+                       IDocument document, boolean overwrite) throws CoreException {
+               if (element instanceof AbstractBulkEditorInput) {
+                       
+                       IEntityPersistenceService persistenceService = (AbstractBulkEditorInput) element;
+                       
+                       // Get new containers from annotation model
+                       LineAnnotationModel model = (LineAnnotationModel) getAnnotationModel(element);
+                       Iterator iterator = model.getAnnotationIterator();
+                       while (iterator.hasNext()) {
+                               Annotation annotation = (Annotation) iterator.next();
+                               if (annotation instanceof IEntityContainer<?>) {
+                                       IEntityContainer<?> container = (IEntityContainer<?>) annotation;
+                                       if (container.isMarkedAsNew() || container.isDirty()) {
+                                               persistenceService.save(container.getEntity()); // save
+                                               container.setDirty(false);
+                                               container.markAsNew(false);
+                                       }
+                               }
+                       }
+                       for (LineAnnotation annotation : model.getDeletedAnnotations()) {
+                               if (annotation.isMarkedAsNew()) {
+                                       continue;
+                               }
+                               if (annotation.isMarkedAsMerged()) {
+                                       persistenceService.merge(annotation.getEntity(), annotation.getMergeTarget()); //  merge                                        
+                               } else {
+                                       // TODO clarify w AM whether this needs to be executed on merged objects
+                                       persistenceService.delete(annotation.getEntity()); // delete
+                               }
+                       }
+                       model.clearDeletedAnnotations();
+               }
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
+               return null;
+       }
+       
+       /** {@inheritDoc} */
+       @Override
+       public boolean isModifiable(Object element) {
+               return true;
+       }
+       
+       /** {@inheritDoc} */
+       @Override
+       public boolean isReadOnly(Object element) {
+               // enables copy & paste
+               return false;
+       }
+
+       /**
+        * <p>Setter for the field <code>entityCreator</code>.</p>
+        *
+        * @param entityCreator a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator} object.
+        * @param element a {@link java.lang.Object} object.
+        */
+       public void setEntityCreator(IEntityCreator<?> entityCreator, Object element) {
+               if (element instanceof IEditorInput) {
+                       this.entityCreator = entityCreator;
+               }
+       }
+       
+       /**
+        * <p>Getter for the field <code>entityCreator</code>.</p>
+        *
+        * @param element a {@link java.lang.Object} object.
+        * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator} object.
+        */
+       public IEntityCreator<?> getEntityCreator(Object element) {
+               if (element instanceof IEditorInput) {
+//                     Assert.isNotNull(entityCreator, "No IEntityCreator set for this element.");
+                       return entityCreator;
+               }
+               return null;
+       }
+
+       /**
+        * <p>Setter for the field <code>lineDisplayStrategy</code>.</p>
+        *
+        * @param lineDisplayStrategy a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy} object.
+        * @param element a {@link java.lang.Object} object.
+        */
+       public void setLineDisplayStrategy(
+                       ILineDisplayStrategy lineDisplayStrategy, Object element) {
+               if (element instanceof IEditorInput) {
+                       this.lineDisplayStrategy = lineDisplayStrategy;
+               }       
+       }
+       
+       /**
+        * <p>Getter for the field <code>lineDisplayStrategy</code>.</p>
+        *
+        * @param element a {@link java.lang.Object} object.
+        * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy} object.
+        */
+       protected ILineDisplayStrategy getLineDisplayStrategy(Object element) {
+               if (element instanceof IEditorInput) {
+                       Assert.isNotNull(lineDisplayStrategy, "No ILineDisplayStrategy set for this element.");
+                       return lineDisplayStrategy;
+               }
+               return null;
+       }
+       
+       /**
+        * <p>removeAnnotatedLine</p>
+        *
+        * @param entity a {@link java.lang.Object} object.
+        */
+       public void removeAnnotatedLine(Object entity){
+               LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotation(entity);
+               removeAnnotatedLine(annotation);
+       }
+       
+       /**
+        * <p>removeAnnotatedLine</p>
+        *
+        * @param lineno a int.
+        * @param element a {@link java.lang.Object} object.
+        */
+       public void removeAnnotatedLine(Object element, int lineno) {
+               LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotationAtLine(lineno, document);
+               removeAnnotatedLine(annotation);
+       }
+       
+       /**
+        * <p>removeAnnotatedLine</p>
+        *
+        * @param annotation a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation} object.
+        */
+       public void removeAnnotatedLine(LineAnnotation annotation) {
+               if (annotation != null) {
+                       Document document = (Document) getDocument(input);
+                       LineAnnotationModel model = (LineAnnotationModel) getAnnotationModel(input);
+                       
+                       Position position = model.getPosition(annotation);
+                       int offset = position.getOffset();
+                       int length = position.getLength();
+                       
+                       Object entity = annotation.getEntity();
+                       annotation.markAsDeleted();
+                       model.removeAnnotation(annotation);
+                       
+                       // Immediately followed by a delimiter?
+                       int annotationEnd = offset + length;
+                       try {
+                               if (document.getLength() > annotationEnd + 1 && document.get(annotationEnd, 2).equals(document.getDefaultLineDelimiter())) {
+                                       length += 2;
+                               }
+                       } catch (BadLocationException e1) {
+                               BulkEditorUtil.error(getClass(), "Problems removing annotated line", e1);
+                       }
+                       
+                       try {
+                               document.replace(offset, length, "");
+                       } catch (BadLocationException e) {
+                               BulkEditorUtil.error(getClass(), "Problems removing annotated line", e);
+                       }
+               }               
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#changed(java.lang.Object)
+        */
+       /** {@inheritDoc} */
+       @Override
+       public void changed(Object entity) {
+               LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotation(entity);
+               if(annotation != null){
+                       annotation.setDirty(true);
+                       updateLineFromAnnotation(annotation);
+               }
+       }
+}