TableView Objects with nested Objects

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

TableView Objects with nested Objects

Separovic, Jason

Hi,

 

I’m developing an app that is able to generate a generic CRUD type interface for a bunch of JPA Classes in a given package.

 

For now, I’ve decided to use ListButtons for OneToOne mappings (and ListViews for OneToMany mappings)

 

I’m testing the OneToOne bit and while I’m able to display the “toString” representation in the listButton, I’m not too sure on what is needed to store the selected object back to the row object prior to persisting it in the DB.

 

This is where I define the cell editor.

 

                                  Class columnClass = f.getType();

                                  List<Object> columnObjects = dao.getAll(columnClass);

 

                                  ListButton listButton = new ListButton();

                                  ArrayList listData = new ArrayList();

                                 

                                  listData.add(null);

                                  for(Object o : columnObjects) {

                                         listData.add(o);

                                  }

                                 

                                  listButton.setListData(listData);

                                  tableViewRowEditor.getCellEditors().put(f.getName(), listButton);

 

Do I need to use a data binding? I was wondering if someone could point me to an example I can look at?

 

Cheers,

 

Jason

 

This message and its attachments may contain legally privileged or confidential information. It is for the intended addressee(s) only.

If you are not the intended recipient you must not disclose or use the information contained in it. If you have received this email in error please notify us immediately by return email and delete the document.

Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of the Company.

Uecomm accepts no liability for any damage caused by this email or its attachments due to viruses, interference, interception, corruption or unauthorised access.


This e-mail message has been scanned for Viruses and Content and cleared by NetIQ MailMarshal
Reply | Threaded
Open this post in threaded view
|

RE: TableView Objects with nested Objects

Roger Whitcomb-2

Hi Jason,

                In a short word, yes, the row editors rely on data binding.  For instance, the TableViewRowEditor.beginEdit method has this code:

        // Get the data being edited

        List<?> tableData = tableViewArgument.getTableData();

        Object tableRow = tableData.get(rowIndexArgument);

 

        // Load the row data into the editor components

        tablePane.load(tableRow);

 

                And likewise the endEdit method does this:

            // Update the row data

            List<Object> tableData = (List<Object>)tableView.getTableData();

            Object tableRow = tableData.get(rowIndex);

            tablePane.store(tableRow);

 

                The standard Pivot Data Binding tutorial is quite helpful:  http://pivot.apache.org/tutorials/data-binding.html

                Basically your data can be a POJO using bean methods to get and set the data, and your column names must match the bean property names.

 

                If you need more help, just ask – we’ve been through this before.

 

Thanks,

~Roger Whitcomb

Reply | Threaded
Open this post in threaded view
|

RE: TableView Objects with nested Objects

Separovic, Jason

Hi Roger,

 

Thanks for the response. I was just missing the setSelectedItemKey bit as per the tutorial.

So my nested object is now binding correctly thanks.

 

ListButton listButton = new ListButton();

ArrayList listData = new ArrayList();

                                 

listData.add(null);

       for(Object o : dao.getAll(f.getType())) {

              listData.add(o);

       }

      

       String key = f.getName();

       listButton.setListData(listData);

       listButton.setSelectedItemKey(key);

       tableViewRowEditor.getCellEditors().put(key, listButton);

 

I’m just trying to figure out how to use a different representation of the object instead of the default toString() method. Is the ItemRenderer responsible for what is displayed in the button?

Do I create my own renderer if I what to use the getName() object method instead of the toString() method?

 

Cheers,

 

Jason

 

 

 

 

 

From: Roger L. Whitcomb [mailto:[hidden email]]
Sent: Friday, 24 May 2013 5:21 AM
To: [hidden email]
Subject: RE: TableView Objects with nested Objects

 

Hi Jason,

                In a short word, yes, the row editors rely on data binding.  For instance, the TableViewRowEditor.beginEdit method has this code:

        // Get the data being edited

        List<?> tableData = tableViewArgument.getTableData();

        Object tableRow = tableData.get(rowIndexArgument);

 

        // Load the row data into the editor components

        tablePane.load(tableRow);

 

                And likewise the endEdit method does this:

            // Update the row data

            List<Object> tableData = (List<Object>)tableView.getTableData();

            Object tableRow = tableData.get(rowIndex);

            tablePane.store(tableRow);

 

                The standard Pivot Data Binding tutorial is quite helpful:  http://pivot.apache.org/tutorials/data-binding.html

                Basically your data can be a POJO using bean methods to get and set the data, and your column names must match the bean property names.

 

                If you need more help, just ask – we’ve been through this before.

 

Thanks,

~Roger Whitcomb

 

This message and its attachments may contain legally privileged or confidential information. It is for the intended addressee(s) only.

If you are not the intended recipient you must not disclose or use the information contained in it. If you have received this email in error please notify us immediately by return email and delete the document.

Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of the Company.

Uecomm accepts no liability for any damage caused by this email or its attachments due to viruses, interference, interception, corruption or unauthorised access.


This e-mail message has been scanned for Viruses and Content and cleared by NetIQ MailMarshal
Reply | Threaded
Open this post in threaded view
|

RE: TableView Objects with nested Objects

Separovic, Jason
In reply to this post by Roger Whitcomb-2

