Fixes #2357
authorn.hoffmann <n.hoffmann@localhost>
Thu, 5 May 2011 12:19:43 +0000 (12:19 +0000)
committern.hoffmann <n.hoffmann@localhost>
Thu, 5 May 2011 12:19:43 +0000 (12:19 +0000)
.gitattributes
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractGraphKeyEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditorDataChangeBehaviour.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyGraphEditor.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyListEditor.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPartDataChangeBehavior.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key/PolytomousKeyDetailElement.java

index d48e698f8f182c9c77852648041e94581cbdadba..689e1e17657d17890f336cbcd127e410b5ad0460 100644 (file)
@@ -344,6 +344,7 @@ eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/intern
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractGraphKeyEditor.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/AbstractIdentificationEditorInput.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditor.java -text
+eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditorDataChangeBehaviour.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/handler/ApplyLayoutHandler.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/IPolytomousKeyEditorPage.java -text
 eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyContentProvider.java -text
@@ -516,6 +517,7 @@ eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigatio
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyContentProvider.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyLabelProvider.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java -text
+eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPartDataChangeBehavior.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/DeleteHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/handler/EditHandler.java -text
 eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/operation/DeleteOperation.java -text
index 81f8b1be6aa0a0ed2e891d347e160c8451c64f25..cb9629bfd9cac8a49ec8ce1e066b0346619b291b 100644 (file)
@@ -51,7 +51,7 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
 
        private CdmFormFactory formFactory;
        private Composite container;
-       private GraphViewer graphViewer;
+       protected GraphViewer viewer;
 
        private LayoutAlgorithm layoutAlgoritm;
        private ZoomContributionViewItem zoomContributionViewItem;
@@ -69,7 +69,7 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
        public void doSave(IProgressMonitor monitor) {
                getConversationHolder().commit(true);
                setDirty(false);
-               graphViewer.refresh();
+               viewer.refresh();
        }
 
        /*
@@ -128,21 +128,21 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
                container = formFactory.createComposite(parent);
 
                container.setLayout(new FillLayout());
-               graphViewer = new GraphViewer(container, SWT.NONE);
-               getSite().setSelectionProvider(graphViewer);
+               viewer = new GraphViewer(container, SWT.NONE);
+               getSite().setSelectionProvider(viewer);
 
-               graphViewer.setContentProvider(getContentProvider());
-               graphViewer.setLabelProvider(getLabelProvider());
+               viewer.setContentProvider(getContentProvider());
+               viewer.setLabelProvider(getLabelProvider());
 
-               graphViewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
+               viewer.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED);
 
-               graphViewer.setLayoutAlgorithm(getLayoutAlgoritm(), false);
+               viewer.setLayoutAlgorithm(getLayoutAlgoritm(), false);
 
                createMenu();
 
                createToolbar();
 
-               graphViewer.setInput(getKey());
+               viewer.setInput(getKey());
 
                container.addControlListener(new ControlListener() {
 
@@ -173,9 +173,9 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
 
                ZoomContributionViewItem zoomItem = getZoomContributionViewItem();
                menuMgr.add(zoomItem);
-               getSite().registerContextMenu(menuMgr, graphViewer);
+               getSite().registerContextMenu(menuMgr, viewer);
 
-               Control control = graphViewer.getGraphControl();
+               Control control = viewer.getGraphControl();
                Menu menu = menuMgr.createContextMenu(control);
 
                control.setMenu(menu);
@@ -195,11 +195,11 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
 
        @Override
        public void setFocus() {
-               graphViewer.getControl().setFocus();
+               viewer.getControl().setFocus();
        }
 
        public void refresh() {
-               graphViewer.refresh();
+               viewer.refresh();
                // graphViewer.applyLayout();
        }
 
@@ -210,7 +210,7 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
 
        @Override
        public AbstractZoomableViewer getZoomableViewer() {
-               return graphViewer;
+               return viewer;
        }
 
        private LayoutAlgorithm getLayoutAlgoritm() {
@@ -243,7 +243,7 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
                refresh();
 
                if (objectAffectedByOperation instanceof PolytomousKeyNode) {
-                       graphViewer.setSelection(new StructuredSelection(
+                       viewer.setSelection(new StructuredSelection(
                                        objectAffectedByOperation), true);
                }
 
@@ -259,7 +259,7 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
        }
 
        public void applyLayout() {
-               graphViewer.applyLayout();
+               viewer.applyLayout();
        }
 
        @Override
@@ -282,7 +282,7 @@ public abstract class AbstractGraphKeyEditor<T extends IIdentificationKey>
        @Override
        public void changed(Object element) {
                setDirty(true);
-               graphViewer.update(element, null);
+               viewer.update(element, null);
        }
 
 }
index e303e0ff6299ec05972d13837cf65c13a9cd5041..74311dc3bf9f1f7ef94a639fef6d728edd0256dd 100644 (file)
@@ -22,6 +22,7 @@ import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyGraphEditor;
 import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyListEditor;
+import eu.etaxonomy.taxeditor.model.DataChangeBridge;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 
@@ -39,6 +40,8 @@ public class KeyEditor extends FormEditor implements IConversationEnabled,
 
        private boolean dirty;
 
+       private KeyEditorDataChangeBehaviour dataChangeBehavior;
+
        /*
         * (non-Javadoc)
         * 
@@ -85,8 +88,11 @@ public class KeyEditor extends FormEditor implements IConversationEnabled,
         * (eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
         */
        @Override
