ref #6908 Avoid opening the same PK in multiple editors
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 26 Oct 2017 15:49:10 +0000 (17:49 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 26 Oct 2017 15:49:10 +0000 (17:49 +0200)
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/e4/handler/RemotingEditPolytomousKeyNodesHandlerE4.java

index 1ba507bb5bf1205cab237a282fd12cbeb6ddd11d..cc3d5d41e7fa01a3fa7de2753192d1c58822b7c7 100644 (file)
@@ -8,6 +8,8 @@
 */
 package eu.etaxonomy.taxeditor.navigation.key.polytomous.e4.handler;
 
+import java.util.Collection;
+
 import javax.inject.Named;
 
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -64,11 +66,26 @@ public class RemotingEditPolytomousKeyNodesHandlerE4 {
                                 public void run() {
                                     try {
                                         PolytomousKey key = (PolytomousKey) selectedObject;
-
-                                        MPart part = partService.createPart("eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4");
+                                        PolytomousKeyEditorInput input = PolytomousKeyEditorInput.NewInstance(key.getUuid());
+
+                                        //check if editor already open
+                                        Collection<MPart> parts = partService.getParts();
+                                        MPart part = null;
+                                        //check if part is already opened
+                                        for (MPart mPart : parts) {
+                                            if(mPart.getObject() instanceof PolytomousKeyListEditorE4
+                                                    && ((PolytomousKeyListEditorE4) mPart.getObject()).getViewerInputKey().equals(input.getKey())){
+                                                part = mPart;
+                                                break;
+                                            }
+                                        }
+                                        if(part==null){
+                                            part = partService.createPart("eu.etaxonomy.taxeditor.editor.key.polytomous.e4.PolytomousKeyListEditorE4");
+                                            part = partService.showPart(part, PartState.ACTIVATE);
+                                            PolytomousKeyListEditorE4 editor = (PolytomousKeyListEditorE4) part.getObject();
+                                            editor.init(input);
+                                        }
                                         part = partService.showPart(part, PartState.ACTIVATE);
-                                        PolytomousKeyListEditorE4 editor = (PolytomousKeyListEditorE4) part.getObject();
-                                        editor.init(PolytomousKeyEditorInput.NewInstance(key.getUuid()));
                                     } catch(Exception ex) {
                                         MessagingUtils.warningDialog(PolytomousKeyViewLabels.ERROR_OPENING_KEY_EDITOR_MESSAGE,
                                                 RemotingEditPolytomousKeyNodesHandlerE4.this,