- added new DataImportEditor for displaying/editing results of specimen search wizard
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / annotatedlineeditor / AnnotatedLineDocumentProvider.java
index 2bd124f21bf3a1739cc4428459b651ba34630e63..5261d35d7ec83f5a681224b2ced9d55549645d30 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -25,8 +25,9 @@ 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;
+import eu.etaxonomy.taxeditor.dataimport.SpecimenEditorInput;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 
 
 
@@ -54,11 +55,11 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
        private LineAnnotationModel annotationModel;
 
        private IEntityCreator<?> entityCreator;
-       
+
        private ILineDisplayStrategy lineDisplayStrategy;
 
        private IEditorInput input;
-       
+
        /**
         * <p>Constructor for AnnotatedLineDocumentProvider.</p>
         *
@@ -67,12 +68,12 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
        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));
@@ -80,10 +81,10 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                        }
                        return annotationModel;
                }
-               
+
                return null;
        }
-       
+
        /** {@inheritDoc} */
        @Override
        protected IAnnotationModel createAnnotationModel(Object element)
@@ -96,28 +97,28 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
        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);
+                                               AbstractUtility.error(getClass(), "Problems creating annotated line: ", e);
                                        }
-                               }       
+                               }
                        }
-                       
+
                        return document;
                }
                return null;
@@ -132,12 +133,12 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
         * @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;
@@ -149,7 +150,7 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                if (useDelimiter) {
                        document.replace(docLength, 0, document.getDefaultLineDelimiter());
                }
-               
+
                String text;
                if (lineDisplayStrategy.isEntityCacheEmpty(entity)) {
                        text = lineDisplayStrategy.getEmptyCacheMessage(entity);
@@ -159,46 +160,46 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                text += lineDisplayStrategy.getSupplementalText(entity);
                docLength = document.getLength();
                document.replace(docLength, 0, text);
-               
+
                Position position = new Position(docLength, text.length());
-               
+
                IAnnotationModel model = getAnnotationModel(element);
                if(model != null){
                        model.addAnnotation(annotation, position);
                }
-                                                       
-//             lineDisplayStrategy.addDisplayListener(entity, 
+
+//             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 offset = model.getPosition(annotation).getOffset();
                        int line = document.getLineOfOffset(offset);
                        int lineLength = document.getLineLength(document.getLineOfOffset(offset));
                        if (document.getLineDelimiter(line) != null) {
@@ -206,18 +207,21 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                        }
                        document.replace(offset, lineLength, text);
                } catch (BadLocationException e) {
-                       BulkEditorUtil.error(getClass(), "Problem updating annotated line: " ,e);
+                       AbstractUtility.error(getClass(), "Problem updating annotated line: " ,e);
                }
        }
-       
+
        /**
-        * @param element 
+        * @param element
         * @return
         */
        private List<?> getEntityList(Object element) {
                if (element instanceof AbstractBulkEditorInput) {
                        return ((AbstractBulkEditorInput)element).getModel();
                }
+               else if(element instanceof SpecimenEditorInput){
+                   return ((SpecimenEditorInput) element).getResults();
+               }
                return null;
        }
 
@@ -226,9 +230,9 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
        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();
@@ -248,7 +252,7 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                                        continue;
                                }
                                if (annotation.isMarkedAsMerged()) {
-                                       persistenceService.merge(annotation.getEntity(), annotation.getMergeTarget()); //  merge                                        
+                                       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
@@ -263,20 +267,20 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
        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>Getter for the field <code>entityCreator</code>.</p>
         *
@@ -300,9 +304,9 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                        ILineDisplayStrategy lineDisplayStrategy, Object element) {
                if (element instanceof IEditorInput) {
                        this.lineDisplayStrategy = lineDisplayStrategy;
-               }       
+               }
        }
-       
+
        /**
         * <p>Getter for the field <code>lineDisplayStrategy</code>.</p>
         *
@@ -316,7 +320,7 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                }
                return null;
        }
-       
+
        /**
         * <p>removeAnnotatedLine</p>
         *
@@ -326,7 +330,7 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotation(entity);
                removeAnnotatedLine(annotation);
        }
-       
+
        /**
         * <p>removeAnnotatedLine</p>
         *
@@ -337,7 +341,7 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotationAtLine(lineno, document);
                removeAnnotatedLine(annotation);
        }
-       
+
        /**
         * <p>removeAnnotatedLine</p>
         *
@@ -347,15 +351,15 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                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 {
@@ -363,17 +367,17 @@ public class AnnotatedLineDocumentProvider extends AbstractDocumentProvider {
                                        length += 2;
                                }
                        } catch (BadLocationException e1) {
-                               BulkEditorUtil.error(getClass(), "Problems removing annotated line", e1);
+                               AbstractUtility.error(getClass(), "Problems removing annotated line", e1);
                        }
-                       
+
                        try {
                                document.replace(offset, length, "");
                        } catch (BadLocationException e) {
-                               BulkEditorUtil.error(getClass(), "Problems removing annotated line", e);
+                               AbstractUtility.error(getClass(), "Problems removing annotated line", e);
                        }
-               }               
+               }
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#changed(java.lang.Object)
         */