I tried to set the Item Renderer with my own implementation but it does not seem to call the toString method:

 

       OrderHandler handler = psfServer.getOrderHandler();

       GenericDao dao = new GenericDao(handler.getEntityManager(), handler.getUserTransaction());

      

       ListButton listButton = new ListButton();

       ArrayList listData = new ArrayList();

      

       listData.add(null);

       for(Object o : dao.getAll(f.getType())) {

              listData.add(o);

       }

      

       String key = f.getName();

       listButton.setListData(listData);

       listButton.setSelectedItemKey(key);

      

       listButton.setItemRenderer(new GetNameItemRenderer());

       tableViewRowEditor.getCellEditors().put(key, listButton);

      

       displayedFields.put(f.getName(), f);

       psfServer.returnOrderHandler(handler);

 

 

public class GetNameItemRenderer extends ListViewItemRenderer {

       @Override

       public String toString(Object item) {

              String name = null;

              try {

                     name = (String) item.getClass().getMethod("getName", new Class[]{String.class}).invoke(item, null);

              } catch (IllegalArgumentException e) {

                     e.printStackTrace();

              } catch (SecurityException e) {

                     e.printStackTrace();

              } catch (IllegalAccessException e) {

                     e.printStackTrace();

              } catch (InvocationTargetException e) {

                     e.printStackTrace();

              } catch (NoSuchMethodException e) {

                     e.printStackTrace();

              }

              return null;

       }

}      

 

 

 

This message and its attachments may contain legally privileged or confidential information. It is for the intended addressee(s) only.

If you are not the intended recipient you must not disclose or use the information contained in it. If you have received this email in error please notify us immediately by return email and delete the document.

Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of the Company.

Uecomm accepts no liability for any damage caused by this email or its attachments due to viruses, interference, interception, corruption or unauthorised access.


This e-mail message has been scanned for Viruses and Content and cleared by NetIQ MailMarshal
Reply | Threaded
Open this post in threaded view
|

Re: TableView Objects with nested Objects

Roger and Beth Whitcomb
In reply to this post by Separovic, Jason
Hi Jason,
   There are actually two renderers you need to set/change: the ItemRenderer is for the drop down items in the list and the (Button) DataRenderer is for the button itself (i.e., the part that is always displayed).  
   If you need help coding those, let us know. But should be pretty simple to use a different method to get the text.

~Roger Whitcomb

Reply | Threaded
Open this post in threaded view
|

Re: TableView Objects with nested Objects

Roger and Beth Whitcomb
In reply to this post by Separovic, Jason
Renderers get their "render" method called. In that method, cast the data object to your type and call the "getName" method of your data object. 

I'm not at my computer right now, but there are several tutorials and demos that use custom renderers that you can look at. 

~Roger Whitcomb

Sent from my iPhone

On May 23, 2013, at 5:52 PM, "Separovic, Jason" <[hidden email]> wrote:

I tried to set the Item Renderer with my own implementation but it does not seem to call the toString method:

 

       OrderHandler handler = psfServer.getOrderHandler();

       GenericDao dao = new GenericDao(handler.getEntityManager(), handler.getUserTransaction());

      

       ListButton listButton = new ListButton();

       ArrayList listData = new ArrayList();

      

       listData.add(null);

       for(Object o : dao.getAll(f.getType())) {

              listData.add(o);

       }

      

       String key = f.getName();

       listButton.setListData(listData);

       listButton.setSelectedItemKey(key);

      

       listButton.setItemRenderer(new GetNameItemRenderer());

       tableViewRowEditor.getCellEditors().put(key, listButton);

      

       displayedFields.put(f.getName(), f);

       psfServer.returnOrderHandler(handler);

 

 

public class GetNameItemRenderer extends ListViewItemRenderer {

       @Override

       public String toString(Object item) {

              String name = null;

              try {

                     name = (String) item.getClass().getMethod("getName", new Class[]{String.class}).invoke(item, null);

              } catch (IllegalArgumentException e) {

                     e.printStackTrace();

              } catch (SecurityException e) {

                     e.printStackTrace();

              } catch (IllegalAccessException e) {

                     e.printStackTrace();

              } catch (InvocationTargetException e) {

                     e.printStackTrace();

              } catch (NoSuchMethodException e) {

                     e.printStackTrace();

              }

              return null;

       }

}      

 

 

 

This message and its attachments may contain legally privileged or confidential information. It is for the intended addressee(s) only.

If you are not the intended recipient you must not disclose or use the information contained in it. If you have received this email in error please notify us immediately by return email and delete the document.

Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of the Company.

Uecomm accepts no liability for any damage caused by this email or its attachments due to viruses, interference, interception, corruption or unauthorised access.


This e-mail message has been scanned for Viruses and Content and cleared by NetIQ MailMarshal
Reply | Threaded
Open this post in threaded view
|

RE: TableView Objects with nested Objects

Separovic, Jason
In reply to this post by Roger and Beth Whitcomb
Thanks Roger, got it working.


    public void render(Object item, int index, ListView listView, boolean selected, boolean checked, boolean highlighted, boolean disabled) {
        renderStyles(listView, selected, highlighted, disabled);
                if(item==null) {
                        label.setText("--select--");
                }
                else {
                try {
                        label.setText((String) item.getClass().getMethod("getName").invoke(item, null));
                        }
                catch (Exception e) {
                                e.printStackTrace();
                        }
                }
    }
This message and its attachments may contain legally privileged or confidential information. It is for the intended addressee(s) only.
If you are not the intended recipient you must not disclose or use the information contained in it. If you have received this email in error please notify us immediately by return email and delete the document.
Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of the Company.
Uecomm accepts no liability for any damage caused by this email or its attachments due to viruses, interference, interception, corruption or unauthorised access.

#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by NetIQ MailMarshal
#####################################################################################
Reply | Threaded
Open this post in threaded view
|

Re: TableView Objects with nested Objects

Roger and Beth Whitcomb
Very cool. Let us know if you have more difficulties.

~Roger Whitcomb