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.bulkeditor.command;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
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.IEditorPart;
|
26
|
import org.eclipse.ui.PlatformUI;
|
27
|
import org.eclipse.ui.actions.CompoundContributionItem;
|
28
|
import org.eclipse.ui.handlers.IHandlerService;
|
29
|
|
30
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
|
32
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
33
|
import eu.etaxonomy.taxeditor.store.TermStore;
|
34
|
|
35
|
/**
|
36
|
* <p>SetMarkerContributionItems class.</p>
|
37
|
*
|
38
|
* @author p.ciardelli
|
39
|
* @created 20.10.2009
|
40
|
* @version 1.0
|
41
|
*/
|
42
|
public class SetMarkerContributionItems extends CompoundContributionItem {
|
43
|
private static final Logger logger = Logger
|
44
|
.getLogger(SetMarkerContributionItems.class);
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
|
48
|
*/
|
49
|
/** {@inheritDoc} */
|
50
|
@Override
|
51
|
protected IContributionItem[] getContributionItems() {
|
52
|
|
53
|
List<IContributionItem> contributions = new ArrayList<IContributionItem>();
|
54
|
|
55
|
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
56
|
if (editor.getEditorInput() instanceof AbstractBulkEditorInput) {
|
57
|
AbstractBulkEditorInput input = (AbstractBulkEditorInput) editor.getEditorInput();
|
58
|
for (final MarkerType markerType : TermStore.getNonTechnicalMarkerTypes()) {
|
59
|
if (input.isMarkerTypeEditingEnabled(markerType) && PreferencesUtil.getEditMarkerTypePreference(input, markerType)) {
|
60
|
contributions.add(new ContributionItem() {
|
61
|
/* (non-Javadoc)
|
62
|
* @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
|
63
|
*/
|
64
|
@Override
|
65
|
public void fill(Menu menu, int index) {
|
66
|
MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE, index);
|
67
|
subMenuItem.setText("Set Flag - \"" + markerType.getLabel() + "\"");
|
68
|
Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
|
69
|
subMenuItem.setMenu(subMenu);
|
70
|
|
71
|
MenuItem trueItem = new MenuItem(subMenu, SWT.PUSH);
|
72
|
trueItem.setText("true");
|
73
|
trueItem.addSelectionListener(new SelectionAdapter() {
|
74
|
public void widgetSelected(SelectionEvent e) {
|
75
|
doSetFlagCommand(markerType, true);
|
76
|
}
|
77
|
});
|
78
|
|
79
|
MenuItem falseItem = new MenuItem(subMenu, SWT.PUSH);
|
80
|
falseItem.setText("false");
|
81
|
falseItem.addSelectionListener(new SelectionAdapter() {
|
82
|
public void widgetSelected(SelectionEvent e) {
|
83
|
doSetFlagCommand(markerType, false);
|
84
|
}
|
85
|
});
|
86
|
}
|
87
|
});
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
return (IContributionItem[]) contributions.toArray(new IContributionItem[contributions.size()]);
|
92
|
}
|
93
|
|
94
|
private void doSetFlagCommand(MarkerType markerType, boolean flag) {
|
95
|
try {
|
96
|
IHandlerService handlerService =
|
97
|
(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
|
98
|
Event event = new Event();
|
99
|
event.data = markerType;
|
100
|
if (flag) {
|
101
|
handlerService.executeCommand("taxeditor-bulkeditor.command.setMarkerFlagTrue", event);
|
102
|
} else {
|
103
|
handlerService.executeCommand("taxeditor-bulkeditor.command.setMarkerFlagFalse", event);
|
104
|
}
|
105
|
} catch (Exception e) {
|
106
|
// TODO Auto-generated catch block
|
107
|
e.printStackTrace();
|
108
|
}
|
109
|
}
|
110
|
}
|