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
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.NotEnabledException
;
15 import org
.eclipse
.core
.commands
.NotHandledException
;
16 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
17 import org
.eclipse
.jface
.action
.ContributionItem
;
18 import org
.eclipse
.jface
.action
.IContributionItem
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.widgets
.Event
;
23 import org
.eclipse
.swt
.widgets
.Menu
;
24 import org
.eclipse
.swt
.widgets
.MenuItem
;
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
.common
.MarkerType
;
30 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditorUtil
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * @created Dec 13, 2010
38 public class DynamicMarkerTypeEditingMenu
extends CompoundContributionItem
{
40 private IHandlerService handlerService
=
41 (IHandlerService
) PlatformUI
.getWorkbench().getService(IHandlerService
.class);
44 * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
47 protected IContributionItem
[] getContributionItems() {
49 return new IContributionItem
[] {
50 new ContributionItem() {
51 public void fill(Menu menu
, int index
){
52 for(MarkerType markerType
: CdmStore
.getTermManager().getPreferredMarkerTypes()){
53 createMenuItem(menu
, markerType
);
60 private void createMenuItem(Menu menu
, final MarkerType markerType
) {
62 MenuItem subMenuItem
= new MenuItem(menu
, SWT
.CASCADE
);
63 subMenuItem
.setText(String
.format("Set Flag '%s'", markerType
.getLabel()));
65 Menu subMenu
= new Menu(menu
.getShell(), SWT
.DROP_DOWN
);
66 subMenuItem
.setMenu(subMenu
);
68 MenuItem trueItem
= new MenuItem(subMenu
, SWT
.PUSH
);
69 trueItem
.setText("Yes");
70 trueItem
.addSelectionListener(new SelectionAdapter() {
71 public void widgetSelected(SelectionEvent e
) {
72 doSetFlagCommand(markerType
, true);
76 MenuItem falseItem
= new MenuItem(subMenu
, SWT
.PUSH
);
77 falseItem
.setText("No");
78 falseItem
.addSelectionListener(new SelectionAdapter() {
79 public void widgetSelected(SelectionEvent e
) {
80 doSetFlagCommand(markerType
, false);
85 private void doSetFlagCommand(MarkerType markerType
, boolean flag
) {
87 Event event
= new Event();
88 event
.data
= new Object
[]{markerType
, flag
};
89 handlerService
.executeCommand("taxeditor-bulkeditor.command.setMarkerFlag", event
);
90 } catch (ExecutionException e
) {
91 BulkEditorUtil
.error(getClass(), e
);
92 } catch (NotDefinedException e
) {
93 BulkEditorUtil
.error(getClass(), e
);
94 } catch (NotEnabledException e
) {
95 BulkEditorUtil
.error(getClass(), e
);
96 } catch (NotHandledException e
) {
97 BulkEditorUtil
.error(getClass(), e
);