Vaadin: How to react to a tray notification click? - vaadin7

I'm using Tray Notifications to let the user know about some pending actions. It works fine but would love to be able to click on it and do what I need it to do like showing the correct screen, etc. Sadly I'm unable to find some click listener like other components.
Am I'm missing something?

As far as I know that's not possible with the default notification in either Vaadin 7 or 8.
If you're using Vaadin 7, you can either fake it using a non-modal window (or something similar), or use the fancy-layouts add-on (also compatible with 8) that offers a FancyNotifications component (online demo and source). It's not exactly the same thing but it may provide what you need. Also be careful to select the v7 version and to add the suggested maven repo.
Basic usage:
public class MyUi extends UI {
#Override
protected void init(VaadinRequest request) {
FancyNotifications fancyNotifications = new FancyNotifications();
fancyNotifications.setPosition(FancyNotificationsState.Position.BOTTOM_RIGHT);
Button button = new Button("Show notification", buttonClickEvent -> {
FancyNotification fancyNotification = new FancyNotification(null, "Meh", "Click me to navigate to GITHUB");
fancyNotification.getTitleLabel().setContentMode(ContentMode.HTML);
fancyNotification.getDescriptionLabel().setContentMode(ContentMode.HTML);
fancyNotification.addLayoutClickListener(notificationClickEvent -> Page.getCurrent().setLocation("https://github.com/alump/FancyLayouts"));
fancyNotifications.showNotification(fancyNotification);
});
VerticalLayout content = new VerticalLayout();
content.setSizeFull();
setContent(content);
content.addComponents(button, fancyNotifications);
content.setComponentAlignment(button, Alignment.MIDDLE_CENTER);
}
}
Result:
If you're using 8, there's the notify add-on (online demo and github page) which supports click-listeners. Please be aware that this add-on currently supports Vaadin 8 and works with browsers that support the Notification API:
Development is mainly done on Chrome. Also Firefox is tested and mainly works as planned. Other browsers are still not tested. IE11 and Edge does not support Notification API as far as I know. Anyway add-on can use used only to show notifications on browsers that do support Notification APIs.
From the github demo:
private void showWithClickHandling() {
Notify.show(new NotifyItem()
.setTitle("Notification can be also clicked")
.setBody("Click here to navigate to project's GitHub page")
.setIcon(new ThemeResource("images/github.png"))
.setClickListener(e -> {
Page.getCurrent().setLocation(GITHUB_URL);
}));
}
... which will look like:

Related

cefsharp - "Links that open a specific application" seem to be not working

