2 * Copyright (C) 2020 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.
9 package eu
.etaxonomy
.taxeditor
.featuretree
.e4
.handler
;
11 import java
.util
.List
;
12 import java
.util
.stream
.Collectors
;
14 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
15 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
16 import org
.eclipse
.e4
.ui
.model
.application
.commands
.MParameter
;
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
.featuretree
.e4
.TermTreeEditor
;
26 import eu
.etaxonomy
.taxeditor
.workbench
.WorkbenchUtility
;
32 public class OpenTermTreeEditorHandler
{
34 public void execute(EPartService partService
, MHandledMenuItem menuItem
, MApplication application
, EModelService modelService
) {
36 String commandId
= menuItem
.getCommand().getElementId();
37 List
<MParameter
> parameters
= menuItem
.getParameters();
38 TermType termType
= null;
39 for (MParameter param
: parameters
){
40 termType
= TermType
.getByKey(param
.getValue());
44 TermType type
= termType
;
46 List
<MPart
> alreadyOpenedEditors
= partService
.getParts().stream()
47 .filter(part
->part
.getObject()!=null && part
.getObject() instanceof TermTreeEditor
)
48 .filter(part
->((TermTreeEditor
)part
.getObject()).getTermType().equals(type
))
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_TERMTREE
);
57 MPartStack editorAreaPartStack
= WorkbenchUtility
.getEditorAreaPartStack(application
, modelService
);
58 if(editorAreaPartStack
!=null){
59 editorAreaPartStack
.getChildren().add(part
);
61 part
= partService
.showPart(part
, PartState
.ACTIVATE
);
62 TermTreeEditor termEditor
= (TermTreeEditor
) part
.getObject();
63 termEditor
.init(termType
, menuItem
.getLocalizedLabel());