www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.dwt - face ArrayContentProvider getElements returns null

reply yidabu <yidabu.spam gmail.com> writes:
I created a ticket for it:
http://www.dsource.org/projects/dwt/ticket/6

he bug is , col.toArray not executed

    public Object[] getElements(Object inputElement) {
        if ( auto aw = cast(ArrayWrapperObject) inputElement ) {
            return aw.array;
        }
        if ( auto col = cast(View!(Object)) inputElement ) {
            return col.toArray();
        }
        return null;
    }

example code:

import dwtx.jface.viewers.ArrayContentProvider;
import dwtx.jface.viewers.LabelProvider;
import dwtx.jface.viewers.TableViewer;
import dwtx.jface.viewers.Viewer;
import dwt.layout.FillLayout;
import dwt.widgets.Display;
import dwt.widgets.Shell;
import dwt.DWT;

import dwt.dwthelper.utils;

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

public class Snippet001TableViewer {

	
	public class MyModel {
		public int counter;
		
		public this(int counter) {
			this.counter = counter;
		}
		
		public String toString() {
			return "Item " ~ to!(char[])(this.counter);
		}
	}
	
	public this(Shell shell) {
		final TableViewer v = new TableViewer(shell);
		v.setLabelProvider(new LabelProvider());
		v.setContentProvider(new ArrayContentProvider());
		ArraySeq!(MyModel) model = createModel();
		v.setInput(model);
		v.getTable().setLinesVisible(true);
	}
	
	private ArraySeq!(MyModel) createModel() {
		ArraySeq!(MyModel) elements = new ArraySeq!(MyModel);
        elements.capacity  = 10;

		for( int i = 0; i < 10; i++ ) {
			elements ~= new MyModel(i);
		}
		
		return elements;
	}
	
}

void main() 
{
    Display display = new Display ();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    new Snippet001TableViewer(shell);
    shell.open ();
		
    while (!shell.isDisposed ()) {
        if (!display.readAndDispatch ()) display.sleep ();
    }
		
    display.dispose ();

}



-- 
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
parent Frank Benoit <keinfarbton googlemail.com> writes:
yidabu schrieb:
 I created a ticket for it:
 http://www.dsource.org/projects/dwt/ticket/6
 
 he bug is , col.toArray not executed
 
     public Object[] getElements(Object inputElement) {
         if ( auto aw = cast(ArrayWrapperObject) inputElement ) {
             return aw.array;
         }
         if ( auto col = cast(View!(Object)) inputElement ) {
             return col.toArray();
         }
         return null;
     }

Hm, yes ArraySeq!(Object) can be casted to View!(Object) MyModel can be casted to Object but ArraySeq!(MyModel) cannot be casted to View!(Object) What i did to solve the problem is, to make ArrayContentProvider a template. Now, if the example is changed to use ArrayContentProvider!(MyModel) is works.
May 22 2008