directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1333956 - in /directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views: ServersTableViewer.java ServersView.java ServersViewLabelProvider.java
Date Fri, 04 May 2012 13:38:24 GMT
Author: pamarcelot
Date: Fri May  4 13:38:23 2012
New Revision: 1333956

URL: http://svn.apache.org/viewvc?rev=1333956&view=rev
Log:
Part of a fix for DIRSTUDIO-811 (Review and remove any source file under Eclipse Public License
(EPL) v 1.0).

Modified:
    directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersTableViewer.java
    directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java
    directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersViewLabelProvider.java

Modified: directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersTableViewer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersTableViewer.java?rev=1333956&r1=1333955&r2=1333956&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersTableViewer.java
(original)
+++ directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersTableViewer.java
Fri May  4 13:38:23 2012
@@ -17,31 +17,23 @@
  *  under the License. 
  *  
  */
-/*******************************************************************************
- * Copyright (c) 2003, 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     IBM Corporation - Initial API and implementation
- *******************************************************************************/
 package org.apache.directory.studio.apacheds.views;
 
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 
+import org.apache.directory.studio.apacheds.model.ServersHandler;
+import org.apache.directory.studio.apacheds.model.ServersHandlerListener;
+import org.apache.directory.studio.apacheds.model.Server;
 import org.apache.directory.studio.apacheds.model.ServerEvent;
 import org.apache.directory.studio.apacheds.model.ServerEventEnum;
-import org.apache.directory.studio.apacheds.model.Server;
 import org.apache.directory.studio.apacheds.model.ServerListener;
 import org.apache.directory.studio.apacheds.model.ServerStateEnum;
-import org.apache.directory.studio.apacheds.model.ServersHandler;
-import org.apache.directory.studio.apacheds.model.ServersHandlerListener;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Tree;
@@ -64,6 +56,9 @@ public class ServersTableViewer extends 
     /** The label provider */
     private ServersViewLabelProvider labelProvider;
 
+    /** The comparator */
+    private ServersComparator comparator;
+
     /** The server handler listener */
     private ServersHandlerListener serversHandlerListener;
 
@@ -77,6 +72,12 @@ public class ServersTableViewer extends 
     private List<Server> serversNeedingAnimation = new ArrayList<Server>();
 
 
