1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.taxeditor.bulkeditor.e4.command;
|
11
|
|
12
|
import java.util.Collections;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import javax.inject.Named;
|
17
|
|
18
|
import org.eclipse.e4.ui.di.AboutToShow;
|
19
|
import org.eclipse.e4.ui.model.application.commands.MCommand;
|
20
|
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
|
21
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
23
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
|
24
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
|
25
|
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
|
26
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
27
|
|
28
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
29
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
|
30
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
|
32
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
33
|
|
34
|
/**
|
35
|
*
|
36
|
* @author pplitzner
|
37
|
* @date 12.09.2017
|
38
|
*
|
39
|
*/
|
40
|
public class DynamicNewObjectMenuE4 {
|
41
|
|
42
|
private Map<? extends Object, String> classLabelPairs;
|
43
|
private BulkEditorE4 editor;
|
44
|
|
45
|
/** {@inheritDoc} */
|
46
|
@AboutToShow
|
47
|
public void aboutToShow(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
48
|
List<MMenuElement> items) {
|
49
|
|
50
|
editor = (BulkEditorE4) activePart.getObject();
|
51
|
|
52
|
classLabelPairs = getClassLabelPairs();
|
53
|
|
54
|
MMenu menu = MMenuFactory.INSTANCE.createMenu();
|
55
|
menu.setLabel(Messages.DynamicNewObjectMenuE4_NEW);
|
56
|
items.add(menu);
|
57
|
|
58
|
for(final Object key : classLabelPairs.keySet()){
|
59
|
createMenuItem(menu, key);
|
60
|
}
|
61
|
}
|
62
|
|
63
|
private void createMenuItem(MMenu menu, final Object key){
|
64
|
MHandledMenuItem menuItem = MMenuFactory.INSTANCE.createHandledMenuItem();
|
65
|
menuItem.setLabel(classLabelPairs.get(key));
|
66
|
MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
|
67
|
mCommand.setElementId(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID);
|
68
|
mCommand.setCommandName(classLabelPairs.get(key));
|
69
|
//set params
|
70
|
menuItem.getTransientData().put(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID+".key", key); //$NON-NLS-1$
|
71
|
|
72
|
menuItem.setCommand(mCommand);
|
73
|
menu.getChildren().add(menuItem);
|
74
|
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Get class label pairs from Annotated Line Editor's entity creator.
|
79
|
* @return
|
80
|
*/
|
81
|
private Map<? extends Object, String> getClassLabelPairs() {
|
82
|
if (editor != null){
|
83
|
AbstractBulkEditorInput input = editor.getEditorInput();
|
84
|
|
85
|
IEntityCreator<?> entityCreator = input.getEntityCreator();
|
86
|
if(entityCreator!=null){
|
87
|
return entityCreator.getKeyLabelPairs();
|
88
|
}
|
89
|
}
|
90
|
|
91
|
return Collections.EMPTY_MAP;
|
92
|
}
|
93
|
}
|