Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » How to register a listener to datachange on Form or Page
How to register a listener to datachange on Form or Page [message #1842323] Wed, 16 June 2021 13:37 Go to next message
Seydou Zakou is currently offline Seydou ZakouFriend
Messages: 44
Registered: May 2020
Member
Hi all,

I have a form with a table field inside And I need to know when the data in the TableField is dirty [modified from some where (another Form) in the application ] to notify the user when he come back to the form so he could reopen/reload the form.
Try to follow indication at this thread https://www.eclipse.org/forums/index.php/t/1100146/ but don't know where to start.

Does anyone has an idea ?

Thank you.
Re: How to register a listener to datachange on Form or Page [message #1842335 is a reply to message #1842323] Wed, 16 June 2021 16:41 Go to previous messageGo to next message
Mr Robot is currently offline Mr RobotFriend
Messages: 72
Registered: March 2020
Member
Hello,

you could use Client Notifications.

Check this:
https://eclipsescout.github.io/10.0/technical-guide.html#client-notifications.

So when form is stored in service you create notification, on client side you have listener to reload form when notification is sent
Re: How to register a listener to datachange on Form or Page [message #1842347 is a reply to message #1842335] Wed, 16 June 2021 19:53 Go to previous messageGo to next message
Seydou Zakou is currently offline Seydou ZakouFriend
Messages: 44
Registered: May 2020
Member
Thanks for your reply.

But if I can listen for change directly from Form or Page, since I saw that AbstractForm and AbstractPage already register for change listeners, it will be simpler than implementing the client notification system, that also lack sample use case.
Re: How to register a listener to datachange on Form or Page [message #1842363 is a reply to message #1842347] Thu, 17 June 2021 07:35 Go to previous messageGo to next message
Claudio Guglielmo is currently offline Claudio GuglielmoFriend
Messages: 259
Registered: March 2010
Senior Member
Hi,

to check, whether a table is dirty, you can use the method isSaveNeeded of ITableField.
If you want to listen for changes, you can add a table listener to the table using ITable.addTableListener. You are probably interested in TableEvent.TYPE_ROWS_INSERTED, TableEvent.TYPE_ROWS_UPDATED, TableEvent.TYPE_ROWS_DELETED.

If you need to be notified when a form is closed, add a form listener to the form using IForm.addFormListener with the type FormEvent.TYPE_CLOSED. With the IForm.getCloseSystemType() you can determine whether the user pressed Ok or Cancel, or just use IForm.isFormStored().

If you want, you can then trigger a DataChangeEvent, as described in the linked post, to inform other widgets that your data changed, but I don't think this is necessary for your use case.

If you want to get informed when another user changes the data displayed on your form, then you should use client notifications.
Re: How to register a listener to datachange on Form or Page [message #1842371 is a reply to message #1842363] Thu, 17 June 2021 09:59 Go to previous messageGo to next message
Seydou Zakou is currently offline Seydou ZakouFriend
Messages: 44
Registered: May 2020
Member
Thank you for your reponse.

If I understand, {ITable, IForm} listeners respond to event on client side, I can't fire these events from server side.
I just tried the client notification as below:
- Shared module
public class NotificationMessage implements serializable {
  private static final long serialVersionUID = -913943548821914510L; 
  private String message;
  // setters/getters/ctors
}

- Server side
NotificationMessage msg = new NotificationMessage("..");
BEANS.get(ClientNotificationRegistry.class).putForAllSessions(msg);

- Client Side
public class MessageNotificationHandler implements INotificationHandler<NotificationMessage> {
	@Override
	public void handleNotification(NotificationMessage notification) {
		ModelJobs.schedule(() -> {
			if (Desktop.CURRENT.get() != null) {
				Desktop.CURRENT.get().addNotification(new DesktopNotification("Notification Got: Message = " + notification.getMessage()));
			}
		}, ModelJobs.newInput(ClientRunContexts.copyCurrent()));
	}
}


My problem now is that I don't know how to attach this handler only on some specific Page or Form, so I can access the widget on it.

Thank you.
Re: How to register a listener to datachange on Form or Page [message #1842383 is a reply to message #1842371] Thu, 17 June 2021 12:40 Go to previous messageGo to next message
Mr Robot is currently offline Mr RobotFriend
Messages: 72
Registered: March 2020
Member
On you handleNotification method, you can check for active form/page.

For example:
if(Desktop.CURRENT.get().getOutline().getActivePage() instanceof SomeActivePage.class) {
       Desktop.CURRENT.get().getOutline().getActivePage().reloadPage();
}


Re: How to register a listener to datachange on Form or Page [message #1842533 is a reply to message #1842383] Tue, 22 June 2021 12:28 Go to previous message
Seydou Zakou is currently offline Seydou ZakouFriend
Messages: 44
Registered: May 2020
Member
Thanks Mr Robot, I will try that.
Previous Topic:Copy to clipboard from table not working
Next Topic:REST with authentication
Goto Forum:
  


Current Time: Wed Dec 11 22:31:27 GMT 2024

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

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

Back to the top