directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r507621 - /directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SearchViewer.java
Date Wed, 14 Feb 2007 16:56:22 GMT
Author: pamarcelot
Date: Wed Feb 14 08:56:21 2007
New Revision: 507621

URL: http://svn.apache.org/viewvc?view=rev&rev=507621
Log:
Fixed DIRSTUDIO-61 (Pressing the down key in the search field of the Search View should pass
the focus to the search results table).

Modified:
    directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SearchViewer.java

Modified: directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SearchViewer.java
URL: http://svn.apache.org/viewvc/directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SearchViewer.java?view=diff&rev=507621&r1=507620&r2=507621
==============================================================================
--- directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SearchViewer.java
(original)
+++ directory/ldapstudio/trunk/ldapstudio-schemas-plugin/src/main/java/org/apache/directory/ldapstudio/schemas/view/viewers/SearchViewer.java
Wed Feb 14 08:56:21 2007
@@ -35,11 +35,12 @@
 import org.apache.log4j.Logger;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
 import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.layout.GridData;
@@ -57,13 +58,17 @@
 
 
 /**
- * This is the main class for the LDAP Studio Search Tool.
- *
+ * This class represents the Search View.
  */
 public class SearchViewer extends ViewPart implements PoolListener
 {
+    /** The view's ID */
     public static final String ID = Application.PLUGIN_ID + ".view.SearchViewer"; //$NON-NLS-1$
+
+    /** The Schema Pool */
     private SchemaPool pool;
+
+    // UI fields
     private Composite top;
     private Table table;
     private TableViewer tableViewer;
@@ -71,22 +76,32 @@
     private Combo typeCombo;
     private SearchContentProvider searchContentProvider;
 
-    //Set the table column property names
+    /** The Type column */
     private final String TYPE_COLUMN = Messages.getString( "SearchViewer.Type_Column" );
//$NON-NLS-1$
+
+    /** The Name column*/
     private final String NAME_COLUMN = Messages.getString( "SearchViewer.Name_Column" );
//$NON-NLS-1$
+
+    /** The Schema column */
     private final String SCHEMA_COLUMN = Messages.getString( "SearchViewer.Schema_Column"
); //$NON-NLS-1$
 
-    // Set column names
+    /** The Columns names Array */
     private String[] columnNames = new String[]
         { TYPE_COLUMN, NAME_COLUMN, SCHEMA_COLUMN, };
 
-    //search types
+    /** The Search All type */
     public static final String SEARCH_ALL = Messages.getString( "SearchViewer.Search_All_metadata"
); //$NON-NLS-1$
+
+    /** The Search Name type */
     public static final String SEARCH_NAME = Messages.getString( "SearchViewer.Search_Name"
); //$NON-NLS-1$
+
+    /** The Search OID type */
     public static final String SEARCH_OID = Messages.getString( "SearchViewer.Search_OID"
); //$NON-NLS-1$
+
+    /** The Search Description type */
     public static final String SEARCH_DESC = Messages.getString( "SearchViewer.Search_Description"
); //$NON-NLS-1$
 
-    //current search type
+    /** The current Search type */
     public static String searchType = SEARCH_ALL;
 
 
@@ -119,7 +134,6 @@
         searchField.setLayoutData( gridData );
         searchField.addModifyListener( new ModifyListener()
         {
-
             public void modifyText( ModifyEvent e )
             {
                 tableViewer.setInput( searchField.getText() );
@@ -127,6 +141,17 @@
 
         } );
 
+        searchField.addKeyListener( new KeyAdapter()
+        {
+            public void keyPressed( KeyEvent e )
+            {
+                if ( e.keyCode == SWT.ARROW_DOWN )
+                {
+                    table.setFocus();
+                }
+            }
+        } );
+
         //search type combo
         typeCombo = new Combo( top, SWT.READ_ONLY | SWT.SINGLE );
 
@@ -166,12 +191,10 @@
      */
     private void createTable( Composite parent )
     {
-        int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION
| SWT.HIDE_SELECTION;
-
-        table = new Table( parent, style );
+        table = new Table( parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
| SWT.FULL_SELECTION
+            | SWT.HIDE_SELECTION );
 
         GridData gridData = new GridData( GridData.FILL, GridData.FILL, true, true, 2, 1
);
-        //gridData.horizontalSpan = 3;
         table.setLayoutData( gridData );
 
         table.setLinesVisible( false );
@@ -186,76 +209,76 @@
         column = new TableColumn( table, SWT.LEFT, 1 );
         column.setText( columnNames[1] );
         column.setWidth( 400 );
-        // Add listener to column so tasks are sorted by name
-        column.addSelectionListener( new SelectionAdapter()
-        {
-            public void widgetSelected( SelectionEvent e )
-            {
-                //tableViewer.setSorter(new ExampleTaskSorter(ExampleTaskSorter.DESCRIPTION));
-            }
-        } );
 
         //3rd column with element defining schema
         column = new TableColumn( table, SWT.LEFT, 2 );
         column.setText( columnNames[2] );
         column.setWidth( 100 );
-        // Add listener to column so tasks are sorted by schema
-        column.addSelectionListener( new SelectionAdapter()
-        {
 
-            public void widgetSelected( SelectionEvent e )
+        table.addMouseListener( new MouseAdapter()
+        {
+            public void mouseDoubleClick( MouseEvent e )
             {
-                //tableViewer.setSorter(new ExampleTaskSorter(ExampleTaskSorter.OWNER));
+                openEditor( ( Table ) e.getSource() );
             }
         } );
-        table.addMouseListener( new MouseListener()
+
+        table.addKeyListener( new KeyAdapter()
         {
-            public void mouseDoubleClick( MouseEvent e )
+            public void keyPressed( KeyEvent e )
             {
-                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-                // Getting the source Table of the double click
-                Table sourceTable = ( Table ) e.getSource();
-
-                IEditorInput input = null;
-                String editorId = null;
-
-                // Here is the double clicked item
-                Object item = sourceTable.getSelection()[0].getData();
-                if ( item instanceof AttributeType )
-                {
-                    input = new AttributeTypeFormEditorInput( ( AttributeType ) item );
-                    editorId = AttributeTypeFormEditor.ID;
-                }
-                else if ( item instanceof ObjectClass )
+                if ( e.keyCode == SWT.ARROW_UP )
                 {
-                    input = new ObjectClassFormEditorInput( ( ObjectClass ) item );
-                    editorId = ObjectClassFormEditor.ID;
+                    searchField.setFocus();
                 }
 
-                // Let's open the editor
-                if ( input != null )
+                if ( e.keyCode == 13 ) // return key
                 {
-                    try
-                    {
-                        page.openEditor( input, editorId );
-                    }
-                    catch ( PartInitException exception )
-                    {
-                        Logger.getLogger( PoolManagerController.class ).debug( "error when
opening the editor" ); //$NON-NLS-1$
-                    }
+                    openEditor( ( Table ) e.getSource() );
                 }
             }
+        } );
+    }
 
 
-            public void mouseDown( MouseEvent e )
-            {
-            }
+    /**
+     * Open the editor associated with the current selection in the table
+     *
+     * @param table
+     *      the associated table
+     */
+    private void openEditor( Table table )
+    {
+        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+
+        IEditorInput input = null;
+        String editorId = null;
 
+        // Here is the double clicked item
+        Object item = table.getSelection()[0].getData();
+        if ( item instanceof AttributeType )
+        {
+            input = new AttributeTypeFormEditorInput( ( AttributeType ) item );
+            editorId = AttributeTypeFormEditor.ID;
+        }
+        else if ( item instanceof ObjectClass )
+        {
+            input = new ObjectClassFormEditorInput( ( ObjectClass ) item );
+            editorId = ObjectClassFormEditor.ID;
+        }
 
-            public void mouseUp( MouseEvent e )
+        // Let's open the editor
+        if ( input != null )
+        {
+            try
             {
+                page.openEditor( input, editorId );
             }
-        } );
+            catch ( PartInitException exception )
+            {
+                Logger.getLogger( PoolManagerController.class ).debug( "error when opening
the editor" ); //$NON-NLS-1$
+            }
+        }
     }
 
 
@@ -264,10 +287,8 @@
      */
     private void createTableViewer()
     {
-
         tableViewer = new TableViewer( table );
         tableViewer.setUseHashlookup( true );
-
         tableViewer.setColumnProperties( columnNames );
     }
 
@@ -303,5 +324,4 @@
     {
         super.setPartName( partName );
     }
-
 }



Mime
View raw message