directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1291282 - in /directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common: dialogs/RenameEntryDialog.java widgets/DnBuilderWidget.java
Date Mon, 20 Feb 2012 14:34:35 GMT
Author: pamarcelot
Date: Mon Feb 20 14:34:35 2012
New Revision: 1291282

URL: http://svn.apache.org/viewvc?rev=1291282&view=rev
Log:
Fix for DIRSTUDIO-783 (The 'Rename Entry' dialog doesn't resize automatically when adding
or removing RDN parts).

Modified:
    directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/RenameEntryDialog.java
    directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java

Modified: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/RenameEntryDialog.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/RenameEntryDialog.java?rev=1291282&r1=1291281&r2=1291282&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/RenameEntryDialog.java
(original)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/dialogs/RenameEntryDialog.java
Mon Feb 20 14:34:35 2012
@@ -69,6 +69,9 @@ public class RenameEntryDialog extends D
     /** The new rdn. */
     private Rdn rdn;
 
+    /** The initialization flag */
+    private boolean initialized = false;
+
 
     /**
      * Creates a new instance of RenameEntryDialog.
@@ -151,6 +154,9 @@ public class RenameEntryDialog extends D
         dnBuilderWidget.setInput( entry.getBrowserConnection(), allAttributeNames, entry.getRdn(),
null );
 
         applyDialogFont( composite );
+
+        initialized = true;
+
         return composite;
     }
 
@@ -164,6 +170,12 @@ public class RenameEntryDialog extends D
         {
             okButton.setEnabled( dnBuilderWidget.getRdn() != null );
         }
+
+        // Forcing the redraw of the whole dialog
+        if ( initialized && ( getShell() != null ) && ( !getShell().isDisposed()
) )
+        {
+            getShell().pack();
+        }
     }
 
 

Modified: directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java?rev=1291282&r1=1291281&r2=1291282&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
(original)
+++ directory/studio/trunk/plugins/ldapbrowser.common/src/main/java/org/apache/directory/studio/ldapbrowser/common/widgets/DnBuilderWidget.java
Mon Feb 20 14:34:35 2012
@@ -41,6 +41,7 @@ import org.eclipse.swt.events.ModifyEven
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
@@ -104,6 +105,45 @@ public class DnBuilderWidget extends Bro
     /** The preview text. */
     private Text previewText;
 