I just begin with Cefsharp on C#.
Everything works fine except Cefsharp can not execute some special links that open/run a specific application on the computer.
The link still works on other Chromium official browsers (Google Chrome), I clicked the link and it launches the application. Cefshap is not, it does nothing when I clicked the link.
The link looks something like this: "runapp://api.abcxyz/..."
How can I make it work on Cefsharp?
image show that the link works on other chromium browsers
Firstly for security reasons loading of external protocols is disabled by default. Historically you would have implemented OnProtocolExecution.
There is currently an upstream bug in OnProtocolExecution see https://bitbucket.org/chromiumembedded/cef/issues/2715/onprotocolexecution-page-goes-blank-after
You can implement a workaround using RequestHandler.OnBeforeBrowser and calling Process.Start
It would look roughly something like the following (Written in Notepad++ very quickly, there maybe minor mistakes that you'd have to correct).
public class ExampleRequestHandler : RequestHandler
{
protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
{
if(request.Url.StartsWith("mailto:"))
{
System.Diagnostics.Process.Start(request.Url);
//Cancel navigation
return true;
}
return false;
}
}
browser.RequestHandler = new ExampleRequestHandler();

Navigation.PopAsync with a PushModalAsync?

i'm doing some support to an existing application. it's a really big application, and several pages are using a base controller, this controller works as the name says controller for all the events and stuff of the form.
the thing is that this application was done on xamarin 2.0 and never updated the version, now i've updated xamarin forms to the actual version 4.0 and some stuff works different. but the issue that bugs me more is Navigation.PopAsync.
In the 2.0 it closes all "windows" it doesn't matter if it's modal or a normal window.
but now with xamarin 4.0, the modal windows are not closed.
is there a way of knowing if the current window in Navigation is a modal or something like that?
Regards.
you could check whether it appears at the top of the Navigation.ModalStack like this:
private bool IsModal(Page page)
{
if (page == Navigation.ModalStack[Navigation.ModalStack.Count])
{
// is modal page
return true;
}
else
{
//not modal page
return false;
}
}

JXBrowser control over dialog website not responding

Hey im having issues with a website in the jxbrowser. it seems like it is running into a timeout or whatever and then in the jxbrowser there is a dialog showing up "website not responding" and i can click on "reload" or "leave".
Can I in any way access this dialog and overwrite it? For instance everytime i would get this dont ask but go to the homepage instead?
I'm having trouble finding this if it is even possible.
I found a solution. JXBrowser has a RenderAdapter where a function exists onRenderUnresponsive wich can be overridden. Look at this: https://jxbrowser.support.teamdev.com/support/solutions/articles/9000091687-detecting-unresponsive-web-page
In my case I simply want to reload the website:
Browser browser = new Browser();
browser.addRenderListener(new RenderAdapter() {
#Override
public void onRenderUnresponsive(RenderEvent event) {
browser.reloadIgnoringCache(false);
}
});

Avoid back button using vaadin

I develop RIA application using Vaadin CDI addon.
About the app : it has two views(viewA and viewB) which maintained by Navigator.
User story is pretty simple:
User enters viewA
Perform some business stuff
Redirects to viewB
Using address bar to go some external website(ex. google.com)
Press back and it goes to he lastest page what he saw(viewB), instead of viewA
Any suggestions/tips-n-tricks how to avoid redirecting to viewB, but redirect to viewA?
Vaadin Forum quiet about this thing.
Thank you
I had same problem but resolved using following code:
getUI().getNavigator().addViewChangeListener(new ViewChangeListener() {
public boolean beforeViewChange(ViewChangeEvent event) {
return changeView;
}
#Override
public void afterViewChange(ViewChangeEvent event) {
// TODO Auto-generated method stub
}});
Set changeView = true only through proper navigation's (eg: On button clicks).
This how you can avoid navigation's using browser back button. In this case if user uses any of browser buttons the view does not changes and it remains on same page.
You could override View.enter(...) in your ViewB, and, according to your application state, update your view URI using Page.getCurrent().setUriFragment(recentUrl, false);

How to avoid the display of multiple alert windows in Flex

I have a timer in my application. For every 30 min, it will hit the web services and fetch the data and updates the UI. The application was working fine till yesterday. Suddenly, because of some issue, the web services were not available for some time. During that period, Application displayed the RPC Error multiple times(More than 100 alert boxes) in alert window. Because of this alert boxes, my application was hanged and i was not able to do anything.
I have tried several approaches, but nothing worked.Finally, I have tried to use a flag. In all the approaches, this looked promising. so i have implemented it.Basically, in this approach whenever we open an alert we will set a flag.While opening and closing alert we will reset this flag. But it didn't work as expected. Is there any approach, which can help us in avoiding multiple alert windows.
Please help me, to fix this issue.
I would write wrapper for opening alerts, and use only this wrapper, not Alert.show in the code:
public class AlertWrapper {
private static var lastAlert:Alert;
public static function showAlert(text:String, title:String):void {
if (lastAlert) {
PopUpManager.removePopUp(lastAlert);
//or
//return; //ignore last alert
}
lastAlert = Alert.show(text, title, null, 4, onAlertClose);
}
private static function onAlertClose(event:CloseEvent):void {
lastAlert = null;
}
}
Imports are missing, but I hope the idea is clear.

Resources