Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Adding rows to tablefield
Adding rows to tablefield [message #932074] Wed, 03 October 2012 20:14 Go to next message
Sebastian Boccardi is currently offline Sebastian BoccardiFriend
Messages: 47
Registered: September 2012
Location: Montevideo
Member
Hi,

I need to add rows to a table field, the posible items for the rows are in a table in the database and it must be easy to find what you are looking to insert. Whats the best way to accomplish this?

There is a form and search form already for the database table. Should i create a special form and call it when the user whants to add something?, or there is a way to reuse the searchform in some way?

thanks in advance
sebastian
Re: Adding rows to tablefield [message #932467 is a reply to message #932074] Thu, 04 October 2012 06:04 Go to previous messageGo to next message
Patrick Baenziger is currently offline Patrick BaenzigerFriend
Messages: 96
Registered: September 2011
Member
Hello Sebastian

If I get your question right, you wish to:

  • Allow the user to choose from a set of elements (defined by a database table)
  • Add the chosen element as a new row into your table
  • (Likely, though not stated in your question: Save those new rows)


There are different ways to achieve what you wish to do.
I would suggest that you do NOT abuse the searchform to create the data but instead choose one of these two possible ways:

  • You can follow the 'open a form to edit/create'-pattern and open a new form to choose the data to insert, store it with the handler, and reload the table afterwards when the form was stored. Use a Smartfield configured with a lookupcall to load the elements from the database and to make sure that the user only chooses from them.
  • You can let the user add rows and edit them right in the table. This approach can work well if your table is opened in a form and when the user clicks 'OK' the changes are saved.

    • You configure the column(s) to be editable (getConfiguredEditable => true)
    • Add a menu to add rows (and possibly one to delete)
    • Use a smartcolumn to choose from your predefined elements using a lookupcall.
    • Use the row status (getStatus()) to determine if a row was changed, updated or deleted. You'll need this to save it.


In both cases, you will likely want to use a LookupCall to load the elements from the databse.

Hope this helps.
Regards, Patrick
Re: Adding rows to tablefield [message #933489 is a reply to message #932467] Fri, 05 October 2012 03:53 Go to previous messageGo to next message
Sebastian Boccardi is currently offline Sebastian BoccardiFriend
Messages: 47
Registered: September 2012
Location: Montevideo
Member
Patrick,

Thank you very much, everything worked... almost.

I decided to let the user add rows to the table and let him choose from a smartcolumn the "type" of item to add. Everything worked very well, is very easy to choose in the smart column, lookupcalls are easy to implement also (i will need some kind of cache i think later on).

The thing is that after the user selected an item, the drop-down disappears and the item appears in the cell, but when you click another cell o press tab or add a new row the item disappears from the cell.

I don't know why.....

Sebastian

Re: Adding rows to tablefield [message #933536 is a reply to message #933489] Fri, 05 October 2012 05:06 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 124
Registered: November 2010
Senior Member
Sebastian Boccardi wrote on Fri, 05 October 2012 05:53
I decided to let the user add rows to the table and let him choose from a smartcolumn the "type" of item to add. Everything worked very well, is very easy to choose in the smart column, lookupcalls are easy to implement also (i will need some kind of cache i think later on).


If you use a code type, your items are cached in the CodeType (on the server and on the client). The drawback is that you have call a reload function when the items in the database changed.

http://wiki.eclipse.org/Scout/Concepts/CodeType
Re: Adding rows to tablefield [message #933645 is a reply to message #933489] Fri, 05 October 2012 07:48 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Sebastian Boccardi wrote on Fri, 05 October 2012 05:53
The thing is that after the user selected an item, the drop-down disappears and the item appears in the cell, but when you click another cell o press tab or add a new row the item disappears from the cell.

I don't know why.....


At the end of Edition, you need to handle what should occurs with execCompleteEdit. In your case, you probably want to assign the selected value of the smartfiled, as value of the row (for this column).

Here a simple example:
@Order(20.0)
public class StyleColumn extends AbstractSmartColumn<Long> {

  @Override
  protected String getConfiguredHeaderText() {
    return ScoutTexts.get("Style");
  }

  @Override
  protected Class<? extends ICodeType> getConfiguredCodeType() {
    return StyleCodeType.class;
  }

  @Override
  protected boolean getConfiguredEditable() {
    return true;
  }

  @Override
  protected void execCompleteEdit(ITableRow row, IFormField editingField) throws ProcessingException {
    setValue(row, ((ILongField) editingField).getValue());
  }
}


We should document editable column, on the Column page in the wiki.
Re: Adding rows to tablefield [message #934494 is a reply to message #933645] Sat, 06 October 2012 02:16 Go to previous messageGo to next message
Sebastian Boccardi is currently offline Sebastian BoccardiFriend
Messages: 47
Registered: September 2012
Location: Montevideo
Member
 @Override
  protected void execCompleteEdit(ITableRow row, IFormField editingField) throws ProcessingException {
    setValue(row, ((ILongField) editingField).getValue());
  }


I don't know if i should take this code exactly as it is, but it throws a class cast exception.

Sebastian
Re: Adding rows to tablefield [message #934501 is a reply to message #934494] Sat, 06 October 2012 02:25 Go to previous messageGo to next message
Sebastian Boccardi is currently offline Sebastian BoccardiFriend
Messages: 47
Registered: September 2012
Location: Montevideo
Member
setValue(row, ((ISmartField<Long>) editingField).getValue())


This works, with a warning.
Re: Adding rows to tablefield [message #936714 is a reply to message #934501] Mon, 08 October 2012 09:00 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Sorry for the wrong class.

"ISmartField<Long>" produces a warning, because at runtime it is not possible to verify that the value is a Long... You can suppress the warning with a SuppressWarnings ("unchecked"), to indicate to the compiler that you are sure that you will get a Long.
==> See What is SuppressWarnings ("unchecked") in Java?


If you do not like having a SuppressWarning, the best you can do is to cast editingField to "ISmartField<?>" instead of "ISmartField<Long>".
But in this case, the value is an Object. So you need to cast this value to a long.
  @Override
  protected void execCompleteEdit(ITableRow row, IFormField editingField) throws ProcessingException {
    Object value ((ISmartField<?>) editingField).getValue();
    setValue(row, (Long) value);
  }


I am not sure which pattern is better.

.
Previous Topic:Wizard test
Next Topic:Problem in Webservices with JAX-WS of Scout Tutorials
Goto Forum:
  


Current Time: Tue Apr 23 06:21:55 GMT 2024

Powered by FUDForum. Page generated in 0.03615 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top