changeset 93:bf8adb3de664

Fix tabs vs. spaces and added snippet to dsss.conf
author Frank Benoit <benoit@tionex.de>
date Fri, 23 May 2008 02:50:33 +0200
parents f5c5b4bf7971
children a35db4f4af8c
files .hgignore jface/dsss.conf jface/snippets/Snippet031TableViewerCustomTooltipsMultiSelection.d
diffstat 3 files changed, 219 insertions(+), 219 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri May 23 07:53:22 2008 +0800
+++ b/.hgignore	Fri May 23 02:50:33 2008 +0200
@@ -43,4 +43,6 @@
 ^jface/ShowPrefs$
 ^jface/ShowFieldPrefs$
 ^jface/Librarian$
+^jface/snippets/Snippet031TableViewerCustomTooltipsMultiSelection$
 
+
--- a/jface/dsss.conf	Fri May 23 07:53:22 2008 +0800
+++ b/jface/dsss.conf	Fri May 23 02:50:33 2008 +0200
@@ -15,7 +15,6 @@
 }
 
 
-
 [FileTreeViewer.d]
 [Librarian.d]
 [ActionAndStatusbar.d]
@@ -27,5 +26,6 @@
 [snippets/Snippet005TreeCustomMenu.d]
 [snippets/Snippet006TableMultiLineCells.d]
 [snippets/Snippet007FullSelection.d]
+[snippets/Snippet031TableViewerCustomTooltipsMultiSelection.d]
 [snippets/Snippet040TableViewerSorting.d]
 
--- a/jface/snippets/Snippet031TableViewerCustomTooltipsMultiSelection.d	Fri May 23 07:53:22 2008 +0800
+++ b/jface/snippets/Snippet031TableViewerCustomTooltipsMultiSelection.d	Fri May 23 02:50:33 2008 +0200
@@ -1,5 +1,3 @@
-module jface.snippets.Snippet031TableViewerCustomTooltipsMultiSelection;
-
 /*******************************************************************************
  * Copyright (c) 2007 Adam Neal and others.
  * All rights reserved. This program and the accompanying materials
@@ -13,6 +11,7 @@
  *     yidabu at gmail dot com  ( D China http://www.d-programming-language-china.org/ ) 
  *******************************************************************************/
 
+module jface.snippets.Snippet031TableViewerCustomTooltipsMultiSelection;
 
 // http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/Snippet031TableViewerCustomTooltipsMultiSelection.java?view=markup
 
@@ -53,261 +52,260 @@
  * This is a modified example taken from Tom Schindl's Snippet023TreeViewerCustomTooltips.java
  * 
  * This code is for users pre 3.3 others could use newly added tooltip support in {@link CellLabelProvider}