+    // Listeners
+    private SelectionListener rdnAddButtonSelectionListener = new SelectionAdapter()
+    {
+        public void widgetSelected( SelectionEvent e )
+        {
+            int index = rdnLineList.size();
+            for ( int i = 0; i < rdnLineList.size(); i++ )
+            {
+                RdnLine rdnLine = rdnLineList.get( i );
+                if ( rdnLine.rdnAddButton == e.widget )
+                {
+                    index = i + 1;
+                }
+            }
+            addRdnLine( rdnComposite, index );
+
+            validate();
+        }
+    };
+
+    private SelectionListener rdnDeleteButtonSelectionListener = new SelectionAdapter()
+    {
+        public void widgetSelected( SelectionEvent e )
+        {
+            int index = 0;
+            for ( int i = 0; i < rdnLineList.size(); i++ )
+            {
+                RdnLine rdnLine = rdnLineList.get( i );
+                if ( rdnLine.rdnDeleteButton == e.widget )
+                {
+                    index = i;
+                }
+            }
+            deleteRdnLine( rdnComposite, index );
+
+            validate();
+        }
+    };
+
 
     /**
      * Creates a new instance of DnBuilderWidget.
@@ -174,8 +214,14 @@ public class DnBuilderWidget extends Bro
                 {
                     Ava ava = atavIterator.next();
                     addRdnLine( rdnComposite, i );
+
+                    removeRdnLineListeners( i );
+
                     rdnLineList.get( i ).rdnTypeCombo.setText( ava.getUpType() );
                     rdnLineList.get( i ).rdnValueText.setText( ava.getNormValue().getString()
);
+
+                    addRdnLineListeners( i );
+
                     if ( i == 0 )
                     {
                         if ( "".equals( rdnLineList.get( i ).rdnTypeCombo ) ) //$NON-NLS-1$
@@ -304,7 +350,7 @@ public class DnBuilderWidget extends Bro
     public void validate()
     {
         Exception rdnE = null;
-        
+
         if ( showRDN )
         {
             try
@@ -312,10 +358,10 @@ public class DnBuilderWidget extends Bro
                 // calculate Rdn
                 String[] rdnTypes = new String[rdnLineList.size()];
                 String[] rdnValues = new String[rdnLineList.size()];
-                
+
                 for ( int i = 0; i < rdnLineList.size(); i++ )
                 {
-                    RdnLine rdnLine = ( RdnLine ) rdnLineList.get( i );
+                    RdnLine rdnLine = rdnLineList.get( i );
                     rdnTypes[i] = rdnLine.rdnTypeCombo.getText();
                     rdnValues[i] = rdnLine.rdnValueText.getText();
 
@@ -328,7 +374,7 @@ public class DnBuilderWidget extends Bro
                         rdnLine.rdnDeleteButton.setEnabled( false );
                     }
                 }
-                
+
                 rdn = DnUtils.composeRdn( rdnTypes, rdnValues );
             }
             catch ( Exception e )
@@ -339,7 +385,7 @@ public class DnBuilderWidget extends Bro
         }
 
         Exception parentE = null;
-        
+
         if ( showParent )
         {
             try
@@ -355,12 +401,12 @@ public class DnBuilderWidget extends Bro
         }
 
         String s = ""; //$NON-NLS-1$
-        
+
         if ( rdnE != null )
         {
             s += rdnE.getMessage() != null ? rdnE.getMessage() : Messages.getString( "DnBuilderWidget.ErrorInRDN"
); //$NON-NLS-1$
         }
-        
+
         if ( parentE != null )
         {
             s += ", " + parentE.getMessage() != null ? parentE.getMessage() : Messages.getString(
"DnBuilderWidget.ErrorInParentDN" ); //$NON-NLS-1$ //$NON-NLS-2$
@@ -407,7 +453,7 @@ public class DnBuilderWidget extends Bro
                 {
                     dn = Dn.EMPTY_DN;
                 }
-                
+
                 previewText.setText( dn.getName() );
             }
         }
@@ -497,67 +543,30 @@ public class DnBuilderWidget extends Bro
 
         rdnLine.rdnAddButton = new Button( rdnComposite, SWT.PUSH );
         rdnLine.rdnAddButton.setText( "  +   " ); //$NON-NLS-1$
-        rdnLine.rdnAddButton.addSelectionListener( new SelectionAdapter()
-        {
-            public void widgetSelected( SelectionEvent e )
-            {
-                int index = rdnLineList.size();
-                for ( int i = 0; i < rdnLineList.size(); i++ )
-                {
-                    RdnLine rdnLine = ( RdnLine ) rdnLineList.get( i );
-                    if ( rdnLine.rdnAddButton == e.widget )
-                    {
-                        index = i + 1;
-                    }
-                }
-                addRdnLine( rdnComposite, index );
-
-                validate();
-            }
-        } );
 
         rdnLine.rdnDeleteButton = new Button( rdnComposite, SWT.PUSH );
         rdnLine.rdnDeleteButton.setText( "  \u2212  " ); //$NON-NLS-1$
-        rdnLine.rdnDeleteButton.addSelectionListener( new SelectionAdapter()
-        {
-            public void widgetSelected( SelectionEvent e )
-            {
-                int index = 0;
-                for ( int i = 0; i < rdnLineList.size(); i++ )
-                {
-                    RdnLine rdnLine = ( RdnLine ) rdnLineList.get( i );
-                    if ( rdnLine.rdnDeleteButton == e.widget )
-                    {
-                        index = i;
-                    }
-                }
-                deleteRdnLine( rdnComposite, index );
-
-                validate();
-            }
-        } );
 
         if ( attributeNames != null )
         {
             rdnLine.rdnTypeCombo.setItems( attributeNames );
         }
 
-        rdnLine.rdnTypeCombo.addModifyListener( this );
-        rdnLine.rdnValueText.addModifyListener( this );
+        addRdnLineListeners( rdnLine );
 
         return rdnLine;
     }
 
 
     /**
-     * Delete thd Rdn line on the given index.
+     * Delete the Rdn line on the given index.
      * 
      * @param rdnComposite the Rdn composite
      * @param index the index
      */
     private void deleteRdnLine( Composite rdnComposite, int index )
     {
-        RdnLine rdnLine = ( RdnLine ) rdnLineList.remove( index );
+        RdnLine rdnLine = rdnLineList.remove( index );
         if ( rdnLine != null )
         {
             rdnLine.rdnTypeCombo.dispose();
@@ -573,6 +582,68 @@ public class DnBuilderWidget extends Bro
         }
     }
 
+
+    /**
+     * Adds listeners for the Rdn line at the given index.
+     *
+     * @param index the index
+     */
+    private void addRdnLineListeners( int index )
+    {
+        if ( rdnLineList != null )
+        {
+            addRdnLineListeners( rdnLineList.get( index ) );
+        }
+    }
+
+
+    /**
+     * Adds listeners for the Rdn line.
+     *
+     * @param rdnLine the Rdn line
+     */
+    private void addRdnLineListeners( RdnLine rdnLine )
+    {
+        if ( rdnLine != null )
+        {
+            rdnLine.rdnAddButton.addSelectionListener( rdnAddButtonSelectionListener );
+            rdnLine.rdnDeleteButton.addSelectionListener( rdnDeleteButtonSelectionListener
);
+            rdnLine.rdnTypeCombo.addModifyListener( this );
+            rdnLine.rdnValueText.addModifyListener( this );
+        }
+    }
+
+
+    /**
+     * Removes listeners for the Rdn line at the given index.
+     *
+     * @param index the index
+     */
+    private void removeRdnLineListeners( int index )
+    {
+        if ( rdnLineList != null )
+        {
+            removeRdnLineListeners( rdnLineList.get( index ) );
+        }
+    }
+
+
+    /**
+     * Removes listeners for the Rdn line.
+     *
+     * @param rdnLine the Rdn line
+     */
+    private void removeRdnLineListeners( RdnLine rdnLine )
+    {
+        if ( rdnLine != null )
+        {
+            rdnLine.rdnAddButton.removeSelectionListener( rdnAddButtonSelectionListener );
+            rdnLine.rdnDeleteButton.removeSelectionListener( rdnDeleteButtonSelectionListener
);
+            rdnLine.rdnTypeCombo.removeModifyListener( this );
+            rdnLine.rdnValueText.removeModifyListener( this );
+        }
+    }
+
     /**
      * The Class RdnLine is a wrapper for all input elements
      * of an Rdn line. It contains a combo for the Rdn attribute,



Mime
View raw message