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 2015/07/04 11:24:35 UTC

svn commit: r1689128 - in /directory/studio/trunk/plugins/common.ui: ./ src/main/java/org/apache/directory/studio/common/ui/dialogs/ src/main/java/org/apache/directory/studio/common/ui/wrappers/

Author: elecharny
Date: Sat Jul  4 09:24:35 2015
New Revision: 1689128

URL: http://svn.apache.org/r1689128
Log:
o Added a wrappers package
o Created a StringValueWrapper class that is used by the AttributeDialog class

Added:
    directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/wrappers/
    directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/wrappers/StringValueWrapper.java
Modified:
    directory/studio/trunk/plugins/common.ui/pom-first.xml
    directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/dialogs/AttributeDialog.java

Modified: directory/studio/trunk/plugins/common.ui/pom-first.xml
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.ui/pom-first.xml?rev=1689128&r1=1689127&r2=1689128&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.ui/pom-first.xml (original)
+++ directory/studio/trunk/plugins/common.ui/pom-first.xml Sat Jul  4 09:24:35 2015
@@ -50,7 +50,9 @@
             <Export-Package>org.apache.directory.studio.common.ui,
  org.apache.directory.studio.common.ui.dialogs,
  org.apache.directory.studio.common.ui.filesystem,
- org.apache.directory.studio.common.ui.widgets</Export-Package>
+ org.apache.directory.studio.common.ui.widgets,
+ org.apache.directory.studio.common.ui.wrappers
+ </Export-Package>
             
             <Require-Bundle>
  org.eclipse.core.runtime,

Modified: directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/dialogs/AttributeDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/dialogs/AttributeDialog.java?rev=1689128&r1=1689127&r2=1689128&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/dialogs/AttributeDialog.java (original)
+++ directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/dialogs/AttributeDialog.java Sat Jul  4 09:24:35 2015
@@ -24,6 +24,7 @@ package org.apache.directory.studio.comm
 import org.apache.directory.studio.common.ui.AddEditDialog;
 import org.apache.directory.studio.common.ui.Messages;
 import org.apache.directory.studio.common.ui.widgets.BaseWidgetUtils;
+import org.apache.directory.studio.common.ui.wrappers.StringValueWrapper;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
@@ -48,7 +49,7 @@ import org.eclipse.swt.widgets.Shell;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class AttributeDialog extends AddEditDialog<String>
+public class AttributeDialog extends AddEditDialog<StringValueWrapper>
 {
     /** The possible attribute types and OIDs. */
     private String[] attributeTypesAndOids;
@@ -94,7 +95,7 @@ public class AttributeDialog extends Add
      */
     protected void okPressed()
     {
-        setEditedElement( typeOrOidCombo.getText() );
+        setEditedElement( new StringValueWrapper( typeOrOidCombo.getText(), false ) );
         super.okPressed();
     }
 
@@ -110,7 +111,7 @@ public class AttributeDialog extends Add
 
         if ( id == IDialogConstants.OK_ID ) 
         {
-            String attribute = (String)getEditedElement();
+            String attribute = ((StringValueWrapper)getEditedElement() ).getValue();
 
             if ( ( attribute == null ) || ( attribute.length() == 0 ) )
             {
@@ -147,7 +148,7 @@ public class AttributeDialog extends Add
         
         if ( getEditedElement() != null )
         {
-            typeOrOidCombo.setText( getEditedElement() );
+            typeOrOidCombo.setText( getEditedElement().getValue() );
         }
         
         typeOrOidCombo.addModifyListener( new ModifyListener()
@@ -197,6 +198,6 @@ public class AttributeDialog extends Add
     public void addNewElement()
     {
         // Default to none
-        setEditedElement( "" );
+        setEditedElement( new StringValueWrapper( "", false  ) );
     }
 }

Added: directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/wrappers/StringValueWrapper.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/wrappers/StringValueWrapper.java?rev=1689128&view=auto
==============================================================================
--- directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/wrappers/StringValueWrapper.java (added)
+++ directory/studio/trunk/plugins/common.ui/src/main/java/org/apache/directory/studio/common/ui/wrappers/StringValueWrapper.java Sat Jul  4 09:24:35 2015
@@ -0,0 +1,156 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.common.ui.wrappers;
+
+/**
+ * A wrapper for a String value.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class StringValueWrapper implements Cloneable, Comparable<StringValueWrapper>
+{
+    /** The value */
+    private String value;
+    
+    /** A flag to tell if the compare should be case sensitive or not */
+    private boolean caseSensitive = true;
+
+    /**
+     * Creates a new instance of StringValueWrapper.
+     *
+     * @param value the value
+     */
+    public StringValueWrapper( String value, boolean caseSensitive )
+    {
+        this.value = value;
+        this.caseSensitive = caseSensitive;
+    }
+
+    
+    /**
+     * @return the value
+     */
+    public String getValue()
+    {
+        return value;
+    }
+
+    /**
+     * @param value the value to set
+     */
+    public void setValue( String value )
+    {
+        this.value = value;
+    }
+    
+    
+    /**
+     * Clone the current object
+     */
+    public StringValueWrapper clone()
+    {
+        try
+        {
+            return (StringValueWrapper)super.clone();
+        }
+        catch ( CloneNotSupportedException e )
+        {
+            return null;
+        }
+    }
+
+    
+    /**
+     * @see Object#equals(Object)
+     */
+    public boolean equals( Object that )
+    {
+        // Quick test
+        if ( this == that )
+        {
+            return true;
+        }
+        
+        if ( that instanceof StringValueWrapper )
+        {
+            StringValueWrapper thatInstance = (StringValueWrapper)that;
+            
+            if ( caseSensitive )
+            {
+                return value.equals( thatInstance.value );
+            }
+            else
+            {
+                return value.equalsIgnoreCase( thatInstance.value );
+            }
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode()
+    {
+        int h = 37;
+        
+        if ( value != null )
+        {
+            h += h*17 + value.hashCode();
+        }
+        
+        return h;
+    }
+
+
+    /**
+     * @see Comparable#compareTo()
+     */
+    public int compareTo( StringValueWrapper that )
+    {
+        if ( that == null )
+        {
+            return 1;
+        }
+        
+        // Check the value
+        if ( ( value == null ) || ( value.length() == 0 ) )
+        {
+            return -1;
+        }
+        else
+        {
+            return value.compareToIgnoreCase( that.value );
+        }
+    }
+    
+    
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        return value;
+    }
+}