1
|
/**
|
2
|
* Copyright (C) 2009 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.editor.definedterm.e4.handler;
|
10
|
import java.util.List;
|
11
|
import java.util.stream.Collectors;
|
12
|
|
13
|
import org.eclipse.e4.core.di.annotations.Execute;
|
14
|
import org.eclipse.e4.ui.model.application.MApplication;
|
15
|
import org.eclipse.e4.ui.model.application.commands.MParameter;
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
|
18
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
19
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
20
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
21
|
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.term.TermType;
|
24
|
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
|
25
|
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
|
26
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
27
|
|
28
|
|
29
|
/**
|
30
|
* @author pplitzner
|
31
|
* @since Aug 22, 2017
|
32
|
*/
|
33
|
public class OpenDefinedTermEditorHandlerE4 {
|
34
|
|
35
|
@Execute
|
36
|
public void execute(EPartService partService, MHandledMenuItem menuItem, MApplication application, EModelService modelService) {
|
37
|
|
38
|
String commandId = menuItem.getCommand().getElementId();
|
39
|
List<MParameter> parameters = menuItem.getParameters();
|
40
|
TermType termType = null;
|
41
|
for (MParameter param: parameters){
|
42
|
termType = TermType.getByKey(param.getValue());
|
43
|
}
|
44
|
|
45
|
// UUID termTypeUuid = (UUID) menuItem.getTransientData().get(commandId+".termTypeUuid");
|
46
|
//
|
47
|
// TermType termType = TermType.getByUuid(termTypeUuid);
|
48
|
if(termType != null){
|
49
|
TermType type = termType;
|
50
|
TermEditorInput termEditorInput = new TermEditorInput(termType);
|
51
|
List<MPart> alreadyOpenedEditors = partService.getParts().stream()
|
52
|
.filter(part->part.getObject()!=null && part.getObject() instanceof DefinedTermEditorE4)
|
53
|
.filter(part->((DefinedTermEditorE4)part.getObject()).getDefinedTermEditorInput().getTermType().equals(type))
|
54
|
.collect(Collectors.toList());
|
55
|
if(!alreadyOpenedEditors.isEmpty()){
|
56
|
//there should never be more than one already opened editor
|
57
|
//so we just open the first
|
58
|
partService.activate(alreadyOpenedEditors.iterator().next());
|
59
|
}
|
60
|
else{
|
61
|
MPart part = partService.createPart(eu.etaxonomy.taxeditor.store.AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERM);
|
62
|
MPartStack editorAreaPartStack = WorkbenchUtility.getEditorAreaPartStack(application, modelService);
|
63
|
if(editorAreaPartStack!=null){
|
64
|
editorAreaPartStack.getChildren().add(part);
|
65
|
}
|
66
|
part = partService.showPart(part, PartState.ACTIVATE);
|
67
|
DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) part.getObject();
|
68
|
termEditor.init(termEditorInput, menuItem.getLocalizedLabel());
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
}
|