directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r775092 - in /directory/studio/trunk: connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/ ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/ ldapbrowser-core/src/main/java/or...
Date Fri, 15 May 2009 11:50:10 GMT
Author: seelmann
Date: Fri May 15 11:50:10 2009
New Revision: 775092

URL: http://svn.apache.org/viewvc?rev=775092&view=rev
Log:
Refresh of attributes and children in the browser tree must be sequential

Modified:
    directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/StudioConnectionJob.java
    directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java
    directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/StudioBrowserJob.java

Modified: directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/StudioConnectionJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/StudioConnectionJob.java?rev=775092&r1=775091&r2=775092&view=diff
==============================================================================
--- directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/StudioConnectionJob.java
(original)
+++ directory/studio/trunk/connection-core/src/main/java/org/apache/directory/studio/connection/core/jobs/StudioConnectionJob.java
Fri May 15 11:50:10 2009
@@ -33,7 +33,7 @@
 
 
 /**
- * Job to run a {@link StudioRunnableWithProgress}.
+ * Job to run {@link StudioRunnableWithProgress} runnables.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -41,23 +41,19 @@
 public class StudioConnectionJob extends Job
 {
 
-    /** The runnable. */
-    private StudioRunnableWithProgress runnable;
-
-    /** The external progress monitor. */
-    private IProgressMonitor externalProgressMonitor;
-
-    /** The external result. */
-    private IStatus externalResult;
+    /** The runnables. */
+    private StudioRunnableWithProgress[] runnables;
 
 
     /**
-     * Creates a new instance of AbstractConnectionJob.
+     * Creates a new instance of StudioConnectionJob.
+     * 
+     * @param runnables the runnables to run
      */
-    public StudioConnectionJob( StudioRunnableWithProgress runnable )
+    public StudioConnectionJob( StudioRunnableWithProgress... runnables )
     {
-        super( runnable.getName() ); //$NON-NLS-1$
-        this.runnable = runnable;
+        super( runnables[0].getName() );
+        this.runnables = runnables;
     }
 
 
