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
.editor
.description
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.jface
.action
.ContributionItem
;
15 import org
.eclipse
.swt
.events
.SelectionEvent
;
16 import org
.eclipse
.swt
.events
.SelectionListener
;
17 import org
.eclipse
.swt
.widgets
.Event
;
18 import org
.eclipse
.swt
.widgets
.Menu
;
19 import org
.eclipse
.swt
.widgets
.MenuItem
;
20 import org
.eclipse
.ui
.handlers
.IHandlerService
;
22 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
23 import eu
.etaxonomy
.taxeditor
.editor
.internal
.TaxeditorEditorPlugin
;
24 import eu
.etaxonomy
.taxeditor
.store
.preference
.PreferencesUtil
;
31 public class DynamicFeatureMenu
extends ContributionItem
{
32 private static final Logger logger
= Logger
33 .getLogger(DynamicFeatureMenu
.class);
37 * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
40 public void fill(Menu menu
, int index
){
41 final IHandlerService handlerService
= (IHandlerService
) TaxeditorEditorPlugin
.getDefault().getWorkbench().getService(IHandlerService
.class);
44 for(final Feature feature
: PreferencesUtil
.getPreferredFeatures()){
45 MenuItem menuItem
= new MenuItem(menu
, -1);
46 menuItem
.setText(feature
.getLabel());
47 // TODO no use for menuItem.data?
48 menuItem
.setData(feature
);
49 menuItem
.addSelectionListener(new SelectionListener(){
51 public void widgetDefaultSelected(SelectionEvent e
) {}
53 public void widgetSelected(SelectionEvent ev
) {
54 Event event
= new Event();
57 handlerService
.executeCommand("eu.etaxonomy.taxeditor.editor.description.createDescriptionElement", event
);
58 } catch (Exception e
) {
59 logger
.error("Error executing command", e
);