1
|
/**
|
2
|
* Copyright (C) 2020 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.termtree.e4.handler;
|
10
|
|
11
|
import java.util.List;
|
12
|
import java.util.stream.Collectors;
|
13
|
|
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;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.term.TermType;
|
25
|
import eu.etaxonomy.taxeditor.termtree.e4.TermTreeEditor;
|
26
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
27
|
|
28
|
/**
|
29
|
* @author k.luther
|
30
|
* @since Dec 11, 2020
|
31
|
*/
|
32
|
public class OpenTermTreeEditorHandler {
|
33
|
@Execute
|
34
|
public void execute(EPartService partService, MHandledMenuItem menuItem, MApplication application, EModelService modelService) {
|
35
|
|
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());
|
41
|
}
|
42
|
|
43
|
if(termType != null){
|
44
|
TermType type = termType;
|
45
|
|
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());
|
54
|
}
|
55
|
else{
|
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);
|
60
|
}
|
61
|
part = partService.showPart(part, PartState.ACTIVATE);
|
62
|
TermTreeEditor termEditor = (TermTreeEditor) part.getObject();
|
63
|
termEditor.init(termType, menuItem.getLocalizedLabel());
|
64
|
}
|
65
|
}
|
66
|
}
|
67
|
|
68
|
}
|