Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » PageBox
PageBox [message #935784] Sun, 07 October 2012 10:07 Go to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi

Does anyone have an example of a pagebox. I want to have a table and a detailform in it and when you select a row in the table you can edit the details of the selected item.

regards Bertin
Re: PageBox [message #937058 is a reply to message #935784] Mon, 08 October 2012 16:11 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Hi Bertin,

Do I understand it correctly that you want to have a table page that is split horizontally: The upper half containing the table and the lower half containing a detail form that is loaded with the selected row from the table?
Re: PageBox [message #937788 is a reply to message #937058] Tue, 09 October 2012 09:00 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi Ken,

that is correct.

I already have the table with the detail form below it (using the pageBox). As soon as a row is selected the details are shown in the form.

Now one step further is when I edit the details, the form should ask for saving it changes before it is reloaded when the user selects another row.

I wondered if there was an example for this because discovering how to do it is time consuming, and maybe this is already available in Scout when you configure the components in the right way.

Regards Bertin
Re: PageBox [message #937955 is a reply to message #937788] Tue, 09 October 2012 12:07 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Hi Bertin,

Can you post a code snippet what you've done so far? I'll have a look at it and will give you some feedback.
Re: PageBox [message #939018 is a reply to message #937955] Wed, 10 October 2012 10:58 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi Ken

The goal is to have a table and a form that work together. I have a table page with just two columns, a number and a name and I have a form with two fields. In the execInitField of the page box these are added to the PageBox. I added a listener to the table that reacts on TYPE_ROW_CLICK.

The problem with using the TYPE_ROW_CLICK is that when you use the arrow-key to change the row nothing happens. (Tried TYPE_ROWS_SELECTED but that makes problems worse when the user selects the cancel button)

When the user selects another row in the table and data is changed, I present a messageBox "Sava changes " with Yes, No and Cancel buttons. Yes and No work fine. But cancel would mean that the row will not be changed. I do this by setting the row back to the previous selected but there is still a focus border visible on the previous selected cell.

So maybe you have some I deas to improve this, already thanks for your effort.

Regards bertin


    @Order(20.0)
    public class TestPageBox extends AbstractPageField {

      @Override
      protected String getConfiguredLabel() {
        return TEXTS.get("TestPage");
      }

      @Override
      protected void execInitField() throws ProcessingException {
        LegoSetsTablePage page = new LegoSetsTablePage();
        setPage(page);

        LegoSetForm form = new LegoSetForm();
        getDetailFormField().setInnerForm(form);

        page.getTable().addTableListener(new TableListener() {

          @Override
          public void tableChangedBatch(TableEvent[] batch) {
          }

          @Override
          public void tableChanged(TableEvent e) {

            boolean stopTableChange = false;
            if (TableEvent.TYPE_ROW_CLICK == e.getType()) {
              LegoSetsTablePage.Table table = (LegoSetsTablePage.Table) e.getTable();

              LegoSetForm form2 = (LegoSetForm) TestPageBox.this.getDetailFormField().getInnerForm();
              LegoSetFormData formData = new LegoSetFormData();
              try {
                form2.exportFormData(formData);
              }
              catch (ProcessingException e3) {
                e3.printStackTrace();
              }
              try {
                form2.checkSaveNeeded();
                if (form2.isSaveNeeded()) {
                  MessageBox messageBox = new MessageBox(
                      null,
                      getCancelVerificationText(),
                      null,
                      TEXTS.get("YesButton"),
                      TEXTS.get("NoButton"),
                      TEXTS.get("CancelButton")
                      );
                  messageBox.setSeverity(IProcessingStatus.INFO);
                  int result = messageBox.startMessageBox();
                  if (result == IMessageBox.YES_OPTION) {
                    formData = SERVICES.getService(ILegoSetProcessService.class).store(formData);
                  }
                  else if (result == IMessageBox.NO_OPTION) {
                  }
                  else {
                    stopTableChange = true;
                  }
                }
              }
              catch (ProcessingException e2) {
                e2.printStackTrace();
              }

              if (stopTableChange) {
                Integer legoSetNr = formData.getLegoSetNr();
                if (legoSetNr != null) {
                  for (int i = 0; i < table.getRowCount(); i++) {
                    if (table.getSetNrColumn().getValue(i).equals(legoSetNr)) {
                      table.selectRow(i);
                      table.scrollToSelection();
                      break;
                    }
                  }
                }
              }
              else
              {
                form2.setLegoSetNr(table.getSetNrColumn().getValue(table.getSelectedRow()));
                try {
                  form2.exportFormData(formData);
                  formData = SERVICES.getService(ILegoSetProcessService.class).load(formData);
                  form2.importFormData(formData);
                  form2.markSaved();
                }
                catch (ProcessingException e1) {
                  e1.printStackTrace();
                }
              }
            }
          }
        });
      }
    }

Re: PageBox [message #939940 is a reply to message #939018] Thu, 11 October 2012 06:54 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin KiekeboschFriend
Messages: 330
Registered: August 2011
Senior Member
Hi Ken,

The problem of the focus border is "solved". This only occurs in the native Swing look and feel. In the Rayo look and feel it looks fine.

I think for the rest we can live with it how it works now. The question left is, is there a better 'Scout' way to achieve this behaviour.

Regards Bertin

Re: PageBox [message #941560 is a reply to message #939940] Fri, 12 October 2012 16:42 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Hi Bertin,

In general, I think your code snippet is fine. The following are only some hints:


  • I would use TableAdapter instead of TableListener. Or was there a reason why you didn't want to implement the tableChangedBatch method?
  • In case you press the cancel button in the message box (stopTableChange = true), I'd rather implement a logic to save the last selected row on the table than iterating over all rows. You might achieve this by extending the setSelectedRows() method to store the currently selected row before the new selected row is set.



Re: PageBox [message #943523 is a reply to message #935784] Sun, 14 October 2012 16:08 Go to previous message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 256
Registered: March 2010
Senior Member
Hi Bertin

I would suggest to move the logic of loading and saving the data to the form rather than doing it in the pagefield itself. This makes the code a lot simpler and more readable, in my opinion. I tried to create an example to show you what I mean.

public class PersonBox extends AbstractPageField<PersonTablePage> {
  private IForm m_currentForm;
  private ITableRow m_selectedRow;

  @Override
  protected String getConfiguredLabel() {
    return TEXTS.get("Person");
  }

  @Override
  @ConfigOperation
  @Order(10.0)
  protected void execInitField() throws ProcessingException {
    setPage(new PersonTablePage());

    getTableField().getTable().addTableListener(new TableAdapter() {
      @Override
      public void tableChanged(TableEvent e) {
        if (e.getType() == TableEvent.TYPE_ROWS_SELECTED) {
          try {
            handleTableRowsSelected(e);
          }
          catch (ProcessingException e1) {
            SERVICES.getService(IExceptionHandlerService.class).handleException(e1);
          }
        }
      }

      private void handleTableRowsSelected(TableEvent e) throws ProcessingException {
        Table table = getPage().getTable();
        if ((m_selectedRow != null && table.getSelectedRow().equals(m_selectedRow))) {
          return;
        }
        if (m_currentForm != null) {
          try {
            //Force cancel confirmation box
            m_currentForm.doCancel();
            m_currentForm = null;
          }
          catch (VetoException vetoException) {
            selectPreviousSelectedRow();
            return;
          }
        }

        String selectedPersonNr = table.getPersonIdColumn().getSelectedValue();
        PersonForm personForm = new PersonForm();
        personForm.setPersonId(selectedPersonNr);
        getDetailFormField().setInnerForm(personForm);
        personForm.startModify();
        m_currentForm = personForm;
        m_selectedRow = table.getSelectedRow();
      }
    });
  }

  private void selectPreviousSelectedRow() {
    if (m_selectedRow == null) {
      return;
    }

    //Selection needs to be scheduled, otherwise it will be ignored, see SwtScoutTable
    ClientSyncJob job = new ClientSyncJob("reverting selection", ClientSession.get()) {
      @Override
      protected void runVoid(IProgressMonitor monitor) throws Throwable {
        getTableField().getTable().selectRow(m_selectedRow);
      }
    };
    job.schedule();
  }
}


Use it with care, I think it should work but it's not very well tested.

Best regards
Claudio
Previous Topic:Eclipse not picking up maven Managed Dependencies
Next Topic:How to split a Scout project to several sub-projects.
Goto Forum:
  


Current Time: Thu Mar 28 12:59:59 GMT 2024

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

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

Back to the top