You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2007/04/22 18:49:25 UTC

svn commit: r531226 - in /directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common: dialogs/SelectEntryDialog.java widgets/search/EntryWidget.java

Author: seelmann
Date: Sun Apr 22 09:49:24 2007
New Revision: 531226

URL: http://svn.apache.org/viewvc?view=rev&rev=531226
Log:
Added local name support, now it's possibe to specify the root entry of the SelectEntryDialog.

Modified:
    directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/SelectEntryDialog.java
    directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/EntryWidget.java

Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/SelectEntryDialog.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/SelectEntryDialog.java?view=diff&rev=531226&r1=531225&r2=531226
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/SelectEntryDialog.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/dialogs/SelectEntryDialog.java Sun Apr 22 09:49:24 2007
@@ -49,7 +49,7 @@
 
     private Image image;
 
-    private IConnection connection;
+    private IEntry rootEntry;
 
     private IEntry initialEntry;
 
@@ -64,20 +64,20 @@
     private BrowserWidget mainWidget;
 
 
-    public SelectEntryDialog( Shell parentShell, String title, IConnection connection, IEntry initialEntry )
+    public SelectEntryDialog( Shell parentShell, String title, IEntry rootEntry, IEntry initialEntry )
     {
         super( parentShell );
         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
         this.title = title;
-        this.connection = connection;
+        this.rootEntry = rootEntry;
         this.initialEntry = initialEntry;
         this.selectedEntry = null;
     }
 
 
-    public SelectEntryDialog( Shell parentShell, String title, Image image, IConnection connection, IEntry initialEntry )
+    public SelectEntryDialog( Shell parentShell, String title, Image image, IEntry rootEntry, IEntry initialEntry )
     {
-        this( parentShell, title, connection, initialEntry );
+        this( parentShell, title, rootEntry, initialEntry );
         this.image = image;
     }
 
@@ -145,7 +145,7 @@
         this.mainWidget = new BrowserWidget( this.configuration, null );
         this.mainWidget.createWidget( composite );
         this.mainWidget.setInput( new IEntry[]
-            { this.connection.getRootDSE() } );
+            { rootEntry } );
 
         // create actions and context menu (and register global actions)
         this.actionGroup = new BrowserActionGroup( this.mainWidget, this.configuration );

Modified: directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/EntryWidget.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/EntryWidget.java?view=diff&rev=531226&r1=531225&r2=531226
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/EntryWidget.java (original)
+++ directory/ldapstudio/trunk/ldapstudio-browser-common/src/main/java/org/apache/directory/ldapstudio/browser/common/widgets/search/EntryWidget.java Sun Apr 22 09:49:24 2007
@@ -75,6 +75,9 @@
     /** The selected DN. */
     private DN dn;
 
+    /** The suffix. */
+    private DN suffix;
+
 
     /**
      * Creates a new instance of EntryWidget.
@@ -94,8 +97,22 @@
      */
     public EntryWidget( IConnection connection, DN dn )
     {
+        this( connection, dn, null );
+    }
+
+
+    /**
+     * Creates a new instance of EntryWidget.
+     *
+     * @param connection the connection
+     * @param dn the initial DN
+     * @param suffix the suffix
+     */
+    public EntryWidget( IConnection connection, DN dn, DN suffix )
+    {
         this.connection = connection;
         this.dn = dn;
+        this.suffix = suffix;
     }
 
 
@@ -163,36 +180,59 @@
             {
                 if ( connection != null )
                 {
-                    IEntry entry = null;
-                    if ( dn != null && dn.getRdns().length > 0 )
+                    // get root entry
+                    IEntry rootEntry = connection.getRootDSE();
+                    if( suffix != null && suffix.getRdns().length > 0 )
                     {
-                        entry = connection.getEntryFromCache( dn );
-                        if ( entry == null )
+                        rootEntry = connection.getEntryFromCache( suffix );
+                        if ( rootEntry == null )
                         {
-                            ReadEntryJob job = new ReadEntryJob( connection, dn );
+                            ReadEntryJob job = new ReadEntryJob( connection, suffix );
                             RunnableContextJobAdapter.execute( job );
-                            entry = job.getReadEntry();
+                            rootEntry = job.getReadEntry();
+                        }
+                    }
+
+                    // calculate initial DN
+                    DN initialDN = dn;
+                    if( suffix != null && suffix.getRdns().length > 0 )
+                    {
+                        if( initialDN != null && initialDN.getRdns().length > 0 )
+                        {
+                            initialDN = new DN( initialDN, suffix );
                         }
                     }
 
-                    if( entry == null )
+                    // get initial entry
+                    IEntry entry = rootEntry;
+                    if ( initialDN != null && initialDN.getRdns().length > 0 )
                     {
-                        entry = connection.getRootDSE();
+                        entry = connection.getEntryFromCache( initialDN );
+                        if ( entry == null )
+                        {
+                            ReadEntryJob job = new ReadEntryJob( connection, initialDN );
+                            RunnableContextJobAdapter.execute( job );
+                            entry = job.getReadEntry();
+                        }
                     }
 
-                    if ( entry != null )
+
+                    // open dialog
+                    SelectEntryDialog dialog = new SelectEntryDialog( parent.getShell(), "Select DN", rootEntry, entry );
+                    dialog.open();
+                    IEntry selectedEntry = dialog.getSelectedEntry();
+
+                    // get selected DN
+                    if ( selectedEntry != null )
                     {
-                        SelectEntryDialog dialog = new SelectEntryDialog( parent.getShell(), "Select DN", connection,
-                            entry );
-                        dialog.open();
-                        IEntry selectedEntry = dialog.getSelectedEntry();
-                        if ( selectedEntry != null )
+                        dn = selectedEntry.getDn();
+                        if( suffix != null && suffix.getRdns().length > 0 )
                         {
-                            dn = selectedEntry.getDn();
-                            dnChanged();
-                            internalSetEnabled();
-                            notifyListeners();
+                            dn = dn.getLocalName( suffix );
                         }
+                        dnChanged();
+                        internalSetEnabled();
+                        notifyListeners();
                     }
                 }
             }
@@ -253,6 +293,17 @@
 
 
     /**
+     * Gets the suffix DN or <code>null</code> if not set.
+     *
+     * @return the suffix DN or <code>null</code> if not set
+     */
+    public DN getSuffix()
+    {
+        return suffix;
+    }
+
+
+    /**
      * Gets the DN or <code>null</code> if the DN isn't valid.
      *
      * @return the DN or <code>null</code> if the DN isn't valid
@@ -282,10 +333,24 @@
      */
     public void setInput( IConnection connection, DN dn )
     {
-        if ( this.connection != connection || this.dn != dn )
+        setInput( connection, dn, null );
+    }
+
+
+    /**
+     * Sets the input.
+     *
+     * @param connection the connection
+     * @param dn the DN
+     * @param suffix the suffix
+     */
+    public void setInput( IConnection connection, DN dn, DN suffix )
+    {
+        if ( this.connection != connection || this.dn != dn || this.suffix != suffix )
         {
             this.connection = connection;
             this.dn = dn;
+            this.suffix = suffix;
             dnChanged();
         }
     }