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