Thread overview
jface.snippets.Snippet031 : Win32 Exception
May 21, 2008
yidabu
May 21, 2008
Frank Benoit
May 21, 2008
yidabu
May 21, 2008
yidabu
Re: jface.snippets.Snippet031 done
May 21, 2008
yidabu
May 22, 2008
yidabu
May 21, 2008
Frank Benoit
May 21, 2008
yidabu
May 21, 2008
debug mode :run time exception: Win32 Exception
release mode: run time exception: Access Violation

ddbg output:

Unhandled Exception: EXCEPTION_PRIV_INSTRUCTION(0xc0000096) at dwt.custom.BusyIn
dicator.BusyIndicator.showWhile.dwt.widgets.Display.Display.dwt.dwthelper.Runnab
le.Runnable dwt-win\dwt\custom\BusyIndicator.d:49 (0x0078727
a)

the code:


/*******************************************************************************
 * Copyright (c) 2007 Adam Neal 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:
 *     Adam Neal - initial API and implementation
 * Port to the D programming language:
 *     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

import tango.util.collection.ArraySeq;
import tango.util.Convert;

import dwtx.jface.viewers.ArrayContentProvider;
import dwtx.jface.viewers.ILabelProviderListener;
import dwtx.jface.viewers.ITableLabelProvider;
import dwtx.jface.viewers.TableViewer;
import dwt.DWT;
import dwt.graphics.Image;
import dwt.graphics.Point;
import dwt.graphics.Rectangle;
import dwt.layout.FillLayout;
import dwt.widgets.Display;
import dwt.widgets.Event;
import dwt.widgets.Label;
import dwt.widgets.Listener;
import dwt.widgets.Shell;
import dwt.widgets.Table;
import dwt.widgets.TableColumn;
import dwt.widgets.TableItem;

import dwt.dwthelper.System;

alias char[] String;
void main(String[] args)
{
    Snippet031TableViewerCustomTooltipsMultiSelection.main(args);
}

/**
 * A simple TableViewer to demonstrate how custom tooltips could be created easily while preserving
 * the multiple selection.
 *
 * 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 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 void addListener(ILabelProviderListener listener) {
			/* Ignore */
		}

		public void dispose() {
			/* Ignore */
		}

		public bool isLabelProperty(Object element, String property) {
			return false;
		}

		public void removeListener(ILabelProviderListener listener) {
			/* Ignore */
		}

	}

    alias ArraySeq!(MyModel) ArrayList;
	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(Shell shell) {

        tooltipLabelListener = new TooltipLabelListener();

		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 */
        tableColumn1.setText(column1);
        tableColumn2.setText(column2);
        tableColumn1.pack();
        tableColumn2.pack();

        v.setColumnProperties([ column1, column2 ]);
		v.setLabelProvider(new MyLableProvider());
		v.setContentProvider(new ArrayContentProvider());
		v.setInput(createModel());

		/**
	     * 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 = new class Listener  {
	    	Shell tooltip = null;
	    	Label label = null;

	    	/*
	    	 * (non-Javadoc)
	    	 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
	    	 */
	    	public void handleEvent (Event 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;
				   				}
				   			}
				   		}
				   	}
			   }
	    	}
		};

		table.addListener (DWT.Dispose, tableListener);
		table.addListener (DWT.KeyDown, tableListener);
		table.addListener (DWT.MouseMove, tableListener);
		table.addListener (DWT.MouseHover, tableListener);
	}

	   /**
	    * 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;



	private ArrayList createModel() {
		ArrayList list = new ArrayList();
		list.append(new MyModel("A", "B"));
		list.append(new MyModel("C", "D"));
		list.append(new MyModel("E", "F"));
		return list;
	}

	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();
	}
}


	    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;
			   }
	    }}



-- 
yidabu <yidabu.spam@gmail.com> http://www.dsource.org/projects/dwin

D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/


May 21, 2008
yidaby, thanks for your ported snippets.

Posting them here is certainly ok, just in case you didn't know:
If you want, you can create mercurial bundles, that would save both of us some work and your name would show up in the commit history. http://www.dsource.org/projects/dwt/wiki/Contribution

I will look at those runtime problems later ...

May 21, 2008
A potential problem might be the access to local variables that were no more alive.
A Java local variable with keyword "final" is like a big red warning for me. When porting this to D, it needs special care to examing the accesses to this variable. In Java the "final" makes this variable to be available for anonymouse classes even if the method exits. This feature is in D2 available as "full closure". In D1, you need to take for this on your own.

In your code, there is this "final Table table = new Table(..." which is accessed from the anonymous Listener directly.
Possible solutions:

1.) create a local variable in the anonymouse class for the table. Call this variable eg. "table_". Create a constructor [1] and pass it table as "new class(table) Listener {...". Replace all "table" accesses in the class with "table_".
The resulting code is verbose and this is error-prune, because there is no compiler supported check if you missed one of the problematic accesses.

2.) Make a named class outside the local scope
This will immediatly show you the problematic accesses. But still the code will be verbose.

3.) use the dgListener template function. you can move the handleEvent function where you want and you do not need the verbose extra variable saving.


[1] initializing the variable directly with the outer var does create new problems. The compiler has to choose for a context pointer for this class. Either the context of the surrounding method or the "this" of the surrounding class. If you initialize the anonymouse class members directly the compiler will choose the methods context and an attemp to access outer member after the surrounded method has exited, => crash.

May 21, 2008
On Wed, 21 May 2008 09:57:00 +0200
Frank Benoit <keinfarbton@googlemail.com> wrote:

> yidaby, thanks for your ported snippets.
> 
> Posting them here is certainly ok, just in case you didn't know:
> If you want, you can create mercurial bundles, that would save both of
> us some work and your name would show up in the commit history.
> http://www.dsource.org/projects/dwt/wiki/Contribution

Thanks, I will create mercurial bundles.



-- 
yidabu <yidabu.spam@gmail.com> http://www.dsource.org/projects/dwin

D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/


May 21, 2008
On Wed, 21 May 2008 10:20:07 +0200
Frank Benoit <keinfarbton@googlemail.com> wrote:

> A potential problem might be the access to local variables that were no
> more alive.
> A Java local variable with keyword "final" is like a big red warning for
> me. When porting this to D, it needs special care to examing the
> accesses to this variable. In Java the "final" makes this variable to be
> available for anonymouse classes even if the method exits. This feature
> is in D2 available as "full closure". In D1, you need to take for this
> on your own.
> 
> In your code, there is this "final Table table = new Table(..." which is
> accessed from the anonymous Listener directly.
> Possible solutions:
> 
> 1.) create a local variable in the anonymouse class for the table. Call
> this variable eg. "table_". Create a constructor [1] and pass it table
> as "new class(table) Listener {...". Replace all "table" accesses in the
> class with "table_".
> The resulting code is verbose and this is error-prune, because there is
> no compiler supported check if you missed one of the problematic accesses.
> 
> 2.) Make a named class outside the local scope
> This will immediatly show you the problematic accesses. But still the
> code will be verbose.
> 
> 3.) use the dgListener template function. you can move the handleEvent function where you want and you do not need the verbose extra variable saving.
> 
> 
> [1] initializing the variable directly with the outer var does create new problems. The compiler has to choose for a context pointer for this class. Either the context of the surrounding method or the "this" of the surrounding class. If you initialize the anonymouse class members directly the compiler will choose the methods context and an attemp to access outer member after the surrounded method has exited, => crash.

Frank Benoit, Thanks a million
I will check the code.

-- 
yidabu <yidabu.spam@gmail.com> http://www.dsource.org/projects/dwin

D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/


May 21, 2008
On Wed, 21 May 2008 09:57:00 +0200
Frank Benoit <keinfarbton@googlemail.com> wrote:

> yidaby, thanks for your ported snippets.
> 
> Posting them here is certainly ok, just in case you didn't know:
> If you want, you can create mercurial bundles, that would save both of
> us some work and your name would show up in the commit history.
> http://www.dsource.org/projects/dwt/wiki/Contribution
> 
> I will look at those runtime problems later ...

code works fine now.
but dwtx.jface.viewers.ArrayContentProvider seems not work, I added code below to figure it out:

    public class MyContentProvider : ArrayContentProvider
    {
        public Object[] getElements(Object inputElement) {
            auto col = cast(ArrayList) inputElement;
            return col.toArray();
        }
    }


-- 
yidabu <yidabu.spam@gmail.com> http://www.dsource.org/projects/dwin

D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/


May 21, 2008
Code:




/*******************************************************************************
 * Copyright (c) 2007 Adam Neal 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:
 *     Adam Neal - initial API and implementation
 * Port to the D programming language:
 *     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

import tango.util.collection.ArrayBag;
alias ArrayBag!(MyModel) ArrayList;
import tango.util.Convert;

import dwtx.jface.viewers.ArrayContentProvider;
import dwtx.jface.viewers.ILabelProviderListener;
import dwtx.jface.viewers.ITableLabelProvider;
import dwtx.jface.viewers.TableViewer;
import dwt.DWT;
import dwt.graphics.Image;
import dwt.graphics.Point;
import dwt.graphics.Rectangle;
import dwt.layout.FillLayout;
import dwt.widgets.Display;
import dwt.widgets.Event;
import dwt.widgets.Label;
import dwt.widgets.Listener;
import dwt.widgets.Shell;
import dwt.widgets.Table;
import dwt.widgets.TableColumn;
import dwt.widgets.TableItem;
import dwt.dwthelper.System;
import dwt.widgets.Listener;

alias char[] String;
void main(String[] args)
{
    Snippet031TableViewerCustomTooltipsMultiSelection.main(args);
}

/**
 * A simple TableViewer to demonstrate how custom tooltips could be created easily while preserving
 * the multiple selection.
 *
 * 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 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 "novalue";
		}

		public void addListener(ILabelProviderListener listener) {
			/* Ignore */
		}

		public void dispose() {
			/* Ignore */
		}

		public bool isLabelProperty(Object element, String property) {
			return false;
		}

		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);
        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 */
        tableColumn1.setText(column1);
        tableColumn2.setText(column2);
        tableColumn1.pack();
        tableColumn2.pack();

        v.setColumnProperties([ column1, column2 ]);
		v.setLabelProvider(new MyLableProvider());
		//v.setContentProvider(new ArrayContentProvider());
		v.setContentProvider(new MyContentProvider());
		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);

		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;
                            }
                        }
                    }
                }
           }

    }

	   /**
	    * 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;
			   }
	    }}



	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;
	}

	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 this(String c1, String c2) {
			col1 = c1;
			col2 = c2;
		}

		public String toString() {
			return col1 ~ col2;
		}

	}

    public class MyContentProvider : ArrayContentProvider
    {
        public Object[] getElements(Object inputElement) {
            auto col = cast(ArrayList) inputElement;
            return col.toArray();
        }
    }




-- 
yidabu <yidabu.spam@gmail.com> http://www.dsource.org/projects/dwin

D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/


May 22, 2008
I will try commit it when ArrayContentProvider issue fixed.




-- 
yidabu <yidabu.spam@gmail.com> http://www.dsource.org/projects/dwin

D 语言-中文(D Chinese): http://www.d-programming-language-china.org/ http://bbs.d-programming-language-china.org/ http://dwin.d-programming-language-china.org/ http://scite4d.d-programming-language-china.org/