import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Shell;
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
+import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator;
+import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
/**
*
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
+ @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
MHandledMenuItem menuItem) {
Object key = menuItem.getTransientData().get(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID+".key");
BulkEditorE4 bulkEditor = (BulkEditorE4) activePart.getObject();
-
if (key != null) {
- IEntityCreator entityCreator = bulkEditor.getEditorInput().getEntityCreator();
String text = menuItem.getCommand().getCommandName();
- Object createdEntity = entityCreator.createEntity(text);
- bulkEditor.getEditorInput().getModel().add(createdEntity);
- bulkEditor.refresh();
+ //FIXME : This should probably go into some ValidatorFactory
+ IInputValidator nonEmptyInputValidator = null;
+ //FIXME : This is a workaround to not allow empty strings in the
+ // input dialog for User and Group entities.
+ // Normally this should be default
+ // behaviour, so we need to discuss whether this handler
+ // should be used to handle the creating new entities of
+ // type other than User and Group.
+ // Once #4348 is fixed this check can be removed.
+ if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) {
+ nonEmptyInputValidator = new IInputValidator() {
+ @Override
+ public String isValid(String text) {
+ if(text == null || text.isEmpty()) {
+ return "Input cannot be empty";
+ }
+ return null;
+ }
+ };
+ }
+ InputDialog dialog = new InputDialog(shell,
+ String.format("Create %s", text), String.format("Enter new %s", text), "",
+ nonEmptyInputValidator);
- // if(!(key instanceof SpecimenOrObservationType)) {
- //
- // //FIXME : This should probably go into some ValidatorFactory
- // IInputValidator nonEmptyInputValidator = null;
- // //FIXME : This is a workaround to not allow empty strings in the
- // // input dialog for User and Group entities.
- // // Normally this should be default
- // // behaviour, so we need to discuss whether this handler
- // // should be used to handle the creating new entities of
- // // type other than User and Group.
- // // Once #4348 is fixed this check can be removed.
- // if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) {
- // nonEmptyInputValidator = new IInputValidator() {
- // @Override
- // public String isValid(String text) {
- // if(text == null || text.isEmpty()) {
- // return "Input cannot be empty";
- // }
- // return null;
- // }
- // };
- // }
- // InputDialog dialog = new InputDialog(shell,
- // String.format("Create %s", text), String.format("Enter new %s", text), "",
- // nonEmptyInputValidator);
- //
- // if (dialog.open() != Window.CANCEL) {
- // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue());
- // }
- // } else {
- // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, "Untitled");
- // }
- //
- // } else {
- // ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject();
- // }
+ if (dialog.open() != Window.CANCEL) {
+ IEntityCreator entityCreator = bulkEditor.getEditorInput().getEntityCreator();
+ Object createdEntity = entityCreator.createEntity(key, dialog.getValue());
+ bulkEditor.getEditorInput().getModel().add(createdEntity);
+ bulkEditor.refresh(true);
+ bulkEditor.setDirty();
+ }
}
}
}