2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
.e4
.handler
;
11 import java
.util
.List
;
12 import java
.util
.UUID
;
13 import java
.util
.stream
.Collectors
;
15 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
16 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
17 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
18 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPartStack
;
19 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
20 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EModelService
;
21 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
22 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
.PartState
;
24 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
25 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.e4
.DefinedTermEditorE4
;
26 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.input
.TermEditorInput
;
27 import eu
.etaxonomy
.taxeditor
.workbench
.WorkbenchUtility
;
36 public class OpenDefinedTermEditorHandlerE4
{
39 public void execute(EPartService partService
, MHandledMenuItem menuItem
, MApplication application
, EModelService modelService
) {
41 String commandId
= menuItem
.getCommand().getElementId();
42 UUID termTypeUuid
= (UUID
) menuItem
.getTransientData().get(commandId
+".termTypeUuid");
44 TermType termType
= TermType
.getByUuid(termTypeUuid
);
45 TermEditorInput termEditorInput
= new TermEditorInput(termType
);
46 List
<MPart
> alreadyOpenedEditors
= partService
.getParts().stream()
47 .filter(part
->part
.getObject()!=null && part
.getObject() instanceof DefinedTermEditorE4
)
48 .filter(part
->((DefinedTermEditorE4
)part
.getObject()).getDefinedTermEditorInput().getTermType().equals(termType
))
49 .collect(Collectors
.toList());
50 if(!alreadyOpenedEditors
.isEmpty()){
51 //there should never be more than one already opened editor
52 //so we just open the first
53 partService
.activate(alreadyOpenedEditors
.iterator().next());
56 MPart part
= partService
.createPart(eu
.etaxonomy
.taxeditor
.store
.AppModelId
.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERM
);
57 MPartStack editorAreaPartStack
= WorkbenchUtility
.getEditorAreaPartStack(application
, modelService
);
58 if(editorAreaPartStack
!=null){
59 editorAreaPartStack
.getChildren().add(part
);
61 part
= partService
.showPart(part
, PartState
.ACTIVATE
);
62 DefinedTermEditorE4 termEditor
= (DefinedTermEditorE4
) part
.getObject();
63 termEditor
.init(termEditorInput
);