ApplicationWorkbenchAdvisor : added comments
[taxeditor.git] / eu.etaxonomy.taxeditor.bulkeditor / src / main / java / eu / etaxonomy / taxeditor / annotatedlineeditor / handler / NewObjectHandler.java
index 77e5606dd93f109a5cd2bb71127a99f31227aed7..fade7f89bf3e898a9ae0b5d487cbfaefdb3e8d52 100644 (file)
 
 package eu.etaxonomy.taxeditor.annotatedlineeditor.handler;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.IInputValidator;
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.widgets.Event;
@@ -47,7 +51,31 @@ public class NewObjectHandler extends AbstractHandler {
                        if (key != null) {
                                if(!(key instanceof SpecimenOrObservationType)) {
                                        String text = ((Event)event.getTrigger()).text; 
-                                       InputDialog dialog = new InputDialog(HandlerUtil.getActiveShell(event), "Create " + text, "Enter new " + text, "", null); 
+                                       
+                                       //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("User") || text.equals("Group")) {
+                                               nonEmptyInputValidator = new IInputValidator() {
+                                                       public String isValid(String text) {                                                    
+                                                               if(text == null || text.isEmpty()) {
+                                                                       return "Input cannot be empty";
+                                                               }
+                                                               return null;
+                                                       }                       
+                                               };
+                                       }
+                                       InputDialog dialog = new InputDialog(HandlerUtil.getActiveShell(event), 
+                                                       "Create " + text, 
+                                                       "Enter new " + text, "",
+                                                       nonEmptyInputValidator); 
+
                                        if (dialog.open() != Window.CANCEL) { 
                                                ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue()); 
                                        }