You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2017/03/14 10:35:31 UTC

svn commit: r1786868 - /directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java

Author: elecharny
Date: Tue Mar 14 10:35:30 2017
New Revision: 1786868

URL: http://svn.apache.org/viewvc?rev=1786868&view=rev
Log:
o Added a constructor with a Validator
o Added a isvalidValue() implementation
o Returns the typed value even if it's wrong

Modified:
    directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java

Modified: directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java?rev=1786868&r1=1786867&r2=1786868&view=diff
==============================================================================
--- directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java (original)
+++ directory/studio/trunk/plugins/valueeditors/src/main/java/org/apache/directory/studio/valueeditors/bool/InPlaceBooleanValueEditor.java Tue Mar 14 10:35:30 2017
@@ -24,6 +24,7 @@ package org.apache.directory.studio.valu
 import org.apache.directory.api.ldap.model.schema.syntaxCheckers.BooleanSyntaxChecker;
 import org.apache.directory.studio.ldapbrowser.core.model.IValue;
 import org.apache.directory.studio.valueeditors.AbstractInPlaceStringValueEditor;
+import org.eclipse.jface.viewers.ICellEditorValidator;
 
 
 /**
@@ -40,6 +41,50 @@ public class InPlaceBooleanValueEditor e
     /** The 'FALSE' value */
     private static final String FALSE = "FALSE";
 
+    /**
+     * Create a new instance of a InPlaceBooleanValueEditor which sets
+     * a validator.
+     */
+    public InPlaceBooleanValueEditor()
+    {
+        super();
+        
+        setValidator(new ICellEditorValidator()
+        {
+            @Override
+            public String isValid( Object value )
+            {
+                if ( value instanceof String )
+                {
+                    String stringValue = ( ( String ) value ).toUpperCase();
+                    
+                    switch ( stringValue )
+                    {
+                        case "F" :
+                        case "FALSE" :
+                        case "N" :
+                        case "NO" :
+                        case "0" :
+                        case "T" :
+                        case "TRUE" :
+                        case "Y" :
+                        case "YES" :
+                        case "1" :
+                        case "" :           // Special case : default to TRUE
+                            return null;
+
+                        default :
+                            return "Invalid boolean";
+                    }
+                }
+                else
+                {
+                    return "Invalid boolean";
+                }
+            }
+        });
+    }
+
 
     /**
      * {@inheritDoc}
@@ -51,9 +96,9 @@ public class InPlaceBooleanValueEditor e
 
         if ( value instanceof String )
         {
-            String stringValue = ( ( String ) value ).toUpperCase();
+            String stringValue = ( String ) value;
             
-            switch ( stringValue )
+            switch ( stringValue.toUpperCase() )
             {
                 case "F" :
                 case "FALSE" :
@@ -71,35 +116,22 @@ public class InPlaceBooleanValueEditor e
                     return TRUE;
 
                 default :
-                    return null;
+                    return stringValue;
             }
         }
 
         return value;
     }
 
-
+    
     /**
      * {@inheritDoc}
-     *
+     */
     @Override
-    protected void doSetValue( Object value )
+    public boolean isValueValid() 
     {
-        Object v = value;
-        
-        if ( value instanceof IValue.EmptyValue )
-        {
-            v = ( ( IValue.EmptyValue ) value ).getStringValue();
-        }
-        
-        if ( value == null )
-        {
-            v = "TRUE";
-        }
-        
-        super.doSetValue( v );
+        return doGetValue() != null;
     }
-    */
 
 
     /**