Revision a2a04809
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/e4/handler/NewObjectHandlerE4.java | ||
---|---|---|
15 | 15 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
16 | 16 |
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem; |
17 | 17 |
import org.eclipse.e4.ui.services.IServiceConstants; |
18 |
import org.eclipse.jface.dialogs.IInputValidator; |
|
19 |
import org.eclipse.jface.dialogs.InputDialog; |
|
20 |
import org.eclipse.jface.window.Window; |
|
21 |
import org.eclipse.swt.widgets.Shell; |
|
18 | 22 |
|
19 | 23 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator; |
20 | 24 |
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants; |
21 | 25 |
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4; |
26 |
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator; |
|
27 |
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator; |
|
22 | 28 |
|
23 | 29 |
/** |
24 | 30 |
* |
... | ... | |
30 | 36 |
|
31 | 37 |
@Execute |
32 | 38 |
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart, |
39 |
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell, |
|
33 | 40 |
MHandledMenuItem menuItem) { |
34 | 41 |
|
35 | 42 |
Object key = menuItem.getTransientData().get(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID+".key"); |
36 | 43 |
|
37 | 44 |
BulkEditorE4 bulkEditor = (BulkEditorE4) activePart.getObject(); |
38 | 45 |
|
39 |
|
|
40 | 46 |
if (key != null) { |
41 |
IEntityCreator entityCreator = bulkEditor.getEditorInput().getEntityCreator(); |
|
42 | 47 |
String text = menuItem.getCommand().getCommandName(); |
43 |
Object createdEntity = entityCreator.createEntity(text); |
|
44 |
bulkEditor.getEditorInput().getModel().add(createdEntity); |
|
45 |
bulkEditor.refresh(); |
|
48 |
//FIXME : This should probably go into some ValidatorFactory |
|
49 |
IInputValidator nonEmptyInputValidator = null; |
|
50 |
//FIXME : This is a workaround to not allow empty strings in the |
|
51 |
// input dialog for User and Group entities. |
|
52 |
// Normally this should be default |
|
53 |
// behaviour, so we need to discuss whether this handler |
|
54 |
// should be used to handle the creating new entities of |
|
55 |
// type other than User and Group. |
|
56 |
// Once #4348 is fixed this check can be removed. |
|
57 |
if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) { |
|
58 |
nonEmptyInputValidator = new IInputValidator() { |
|
59 |
@Override |
|
60 |
public String isValid(String text) { |
|
61 |
if(text == null || text.isEmpty()) { |
|
62 |
return "Input cannot be empty"; |
|
63 |
} |
|
64 |
return null; |
|
65 |
} |
|
66 |
}; |
|
67 |
} |
|
68 |
InputDialog dialog = new InputDialog(shell, |
|
69 |
String.format("Create %s", text), String.format("Enter new %s", text), "", |
|
70 |
nonEmptyInputValidator); |
|
46 | 71 |
|
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 |
// } |
|
72 |
if (dialog.open() != Window.CANCEL) { |
|
73 |
IEntityCreator entityCreator = bulkEditor.getEditorInput().getEntityCreator(); |
|
74 |
Object createdEntity = entityCreator.createEntity(key, dialog.getValue()); |
|
75 |
bulkEditor.getEditorInput().getModel().add(createdEntity); |
|
76 |
bulkEditor.refresh(true); |
|
77 |
bulkEditor.setDirty(); |
|
78 |
} |
|
83 | 79 |
} |
84 | 80 |
} |
85 | 81 |
} |
Also available in: Unified diff
ref #6932 Fix new element handler and save