+    /**
+     * Creates a new instance of ServersTableViewer.
+     *
+     * @param tree
+     *      the associated tree
+     */
     public ServersTableViewer( Tree tree )
     {
         super( tree );
@@ -85,7 +86,8 @@ public class ServersTableViewer extends 
         setLabelProvider( labelProvider );
         setContentProvider( new ServersViewContentProvider() );
 
-        setComparator( new ServersViewerComparator( labelProvider ) );
+        comparator = new ServersComparator();
+        setComparator( new ViewerComparator( comparator ) );
 
         setInput( ROOT );
 
@@ -126,7 +128,7 @@ public class ServersTableViewer extends 
         ServersHandler.getDefault().addListener( serversHandlerListener );
 
         // The server listener
-        serverListener = new ServerListener()
+        serverListener = new  ServerListener()
         {
             public void serverChanged( ServerEvent event )
             {
@@ -141,12 +143,12 @@ public class ServersTableViewer extends 
                 Server server = event.getServer();
                 switch ( kind )
                 {
-                    // The server state has changed
+                    // The server status has changed
                     case STATE_CHANGED:
                         // First, we refresh the server
                         refreshServer( server );
 
-                        // Then, we get the state of the server to see if we
+                        // Then, we get the status of the server to see if we
                         // need to start or stop the animation thread
                         ServerStateEnum state = server.getState();
 
@@ -245,16 +247,9 @@ public class ServersTableViewer extends 
         {
             public void run()
             {
-                try
-                {
-                    refresh( server );
-                    ISelection sel = ServersTableViewer.this.getSelection();
-                    ServersTableViewer.this.setSelection( sel );
-                }
-                catch ( Exception e )
-                {
-                    // ignore
-                }
+                refresh( server );
+                ISelection sel = ServersTableViewer.this.getSelection();
+                ServersTableViewer.this.setSelection( sel );
             }
         } );
     }
@@ -295,24 +290,17 @@ public class ServersTableViewer extends 
                 // Checking if we need to stop the animation
                 if ( !stopAnimation )
                 {
-                    try
-                    {
-                        // Changing the animation state on the label provider
-                        labelProvider.animate();
+                    // Changing the animation state on the label provider
+                    labelProvider.animate();
 
-                        // Looping on the currently starting servers
-                        for ( Server server : serversNeedingAnimation.toArray( new Server[0]
) )
+                    // Looping on the currently starting servers
+                    for ( Server server : serversNeedingAnimation.toArray( new Server[0]
) )
+                    {
+                        if ( server != null && getTree() != null && !getTree().isDisposed()
)
                         {
-                            if ( server != null && getTree() != null && !getTree().isDisposed()
)
-                            {
-                                updateAnimation( server );
-                            }
+                            updateAnimation( server );
                         }
                     }
-                    catch ( Exception e )
-                    {
-                        //                        Trace.trace( Trace.FINEST, "Error in Servers
view animation", e ); TODO
-                    }
 
                     // Re-launching the animation
                     display.timerExec( SLEEP, animatorThread[0] );
@@ -348,60 +336,84 @@ public class ServersTableViewer extends 
      */
     private void updateAnimation( Server server )
     {
-        try
-        {
-            Widget widget = doFindItem( server );
-            TreeItem item = ( TreeItem ) widget;
-            item.setText( 1, labelProvider.getColumnText( server, 1 ) );
-            item.setImage( 1, labelProvider.getColumnImage( server, 1 ) );
-        }
-        catch ( Exception e )
-        {
-            //            Trace.trace( Trace.WARNING, "Error in optimized animation", e );
-            //TODO
-        }
+        Widget widget = doFindItem( server );
+        TreeItem item = ( TreeItem ) widget;
+        item.setText( 1, labelProvider.getColumnText( server, 1 ) );
+        item.setImage( 1, labelProvider.getColumnImage( server, 1 ) );
     }
 
 
     /**
-     * Resorts the table based on field.
-     * 
-     * @param column 
-     *      the column being updated
-     * @param col
-     *      the column
+     * Sorts the table.
+     *
+     * @param treeColumn the tree column
+     * @param column the column number
      */
-    protected void resortTable( final TreeColumn column, int col )
+    public void sort( final TreeColumn treeColumn, int column )
     {
-        ServersViewerComparator sorter = ( ServersViewerComparator ) getComparator();
-
-        if ( col == sorter.getTopPriority() )
-            sorter.reverseTopPriority();
+        if ( column == comparator.column )
+        {
+            comparator.reverseOrder();
+        }
         else
-            sorter.setTopPriority( col );
+        {
+            comparator.column = column;
+        }
 
         PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable()
         {
             public void run()
             {
                 refresh();
-                updateDirectionIndicator( column );
+
+                Tree tree = getTree();
+                tree.setSortColumn( treeColumn );
+                if ( comparator.order == ServersComparator.ASCENDING )
+                {
+                    tree.setSortDirection( SWT.UP );
+                }
+                else
+                {
+                    tree.setSortDirection( SWT.DOWN );
+                }
             }
         } );
     }
 
-
     /**
-     * Updates the direction indicator as column is now the primary column.
-     * 
-     * @param column
+     * This class implements a comparator for servers.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
      */
-    protected void updateDirectionIndicator( TreeColumn column )
+    private class ServersComparator implements Comparator<Object>
     {
-        getTree().setSortColumn( column );
-        if ( ( ( ServersViewerComparator ) getComparator() ).getTopPriorityDirection() ==
ServersViewerComparator.ASCENDING )
-            getTree().setSortDirection( SWT.UP );
-        else
-            getTree().setSortDirection( SWT.DOWN );
+        public static final int ASCENDING = 1;
+
+        /** The comparison order */
+        int order = ASCENDING;
+
+        /** The column used to compare objects */
+        int column = 0;
+
+
+        /**
+         * Reverses the order.
+         */
+        public void reverseOrder()
+        {
+            order = order * -1;
+        }
+
+
+        /**
+         * {@inheritDoc}
+         */
+        public int compare( Object o1, Object o2 )
+        {
+            String s1 = labelProvider.getColumnText( o1, column );
+            String s2 = labelProvider.getColumnText( o2, column );
+
+            return s1.compareToIgnoreCase( s2 ) * order;
+        }
     }
 }
\ No newline at end of file

Modified: directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java?rev=1333956&r1=1333955&r2=1333956&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java
(original)
+++ directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java
Fri May  4 13:38:23 2012
@@ -149,14 +149,14 @@ public class ServersView extends ViewPar
         TreeColumn serverColumn = new TreeColumn( tree, SWT.SINGLE );
         serverColumn.setText( Messages.getString( "ServersView.server" ) ); //$NON-NLS-1$
         serverColumn.setWidth( columnWidths[0] );
-        serverColumn.addSelectionListener( getHeaderListener( 0 ) );
+        serverColumn.addSelectionListener( getColumnSelectionListener( 0 ) );
         tree.setSortColumn( serverColumn );
         tree.setSortDirection( SWT.UP );
 
         TreeColumn stateColumn = new TreeColumn( tree, SWT.SINGLE );
         stateColumn.setText( Messages.getString( "ServersView.state" ) ); //$NON-NLS-1$
         stateColumn.setWidth( columnWidths[1] );
-        stateColumn.addSelectionListener( getHeaderListener( 1 ) );
+        stateColumn.addSelectionListener( getColumnSelectionListener( 1 ) );
 
         // Creating the viewer
         tableViewer = new ServersTableViewer( tree );
@@ -172,27 +172,14 @@ public class ServersView extends ViewPar
     }
 
 
-    /**
-     * Gets a header listener for the given column.
-     * 
-     * @param col
-     *      the column
-     * @return
-     *      a header listener for the given column
-     */
-    private SelectionListener getHeaderListener( final int col )
+    private SelectionListener getColumnSelectionListener( final int column )
     {
         return new SelectionAdapter()
         {
-            /**
-             * Handles the case of user selecting the header area.
-             */
             public void widgetSelected( SelectionEvent e )
             {
-                if ( tableViewer == null )
-                    return;
-                TreeColumn column = ( TreeColumn ) e.widget;
-                tableViewer.resortTable( column, col );
+                TreeColumn treeColumn = ( TreeColumn ) e.widget;
+                tableViewer.sort( treeColumn, column );
             }
         };
     }

Modified: directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersViewLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersViewLabelProvider.java?rev=1333956&r1=1333955&r2=1333956&view=diff
==============================================================================
--- directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersViewLabelProvider.java
(original)
+++ directory/studio/trunk/plugins/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersViewLabelProvider.java
Fri May  4 13:38:23 2012
@@ -74,7 +74,7 @@ public class ServersViewLabelProvider ex
 
         }
 
-        return null;
+        return super.getText( element );
     }
 
 
@@ -146,7 +146,7 @@ public class ServersViewLabelProvider ex
             }
         }
 
-        return null;
+        return super.getImage( element );
     }
 
 



Mime
View raw message