directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1333562 - in /directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views: ServersTableViewer.java ServersView.java ServersViewLabelProvider.java
Date Thu, 03 May 2012 17:26:43 GMT
Author: pamarcelot
Date: Thu May  3 17:26:42 2012
New Revision: 1333562

URL: http://svn.apache.org/viewvc?rev=1333562&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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java
    directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java
    directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java

Modified: directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java?rev=1333562&r1=1333561&r2=1333562&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java
(original)
+++ directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersTableViewer.java
Thu May  3 17:26:42 2012
@@ -21,6 +21,7 @@ package org.apache.directory.studio.ldap
 
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 
 import org.apache.directory.studio.ldapservers.LdapServersManager;
@@ -32,10 +33,14 @@ import org.apache.directory.studio.ldaps
 import org.apache.directory.studio.ldapservers.model.LdapServerStatus;
 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;
+import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.swt.widgets.TreeItem;
 import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.PlatformUI;
 
 
 /**
@@ -51,6 +56,9 @@ public class ServersTableViewer extends 
     /** The label provider */
     private ServersViewLabelProvider labelProvider;
 
+    /** The comparator */
+    private ServersComparator comparator;
+
     /** The server handler listener */
     private LdapServersManagerListener serversHandlerListener;
 
@@ -78,6 +86,9 @@ public class ServersTableViewer extends 
         setLabelProvider( labelProvider );
         setContentProvider( new ServersViewContentProvider() );
 
+        comparator = new ServersComparator();
+        setComparator( new ViewerComparator( comparator ) );
+
         setInput( ROOT );
 
         addListeners();
@@ -330,4 +341,79 @@ public class ServersTableViewer extends 
         item.setText( 1, labelProvider.getColumnText( server, 1 ) );
         item.setImage( 1, labelProvider.getColumnImage( server, 1 ) );
     }
+
+
+    /**
+     * Sorts the table.
+     *
+     * @param treeColumn the tree column
+     * @param column the column number
+     */
+    public void sort( final TreeColumn treeColumn, int column )
+    {
+        if ( column == comparator.column )
+        {
+            comparator.reverseOrder();
+        }
+        else
+        {
+            comparator.column = column;
+        }
+
+        PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable()
+        {
+            public void run()
+            {
+                refresh();
+
+                Tree tree = getTree();
+                tree.setSortColumn( treeColumn );
+                if ( comparator.order == ServersComparator.ASCENDING )
+                {
+                    tree.setSortDirection( SWT.UP );
+                }
+                else
+                {
+                    tree.setSortDirection( SWT.DOWN );
+                }
+            }
+        } );
+    }
+
+    /**
+     * This class implements a comparator for servers.
+     *
+     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+     */
+    private class ServersComparator implements Comparator<Object>
+    {
+        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/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java?rev=1333562&r1=1333561&r2=1333562&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java
(original)
+++ directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersView.java
Thu May  3 17:26:42 2012
@@ -44,6 +44,9 @@ import org.eclipse.jface.viewers.Selecti
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.swt.SWT;
+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.Composite;
 import org.eclipse.swt.widgets.Display;
@@ -137,12 +140,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( 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( getColumnSelectionListener( 1 ) );
 
         // Creating the viewer
         tableViewer = new ServersTableViewer( tree );
@@ -158,6 +163,7 @@ public class ServersView extends ViewPar
         //            .setHelp( parent, ApacheDsPluginConstants.PLUGIN_ID + "." + "gettingstarted_views_servers"
); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
+
     /**
      * {@inheritDoc}
      */
@@ -498,4 +504,17 @@ public class ServersView extends ViewPar
             }
         } );
     }
+
+
+    private SelectionListener getColumnSelectionListener( final int column )
+    {
+        return new SelectionAdapter()
+        {
+            public void widgetSelected( SelectionEvent e )
+            {
+                TreeColumn treeColumn = ( TreeColumn ) e.widget;
+                tableViewer.sort( treeColumn, column );
+            }
+        };
+    }
 }

Modified: directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java?rev=1333562&r1=1333561&r2=1333562&view=diff
==============================================================================
--- directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java
(original)
+++ directory/studio/trunk/plugins/ldapservers/src/main/java/org/apache/directory/studio/ldapservers/views/ServersViewLabelProvider.java
Thu May  3 17:26:42 2012
@@ -77,7 +77,7 @@ public class ServersViewLabelProvider ex
 
         }
 
-        return null;
+        return super.getText( element );
     }
 
 
@@ -155,7 +155,7 @@ public class ServersViewLabelProvider ex
             }
         }
 
-        return null;
+        return super.getImage( element );
     }
 
 



Mime
View raw message