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.Map;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.eclipse.jface.action.ContributionItem;
|
17
|
import org.eclipse.jface.action.IContributionItem;
|
18
|
import org.eclipse.swt.events.SelectionEvent;
|
19
|
import org.eclipse.swt.events.SelectionListener;
|
20
|
import org.eclipse.swt.widgets.Event;
|
21
|
import org.eclipse.swt.widgets.Menu;
|
22
|
import org.eclipse.swt.widgets.MenuItem;
|
23
|
import org.eclipse.ui.IEditorPart;
|
24
|
import org.eclipse.ui.PlatformUI;
|
25
|
import org.eclipse.ui.actions.CompoundContributionItem;
|
26
|
import org.eclipse.ui.handlers.IHandlerService;
|
27
|
|
28
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineDocumentProvider;
|
29
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor;
|
30
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
|
32
|
|
33
|
/**
|
34
|
* <p>DynamicNewObjectMenu class.</p>
|
35
|
*
|
36
|
* @author n.hoffmann
|
37
|
* @created 17.04.2009
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
@Deprecated // remove this
|
41
|
public class DynamicNewObjectMenu extends CompoundContributionItem {
|
42
|
private static final Logger logger = Logger
|
43
|
.getLogger(DynamicNewObjectMenu.class);
|
44
|
|
45
|
/* (non-Javadoc)
|
46
|
* @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
|
47
|
*/
|
48
|
/** {@inheritDoc} */
|
49
|
@Override
|
50
|
protected IContributionItem[] getContributionItems() {
|
51
|
|
52
|
return new IContributionItem[] {
|
53
|
new ContributionItem() {
|
54
|
public void fill(Menu menu, int index){
|
55
|
|
56
|
final Map<Object, String> classLabelPairs = getClassLabelPairs();
|
57
|
|
58
|
final IHandlerService handlerService =
|
59
|
(IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
|
60
|
|
61
|
for(final Object key : classLabelPairs.keySet()){
|
62
|
MenuItem menuItem = new MenuItem(menu, -1);
|
63
|
menuItem.setText(classLabelPairs.get(key));
|
64
|
menuItem.addSelectionListener(new SelectionListener(){
|
65
|
|
66
|
public void widgetDefaultSelected(SelectionEvent e) {}
|
67
|
|
68
|
public void widgetSelected(SelectionEvent ev) {
|
69
|
Event event = new Event();
|
70
|
event.data = key;
|
71
|
event.text = classLabelPairs.get(key);
|
72
|
try {
|
73
|
handlerService.executeCommand(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID, event);
|
74
|
} catch (Exception e) {
|
75
|
logger.error("Error executing command", e);
|
76
|
throw new RuntimeException("Error executing command", e);
|
77
|
}
|
78
|
}
|
79
|
});
|
80
|
}
|
81
|
}
|
82
|
}
|
83
|
};
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Get class label pairs from Annotated Line Editor's entity creator.
|
88
|
* @return
|
89
|
*/
|
90
|
private Map<Object, String> getClassLabelPairs() {
|
91
|
IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
92
|
if (editor == null || !(editor instanceof AnnotatedLineEditor) || !(((AnnotatedLineEditor) editor).getDocumentProvider() instanceof AnnotatedLineDocumentProvider)) {
|
93
|
return null;
|
94
|
}
|
95
|
IEntityCreator<?> entityCreator = ((AnnotatedLineDocumentProvider) ((AnnotatedLineEditor) editor).getDocumentProvider()).getEntityCreator(editor.getEditorInput());
|
96
|
return entityCreator.getKeyLabelPairs();
|
97
|
}
|
98
|
}
|