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
.annotatedlineeditor
.handler
;
14 import java
.net
.URISyntaxException
;
16 import org
.eclipse
.core
.commands
.AbstractHandler
;
17 import org
.eclipse
.core
.commands
.ExecutionEvent
;
18 import org
.eclipse
.core
.commands
.ExecutionException
;
19 import org
.eclipse
.jface
.dialogs
.IInputValidator
;
20 import org
.eclipse
.jface
.dialogs
.InputDialog
;
21 import org
.eclipse
.jface
.window
.Window
;
22 import org
.eclipse
.swt
.widgets
.Event
;
23 import org
.eclipse
.ui
.IEditorInput
;
24 import org
.eclipse
.ui
.IEditorPart
;
25 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
28 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.AnnotatedLineEditor
;
31 * <p>NewObjectHandler class.</p>
37 public class NewObjectHandler
extends AbstractHandler
{
40 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
43 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
45 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
46 IEditorInput input
= editor
.getEditorInput();
48 if (editor
instanceof AnnotatedLineEditor
) {
50 Object key
= ((Event
)event
.getTrigger()).data
;
52 if(!(key
instanceof SpecimenOrObservationType
)) {
53 String text
= ((Event
)event
.getTrigger()).text
;
55 //FIXME : This should probably go into some ValidatorFactory
56 IInputValidator nonEmptyInputValidator
= null;
57 //FIXME : This is a workaround to not allow empty strings in the
58 // input dialog for User and Group entities.
59 // Normally this should be default
60 // behaviour, so we need to discuss whether this handler
61 // should be used to handle the creating new entities of
62 // type other than User and Group.
63 // Once #4348 is fixed this check can be removed.
64 if(text
.equals("User") || text
.equals("Group")) {
65 nonEmptyInputValidator
= new IInputValidator() {
66 public String
isValid(String text
) {
67 if(text
== null || text
.isEmpty()) {
68 return "Input cannot be empty";
74 InputDialog dialog
= new InputDialog(HandlerUtil
.getActiveShell(event
),
76 "Enter new " + text
, "",
77 nonEmptyInputValidator
);
79 if (dialog
.open() != Window
.CANCEL
) {
80 ((AnnotatedLineEditor
) editor
).createAnnotatedLineNewObject(key
, dialog
.getValue());
83 ((AnnotatedLineEditor
) editor
).createAnnotatedLineNewObject(key
, "Untitled");
87 ((AnnotatedLineEditor
) editor
).createAnnotatedLineNewObject();