-       public void update(CdmDataChangeMap arg0) {
-               // TODO Auto-generated method stub
+       public void update(CdmDataChangeMap map) {
+               if(dataChangeBehavior == null){
+                       dataChangeBehavior = new KeyEditorDataChangeBehaviour(this);
+               }
+               DataChangeBridge.handleDataChange(map, dataChangeBehavior);
        }
 
        /*
@@ -112,8 +118,8 @@ public class KeyEditor extends FormEditor implements IConversationEnabled,
        public void changed(Object element) {
                editorDirtyStateChanged();
                IEditorPart activeEditor = getActiveEditor();
-               if (activeEditor instanceof PolytomousKeyListEditor) {
-                       ((PolytomousKeyListEditor) activeEditor).changed(element);
+               if (activeEditor instanceof IDirtyMarkableSelectionProvider) {
+                       ((IDirtyMarkableSelectionProvider) activeEditor).changed(element);
                }
        }
 
@@ -183,9 +189,18 @@ public class KeyEditor extends FormEditor implements IConversationEnabled,
                        EditorUtil.error(getClass(), e);
                }
 
-               PolytomousKey key = (PolytomousKey) input.getKey();
+               
 
-               setPartName(key.getTitleCache());
+               setPartName();
+
+       }
 
+       /**
+        * 
+        */
+       public void setPartName() {
+               AbstractIdentificationEditorInput input = (AbstractIdentificationEditorInput) getEditorInput();
+               PolytomousKey key = (PolytomousKey) input.getKey();
+               setPartName(key.getTitleCache());
        }
 }
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditorDataChangeBehaviour.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/KeyEditorDataChangeBehaviour.java
new file mode 100644 (file)
index 0000000..0a46ae0
--- /dev/null
@@ -0,0 +1,66 @@
+// $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.editor.key;
+
+import java.util.Vector;
+
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.key.polytomous.PolytomousKeyEditorInput;
+import eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour;
+
+/**
+ * @author n.hoffmann
+ * @created May 5, 2011
+ * @version 1.0
+ */
+public class KeyEditorDataChangeBehaviour extends AbstractDataChangeBehaviour {
+
+       private final KeyEditor source;
+       private PolytomousKeyEditorInput input;
+
+       /**
+        * @param keyEditor
+        */
+       public KeyEditorDataChangeBehaviour(KeyEditor keyEditor) {
+               source = keyEditor;
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour#reactOnDataChange(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+        */
+       @Override
+       public void reactOnDataChange(CdmDataChangeMap changeEvents) {
+               input = (PolytomousKeyEditorInput) source.getEditorInput();
+               
+               if(changeEvents.sizeByEventType(EventType.UPDATE) > 0){
+                       reactOnUpdate(changeEvents.getEvents(EventType.UPDATE));
+               }
+       }
+
+       /** {@inheritDoc} */
+       @Override
+       public void reactOnUpdate(Vector<CdmDataChangeEvent> events){
+
+               for(CdmDataChangeEvent event : events){
+                       
+                       // update editor title
+                       if(event.getEntity() instanceof PolytomousKey){
+                               if(input.getKey().equals(event.getEntity())){
+                                       // set the name of the editor window
+                                       source.setPartName();
+                               }
+                       }
+               }
+       }
+}
index 6eaddbfb1b3ce632cebeec504e04ca1dc3f75b70..03a4b1aac0b0359f0e4a8411ce642b274b361eec 100644 (file)
@@ -28,7 +28,7 @@ public class PolytomousKeyGraphEditor extends
        public PolytomousKeyGraphEditor(KeyEditor editor) {
                this.editor = editor;
        }
-
+       
        @Override
        public ConversationHolder getConversationHolder() {
                return ((PolytomousKeyEditorInput) getEditorInput())
index 324aad4ed932e41a0ceb1487f82570d66af2cb01..3ee69768839a738d2b93f822d28791363e87d8c6 100644 (file)
@@ -191,7 +191,6 @@ public class PolytomousKeyListEditor extends EditorPart implements
         */
        @Override
        public boolean isDirty() {
-               // TODO Auto-generated method stub
                return false;
        }
 
@@ -277,7 +276,7 @@ public class PolytomousKeyListEditor extends EditorPart implements
         */
        @Override
        public void setFocus() {
-               setPartName("Test");
+               
        }
 
        /*
index 9dfdfb3255a8a5ef2f1b275ad87ab03131e14f52..4909068443a423c6b545ad12dc69dc8758b3602b 100644 (file)
@@ -38,6 +38,7 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
+import eu.etaxonomy.taxeditor.model.DataChangeBridge;
 import eu.etaxonomy.taxeditor.model.IContextListener;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
@@ -104,9 +105,11 @@ public class PolytomousKeyViewPart extends ViewPart implements
        private ListViewer viewer;
        private ConversationHolder conversation;
        private IContextListener contextListener;
-       private CdmFormFactory formFactory;
+       private final CdmFormFactory formFactory;
        private Text text_filter;
 
+       private PolytomousKeyViewPartDataChangeBehavior dataChangeBehavior;
+
        public PolytomousKeyViewPart(){
                formFactory = new CdmFormFactory(Display.getDefault());
        }
@@ -177,6 +180,7 @@ public class PolytomousKeyViewPart extends ViewPart implements
 
        private void setInput() {
                conversation = CdmStore.createConversation();
+               conversation.registerForDataStoreChanges(this);
                List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);                 
                viewer.setInput(input);
        }
@@ -193,7 +197,13 @@ public class PolytomousKeyViewPart extends ViewPart implements
         * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
         */
        @Override
-       public void update(CdmDataChangeMap changeEvents) {}
+       public void update(CdmDataChangeMap changeEvents) {
+               if (dataChangeBehavior == null) {
+                       dataChangeBehavior = new PolytomousKeyViewPartDataChangeBehavior(this);
+               }
+
+               DataChangeBridge.handleDataChange(changeEvents, dataChangeBehavior);
+       }
 
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
@@ -208,6 +218,8 @@ public class PolytomousKeyViewPart extends ViewPart implements
         */
        @Override
        public void dispose() {
+               conversation.unregisterForDataStoreChanges(this);
+               conversation.close();
                CdmStore.getContextManager().removeContextListener(contextListener);
                super.dispose();
        }
@@ -229,4 +241,13 @@ public class PolytomousKeyViewPart extends ViewPart implements
                return true;
        }
 
+       /**
+        * 
+        */
+       public void refresh() {
+               getConversationHolder().bind();
+               List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);                 
+               viewer.setInput(input);
+       }
+
 }
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPartDataChangeBehavior.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPartDataChangeBehavior.java
new file mode 100644 (file)
index 0000000..51ee07a
--- /dev/null
@@ -0,0 +1,112 @@
+// $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.navigation.key.polytomous;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.description.PolytomousKey;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeEvent.EventType;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour;
+
+/**
+ * @author n.hoffmann
+ * @created May 5, 2011
+ * @version 1.0
+ */
+public class PolytomousKeyViewPartDataChangeBehavior extends
+               AbstractDataChangeBehaviour {
+
+       private final PolytomousKeyViewPart source;
+
+       /**
+        * @param polytomousKeyViewPart
+        */
+       public PolytomousKeyViewPartDataChangeBehavior(
+                       PolytomousKeyViewPart polytomousKeyViewPart) {
+               source = polytomousKeyViewPart;
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.model.AbstractDataChangeBehaviour#reactOnDataChange(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+        */
+       @Override
+       public void reactOnDataChange(CdmDataChangeMap changeEvents) {
+               if(isRelevant(changeEvents)){
+                       final Display display = Display.getCurrent();
+                       Job job = new Job("Updating Polytomous Key Viewer") {
+                               
+                               @Override
+                               protected IStatus run(IProgressMonitor monitor) {
+                                       monitor.beginTask("Updating Polytomous Key Viewer", 3);
+                                       monitor.worked(1);
+                                       
+                                       // clear the session completely
+                                       monitor.subTask("Clearing Polytomous Key Viewer session");
+                                       display.asyncExec(new Runnable() {
+                                                public void run() {
+                                                        source.getConversationHolder().clear();
+                                                }
+                                       });                                     
+                                       // FIXME completely clearing the session is a brute force approach. 
+                                       // It would be much more elegant to clear only those elements that have been changed.
+                                       // I could not get that to work but we should consider workin on this because we might
+                                       // run into serious performance issues, especially when it comes to large trees
+                                       //
+                                       // at least, we moved this to a job so it can run in a background thred
+                                       // seems to improve the situation but not sure if final solution
+                                       monitor.worked(1);
+                                       
+                                       monitor.subTask("Refreshing viewer");
+                                       
+                                       display.asyncExec(new Runnable() {
+                                           public void run() {
+                                               source.refresh();
+                                           }
+                                       });
+                                       
+                                       
+                                       
+                                       monitor.worked(1);
+                                       monitor.done();
+                                       return Status.OK_STATUS;
+                               }
+                       };
+                       
+                       job.setPriority(Job.SHORT);
+                       job.schedule();
+                       
+               }
+       }
+       
+       /**
+        * @return
+        */
+       private boolean isRelevant(CdmDataChangeMap changeEvents) {
+               for(CdmDataChangeEvent event : changeEvents.getAllEvents()){
+                       EventType eventType = event.getEventType();
+                       CdmBase eventEntity = event.getEntity();
+                       
+                       // all poyltomous key changes are relevant
+                       if((eventType == EventType.INSERT || eventType == EventType.DELETE || eventType == EventType.UPDATE) 
+                                       && eventEntity instanceof PolytomousKey){
+                               return true;
+                       }
+               }
+               return false;
+       }
+}
index ffcf4f6fe3b863cb0a95f683b12c0a12a933219f..e94f2f2ff537eb769554928f25fb7d4c6ff40d02 100644 (file)
@@ -7,6 +7,7 @@ import org.eclipse.swt.SWT;
 
 import eu.etaxonomy.cdm.model.description.PolytomousKey;
 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.forms.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
@@ -45,5 +46,6 @@ public class PolytomousKeyDetailElement extends
                if (eventSource == text_title) {
                        getEntity().setTitleCache(text_title.getText());
                }
+               firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
        }
 }