|
|
|
|
Re: PageBox [message #939018 is a reply to message #937955] |
Wed, 10 October 2012 10:58 |
Bertin Kiekebosch 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 #943523 is a reply to message #935784] |
Sun, 14 October 2012 16:08 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03844 seconds