Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Rich content in desktop notifications
Rich content in desktop notifications [message #1806461] Thu, 09 May 2019 12:06 Go to next message
Krzysztof Leja is currently offline Krzysztof LejaFriend
Messages: 55
Registered: April 2019
Member
Hi,
Is it possible to include richer content (eg icons, buttons, html content) in the desktop notification - triggered by ClientSession.get().getDesktop().addNotification() - such as in a popup?

In the example from the page https://scout.bsi-software.com/widgets/?dl=widget-desktop I can see that you can include only simple text in the notification. But when, for example, I click "View source on GitHub" there, it displays notification "Opening a new window automatically was blocked by the browser" with an additional "Open manually" button. This would indicate that there is some method to add additional elements to the notification.
Re: Rich content in desktop notifications [message #1806557 is a reply to message #1806461] Fri, 10 May 2019 10:59 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
Hi Krzysztof

Yes, when you take a look at the JavaScript source-code in PopupBlockerHandler#showNotification, you'll see that a "variant" of DesktopNotification.js is created instead of the regular Notification:

notification = scout.create('DesktopNotification:PopupBlocker', {
    parent: desktop,
    linkUrl: linkUrl,
    preserveOpener: this.preserveOpener
  });


This instantiates the class PopupBlockerDesktopNotification.js, where the _render function creates the HTML you mentioned in your post.

In a Scout Java application you could use a @ModelVariant to mark a specific Notification class, like this:

@ModelVariant("Special")
class SpecialDesktopNotification extends DesktopNotification {
  public SpecialDesktopNotification(IStatus status, long duration, boolean closable) {
    super(status, duration, closable);
  }
}


And add the notification like this:

DesktopNotification notification = new SpecialDesktopNotification(status, duration, closeable);
ClientSession.get().getDesktop().addNotification(notification);


In your *.ui.html project you need to add a JavaScript class "SpecialDesktopNotification.js" that extends DesktopNotification.js and register it in your module.js. Scout finds and instantiates this class by name-magic. In that class you can override the _render or _renderMessage function and implement whatever you need. A very simple approach could override _renderMessage and simply add the message from the status object as HTML, without encoding HTML as DesktopNotification.js does. Example:

scout.SpecialDesktopNotification.prototype._renderMessage = function() {
  var html = scout.nvl(this.status.message, '');
  this.$messageText.html(html);
};


André


Eclipse Scout Homepage | Documentation | GitHub
Re: Rich content in desktop notifications [message #1806563 is a reply to message #1806557] Fri, 10 May 2019 11:55 Go to previous messageGo to next message
Krzysztof Leja is currently offline Krzysztof LejaFriend
Messages: 55
Registered: April 2019
Member
Hi Andre,

Thank you for a detailed description of the solution for my case.
I will try to use your example with HTML content. It will do the job.

PS. Assuming you are from the development team of the Eclipse scout platform, I will ask you: are there any plans to add native support for richer notifications in the next releases of this platform?
I think that this would be often used functionality.
In particular, it would be nice to be able to display an additional icon in these notifications, in order to better illustrate to the user what the notification is about.
Re: Rich content in desktop notifications [message #1806568 is a reply to message #1806563] Fri, 10 May 2019 12:28 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
You're welcome.

Currently there's no specific plan to enhance the DesktopNotification. But I like the idea of making the notification more flexible, and while I was writing the post above, I thought it would be a good idea to add at least a "htmlEnabled" property. Some other widgets, like LabelField.js, already have that property, which allows to provide HTML content instead of plain text.

I'll add this (and your proposal about icon support) to our backlog.


Eclipse Scout Homepage | Documentation | GitHub
Re: Rich content in desktop notifications [message #1835257 is a reply to message #1806461] Sat, 28 November 2020 09:29 Go to previous messageGo to next message
Krzysztof Leja is currently offline Krzysztof LejaFriend
Messages: 55
Registered: April 2019
Member
Hi,
I used the above idea with @ModelVariant and HTML content and it works fine. I can display icons and other graphical objects.

However, I still have a problem, how to add a button in the notification that triggers an action in the client module, e.g. opening a form window. I tried to use HTML.appLink in the notification body for this, but I don't see any execAppLinkAction method in the Desktop class.

Is there any simple method to achieve this?
Re: Rich content in desktop notifications [message #1835339 is a reply to message #1835257] Tue, 01 December 2020 07:58 Go to previous message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
Hi Krzysztof

You can pass a special "app link handler" to the constructor of your DesktopNotification instance. Something like this:

  IStatus status = new Status(HTML.span("Click me").appLink("myRef").toHtml(), IStatus.INFO);
  IDesktopNotification notification = new DesktopNotification(status, IDesktopNotification.INFINITE_DURATION, true, true, ref -> MessageBoxes.createOk().withBody("You clicked this link: " + ref).show());
  desktop.addNotification(notification);


Regards,
Beat
Previous Topic:getAdditionalRowData returns null
Next Topic:Scout Ui html client + dedicated certificate
Goto Forum:
  


Current Time: Sat Apr 20 00:40:22 GMT 2024

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

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

Back to the top