Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Ticket #6 (closed defect: fixed)

Opened 13 years ago

Last modified 13 years ago

jface ArrayContentProvider getElements return null

Reported by: yidabu Assigned to: keinfarbton
Priority: major Milestone: milestone4
Component: DWT-Addons Version: 1.0
Keywords: ArrayContentProvider Cc: yidabu@gmail.com

Description

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

}

Change History

05/22/08 18:10:27 changed by keinfarbton

  • status changed from new to closed.
  • resolution set to fixed.

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.