@@ -66,34 +62,37 @@
      */
     protected final IStatus run( IProgressMonitor ipm )
     {
-        StudioProgressMonitor monitor = new StudioProgressMonitor( externalProgressMonitor
== null ? ipm
-            : externalProgressMonitor );
+        StudioProgressMonitor monitor = new StudioProgressMonitor( ipm );
 
         // ensure that connections are opened
-        Connection[] connections = runnable.getConnections();
-        if ( connections != null )
+        for ( StudioRunnableWithProgress runnable : runnables )
         {
-            for ( Connection connection : connections )
+            Connection[] connections = runnable.getConnections();
+            if ( connections != null )
             {
-                if ( connection != null && !connection.getJNDIConnectionWrapper().isConnected()
)
+                for ( Connection connection : connections )
                 {
-                    monitor.setTaskName( Messages.bind( Messages.jobs__open_connections_task,
new String[]
-                        { connection.getName() } ) );
-                    monitor.worked( 1 );
-
-                    connection.getJNDIConnectionWrapper().connect( monitor );
-                    if ( connection.getJNDIConnectionWrapper().isConnected() )
+                    if ( connection != null && !connection.getJNDIConnectionWrapper().isConnected()
)
                     {
-                        connection.getJNDIConnectionWrapper().bind( monitor );
-                    }
+                        monitor.setTaskName( Messages.bind( Messages.jobs__open_connections_task,
new String[]
+                            { connection.getName() } ) );
+                        monitor.worked( 1 );
 
-                    if ( connection.getJNDIConnectionWrapper().isConnected() )
-                    {
-                        for ( IConnectionListener listener : ConnectionCorePlugin.getDefault().getConnectionListeners()
)
+                        connection.getJNDIConnectionWrapper().connect( monitor );
+                        if ( connection.getJNDIConnectionWrapper().isConnected() )
                         {
-                            listener.connectionOpened( connection, monitor );
+                            connection.getJNDIConnectionWrapper().bind( monitor );
+                        }
+
+                        if ( connection.getJNDIConnectionWrapper().isConnected() )
+                        {
+                            for ( IConnectionListener listener : ConnectionCorePlugin.getDefault()
+                                .getConnectionListeners() )
+                            {
+                                listener.connectionOpened( connection, monitor );
+                            }
+                            ConnectionEventRegistry.fireConnectionOpened( connection, this
);
                         }
-                        ConnectionEventRegistry.fireConnectionOpened( connection, this );
                     }
                 }
             }
@@ -104,25 +103,27 @@
         {
             try
             {
-                if ( runnable instanceof StudioBulkRunnableWithProgress )
+                for ( StudioRunnableWithProgress runnable : runnables )
                 {
-                    StudioBulkRunnableWithProgress bulkRunnable = ( StudioBulkRunnableWithProgress
) runnable;
-                    suspendEventFireingInCurrentThread();
-                    try
+                    if ( runnable instanceof StudioBulkRunnableWithProgress )
                     {
-                        bulkRunnable.run( monitor );
+                        StudioBulkRunnableWithProgress bulkRunnable = ( StudioBulkRunnableWithProgress
) runnable;
+                        suspendEventFiringInCurrentThread();
+                        try
+                        {
+                            bulkRunnable.run( monitor );
+                        }
+                        finally
+                        {
+                            resumeEventFiringInCurrentThread();
+                        }
+                        bulkRunnable.runNotification();
                     }
-                    finally
+                    else
                     {
-                        resumeEventFireingInCurrentThread();
+                        runnable.run( monitor );
                     }
-                    bulkRunnable.runNotification();
-                }
-                else
-                {
-                    runnable.run( monitor );
                 }
-
             }
             catch ( Exception e )
             {
@@ -138,70 +139,38 @@
         // error handling
         if ( monitor.isCanceled() )
         {
-            externalResult = Status.CANCEL_STATUS;
             return Status.CANCEL_STATUS;
         }
         else if ( monitor.errorsReported() )
         {
-            externalResult = monitor.getErrorStatus( runnable.getErrorMessage() );
-            if ( externalProgressMonitor == null )
-            {
-                return externalResult;
-            }
-            else
-            {
-                return Status.OK_STATUS;
-            }
+            return Status.OK_STATUS;
         }
         else
         {
-            externalResult = Status.OK_STATUS;
             return Status.OK_STATUS;
         }
+
     }
 
 
     /**
-     * Suspends event fireing in current thread.
+     * Suspends event firing in current thread.
      */
-    protected void suspendEventFireingInCurrentThread()
+    protected void suspendEventFiringInCurrentThread()
     {
         ConnectionEventRegistry.suspendEventFiringInCurrentThread();
     }
 
 
     /**
-     * Resumes event fireing in current thread.
+     * Resumes event firing in current thread.
      */
-    protected void resumeEventFireingInCurrentThread()
+    protected void resumeEventFiringInCurrentThread()
     {
         ConnectionEventRegistry.resumeEventFiringInCurrentThread();
     }
 
 
-//    /**
-//     * Sets the external progress monitor.
-//     * 
-//     * @param externalProgressMonitor the external progress monitor
-//     */
-//    public void setExternalProgressMonitor( IProgressMonitor externalProgressMonitor )
-//    {
-//        this.externalProgressMonitor = externalProgressMonitor;
-//    }
-//
-//
-//    /**
-//     * Gets the result of the executed job. Either Status.OK_STATUS, 
-//     * Status.CANCEL_STATUS or an error status.
-//     * 
-//     * @return the result of the executed job
-//     */
-//    public IStatus getExternalResult()
-//    {
-//        return this.externalResult;
-//    }
-
-
     /**
      * Executes the job.
      */
@@ -220,30 +189,36 @@
         // We don't schedule a job if the same type of runnable should run
         // that works on the same entry as the current runnable.
 
-        Object[] myLockedObjects = runnable.getLockedObjects();
-        String[] myLockedObjectsIdentifiers = getLockIdentifiers( myLockedObjects );
-
-        Job[] jobs = getJobManager().find( null );
-        for ( int i = 0; i < jobs.length; i++ )
+        for ( StudioRunnableWithProgress runnable : runnables )
         {
-            Job job = jobs[i];
-            if ( job instanceof StudioConnectionJob )
+            Object[] myLockedObjects = runnable.getLockedObjects();
+            String[] myLockedObjectsIdentifiers = getLockIdentifiers( myLockedObjects );
+
+            Job[] jobs = getJobManager().find( null );
+            for ( int i = 0; i < jobs.length; i++ )
             {
-                StudioConnectionJob otherJob = ( StudioConnectionJob ) job;
-                if ( this.runnable.getClass() == otherJob.runnable.getClass() &&
this.runnable != otherJob.runnable )
+                Job job = jobs[i];
+                if ( job instanceof StudioConnectionJob )
                 {
-                    Object[] otherLockedObjects = otherJob.runnable.getLockedObjects();
-                    String[] otherLockedObjectIdentifiers = getLockIdentifiers( otherLockedObjects
);
-
-                    for ( int j = 0; j < otherLockedObjectIdentifiers.length; j++ )
+                    StudioConnectionJob otherJob = ( StudioConnectionJob ) job;
+                    for ( StudioRunnableWithProgress otherRunnable : otherJob.runnables )
                     {
-                        String other = otherLockedObjectIdentifiers[j];
-                        for ( int k = 0; k < myLockedObjectsIdentifiers.length; k++ )
+                        if ( runnable.getClass() == otherRunnable.getClass() && runnable
!= otherRunnable )
                         {
-                            String my = myLockedObjectsIdentifiers[k];
-                            if ( other.startsWith( my ) || my.startsWith( other ) )
+                            Object[] otherLockedObjects = otherRunnable.getLockedObjects();
+                            String[] otherLockedObjectIdentifiers = getLockIdentifiers( otherLockedObjects
);
+
+                            for ( int j = 0; j < otherLockedObjectIdentifiers.length;
j++ )
                             {
-                                return false;
+                                String other = otherLockedObjectIdentifiers[j];
+                                for ( int k = 0; k < myLockedObjectsIdentifiers.length;
k++ )
+                                {
+                                    String my = myLockedObjectsIdentifiers[k];
+                                    if ( other.startsWith( my ) || my.startsWith( other )
)
+                                    {
+                                        return false;
+                                    }
+                                }
                             }
                         }
                     }

Modified: directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java?rev=775092&r1=775091&r2=775092&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java
(original)
+++ directory/studio/trunk/ldapbrowser-common/src/main/java/org/apache/directory/studio/ldapbrowser/common/actions/RefreshAction.java
Fri May 15 11:50:10 2009
@@ -23,17 +23,21 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
 import org.apache.directory.studio.ldapbrowser.common.BrowserCommonActivator;
 import org.apache.directory.studio.ldapbrowser.common.BrowserCommonConstants;
 import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeAttributesRunnable;
 import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeChildrenRunnable;
+import org.apache.directory.studio.ldapbrowser.core.jobs.InitializeRootDSERunnable;
 import org.apache.directory.studio.ldapbrowser.core.jobs.SearchRunnable;
 import org.apache.directory.studio.ldapbrowser.core.jobs.StudioBrowserJob;
+import org.apache.directory.studio.ldapbrowser.core.model.IBookmark;
 import org.apache.directory.studio.ldapbrowser.core.model.IEntry;
 import org.apache.directory.studio.ldapbrowser.core.model.IRootDSE;
 import org.apache.directory.studio.ldapbrowser.core.model.ISearch;
+import org.apache.directory.studio.ldapbrowser.core.model.ISearchResult;
 import org.eclipse.jface.resource.ImageDescriptor;
 
 
@@ -59,16 +63,16 @@
      */
     public String getText()
     {
-        IEntry[] entries = getEntries();
+        List<IEntry> entries = getEntries();
         ISearch[] searches = getSearches();
         IEntry entryInput = getEntryInput();
         ISearch searchInput = getSearchInput();
 
-        if ( entries.length > 0 && searches.length == 0 && entryInput
== null && searchInput == null )
+        if ( entries.size() > 0 && searches.length == 0 && entryInput
== null && searchInput == null )
         {
-            return Messages.getString("RefreshAction.ReloadAttributesAndChildren"); //$NON-NLS-1$
+            return Messages.getString( "RefreshAction.ReloadAttributesAndChildren" ); //$NON-NLS-1$
         }
-        else if ( searches.length > 0 && entries.length == 0 && entryInput
== null && searchInput == null )
+        else if ( searches.length > 0 && entries.size() == 0 && entryInput
== null && searchInput == null )
         {
             boolean searchAgain = true;
             for ( int i = 0; i < searches.length; i++ )
@@ -81,24 +85,24 @@
             }
             if ( searchAgain )
             {
-                return Messages.getString("RefreshAction.SearchAgain"); //$NON-NLS-1$
+                return Messages.getString( "RefreshAction.SearchAgain" ); //$NON-NLS-1$
             }
             else
             {
-                return searches.length == 1 ? Messages.getString("RefreshAction.PerformSearch")
: Messages.getString("RefreshAction.PerformSearches"); //$NON-NLS-1$ //$NON-NLS-2$
+                return searches.length == 1 ? Messages.getString( "RefreshAction.PerformSearch"
) : Messages.getString( "RefreshAction.PerformSearches" ); //$NON-NLS-1$ //$NON-NLS-2$
             }
         }
-        else if ( entryInput != null && searches.length == 0 && entries.length
== 0 && searchInput == null )
+        else if ( entryInput != null && searches.length == 0 && entries.size()
== 0 && searchInput == null )
         {
-            return Messages.getString("RefreshAction.RelaodAttributes"); //$NON-NLS-1$
+            return Messages.getString( "RefreshAction.RelaodAttributes" ); //$NON-NLS-1$
         }
         else if ( searchInput != null && searches.length == 0 && entryInput
== null )
         {
-            return searchInput.getSearchResults() == null ? Messages.getString("RefreshAction.PerformSearch")
: Messages.getString("RefreshAction.SearchAgain"); //$NON-NLS-1$ //$NON-NLS-2$
+            return searchInput.getSearchResults() == null ? Messages.getString( "RefreshAction.PerformSearch"
) : Messages.getString( "RefreshAction.SearchAgain" ); //$NON-NLS-1$ //$NON-NLS-2$
         }
         else
         {
-            return Messages.getString("RefreshAction.Refresh"); //$NON-NLS-1$
+            return Messages.getString( "RefreshAction.Refresh" ); //$NON-NLS-1$
         }
     }
 
@@ -126,21 +130,32 @@
      */
     public void run()
     {
-        IEntry[] entries = getEntries();
+        List<IEntry> entries = getEntries();
         ISearch[] searches = getSearches();
         IEntry entryInput = getEntryInput();
         ISearch searchInput = getSearchInput();
 
-        if ( entries.length > 0 )
+        if ( entries.size() > 0 )
         {
-            boolean foa = entries[0].getBrowserConnection().isFetchOperationalAttributes()
-                || entries[0].isOperationalAttributesInitialized();
-            new StudioBrowserJob( new InitializeAttributesRunnable( entries, foa ) ).execute();
+            boolean foa = entries.get( 0 ).getBrowserConnection().isFetchOperationalAttributes()
+                || entries.get( 0 ).isOperationalAttributesInitialized();
+
             // avoid duplicate search on Root DSE
-            if ( entries.length > 1 || !( entries[0] instanceof IRootDSE ) )
+            for ( Iterator<IEntry> it = entries.iterator(); it.hasNext(); )
             {
-                new StudioBrowserJob( new InitializeChildrenRunnable( entries ) ).execute();
+                IEntry entry = it.next();
+                if ( entry instanceof IRootDSE )
+                {
+                    new StudioBrowserJob( new InitializeRootDSERunnable( ( IRootDSE ) entry
) ).execute();
+                    it.remove();
+                }
             }
+
+            InitializeAttributesRunnable initializeAttributesRunnable = new InitializeAttributesRunnable(
entries
+                .toArray( new IEntry[0] ), foa );
+            InitializeChildrenRunnable initializeChildrenRunnable = new InitializeChildrenRunnable(
entries
+                .toArray( new IEntry[0] ) );
+            new StudioBrowserJob( initializeAttributesRunnable, initializeChildrenRunnable
).execute();
         }
         if ( searches.length > 0 )
         {
@@ -172,12 +187,12 @@
      */
     public boolean isEnabled()
     {
-        IEntry[] entries = getEntries();
+        List<IEntry> entries = getEntries();
         ISearch[] searches = getSearches();
         IEntry entryInput = getEntryInput();
         ISearch searchInput = getSearchInput();
 
-        return entries.length > 0 || searches.length > 0 || entryInput != null || searchInput
!= null;
+        return entries.size() > 0 || searches.length > 0 || entryInput != null || searchInput
!= null;
     }
 
 
@@ -187,19 +202,19 @@
      * @return
      *      the entries
      */
-    protected IEntry[] getEntries()
+    protected List<IEntry> getEntries()
     {
-        List<IEntry> entriesList = new ArrayList<IEntry>();
-        entriesList.addAll( Arrays.asList( getSelectedEntries() ) );
-        for ( int i = 0; i < getSelectedSearchResults().length; i++ )
+        List<IEntry> entries = new ArrayList<IEntry>();
+        entries.addAll( Arrays.asList( getSelectedEntries() ) );
+        for ( ISearchResult searchResult : getSelectedSearchResults() )
         {
-            entriesList.add( getSelectedSearchResults()[i].getEntry() );
+            entries.add( searchResult.getEntry() );
         }
-        for ( int i = 0; i < getSelectedBookmarks().length; i++ )
+        for ( IBookmark bookmark : getSelectedBookmarks() )
         {
-            entriesList.add( getSelectedBookmarks()[i].getEntry() );
+            entries.add( bookmark.getEntry() );
         }
-        return entriesList.toArray( new IEntry[entriesList.size()] );
+        return entries;
     }
 
 

Modified: directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/StudioBrowserJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/StudioBrowserJob.java?rev=775092&r1=775091&r2=775092&view=diff
==============================================================================
--- directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/StudioBrowserJob.java
(original)
+++ directory/studio/trunk/ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/jobs/StudioBrowserJob.java
Fri May 15 11:50:10 2009
@@ -19,30 +19,44 @@
  */
 package org.apache.directory.studio.ldapbrowser.core.jobs;
 
+
 import org.apache.directory.studio.connection.core.jobs.StudioConnectionJob;
 import org.apache.directory.studio.connection.core.jobs.StudioRunnableWithProgress;
 import org.apache.directory.studio.ldapbrowser.core.events.EventRegistry;
 
+
+/**
+ * Job to run {@link StudioRunnableWithProgress} runnables.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
 public class StudioBrowserJob extends StudioConnectionJob
 {
 
-    public StudioBrowserJob( StudioRunnableWithProgress runnable )
+    /**
+     * Creates a new instance of StudioBrowserJob.
+     * 
+     * @param runnables the runnables to run
+     */
+    public StudioBrowserJob( StudioRunnableWithProgress... runnables )
     {
-        super( runnable );
+        super( runnables );
     }
 
-    
+
     @Override
-    protected void suspendEventFireingInCurrentThread()
+    protected void suspendEventFiringInCurrentThread()
     {
         EventRegistry.suspendEventFiringInCurrentThread();
-        super.suspendEventFireingInCurrentThread();
+        super.suspendEventFiringInCurrentThread();
     }
-    
+
+
     @Override
-    protected void resumeEventFireingInCurrentThread()
+    protected void resumeEventFiringInCurrentThread()
     {
         EventRegistry.resumeEventFiringInCurrentThread();
-        super.resumeEventFireingInCurrentThread();
+        super.resumeEventFiringInCurrentThread();
     }
 }



Mime
View raw message