3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
.command
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.jface
.action
.ContributionItem
;
17 import org
.eclipse
.jface
.action
.IContributionItem
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.events
.SelectionListener
;
20 import org
.eclipse
.swt
.widgets
.Event
;
21 import org
.eclipse
.swt
.widgets
.Menu
;
22 import org
.eclipse
.swt
.widgets
.MenuItem
;
23 import org
.eclipse
.ui
.IEditorInput
;
24 import org
.eclipse
.ui
.IEditorPart
;
25 import org
.eclipse
.ui
.PlatformUI
;
26 import org
.eclipse
.ui
.actions
.CompoundContributionItem
;
27 import org
.eclipse
.ui
.handlers
.IHandlerService
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
30 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorConstants
;
33 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.AbstractBulkEditorInput
;
36 * <p>DynamicNewObjectMenu class.</p>
42 public class DynamicNewObjectMenu
extends CompoundContributionItem
{
43 private static final Logger logger
= Logger
44 .getLogger(DynamicNewObjectMenu
.class);
46 private IHandlerService handlerService
= (IHandlerService
) BulkEditorUtil
.getService(IHandlerService
.class);
47 private Map
<Object
, String
> classLabelPairs
;
49 * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
53 protected IContributionItem
[] getContributionItems() {
55 classLabelPairs
= getClassLabelPairs();
57 return new IContributionItem
[] {
58 new ContributionItem() {
59 public void fill(Menu menu
, int index
){
60 for(final Object key
: classLabelPairs
.keySet()){
61 createMenuItem(menu
, key
);
68 private void createMenuItem(Menu menu
, final Object key
){
69 MenuItem menuItem
= new MenuItem(menu
, -1);
70 menuItem
.setText(classLabelPairs
.get(key
));
71 menuItem
.addSelectionListener(new SelectionListener(){
73 public void widgetDefaultSelected(SelectionEvent e
) {}
75 public void widgetSelected(SelectionEvent ev
) {
76 Event event
= new Event();
78 event
.text
= classLabelPairs
.get(key
);
80 handlerService
.executeCommand(IBulkEditorConstants
.DYNAMIC_OPEN_OBJECT_ID
, event
);
81 } catch (Exception e
) {
82 logger
.error("Error executing command", e
);
83 throw new RuntimeException("Error executing command", e
);
88 //FIXME:3.3MC Need corresponding Details Viewer section for FieldUnit
89 if(key
== SpecimenOrObservationType
.FieldUnit
){
90 menuItem
.setEnabled(false);
95 * Get class label pairs from Annotated Line Editor's entity creator.
98 private Map
<Object
, String
> getClassLabelPairs() {
99 IEditorPart editor
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
101 IEditorInput input
= editor
.getEditorInput();
103 if(input
instanceof AbstractBulkEditorInput
){
104 IEntityCreator
<?
> entityCreator
= ((AbstractBulkEditorInput
) input
).getEntityCreator();
105 return entityCreator
.getKeyLabelPairs();