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.annotatedlineeditor.handler;
|
12
|
|
13
|
import org.eclipse.core.commands.AbstractHandler;
|
14
|
import org.eclipse.core.commands.ExecutionEvent;
|
15
|
import org.eclipse.core.commands.ExecutionException;
|
16
|
import org.eclipse.jface.dialogs.InputDialog;
|
17
|
import org.eclipse.jface.window.Window;
|
18
|
import org.eclipse.swt.widgets.Event;
|
19
|
import org.eclipse.ui.IEditorInput;
|
20
|
import org.eclipse.ui.IEditorPart;
|
21
|
import org.eclipse.ui.handlers.HandlerUtil;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
24
|
import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor;
|
25
|
|
26
|
/**
|
27
|
* <p>NewObjectHandler class.</p>
|
28
|
*
|
29
|
* @author p.ciardelli
|
30
|
* @created 14.08.2009
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class NewObjectHandler extends AbstractHandler {
|
34
|
|
35
|
/* (non-Javadoc)
|
36
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
37
|
*/
|
38
|
/** {@inheritDoc} */
|
39
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
40
|
|
41
|
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
42
|
IEditorInput input = editor.getEditorInput();
|
43
|
|
44
|
if (editor instanceof AnnotatedLineEditor) {
|
45
|
|
46
|
Object key = ((Event)event.getTrigger()).data;
|
47
|
if (key != null) {
|
48
|
if(!(key instanceof SpecimenOrObservationType)) {
|
49
|
String text = ((Event)event.getTrigger()).text;
|
50
|
InputDialog dialog = new InputDialog(HandlerUtil.getActiveShell(event), "Create " + text, "Enter new " + text, "", null);
|
51
|
if (dialog.open() != Window.CANCEL) {
|
52
|
((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue());
|
53
|
}
|
54
|
} else {
|
55
|
((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, "Untitled");
|
56
|
}
|
57
|
|
58
|
} else {
|
59
|
((AnnotatedLineEditor) editor).createAnnotatedLineNewObject();
|
60
|
}
|
61
|
}
|
62
|
return null;
|
63
|
}
|
64
|
}
|