commit c8c645a24b09f9a3825298d3aab3c8c279159f59
Author: Patric Plitzner <p.plitzner@bgbm.org>
Date:   Tue Nov 26 13:54:42 2013 +0000

     - added "isDirty" functionality to DerivateView to allow saving of edited derivates

diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/CreateDerivateContextMenu.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/CreateDerivateContextMenu.java
index 9a8bd5708..d745f8067 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/CreateDerivateContextMenu.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/CreateDerivateContextMenu.java
@@ -2,7 +2,6 @@ package eu.etaxonomy.taxeditor.editor.view.derivate;
 
 import java.util.UUID;
 
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.action.ContributionItem;
 import org.eclipse.jface.action.IContributionItem;
 import org.eclipse.jface.viewers.ISelection;
@@ -73,7 +72,6 @@ public class CreateDerivateContextMenu extends CompoundContributionItem {
                                         if(activePart instanceof DerivateView){
                                             DerivateView derivateView = (DerivateView)activePart;
                                             derivateView.viewer.refresh();
-                                            derivateView.doSave(new NullProgressMonitor());
                                         }
                                     }
 
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java
index 992f99b15..ba12717ff 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java
@@ -5,7 +5,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
 import org.eclipse.jface.viewers.Viewer;
 
@@ -28,8 +27,8 @@ public class DerivateContentProvider implements ITreeContentProvider {
 
 	@Override
 	public Object[] getElements(Object inputElement) {
-	    if(inputElement instanceof IStructuredSelection){
-	        inputElement = ((IStructuredSelection) inputElement).getFirstElement();
+	    if(inputElement instanceof DerivateViewEditorInput){
+	        inputElement = ((DerivateViewEditorInput) inputElement).getDerivate();
 	    }
 	    // return the parent FieldUnit if element is a DerivedUnit
 	    if(inputElement instanceof DerivedUnit){
@@ -53,8 +52,8 @@ public class DerivateContentProvider implements ITreeContentProvider {
 
 	@Override
 	public Object[] getChildren(Object parentElement) {
-	    if(parentElement instanceof IStructuredSelection){
-	        parentElement = ((IStructuredSelection) parentElement).getFirstElement();
+        if(parentElement instanceof DerivateViewEditorInput){
+            parentElement = ((DerivateViewEditorInput) parentElement).getDerivate();
 	    }
 	    if(parentElement instanceof SpecimenOrObservationBase){
 	        return getDerivates((SpecimenOrObservationBase) parentElement).toArray();
@@ -64,8 +63,8 @@ public class DerivateContentProvider implements ITreeContentProvider {
 
 	@Override
 	public Object getParent(Object element) {
-	    if(element instanceof IStructuredSelection){
-	        element = ((IStructuredSelection) element).getFirstElement();
+        if(element instanceof DerivateViewEditorInput){
+            element = ((DerivateViewEditorInput) element).getDerivate();
 	    }
 	    if(element instanceof DerivedUnit){
 	        DerivedUnit derivedUnit = (DerivedUnit)element;
@@ -76,8 +75,8 @@ public class DerivateContentProvider implements ITreeContentProvider {
 
 	@Override
 	public boolean hasChildren(Object element) {
-	    if(element instanceof IStructuredSelection){
-	        element = ((IStructuredSelection) element).getFirstElement();
+        if(element instanceof DerivateViewEditorInput){
+            element = ((DerivateViewEditorInput) element).getDerivate();
 	    }
 	    if(element instanceof SpecimenOrObservationBase){
 	        SpecimenOrObservationBase specimenOrObservation = (SpecimenOrObservationBase)element;
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
index ba4baf6e9..ba20edf10 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
@@ -9,28 +9,38 @@ import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IEditorSite;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.part.EditorPart;
 
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
  * Displays the derivate hierarchy of all derivates belonging to a taxon.
  *
  */
-public class DerivateView extends EditorPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
+public class DerivateView extends EditorPart implements IDirtyMarkableSelectionProvider, IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData {
 
 	/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.desc"{trunked}</code> */
 	public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView";
 
+	private ConversationHolder conversation;
+
 	protected TreeViewer viewer;
 
 	private SpecimenOrObservationBase<DerivedUnitFacadeCacheStrategy> derivate;
 
+    private boolean isDirty;
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
      */
@@ -54,7 +64,7 @@ public class DerivateView extends EditorPart implements IPartContentHasDetails,
         control.setMenu(menu);
 
 
-        viewer.setInput(derivate);
+        viewer.setInput(getEditorInput());
     }
 
     /* (non-Javadoc)
@@ -62,8 +72,20 @@ public class DerivateView extends EditorPart implements IPartContentHasDetails,
      */
     @Override
     public void doSave(IProgressMonitor monitor) {
-        // TODO Auto-generated method stub
+        monitor.beginTask("Saving Derivates", 3);
+        if (!conversation.isBound()) {
+            conversation.bind();
+        }
+        monitor.worked(1);
 
+        // commit the conversation and start a new transaction immediately
+        conversation.commit(true);
+        monitor.worked(1);
+
+        this.setDirty(false);
+        monitor.worked(1);
+        monitor.done();
+        firePropertyChange(PROP_DIRTY);
     }
 
     /* (non-Javadoc)
@@ -89,6 +111,7 @@ public class DerivateView extends EditorPart implements IPartContentHasDetails,
      */
     @Override
     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
+        conversation = CdmStore.createConversation();
         setSite(site);
         setInput(input);
         if(input instanceof DerivateViewEditorInput){
@@ -104,8 +127,14 @@ public class DerivateView extends EditorPart implements IPartContentHasDetails,
      */
     @Override
     public boolean isDirty() {
-        // TODO Auto-generated method stub
-        return false;
+        return isDirty;
+    }
+
+    /**
+     * @param isDirty the isDirty to set
+     */
+    public void setDirty(boolean isDirty) {
+        this.isDirty = isDirty;
     }
 
     /* (non-Javadoc)
@@ -127,4 +156,31 @@ public class DerivateView extends EditorPart implements IPartContentHasDetails,
 
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+     */
+    @Override
+    public void update(CdmDataChangeMap changeEvents) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
+     */
+    @Override
+    public ConversationHolder getConversationHolder() {
+        return conversation;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#changed(java.lang.Object)
+     */
+    @Override
+    public void changed(Object element) {
+        firePropertyChange(IEditorPart.PROP_DIRTY);
+        viewer.setInput(getEditorInput());
+        setDirty(true);
+    }
+
 }