-
  * @author Adam Neal <Adam_Neal@ca.ibm.com>
  * 
  */
 public class Snippet031TableViewerCustomTooltipsMultiSelection {
-	public class MyLableProvider : ITableLabelProvider {
+    public class MyLableProvider : ITableLabelProvider {
 
-		public Image getColumnImage(Object element, int columnIndex) {
-			return null;
-		}
+        public Image getColumnImage(Object element, int columnIndex) {
+            return null;
+        }
 
-		public String getColumnText(Object element, int columnIndex) {
-			//if (element instanceof MyModel) {            
-				switch (columnIndex) {
-					case 0: return (cast(MyModel)element).col1;
-					case 1: return (cast(MyModel)element).col2;
-				}
-			//}
-            
-			return "";
-		}
+        public String getColumnText(Object element, int columnIndex) {
+            //if (element instanceof MyModel) {            
+                switch (columnIndex) {
+                    case 0: return (cast(MyModel)element).col1;
+                    case 1: return (cast(MyModel)element).col2;
+                }
+            //}
+
+            return "";
+        }
 
-		public void addListener(ILabelProviderListener listener) {
-			/* Ignore */
-		}
+        public void addListener(ILabelProviderListener listener) {
+            /* Ignore */
+        }
 
-		public void dispose() {
-			/* Ignore */
-		}
+        public void dispose() {
+            /* Ignore */
+        }
 
-		public bool isLabelProperty(Object element, String property) {
-			return false;
-		}
+        public bool isLabelProperty(Object element, String property) {
+            return false;
+        }
 
-		public void removeListener(ILabelProviderListener listener) {
-			/* Ignore */
-		}
-		
-	}
-	
+        public void removeListener(ILabelProviderListener listener) {
+            /* Ignore */
+        }
+
+    }
 
 
-	public this(Shell shell) {
-        
-        
-		final Table table = new Table(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.MULTI | DWT.FULL_SELECTION);
-		table.setHeaderVisible(true);
+
+    public this(Shell shell) {
+
+
+        final Table table = new Table(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.MULTI | DWT.FULL_SELECTION);
+        table.setHeaderVisible(true);
         table.setLinesVisible(true);
-        
-		final TableViewer v = new TableViewer(table);
-		TableColumn tableColumn1 = new TableColumn(table, DWT.NONE);
-		TableColumn tableColumn2 = new TableColumn(table, DWT.NONE);
-		
-		String column1 = "Column 1", column2 = "Column 2";
-		/* Setup the table  columns */
+
+        final TableViewer v = new TableViewer(table);
+        TableColumn tableColumn1 = new TableColumn(table, DWT.NONE);
+        TableColumn tableColumn2 = new TableColumn(table, DWT.NONE);
+
+        String column1 = "Column 1", column2 = "Column 2";
+        /* Setup the table  columns */
         tableColumn1.setText(column1);
         tableColumn2.setText(column2);
         tableColumn1.pack();
         tableColumn2.pack();
-        
+
         v.setColumnProperties([ column1, column2 ]);
-		v.setLabelProvider(new MyLableProvider());
-		v.setContentProvider(new ArrayContentProvider!(MyModel));
-		v.setInput(createModel());
+        v.setLabelProvider(new MyLableProvider());
+        v.setContentProvider(new ArrayContentProvider!(MyModel));
+        v.setInput(createModel());
 
         tooltipLabelListener = new TooltipLabelListener();
 
-		/**
-	     * The listener that gets added to the table.  This listener is responsible for creating the tooltips
-	     * when hovering over a cell item. This listener will listen for the following events:
-	     *  <li>DWT.KeyDown		- to remove the tooltip</li>
-	     *  <li>DWT.Dispose		- to remove the tooltip</li>
-	     *  <li>DWT.MouseMove	- to remove the tooltip</li>
-	     *  <li>DWT.MouseHover	- to set the tooltip</li>
-	     */
-         
-	    Listener tableListener = dgListener(&handleTableListener, table);
+        /**
+         * The listener that gets added to the table.  This listener is responsible for creating the tooltips
+         * when hovering over a cell item. This listener will listen for the following events:
+         *  <li>DWT.KeyDown     - to remove the tooltip</li>
+         *  <li>DWT.Dispose     - to remove the tooltip</li>
+         *  <li>DWT.MouseMove   - to remove the tooltip</li>
+         *  <li>DWT.MouseHover  - to set the tooltip</li>
+         */
 
-		table.addListener (DWT.Dispose, tableListener);
-		table.addListener (DWT.KeyDown, tableListener);
-		table.addListener (DWT.MouseMove, tableListener);
-		table.addListener (DWT.MouseHover, tableListener);
-	}
+        Listener tableListener = dgListener(&handleTableListener, table);
+
+        table.addListener (DWT.Dispose, tableListener);
+        table.addListener (DWT.KeyDown, tableListener);
+        table.addListener (DWT.MouseMove, tableListener);
+        table.addListener (DWT.MouseHover, tableListener);
+    }
 
     void handleTableListener(Event event, Table table)
     {
         Shell tooltip = null;
         Label label = null;
-        
+
         /*
          * (non-Javadoc)
          * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
          */
-           switch (event.type) {
-                case DWT.KeyDown:
-                case DWT.Dispose:
-                case DWT.MouseMove: {
-                    if (tooltip is null) break;
-                    tooltip.dispose ();
-                    tooltip = null;
-                    label = null;
-                    break;
-                }
-                case DWT.MouseHover: {
-                    Point coords = new Point(event.x, event.y);
-                    TableItem item = table.getItem(coords);
-                    if (item !is null) {
-                        int columnCount = table.getColumnCount();
-                        for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
-                            if (item.getBounds(columnIndex).contains(coords)) {
-                                /* Dispose of the old tooltip (if one exists */
-                                if (tooltip !is null  && !tooltip.isDisposed ()) tooltip.dispose ();
-                                
-                                /* Create a new Tooltip */
-                                tooltip = new Shell (table.getShell(), DWT.ON_TOP | DWT.NO_FOCUS | DWT.TOOL);
-                                tooltip.setBackground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_BACKGROUND));
-                                FillLayout layout = new FillLayout ();
-                                layout.marginWidth = 2;
-                                tooltip.setLayout (layout);
-                                label = new Label (tooltip, DWT.NONE);
-                                label.setForeground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_FOREGROUND));
-                                label.setBackground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_BACKGROUND));
-                                
-                                /* Store the TableItem with the label so we can pass the mouse event later */
-                                label.setData ("_TableItem_", item);
-                                
-                                /* Set the tooltip text */
-                                label.setText("Tooltip: " ~ to!(char[])(item.getData()) ~ " : " ~ to!(char[])(columnIndex));
-                                
-                                /* Setup Listeners to remove the tooltip and transfer the received mouse events */
-                                label.addListener (DWT.MouseExit, tooltipLabelListener);
-                                label.addListener (DWT.MouseDown, tooltipLabelListener);
-                                
-                                /* Set the size and position of the tooltip */
-                                Point size = tooltip.computeSize (DWT.DEFAULT, DWT.DEFAULT);
-                                Rectangle rect = item.getBounds (columnIndex);
-                                Point pt = table.toDisplay (rect.x, rect.y);
-                                tooltip.setBounds (pt.x, pt.y, size.x, size.y);
-                                
-                                /* Show it */
-                                tooltip.setVisible (true);
-                                break;
-                            }
+       switch (event.type) {
+            case DWT.KeyDown:
+            case DWT.Dispose:
+            case DWT.MouseMove: {
+                if (tooltip is null) break;
+                tooltip.dispose ();
+                tooltip = null;
+                label = null;
+                break;
+            }
+            case DWT.MouseHover: {
+                Point coords = new Point(event.x, event.y);
+                TableItem item = table.getItem(coords);
+                if (item !is null) {
+                    int columnCount = table.getColumnCount();
+                    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
+                        if (item.getBounds(columnIndex).contains(coords)) {
+                            /* Dispose of the old tooltip (if one exists */
+                            if (tooltip !is null  && !tooltip.isDisposed ()) tooltip.dispose ();
+
+                            /* Create a new Tooltip */
+                            tooltip = new Shell (table.getShell(), DWT.ON_TOP | DWT.NO_FOCUS | DWT.TOOL);
+                            tooltip.setBackground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_BACKGROUND));
+                            FillLayout layout = new FillLayout ();
+                            layout.marginWidth = 2;
+                            tooltip.setLayout (layout);
+                            label = new Label (tooltip, DWT.NONE);
+                            label.setForeground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_FOREGROUND));
+                            label.setBackground (table.getDisplay().getSystemColor (DWT.COLOR_INFO_BACKGROUND));
+
+                            /* Store the TableItem with the label so we can pass the mouse event later */
+                            label.setData ("_TableItem_", item);
+
+                            /* Set the tooltip text */
+                            label.setText("Tooltip: " ~ to!(char[])(item.getData()) ~ " : " ~ to!(char[])(columnIndex));
+
+                            /* Setup Listeners to remove the tooltip and transfer the received mouse events */
+                            label.addListener (DWT.MouseExit, tooltipLabelListener);
+                            label.addListener (DWT.MouseDown, tooltipLabelListener);
+
+                            /* Set the size and position of the tooltip */
+                            Point size = tooltip.computeSize (DWT.DEFAULT, DWT.DEFAULT);
+                            Rectangle rect = item.getBounds (columnIndex);
+                            Point pt = table.toDisplay (rect.x, rect.y);
+                            tooltip.setBounds (pt.x, pt.y, size.x, size.y);
+
+                            /* Show it */
+                            tooltip.setVisible (true);
+                            break;
                         }
                     }
                 }
