2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.command
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.eclipse
.core
.commands
.NotEnabledException
;
14 import org
.eclipse
.core
.commands
.NotHandledException
;
15 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
16 import org
.eclipse
.jface
.action
.ContributionItem
;
17 import org
.eclipse
.jface
.action
.IContributionItem
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.widgets
.Event
;
22 import org
.eclipse
.swt
.widgets
.Menu
;
23 import org
.eclipse
.swt
.widgets
.MenuItem
;
24 import org
.eclipse
.ui
.PlatformUI
;
25 import org
.eclipse
.ui
.actions
.CompoundContributionItem
;
26 import org
.eclipse
.ui
.handlers
.IHandlerService
;
28 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
29 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 * @created Dec 13, 2010
37 public class DynamicMarkerTypeEditingMenu
extends CompoundContributionItem
{
39 private IHandlerService handlerService
=
40 (IHandlerService
) PlatformUI
.getWorkbench().getService(IHandlerService
.class);
43 * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
46 protected IContributionItem
[] getContributionItems() {
48 return new IContributionItem
[] {
49 new ContributionItem() {
50 public void fill(Menu menu
, int index
){
51 for(MarkerType markerType
: CdmStore
.getTermManager().getPreferredTerms(MarkerType
.class)){
52 createMenuItem(menu
, markerType
);
59 private void createMenuItem(Menu menu
, final MarkerType markerType
) {
61 MenuItem subMenuItem
= new MenuItem(menu
, SWT
.CASCADE
);
62 subMenuItem
.setText(String
.format("Set Flag '%s'", markerType
.getLabel()));
64 Menu subMenu
= new Menu(menu
.getShell(), SWT
.DROP_DOWN
);
65 subMenuItem
.setMenu(subMenu
);
67 MenuItem trueItem
= new MenuItem(subMenu
, SWT
.PUSH
);
68 trueItem
.setText("Yes");
69 trueItem
.addSelectionListener(new SelectionAdapter() {
70 public void widgetSelected(SelectionEvent e
) {
71 doSetFlagCommand(markerType
, true);
75 MenuItem falseItem
= new MenuItem(subMenu
, SWT
.PUSH
);
76 falseItem
.setText("No");
77 falseItem
.addSelectionListener(new SelectionAdapter() {
78 public void widgetSelected(SelectionEvent e
) {
79 doSetFlagCommand(markerType
, false);
84 private void doSetFlagCommand(MarkerType markerType
, boolean flag
) {
86 Event event
= new Event();
87 event
.data
= new Object
[]{markerType
, flag
};
88 handlerService
.executeCommand("taxeditor-bulkeditor.command.setMarkerFlag", event
);
89 } catch (ExecutionException e
) {
90 MessagingUtils
.error(getClass(), e
);
91 } catch (NotDefinedException e
) {
92 MessagingUtils
.error(getClass(), e
);
93 } catch (NotEnabledException e
) {
94 MessagingUtils
.error(getClass(), e
);
95 } catch (NotHandledException e
) {
96 MessagingUtils
.error(getClass(), e
);