59f1d1d30a4c270c6748f48f909a9669f3c22381
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / description / DynamicFeatureMenu.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.editor.description;
12
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;
21
22 import eu.etaxonomy.cdm.model.description.Feature;
23 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24 import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26 import eu.etaxonomy.taxeditor.store.preference.PreferencesUtil;
27
28 /**
29 * @author n.hoffmann
30 * @created 17.04.2009
31 * @version 1.0
32 */
33 public class DynamicFeatureMenu extends ContributionItem {
34 private static final Logger logger = Logger
35 .getLogger(DynamicFeatureMenu.class);
36
37 /*
38 * (non-Javadoc)
39 * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
40 */
41 @Override
42 public void fill(Menu menu, int index){
43 final IHandlerService handlerService = (IHandlerService) TaxeditorEditorPlugin.getDefault().getWorkbench().getService(IHandlerService.class);
44
45
46 for(final Feature feature : PreferencesUtil.getPreferredFeatures()){
47 MenuItem menuItem = new MenuItem(menu, -1);
48 menuItem.setText(feature.getLabel());
49 // TODO no use for menuItem.data?
50 menuItem.setData(feature);
51 menuItem.addSelectionListener(new SelectionListener(){
52
53 public void widgetDefaultSelected(SelectionEvent e) {}
54
55 public void widgetSelected(SelectionEvent ev) {
56 Event event = new Event();
57 event.data = feature;
58 try {
59 handlerService.executeCommand("eu.etaxonomy.taxeditor.editor.description.createDescriptionElement", event);
60 } catch (Exception e) {
61 logger.error("Error executing command", e);
62 }
63 }
64 });
65 }
66
67 }
68 }