-           }
-        
-    }    
-	
-	   /**
-	    * This listener is added to the tooltip so that it can either dispose itself if the mouse
-	    * exits the tooltip or so it can pass the selection event through to the table.
-	    */
-	    final TooltipLabelListener tooltipLabelListener;
-	    final class TooltipLabelListener : Listener {
-	        private bool isCTRLDown(Event e) {
-	        	return (e.stateMask & DWT.CTRL) != 0;
-	        }
-		   /*
-		    * (non-Javadoc)
-		    * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
-		    */
-		   public void handleEvent (Event event) {
-			   Label label = cast(Label)event.widget;
-			   Shell shell = label.getShell ();
-			   switch (event.type) {
-				   	case DWT.MouseDown:	/* Handle a user Click */
-				   		/* Extract our Data */
-				   		Event e = new Event ();
-				   		e.item = cast(TableItem) label.getData ("_TableItem_");
-				   		Table table = (cast(TableItem) e.item).getParent();
-				   		
-				   		/* Construct the new Selection[] to show */
-				   		TableItem [] newSelection = null;
-				   		if (isCTRLDown(event)) {
-				   			/* We have 2 scenario's.  
-				   			 * 	1) We are selecting an already selected element - so remove it from the selected indices
-				   			 *  2) We are selecting a non-selected element - so add it to the selected indices
-				   			 */
-				   			TableItem[] sel = table.getSelection();
-				   			for (int i = 0; i < sel.length; ++i) {
-				   				//if (e.item.equals(sel[i])) {
-				   				if (e.item is sel[i]) {
-				   					// We are de-selecting this element
-				   					newSelection = new TableItem[sel.length - 1];
-				   					System.arraycopy(sel, 0, newSelection, 0, i);
-				   					System.arraycopy(sel, i+1, newSelection, i, sel.length - i - 1);
-				   					break;
-				   				}
-		   					}
-				   			
-				   			/*
-				   			 * If we haven't created the newSelection[] yet, than we are adding the newly selected element
-				   			 * into the list of selected indicies
-				   			 */
-				   			if (newSelection is null) {
-				   				newSelection = new TableItem[sel.length + 1];
-				   				System.arraycopy(sel, 0, newSelection, 0, sel.length);
-				   				newSelection[sel.length] = cast(TableItem) e.item;
-				   			}
-				   			
-				   		} else {
-				   			/* CTRL is not down, so we simply select the single element */
-				   			newSelection = [ cast(TableItem) e.item ];
-				   		}
-				   		/* Set the new selection of the table and notify the listeners */
-				   		table.setSelection (newSelection);
-				   		table.notifyListeners (DWT.Selection, e);
-				   		
-				   		/* Remove the Tooltip */
-				   		shell.dispose ();
-				   		table.setFocus();
-				   		break;
-				   	case DWT.MouseExit:
-				   		shell.dispose ();
-				   		break;
-			   }
-	    }}    
+            }
+        }
+    }
+
+    /**
+     * This listener is added to the tooltip so that it can either dispose itself if the mouse
+     * exits the tooltip or so it can pass the selection event through to the table.
+     */
+    final TooltipLabelListener tooltipLabelListener;
+    final class TooltipLabelListener : Listener {
+        private bool isCTRLDown(Event e) {
+            return (e.stateMask & DWT.CTRL) != 0;
+        }
+       /*
+        * (non-Javadoc)
+        * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
+        */
+       public void handleEvent (Event event) {
+           Label label = cast(Label)event.widget;
+           Shell shell = label.getShell ();
+           switch (event.type) {
+                case DWT.MouseDown: /* Handle a user Click */
+                    /* Extract our Data */
+                    Event e = new Event ();
+                    e.item = cast(TableItem) label.getData ("_TableItem_");
+                    Table table = (cast(TableItem) e.item).getParent();
+
+                    /* Construct the new Selection[] to show */
+                    TableItem [] newSelection = null;
+                    if (isCTRLDown(event)) {
+                        /* We have 2 scenario's.  
+                         *  1) We are selecting an already selected element - so remove it from the selected indices
+                         *  2) We are selecting a non-selected element - so add it to the selected indices
+                         */
+                        TableItem[] sel = table.getSelection();
+                        for (int i = 0; i < sel.length; ++i) {
+                            //if (e.item.equals(sel[i])) {
+                            if (e.item is sel[i]) {
+                                // We are de-selecting this element
+                                newSelection = new TableItem[sel.length - 1];
+                                System.arraycopy(sel, 0, newSelection, 0, i);
+                                System.arraycopy(sel, i+1, newSelection, i, sel.length - i - 1);
+                                break;
+                            }
+                        }
 
-		
-	private ArrayList createModel() {
-		ArrayList list = new ArrayList;
-		list.add(new MyModel("A", "B"));
-		list.add(new MyModel("C", "D"));
-		list.add(new MyModel("E", "F"));
-		return list;
-	}
+                        /*
+                         * If we haven't created the newSelection[] yet, than we are adding the newly selected element
+                         * into the list of selected indicies
+                         */
+                        if (newSelection is null) {
+                            newSelection = new TableItem[sel.length + 1];
+                            System.arraycopy(sel, 0, newSelection, 0, sel.length);
+                            newSelection[sel.length] = cast(TableItem) e.item;
+                        }
+
+                    } else {
+                        /* CTRL is not down, so we simply select the single element */
+                        newSelection = [ cast(TableItem) e.item ];
+                    }
+                    /* Set the new selection of the table and notify the listeners */
+                    table.setSelection (newSelection);
+                    table.notifyListeners (DWT.Selection, e);
 
-	public static void main(String[] args) {
-		Display display = new Display();
-		Shell shell = new Shell(display);
-		shell.setLayout(new FillLayout());
-		new Snippet031TableViewerCustomTooltipsMultiSelection(shell);
-		shell.open();
+                    /* Remove the Tooltip */
+                    shell.dispose ();
+                    table.setFocus();
+                    break;
+                case DWT.MouseExit:
+                    shell.dispose ();
+                    break;
+            }
+        }
+    }
+
 
-		while (!shell.isDisposed()) {
-			if (!display.readAndDispatch())
-				display.sleep();
-		}
+    private ArrayList createModel() {
+        ArrayList list = new ArrayList;
+        list.add(new MyModel("A", "B"));
+        list.add(new MyModel("C", "D"));
+        list.add(new MyModel("E", "F"));
+        return list;
+    }
 
-		display.dispose();
-	}
+    public static void main(String[] args) {
+        Display display = new Display();
+        Shell shell = new Shell(display);
+        shell.setLayout(new FillLayout());
+        new Snippet031TableViewerCustomTooltipsMultiSelection(shell);
+        shell.open();
+
+        while (!shell.isDisposed()) {
+            if (!display.readAndDispatch())
+                display.sleep();
+        }
+
+        display.dispose();
+    }
 }
 
-	public class MyModel {
-		public String col1, col2;
+public class MyModel {
+    public String col1, col2;
 
-		public this(String c1, String c2) {
-			col1 = c1;
-			col2 = c2;
-		}
-		
-		public String toString() {
-			return col1 ~ col2;
-		}
+    public this(String c1, String c2) {
+        col1 = c1;
+        col2 = c2;
+    }
 
-	}
+    public String toString() {
+        return col1 ~ col2;
+    }
+}
+