+++ /dev/null
-/**
- * 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.e4;
-
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.IVerticalRuler;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.editors.text.TextEditor;
-import org.eclipse.ui.texteditor.IDocumentProvider;
-
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.api.service.IOccurrenceService;
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineDocumentProvider;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation;
-import eu.etaxonomy.taxeditor.annotatedlineeditor.LineSelectionViewer;
-import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
-import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-/**
- * A list-based editor, where each line in the editor's document is associated with a domain object.
- * <p>
- * Extending classes must set:
- * <ul>
- * <li>an {@link IEntityPersistenceService} for interacting with the persistence layer; and
- * <li>an {@link ILineDisplayStrategy} for various visual manifestations of the domain object.
- * </ul>
- *
- * @author p.ciardelli
- * @created 25.06.2009
- * @version 1.0
- */
-public class AnnotatedLineEditorE4 extends TextEditor implements IConversationEnabled, IPostOperationEnabled {
-
- protected ConversationHolder conversation;
-
- private IEntityPersistenceService persistenceService;
- protected ILineDisplayStrategy lineDisplayStrategy;
-
-
- /**
- * <p>Constructor for AnnotatedLineEditor.</p>
- *
- * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
- */
- public AnnotatedLineEditorE4(ConversationHolder conversation) {
- this.conversation = conversation;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.editors.text.TextEditor#doSetInput(org.eclipse.ui.IEditorInput)
- */
- /** {@inheritDoc} */
- @Override
- protected void doSetInput(IEditorInput input) throws CoreException {
-
- AnnotatedLineDocumentProvider provider = new AnnotatedLineDocumentProvider(input);
-
- provider.setLineDisplayStrategy(lineDisplayStrategy, input);
- setDocumentProvider(provider);
-
- super.doSetInput(input);
- }
-
- /**
- * <p>Setter for the field <code>persistenceService</code>.</p>
- *
- * @param persistenceService a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService} object.
- */
- protected void setPersistenceService(
- IEntityPersistenceService persistenceService) {
- this.persistenceService = persistenceService;
- }
-
- /**
- * <p>Getter for the field <code>persistenceService</code>.</p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityPersistenceService} object.
- */
- protected IEntityPersistenceService getPersistenceService() {
- return persistenceService;
- }
-
- /**
- * <p>Setter for the field <code>lineDisplayStrategy</code>.</p>
- *
- * @param lineDisplayStrategy a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.ILineDisplayStrategy} object.
- */
- protected void setLineDisplayStrategy(
- ILineDisplayStrategy lineDisplayStrategy) {
- this.lineDisplayStrategy = lineDisplayStrategy;
- }
-
- /** {@inheritDoc} */
- @Override
- protected ISourceViewer createSourceViewer(Composite parent,
- IVerticalRuler ruler, int styles) {
-
- fAnnotationAccess= getAnnotationAccess();
- fOverviewRuler= createOverviewRuler(getSharedColors());
- LineSelectionViewer viewer = new LineSelectionViewer(parent, ruler, getOverviewRuler(),
- isOverviewRulerVisible(), styles);
- // isOverviewRulerVisible(), styles | SWT.WRAP);
- getSourceViewerDecorationSupport(viewer);
-
- return viewer;
- }
-
- /**
- * Create an annotated line with an "empty" entity, i.e. using the editor
- * input's default entity type and a zero-length title cache.
- *
- * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation} object.
- */
- public LineAnnotation createAnnotatedLineNewObject() {
-
- // Create new object
-
- AnnotatedLineDocumentProvider documentProvider = (AnnotatedLineDocumentProvider) getDocumentProvider();
- IEntityCreator entityCreator = documentProvider.getEntityCreator(getEditorInput());
- Object entity = entityCreator.createEntity(null);
-
- LineAnnotation annotation = createAnnotatedLine(entity);
- if (annotation != null) {
- annotation.markAsNew(true);
- }
- return annotation;
- }
-
- /**
- * Create an annotated line, first creating an entity of type "key" - this key
- * must be recognized by the editor's entity creator.
- *
- * @param key a {@link java.lang.Object} object.
- * @param titleCache a {@link java.lang.String} object.
- * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation} object.
- */
- public LineAnnotation createAnnotatedLineNewObject(Object key, String titleCache) {
-
-
-
- // Create new object
- Object entity = ((AnnotatedLineDocumentProvider) getDocumentProvider()).
- getEntityCreator(getEditorInput()).createEntity(key, titleCache);
- // checks if the creator also saves the entity (in a different conversation), in which case
- // we need to bind back this editors conversation
- // we also need to reload the entity because the conversation used to
- // to create / save the entity may have been closed
- if(entity != null && ((AnnotatedLineDocumentProvider) getDocumentProvider()).getEntityCreator(getEditorInput()).savesEntity()) {
- getConversationHolder().bind();
- //FIXME: why do we use IOccurrenceService here? is this generic?
- //because this method is only invoked by the handler which is used in the
- //specimen bulk editor. This is unsafe and should be refactored!
- Object object = CdmStore.getService(IOccurrenceService.class).load(((CdmBase)entity).getUuid());
- entity = HibernateProxyHelper.deproxy(object);
- }
-
- if(entity == null) {
- return null;
- }
- LineAnnotation annotation = createAnnotatedLine(entity);
- if (annotation != null) {
- annotation.markAsNew(true);
- }
-
- return annotation;
-
- }
-
- @Override
- public boolean isDirty() {
- return super.isDirty();
- }
-
- /**
- * Creates an annotated line at the end of the document. The annotation contains the entity.
- *
- * @param entity a {@link java.lang.Object} object.
- * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation} object.
- */
- public LineAnnotation createAnnotatedLine(Object entity) {
-
- IEditorInput input = getEditorInput();
- this.conversation.close();
- this.conversation = ((AbstractBulkEditorInput)input).getConversation();
- AnnotatedLineDocumentProvider provider = (AnnotatedLineDocumentProvider) getDocumentProvider();
-
- LineAnnotation annotation = null;
- try {
- annotation = provider.createAnnotatedLine(input, entity);
-
- // Jump to new line
- IAnnotationModel model = provider.getAnnotationModel(input);
- if(model != null){
- int start= model.getPosition(annotation).getOffset();
- selectAndReveal(start, 0);
- }
-
- } catch (BadLocationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return annotation;
- }
-
- /**
- * <p>removeAnnotatedLine</p>
- *
- * @param lineno a int.
- */
- public void removeAnnotatedLine(int lineno) {
- ((AnnotatedLineDocumentProvider) getDocumentProvider()).removeAnnotatedLine(lineno);
- }
-
- /**
- * <p>removeAnnotatedLine</p>
- *
- * @param annotation a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotation} object.
- */
- public void removeAnnotatedLine(LineAnnotation annotation) {
- ((AnnotatedLineDocumentProvider) getDocumentProvider()).removeAnnotatedLine(annotation);
-
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSave(org.eclipse.core.runtime.IProgressMonitor)
- */
- /** {@inheritDoc} */
- @Override
- public void doSave(IProgressMonitor progressMonitor) {
- if (getConversationHolder() != null) {
- if( ! getConversationHolder().isBound()){
- getConversationHolder().bind();
- }
- super.doSave(progressMonitor);
- getConversationHolder().commit(true);
- } else {
- super.doSave(progressMonitor);
- }
- firePropertyChange(PROP_DIRTY);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.AbstractTextEditor#setFocus()
- */
- /** {@inheritDoc} */
- @Override
- public void setFocus() {
- super.setFocus();
- if (getConversationHolder() != null) {
- getConversationHolder().bind();
- }
- ((AbstractBulkEditorInput)getEditorInput()).bind();
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setFocus();
- // TODO pass focus to underlying widgets
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
- */
- /**
- * <p>getConversationHolder</p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
- */
- @Override
- public ConversationHolder getConversationHolder() {
- return conversation;
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
- */
- /** {@inheritDoc} */
- @Override
- public void update(CdmDataChangeMap changeEvents) {}
-
- /**
- * Refreshes text in all lines.
- */
- protected void refreshLineDisplay() {
- IDocumentProvider provider = getDocumentProvider();
- IEditorInput input = getEditorInput();
- IAnnotationModel model = provider.getAnnotationModel(input);
- Iterator iter = getDocumentProvider().getAnnotationModel(getEditorInput()).getAnnotationIterator();
- while (iter.hasNext()) {
- Object next = iter.next();
- if (next instanceof LineAnnotation) {
- LineAnnotation annotation = (LineAnnotation) next;
- ((AnnotatedLineDocumentProvider) getDocumentProvider()).
- updateLineFromAnnotation(annotation);
- }
- }
- }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
- */
- /** {@inheritDoc} */
- @Override
- public boolean postOperation(CdmBase objectAffectedByOperation) {
- refreshLineDisplay();
-
- return true;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.editors.text.TextEditor#dispose()
- */
- /** {@inheritDoc} */
- @Override
- public void dispose() {
- super.dispose();
- conversation.close();
- ((AbstractBulkEditorInput)getEditorInput()).dispose();
- }
-
- /**
- * <p>onComplete</p>
- *
- * @return a boolean.
- */
- @Override
- public boolean onComplete() {
- // TODO Auto-generated method stub
- return false;
- }
-
-
-}