ref #7011 harmonize creation and showing of MParts
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 27 Feb 2018 10:06:12 +0000 (11:06 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 27 Feb 2018 10:06:27 +0000 (11:06 +0100)
 - also allow authority editor to be opened in multiple parts

eu.etaxonomy.taxeditor.editor/fragment.e4xmi
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java

index fdf2653328c2a3eba63802db3b88f430f420cc06..feb8e2f1390e3421fab878b0ee6305aa2dfce574 100644 (file)
         <children xsi:type="menu:HandledMenuItem" xmi:id="_Rf4A8KRREeePufXF8uhoCw" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.polytomouskeylist.delete" label="%command.label.26" command="_uM4zsKO8EeeWePK798pdTw"/>
       </menus>
     </elements>
-    <elements xsi:type="basic:PartDescriptor" xmi:id="_ARZyMKz2EeeBIsZyvYlAaA" elementId="eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4" label="%editor.name.4" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4"/>
+    <elements xsi:type="basic:PartDescriptor" xmi:id="_ARZyMKz2EeeBIsZyvYlAaA" elementId="eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4" label="%editor.name.4" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4"/>
     <elements xsi:type="basic:PartDescriptor" xmi:id="_Fa8l4M7XEeex0rHJ7p8Zdw" elementId="eu.etaxonomy.taxeditor.editor.view.workingSet.WorkingSetEditor" label="Working Set Editor" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.editor/icons/ws_icon.gif" tooltip="Working Set Editor" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.workingSet.WorkingSetEditor"/>
     <elements xsi:type="basic:PartDescriptor" xmi:id="_rpaDsNK2EeeWSJT7vW9jsw" elementId="eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrixPart" label="Character Matrix" tooltip="Character Matrix" allowMultiple="true" closeable="true" dirtyable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrixPart">
       <handlers xmi:id="_d_HUYOPBEeeIH8IplZ0cuA" elementId="eu.etaxonomy.taxeditor.editor.handler.2" contributionURI="bundleclass://eu.etaxonomy.taxeditor.editor/eu.etaxonomy.taxeditor.editor.view.charactermatrix.handler.ExportCharacterMatrixHandler" command="_YeWagOPBEeeIH8IplZ0cuA"/>
index 7f210a6049cb904ef344768f116f8899172e6e24..3a5f6664100508a1244646de9c2b83f5d22ed743 100644 (file)
@@ -27,7 +27,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
@@ -63,52 +62,44 @@ public class EditorUtil extends AbstractUtility {
     private static final String NAME_EDITOR_ID = "eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4";
     private static boolean isSaving = false;
 
-       /**
-        * Opens a new {@link DataImportEditor} for the given input
-        * @param input a {@link DataImportEditorInput}
-        * @throws PartInitException
-        */
-//     public static void open(DataImportEditorInput<?> input)
-//             throws PartInitException {
-//         if(input instanceof BioCaseEditorInput){
-//             open(input, SpecimenImportEditor.ID);
-//         }
-//         else if(input instanceof GbifImportEditorInput){
-//             open(input, GbifImportEditor.ID);
-//         }
-//     }
-
     public static void openWorkingSetEditor(UUID workingSetUuid, EModelService modelService, EPartService partService, MApplication application){
-        MPart part = partService.createPart("eu.etaxonomy.taxeditor.editor.view.workingSet.WorkingSetEditor");
-        MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
-        if(editorAreaPartStack!=null){
-            editorAreaPartStack.getChildren().add(part);
-        }
-        part = partService.showPart(part, PartState.ACTIVATE);
+        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_WORKINGSET_WORKINGSETEDITOR;
+        MPart part = showPart(partId, modelService, partService, application);
         WorkingSetEditor editor = (WorkingSetEditor) part.getObject();
         editor.init(workingSetUuid);
     }
 
     public static void openCharacterMatrix(UUID workingSetUuid, EModelService modelService, EPartService partService, MApplication application){
-        MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_WORKINGSET_MATRIX_CHARACTERMATRIXPART);
-        MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
-        if(editorAreaPartStack!=null){
-            editorAreaPartStack.getChildren().add(part);
-        }
-        part = partService.showPart(part, PartState.ACTIVATE);
+        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_WORKINGSET_MATRIX_CHARACTERMATRIXPART;
+        MPart part = showPart(partId, modelService, partService, application);
         CharacterMatrixPart editor = (CharacterMatrixPart) part.getObject();
         editor.init(workingSetUuid, true);
     }
 
     public static void openSpecimenEditor(DerivateViewEditorInput input, EModelService modelService, EPartService partService, MApplication application){
-        MPart part = partService.createPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW);
+        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_VIEW_DERIVATE_DERIVATEVIEW;
+        MPart part = showPart(partId, modelService, partService, application);
+        DerivateView derivateView = (DerivateView) part.getObject();
+        derivateView.init(input);
+    }
+
+    public static void openRightsEditor(CdmAuthorityEditorInput input, EModelService modelService, EPartService partService, MApplication application){
+        String partId = AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_GROUP_AUTHORITY_E4_CDMAUTHORITYEDITORE4;
+        MPart part = showPart(partId, modelService, partService, application);
+        CdmAuthorityEditorE4 authorityView = (CdmAuthorityEditorE4) part.getObject();
+        authorityView.init(input);
+    }
+
+    private static MPart showPart(String partId, EModelService modelService, EPartService partService, MApplication application){
+        MPart part = partService.findPart(partId);
+        if(part==null || modelService.getPartDescriptor(partId).isAllowMultiple()){
+            part = partService.createPart(partId);
+        }
         MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
         if(editorAreaPartStack!=null){
             editorAreaPartStack.getChildren().add(part);
         }
-        part = partService.showPart(part, PartState.ACTIVATE);
-        DerivateView derivateView = (DerivateView) part.getObject();
-        derivateView.init(input);
+        return partService.showPart(part, PartState.ACTIVATE);
     }
 
        public static void openTaxonNodeE4(UUID taxonNodeUuid, EModelService modelService, EPartService partService, MApplication application) {
@@ -156,27 +147,10 @@ public class EditorUtil extends AbstractUtility {
                 break;
             }
         }
-        MPart part = partService.createPart(NAME_EDITOR_ID);
-
-        MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
-        if(editorAreaPartStack!=null){
-            editorAreaPartStack.getChildren().add(part);
-        }
-        part = partService.showPart(part, PartState.ACTIVATE);
-
+        MPart part = showPart(NAME_EDITOR_ID, modelService, partService, application);
         TaxonNameEditorE4 editor = (TaxonNameEditorE4) part.getObject();
         editor.init(input);
     }
-    public static void openRightsEditor(CdmAuthorityEditorInput input, EModelService modelService, EPartService partService, MApplication application){
-        MPart part = partService.createPart("eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4");
-        MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
-        if(editorAreaPartStack!=null){
-            editorAreaPartStack.getChildren().add(part);
-        }
-        part = partService.showPart(part, PartState.ACTIVATE);
-        CdmAuthorityEditorE4 authorityView = (CdmAuthorityEditorE4) part.getObject();
-        authorityView.init(input);
-    }
 
        /**
         * An uninitialized taxon is one that hasn't been saved yet. As such, it