// $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.
*/
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;
private LineAnnotationModel annotationModel;
private IEntityCreator<?> entityCreator;
-
+
private ILineDisplayStrategy lineDisplayStrategy;
private IEditorInput input;
-
+
/**
* <p>Constructor for AnnotatedLineDocumentProvider.</p>
*
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));
}
return annotationModel;
}
-
+
return null;
}
-
+
/** {@inheritDoc} */
@Override
protected IAnnotationModel createAnnotationModel(Object element)
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;
* @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 (useDelimiter) {
document.replace(docLength, 0, document.getDefaultLineDelimiter());
}
-
+
String text;
if (lineDisplayStrategy.isEntityCacheEmpty(entity)) {
text = lineDisplayStrategy.getEmptyCacheMessage(entity);
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) {
}
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;
}
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();
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
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>
*
ILineDisplayStrategy lineDisplayStrategy, Object element) {
if (element instanceof IEditorInput) {
this.lineDisplayStrategy = lineDisplayStrategy;
- }
+ }
}
-
+
/**
* <p>Getter for the field <code>lineDisplayStrategy</code>.</p>
*
}
return null;
}
-
+
/**
* <p>removeAnnotatedLine</p>
*
LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotation(entity);
removeAnnotatedLine(annotation);
}
-
+
/**
* <p>removeAnnotatedLine</p>
*
LineAnnotation annotation = (LineAnnotation) annotationModel.getAnnotationAtLine(lineno, document);
removeAnnotatedLine(annotation);
}
-
+
/**
* <p>removeAnnotatedLine</p>
*
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 {
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)
*/