ref #6932 Migrate bulk editor handlers and add annotation merge support
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / annotatedlineeditor / e4 / handler / NewObjectHandlerE4.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.annotatedlineeditor.e4.handler;
11
12 import javax.inject.Named;
13
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;
18
19 import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
20 import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
21 import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
22
23 /**
24 *
25 * @author pplitzner
26 * @date 12.09.2017
27 *
28 */
29 public class NewObjectHandlerE4 {
30
31 @Execute
32 public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
33 MHandledMenuItem menuItem) {
34
35 Object key = menuItem.getTransientData().get(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID+".key");
36
37 BulkEditorE4 bulkEditor = (BulkEditorE4) activePart.getObject();
38
39
40 if (key != null) {
41 IEntityCreator entityCreator = bulkEditor.getEditorInput().getEntityCreator();
42 String text = menuItem.getCommand().getCommandName();
43 Object createdEntity = entityCreator.createEntity(text);
44 bulkEditor.getEditorInput().getModel().add(createdEntity);
45 bulkEditor.refresh();
46
47 // if(!(key instanceof SpecimenOrObservationType)) {
48 //
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() {
60 // @Override
61 // public String isValid(String text) {
62 // if(text == null || text.isEmpty()) {
63 // return "Input cannot be empty";
64 // }
65 // return null;
66 // }
67 // };
68 // }
69 // InputDialog dialog = new InputDialog(shell,
70 // String.format("Create %s", text), String.format("Enter new %s", text), "",
71 // nonEmptyInputValidator);
72 //
73 // if (dialog.open() != Window.CANCEL) {
74 // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue());
75 // }
76 // } else {
77 // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, "Untitled");
78 // }
79 //
80 // } else {
81 // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject();
82 // }
83 }
84 }
85 }