-// $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 org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.jface.text.BadLocationException;\r
-import org.eclipse.jface.text.source.ISourceViewer;\r
-import org.eclipse.jface.text.source.IVerticalRuler;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.editors.text.TextEditor;\r
-\r
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;\r
-import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;\r
-import eu.etaxonomy.cdm.model.common.CdmBase;\r
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;\r
-import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;\r
-\r
-/**\r
- * A list-based editor, where each line in the editor's document is associated with a domain object.\r
- * <p>\r
- * Extending classes must set:\r
- * <ul>\r
- * <li>an <code>IEntityCreator</code> to create a new domain object when the user creates a new line;\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
- */\r
-public class AnnotatedLineEditor extends TextEditor implements IConversationEnabled, IPostOperationEnabled {\r
- \r
- private ConversationHolder conversation;\r
- \r
- private IEntityPersistenceService persistenceService;\r
- protected ILineDisplayStrategy lineDisplayStrategy;\r
- private IEntityCreatorService entityCreatorService;\r
- private IEntityCreator<?> entityCreator;\r
- \r
- \r
- public AnnotatedLineEditor(ConversationHolder conversation) {\r
- this.conversation = conversation;\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.editors.text.TextEditor#doSetInput(org.eclipse.ui.IEditorInput)\r
- */\r
- @Override\r
- protected void doSetInput(IEditorInput input) throws CoreException {\r
-\r
- AnnotatedLineDocumentProvider provider = createAnnotatedLineDocumentProvider();\r
- if (entityCreatorService != null) {\r
- provider.setEntityCreator(entityCreatorService.getEntityCreator(input), input);\r
- } else {\r
- provider.setEntityCreator(entityCreator, input);\r
- }\r
- provider.setLineDisplayStrategy(lineDisplayStrategy, input);\r
- setDocumentProvider(provider);\r
- \r
- super.doSetInput(input); \r
- }\r
- \r
- /**\r
- * @return\r
- */\r
- protected AnnotatedLineDocumentProvider createAnnotatedLineDocumentProvider() {\r
- return new AnnotatedLineDocumentProvider(getEditorInput());\r
- }\r
-\r
- /**\r
- * @param entityCreatorService\r
- */\r
- protected void setEntityCreatorService(IEntityCreatorService entityCreatorService) {\r
- this.entityCreatorService = entityCreatorService;\r
- }\r
- \r
- protected void setEntityCreator(IEntityCreator entityCreator) {\r
- this.entityCreator = entityCreator;\r
- }\r
- \r
- /**\r
- * @param bulkEditorPersistenceService\r
- */\r
- protected void setPersistenceService(\r
- IEntityPersistenceService persistenceService) {\r
- this.persistenceService = persistenceService; \r
- }\r
- \r
- protected IEntityPersistenceService getPersistenceService() {\r
- return persistenceService; \r
- }\r
-\r
- /**\r
- * @param bulkEditorLineDisplay\r
- */\r
- protected void setLineDisplayStrategy(\r
- ILineDisplayStrategy lineDisplayStrategy) {\r
- this.lineDisplayStrategy = lineDisplayStrategy; \r
- }\r
- \r
- @Override\r
- protected ISourceViewer createSourceViewer(Composite parent,\r
- IVerticalRuler ruler, int styles) {\r
- \r
- fAnnotationAccess= getAnnotationAccess();\r
- fOverviewRuler= createOverviewRuler(getSharedColors()); \r
- LineSelectionViewer viewer = new LineSelectionViewer(parent, ruler, getOverviewRuler(), \r
- isOverviewRulerVisible(), styles);\r
-// isOverviewRulerVisible(), styles | SWT.WRAP);\r
- getSourceViewerDecorationSupport(viewer);\r
- \r
- return viewer;\r
- }\r
- \r
- /**\r
- * Create an annotated line with an "empty" entity, i.e. using the editor\r
- * input's default entity type and a zero-length title cache. \r
- * \r
- * @return\r
- */\r
- public LineAnnotation createAnnotatedLineNewObject() {\r
- \r
- // Create new object\r
- Object entity = ((AnnotatedLineDocumentProvider) getDocumentProvider()).\r
- getEntityCreator(getEditorInput()).createEntity(null);\r
-\r
- LineAnnotation annotation = createAnnotatedLine(entity);\r
- if (annotation != null) {\r
- annotation.markAsNew(true);\r
- }\r
- return annotation;\r
- }\r
- \r
- /**\r
- * Create an annotated line, first creating an entity of type "key" - this key\r
- * must be recognized by the editor's entity creator.\r
- * \r
- * @param key\r
- * @param value\r
- * @return \r
- */\r
- public LineAnnotation createAnnotatedLineNewObject(Object key, String titleCache) {\r
- \r
- // Create new object\r
- Object entity = ((AnnotatedLineDocumentProvider) getDocumentProvider()).\r
- getEntityCreator(getEditorInput()).createEntity(key, titleCache);\r
-\r
- LineAnnotation annotation = createAnnotatedLine(entity);\r
- if (annotation != null) {\r
- annotation.markAsNew(true);\r
- }\r
- return annotation;\r
- \r
- }\r
- \r
- /**\r
- * Creates an annotated line at the end of the document. The annotation contains the entity.\r
- * \r
- * @param entity\r
- * @return\r
- */\r
- public LineAnnotation createAnnotatedLine(Object entity) {\r
- \r
- IEditorInput input = getEditorInput();\r
- AnnotatedLineDocumentProvider provider = (AnnotatedLineDocumentProvider) getDocumentProvider();\r
- \r
- LineAnnotation annotation = null;\r
- try {\r
- annotation = provider.createAnnotatedLine(input, entity);\r
-\r
- // Jump to new line\r
- int start= provider.getAnnotationModel(input).getPosition(annotation).getOffset();\r
- selectAndReveal(start, 0);\r
- \r
- } catch (BadLocationException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } \r
- return annotation;\r
- }\r
- \r
- /**\r
- * @param line\r
- */\r
- public void removeAnnotatedLine(int lineno) {\r
- ((AnnotatedLineDocumentProvider) getDocumentProvider()).removeAnnotatedLine(lineno);\r
- }\r
-\r
- /**\r
- * @param annotation\r
- */\r
- public void removeAnnotatedLine(LineAnnotation annotation) {\r
- ((AnnotatedLineDocumentProvider) getDocumentProvider()).removeAnnotatedLine(annotation);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.texteditor.AbstractTextEditor#doSave(org.eclipse.core.runtime.IProgressMonitor)\r
- */\r
- @Override\r
- public void doSave(IProgressMonitor progressMonitor) {\r
- if (getConversationHolder() != null) {\r
- if( ! getConversationHolder().isBound()){\r
- getConversationHolder().bind();\r
- }\r
- super.doSave(progressMonitor);\r
- getConversationHolder().commit(true);\r
- } else {\r
- super.doSave(progressMonitor); \r
- }\r
- firePropertyChange(PROP_DIRTY);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.texteditor.AbstractTextEditor#setFocus()\r
- */\r
- @Override\r
- public void setFocus() {\r
- super.setFocus();\r
- if (getConversationHolder() != null) {\r
- getConversationHolder().bind();\r
- }\r
- // TODO pass focus to underlying widgets\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()\r
- */\r
- public ConversationHolder getConversationHolder() {\r
- return conversation;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)\r
- */\r
- public void update(CdmDataChangeMap changeEvents) {}\r
-\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)\r
- */\r
- public boolean postOperation(CdmBase objectAffectedByOperation) {\r
- return false;\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.eclipse.ui.editors.text.TextEditor#dispose()\r
- */\r
- @Override\r
- public void dispose() {\r
- super.dispose();\r
- conversation.close();\r
- }\r
-\r
- public boolean onComplete() {\r
- // TODO Auto-generated method stub\r
- return false;\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 org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.BadLocationException;
+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.editors.text.TextEditor;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled;
+
+/**
+ * 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 <code>IEntityCreator</code> to create a new domain object when the user creates a new line;
+ * <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
+ * @created 25.06.2009
+ * @version 1.0
+ */
+public class AnnotatedLineEditor extends TextEditor implements IConversationEnabled, IPostOperationEnabled {
+
+ private ConversationHolder conversation;
+
+ private IEntityPersistenceService persistenceService;
+ protected ILineDisplayStrategy lineDisplayStrategy;
+ private IEntityCreatorService entityCreatorService;
+ private IEntityCreator<?> entityCreator;
+
+
+ /**
+ * <p>Constructor for AnnotatedLineEditor.</p>
+ *
+ * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ */
+ public AnnotatedLineEditor(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 = createAnnotatedLineDocumentProvider();
+ if (entityCreatorService != null) {
+ provider.setEntityCreator(entityCreatorService.getEntityCreator(input), input);
+ } else {
+ provider.setEntityCreator(entityCreator, input);
+ }
+ provider.setLineDisplayStrategy(lineDisplayStrategy, input);
+ setDocumentProvider(provider);
+
+ super.doSetInput(input);
+ }
+
+ /**
+ * <p>createAnnotatedLineDocumentProvider</p>
+ *
+ * @return a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineDocumentProvider} object.
+ */
+ protected AnnotatedLineDocumentProvider createAnnotatedLineDocumentProvider() {
+ return new AnnotatedLineDocumentProvider(getEditorInput());
+ }
+
+ /**
+ * <p>Setter for the field <code>entityCreatorService</code>.</p>
+ *
+ * @param entityCreatorService a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreatorService} object.
+ */
+ protected void setEntityCreatorService(IEntityCreatorService entityCreatorService) {
+ this.entityCreatorService = entityCreatorService;
+ }
+
+ /**
+ * <p>Setter for the field <code>entityCreator</code>.</p>
+ *
+ * @param entityCreator a {@link eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator} object.
+ */
+ protected void setEntityCreator(IEntityCreator entityCreator) {
+ this.entityCreator = entityCreator;
+ }
+
+ /**
+ * <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
+ Object entity = ((AnnotatedLineDocumentProvider) getDocumentProvider()).
+ getEntityCreator(getEditorInput()).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);
+
+ LineAnnotation annotation = createAnnotatedLine(entity);
+ if (annotation != null) {
+ annotation.markAsNew(true);
+ }
+ return annotation;
+
+ }
+
+ /**
+ * 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();
+ AnnotatedLineDocumentProvider provider = (AnnotatedLineDocumentProvider) getDocumentProvider();
+
+ LineAnnotation annotation = null;
+ try {
+ annotation = provider.createAnnotatedLine(input, entity);
+
+ // Jump to new line
+ int start= provider.getAnnotationModel(input).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();
+ }
+ // 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.
+ */
+ public ConversationHolder getConversationHolder() {
+ return conversation;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+ */
+ /** {@inheritDoc} */
+ public void update(CdmDataChangeMap changeEvents) {}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ /** {@inheritDoc} */
+ public boolean postOperation(CdmBase objectAffectedByOperation) {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.editors.text.TextEditor#dispose()
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void dispose() {
+ super.dispose();
+ conversation.close();
+ }
+
+ /**
+ * <p>onComplete</p>
+ *
+ * @return a boolean.
+ */
+ public boolean onComplete() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+}