2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.handler
;
12 import org
.eclipse
.core
.commands
.AbstractHandler
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.jface
.dialogs
.IInputValidator
;
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
;
23 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
24 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.AnnotatedLineEditor
;
25 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.entitycreator
.GroupCreator
;
26 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.entitycreator
.UserCreator
;
29 * <p>NewObjectHandler class.</p>
35 public class NewObjectHandler
extends AbstractHandler
{
38 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
42 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
44 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
45 IEditorInput input
= editor
.getEditorInput();
47 if (editor
instanceof AnnotatedLineEditor
) {
49 Object key
= ((Event
)event
.getTrigger()).data
;
51 if(!(key
instanceof SpecimenOrObservationType
)) {
52 String text
= ((Event
)event
.getTrigger()).text
;
54 //FIXME : This should probably go into some ValidatorFactory
55 IInputValidator nonEmptyInputValidator
= null;
56 //FIXME : This is a workaround to not allow empty strings in the
57 // input dialog for User and Group entities.
58 // Normally this should be default
59 // behaviour, so we need to discuss whether this handler
60 // should be used to handle the creating new entities of
61 // type other than User and Group.
62 // Once #4348 is fixed this check can be removed.
63 if(text
.equals(UserCreator
.USER
) || text
.equals(GroupCreator
.GROUP
)) {
64 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
),
75 String
.format("Create %s", text
), String
.format("Enter new %s", text
), "",
76 nonEmptyInputValidator
);
78 if (dialog
.open() != Window
.CANCEL
) {
79 ((AnnotatedLineEditor
) editor
).createAnnotatedLineNewObject(key
, dialog
.getValue());
82 ((AnnotatedLineEditor
) editor
).createAnnotatedLineNewObject(key
, "Untitled");
86 ((AnnotatedLineEditor
) editor
).createAnnotatedLineNewObject();