Hi Todd,

Attached is some sample code that causes a cast exception.

On Thu, 5 Nov 2009 02:30:02 am Todd Volkert wrote:
> It should work as you expect.  A few things to check:
> 
>    - Are you constructing it using a <DataTableView> element?
>    - If you put a sys-out in your DataTableView constructor, is it getting
>    run?
>    - Do you provide a no-args constructor in DataTableView?
> 
> If none of these checks yield any leads, you can send the WTKX in question,
> and I'll have a look.
> 
> -T
> 
> On Tue, Nov 3, 2009 at 8:44 PM, Scott Lanham <[email protected]> wrote:
> > Hi,
> >
> > I have a ScrollPane that contains as it's view a simple subclass of
> > TableView
> > called DataTableView. When retrieving an instance of DataTableView
> > defined in a
> > wtkx file using WTKXSerializer.get() a TableView is returned, not a
> > DataTableView. The strange thing is that I have previously had success
> > with a
> > custom Form done in the same way. Any clues as to where I may be going
> > wrong
> > is very appreciated.
> >
> > Cheers,
> >
> > Scott.
> 
package testing;

import org.apache.pivot.collections.HashMap;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.Button;
import org.apache.pivot.wtk.ButtonPressListener;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;

import org.apache.pivot.wtk.PushButton;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.content.TableViewRowEditor;
import org.apache.pivot.wtkx.WTKXSerializer;

public class testing implements Application
{
    private Window appWindow = null;
    private TestTableView view = null;
    private PushButton btn = null;
    
    public static void main(String[] args)
    {
        DesktopApplicationContext.main( testing.class, args );
    }

    public void startup( Display display, Map<String, String> properties ) throws Exception
    {        
        WTKXSerializer serial = new WTKXSerializer();
        appWindow = (Window) serial.readObject( this, "testing.xml" );

        view = (TestTableView) serial.get( "view" );

        TableViewRowEditor editor = new TableViewRowEditor();
        view.setRowEditor( editor );

        btn = (PushButton) serial.get( "btnNewRow" );

        btn.getButtonPressListeners().add( new ButtonPressListener()
        {
            public void buttonPressed( Button button )
            {
                HashMap<String, Object> map = new HashMap<String, Object>();

                map.put( "col1", "newCol1" );
                map.put( "col2", "newCol2" );

                ((List<Object>)(view.getTableData())).add( map );

                //view.getRowEditor().edit( view, ((List<Object>)(view.getTableData())).indexOf( map ), 0 );
                view.getRowEditor().editRow( view, 0, 0 );
            }
        });

        PushButton btnDel = (PushButton) serial.get( "btnDelRow" );

        btnDel.getButtonPressListeners().add( new ButtonPressListener()
        {
            public void buttonPressed( Button button )
            {
                int selectIndex = view.getSelectedIndex();

                if ( selectIndex != -1 )
                    ((List<Object>)(view.getTableData())).remove( selectIndex, 1 );
            }
        });

        PushButton btnMax = (PushButton) serial.get( "btnMaxWidthTest" );

        btnMax.getButtonPressListeners().add( new ButtonPressListener()
        {
            public void buttonPressed( Button button )
            {
                view.getColumns().get( 0 ).setMaximumWidth( 100 );
            }
        });

        appWindow.open(display);
    }

    public boolean shutdown( boolean optional ) throws Exception
    {
        if ( appWindow != null )
            appWindow.close();

        return false;
    }

    public void suspend() throws Exception
    {
    }

    public void resume() throws Exception
    {
    }
}

Attachment: testing.xml
Description: XML document

// Copyright 2008 SAEL Pty Ltd, Australia.

package testing;

import org.apache.pivot.wtk.TableView;

public class TestTableView extends TableView
{
    public TestTableView()
    {
    }
}

Reply via email to