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
.e4
.handler
;
12 import javax
.inject
.Named
;
14 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
15 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
17 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
19 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityCreator
;
20 import eu
.etaxonomy
.taxeditor
.bulkeditor
.IBulkEditorConstants
;
21 import eu
.etaxonomy
.taxeditor
.bulkeditor
.e4
.BulkEditorE4
;
29 public class NewObjectHandlerE4
{
32 public void execute(@Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
33 MHandledMenuItem menuItem
) {
35 Object key
= menuItem
.getTransientData().get(IBulkEditorConstants
.DYNAMIC_OPEN_OBJECT_ID
+".key");
37 BulkEditorE4 bulkEditor
= (BulkEditorE4
) activePart
.getObject();
41 IEntityCreator entityCreator
= bulkEditor
.getEditorInput().getEntityCreator();
42 String text
= menuItem
.getCommand().getCommandName();
43 Object createdEntity
= entityCreator
.createEntity(text
);
44 bulkEditor
.getEditorInput().getModel().add(createdEntity
);
47 // if(!(key instanceof SpecimenOrObservationType)) {
49 // //FIXME : This should probably go into some ValidatorFactory
50 // IInputValidator nonEmptyInputValidator = null;
51 // //FIXME : This is a workaround to not allow empty strings in the
52 // // input dialog for User and Group entities.
53 // // Normally this should be default
54 // // behaviour, so we need to discuss whether this handler
55 // // should be used to handle the creating new entities of
56 // // type other than User and Group.
57 // // Once #4348 is fixed this check can be removed.
58 // if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) {
59 // nonEmptyInputValidator = new IInputValidator() {
61 // public String isValid(String text) {
62 // if(text == null || text.isEmpty()) {
63 // return "Input cannot be empty";
69 // InputDialog dialog = new InputDialog(shell,
70 // String.format("Create %s", text), String.format("Enter new %s", text), "",
71 // nonEmptyInputValidator);
73 // if (dialog.open() != Window.CANCEL) {
74 // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue());
77 // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, "Untitled");
81 // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject();