You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2008/05/28 15:34:53 UTC
svn commit: r660946 - in
/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds:
ApacheDsPlugin.java views/ServerTableViewer.java
views/ServerViewerComparator.java views/ServersView.java
Author: pamarcelot
Date: Wed May 28 06:34:52 2008
New Revision: 660946
URL: http://svn.apache.org/viewvc?rev=660946&view=rev
Log:
Added the ability to sort the servers view using its columns.
Added:
directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerViewerComparator.java
Modified:
directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPlugin.java
directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerTableViewer.java
directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java
Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPlugin.java?rev=660946&r1=660945&r2=660946&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPlugin.java (original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/ApacheDsPlugin.java Wed May 28 06:34:52 2008
@@ -23,11 +23,8 @@
import java.net.URL;
import org.apache.directory.studio.apacheds.model.ServersHandler;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerTableViewer.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerTableViewer.java?rev=660946&r1=660945&r2=660946&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerTableViewer.java (original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerTableViewer.java Wed May 28 06:34:52 2008
@@ -17,6 +17,16 @@
* 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;
@@ -32,10 +42,13 @@
import org.apache.directory.studio.apacheds.model.ServersHandlerListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeViewer;
+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;
/**
@@ -72,6 +85,8 @@
setLabelProvider( labelProvider );
setContentProvider( new ServersViewContentProvider() );
+ setComparator( new ServerViewerComparator( labelProvider ) );
+
setInput( ROOT );
addListeners();
@@ -346,4 +361,47 @@
//TODO
}
}
+
+
+ /**
+ * Resorts the table based on field.
+ *
+ * @param column
+ * the column being updated
+ * @param col
+ * the column
+ */
+ protected void resortTable( final TreeColumn column, int col )
+ {
+ ServerViewerComparator sorter = ( ServerViewerComparator ) getComparator();
+
+ if ( col == sorter.getTopPriority() )
+ sorter.reverseTopPriority();
+ else
+ sorter.setTopPriority( col );
+
+ PlatformUI.getWorkbench().getDisplay().asyncExec( new Runnable()
+ {
+ public void run()
+ {
+ refresh();
+ updateDirectionIndicator( column );
+ }
+ } );
+ }
+
+
+ /**
+ * Updates the direction indicator as column is now the primary column.
+ *
+ * @param column
+ */
+ protected void updateDirectionIndicator( TreeColumn column )
+ {
+ getTree().setSortColumn( column );
+ if ( ( ( ServerViewerComparator ) getComparator() ).getTopPriorityDirection() == ServerViewerComparator.ASCENDING )
+ getTree().setSortDirection( SWT.UP );
+ else
+ getTree().setSortDirection( SWT.DOWN );
+ }
}
\ No newline at end of file
Added: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerViewerComparator.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerViewerComparator.java?rev=660946&view=auto
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerViewerComparator.java (added)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServerViewerComparator.java Wed May 28 06:34:52 2008
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * 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 org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+
+/**
+ * This class implements the servers table viewer comparator.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerViewerComparator extends ViewerComparator
+{
+ public static final int MAX_DEPTH = 3;
+ public static final int ASCENDING = 1;
+ public static final int DESCENDING = -1;
+
+ protected ServersViewLabelProvider labelProvider;
+
+ protected int[] priorities = new int[]
+ { 0 };
+
+ protected int[] directions = new int[]
+ { ASCENDING };
+
+
+ /**
+ * Creates a new instance of ServerViewerComparator.
+ *
+ * @param labelProvider
+ * the label provider
+ */
+ public ServerViewerComparator( ServersViewLabelProvider labelProvider )
+ {
+ this.labelProvider = labelProvider;
+ }
+
+
+ /**
+ * Sets the top priority.
+ *
+ * @param priority
+ * the priority
+ */
+ public void setTopPriority( int priority )
+ {
+ if ( priorities[0] == priority )
+ {
+ return;
+ }
+
+ int len = priorities.length + 1;
+ if ( len > MAX_DEPTH )
+ {
+ len = MAX_DEPTH;
+ }
+
+ int[] temp = new int[len];
+ System.arraycopy( priorities, 0, temp, 1, len - 1 );
+ temp[0] = priority;
+ priorities = temp;
+
+ temp = new int[len];
+ System.arraycopy( directions, 0, temp, 1, len - 1 );
+ temp[0] = ASCENDING;
+ directions = temp;
+ }
+
+
+ /**
+ * Gets the top priority.
+ *
+ * @return
+ * the top priority
+ */
+ public int getTopPriority()
+ {
+ return priorities[0];
+ }
+
+
+ /**
+ * Sets the top priority direction
+ *
+ * @param direction
+ * the direction
+ */
+ public void setTopPriorityDirection( int direction )
+ {
+ if ( direction == ASCENDING || direction == DESCENDING )
+ {
+ directions[0] = direction;
+ }
+ }
+
+
+ /**
+ * Gets the top priority direction
+ *
+ * @return
+ * the top priority direction
+ */
+ public int getTopPriorityDirection()
+ {
+ return directions[0];
+ }
+
+
+ /**
+ * Reverses the top priority
+ */
+ public void reverseTopPriority()
+ {
+ directions[0] *= -1;
+ }
+
+
+ /**
+ * Returns a negative, zero, or positive number depending on whether
+ * the first element is less than, equal to, or greater than
+ * the second element.
+ * <p>
+ * The default implementation of this method is based on
+ * comparing the elements' categories as computed by the <code>category</code>
+ * framework method. Elements within the same category are further
+ * subjected to a case insensitive compare of their label strings, either
+ * as computed by the content viewer's label provider, or their
+ * <code>toString</code> values in other cases. Subclasses may override.
+ * </p>
+ *
+ * @param viewer the viewer
+ * @param e1 the first element
+ * @param e2 the second element
+ * @param a the direction
+ * @return a negative number if the first element is less than the
+ * second element; the value <code>0</code> if the first element is
+ * equal to the second element; and a positive number if the first
+ * element is greater than the second element
+ */
+ public int compare( Viewer viewer, Object e1, Object e2, int a )
+ {
+ int col = priorities[a];
+
+ String s1 = labelProvider.getColumnText( e1, col );
+ String s2 = labelProvider.getColumnText( e2, col );
+
+ int s = s1.compareToIgnoreCase( s2 ) * directions[a];
+ if ( s == 0 )
+ {
+ if ( a == priorities.length - 1 )
+ {
+ return 0;
+ }
+ return compare( viewer, e1, e2, a + 1 );
+ }
+ return s;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public int compare( Viewer viewer, Object e1, Object e2 )
+ {
+ return compare( viewer, e1, e2, 0 );
+ }
+}
\ No newline at end of file
Modified: directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java?rev=660946&r1=660945&r2=660946&view=diff
==============================================================================
--- directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java (original)
+++ directory/studio/branches/apacheds-plugin-branch/apacheds/src/main/java/org/apache/directory/studio/apacheds/views/ServersView.java Wed May 28 06:34:52 2008
@@ -41,6 +41,9 @@
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.Tree;
@@ -107,6 +110,20 @@
tableViewer.refresh();
}
};
+
+ private SelectionListener getHeaderListener(final int col) {
+ 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);
+ }
+ };
+ }
private Tree tree;
@@ -126,10 +143,12 @@
TreeColumn serverColumn = new TreeColumn( tree, SWT.SINGLE );
serverColumn.setText( "Server" );
serverColumn.setWidth( cols[0] );
+ serverColumn.addSelectionListener( getHeaderListener( 0 ) );
TreeColumn stateColumn = new TreeColumn( tree, SWT.SINGLE );
stateColumn.setText( "State" );
stateColumn.setWidth( cols[1] );
+ stateColumn.addSelectionListener( getHeaderListener( 1 ) );
// Creating the viewer
tableViewer = new ServerTableViewer( this, tree );