Inter module communication using event bus in mvp4g gwt - gwt

Our web application is based on mvp4g framework. To explain my situation I will be using the following notations:
A, B - two different gwt modules
presenterA, viewA - presenter and view pair in module A
viewA contains an iframe and a button along with other UI components
presenterB, viewB - presenter and view pair in module B
eventBusA - an eventBus in A with event handler in presenterA
eventBusB - an eventBus in B with event handler in presenterB
Flow of application starts with loading of A. viewA is displayed and contains a button and an iframe on click of which module B is loaded inside the iframe by calling a URL and simultaneously hides the viewA from active viewing. Thus it is still active in the background. B is a seperate module(no child parent relationship between A and B). It loads viewB and after a button click in viewB I want to go again to an event in eventBusA since I want to change the status of viewA from hidden to visible. But eventBusA is not accessible from either presenterB or eventBusB.
I have tried the following which did not work:
Created and event in eventBusB to respond to click in viewB via presenterB. Added presenterA as the handler.
On the same event added moduleToLoad with module A as the target. It requires A to be declared as the child module.
Thought about javascript API using GWT-Exporter project.

Your problem is, that module B has to send a push notification to module A. There is no ready solution for that.
Best solution will be, to send an URL to start Module A again and use the Place pattern to restore the application state of module A.
Therefore module A has to send a token (history token) to module B. Module B has to save the token and if you module B will give back the control to module A, it has to call the url for module A and use the token as a #-parameter. Take a look at the history doumentation of mvp4g.

Related

ICommand not binding in Loaded event using MVVMLight framework

I am wondering why binding a button inside the Loaded event in WPF page does not work and will only work after navigating to another page, and going back.
I have an inventory app and on the main page, most of the ViewModel are called because of a Back button which goes back to a specific lists and what causes that is, it will start binding the even if that command is not for that page and it will also load the collections for other pages.
So I used Loaded page event to call the necessary methods to populate the lists and also start binding commands for this specific page. I also used Unloaded page event for clean up like unsubscribing to some CRUD events.
The problem now though is, buttons does not get binding in Loaded page event. I do not know why..
I have made a miniature app to demo the problem. It can be downloaded here
(full source code included)
https://www.dropbox.com/s/qzumzyicuvrktsi/ICommandTest.zip?dl=0
This is because your views are not getting notified about the change of Command_ShowAddWindow and Command_ClickMe. Let me explain:
When your Page constructor is first run the bindings to your commands are initialized and transferred to the view, but by that time your commands are null, so the view binds both buttons' commands to null.
Then when your Loaded event is fired the commands are initialized, but the view is not getting notified about it, so it keeps command bindings to null.
The solutions to the problem are:
You manually call RaisePropertyChanged to notify the view about commands change when you initialize them:
void InitCommands()
{
Command_ShowAddWindow = new RelayCommand(Command_ShowAddWindow_Click);
Command_ClickMe = new RelayCommand(Command_ClickMe_Click);
RaisePropertyChanged("Command_ShowAddWindow");
RaisePropertyChanged("Command_ClickMe");
}
Or you initialize your commands in your ViewModel constructor before DataBindings are initialized:
public ViewModel_Page1()
{
InitCommands();
...
}

Best place to load data from service in xamarin forms MVVM

What is the best place to call a service and load data in xamarin forms
Till now I am calling the service in the view model constructor and loading data
I have a new situation -
In my app I check for network connectivity, if it's not connected to internet I will not load data in the main form and show a modal form saying network is not available check. If the recheck is success will pop the modal but as the data is not loaded the main form is empty.
So in this case I have to write service call in on appearing override function. Which gets called after the modal popped. Which is okay. But problem is every time when we navigate to that view it will make a service call.
Please guide me the best place to call these services
For your problem, you can use C# Events (Publisher-Subscriber) as the solution
Write a event called InternetDisconnectedEvent in the View Model. Subscribe to that event in Code behind of the View (.xaml.cs)
Make UI Changes in the View, when internet disconnected.
For more about Event & Delegates, check this tutorial
"...But problem is every time when we navigate to that view it will make a service call."
Create a flag (a boolean property), say IsLoaded in the viewmodel (or view, depending on your current implementation), that set to false initially. Then add a logic that check IsLoaded flag before calling the service. If IsLoaded is false, run your current logic of checking internet connection, calling service, so on.. and lastly update IsLoaded to true.

Cleaning ViewModels MVVM Light and Xamarin forms

I'm trying to clean one view model when i'm leaving back one page as shown in this sketch:
A -> B -> C -> B
when i get back from C->A i want to clean the viewmodel.
I tried to override OnAppearing() and OnDisappearing() from ContentPage, but they called everytime I enter/leave one page. Is it possible to get the navigation direction?
You might want to hook into some of the navigation events . Another approach is to do viewmodel -> viewmodel navigation. in each viewmodel you inject a provider to your data e.g. IWizardDataProvider. Then you use this provider to encapsulate a singleton og have it injected as a singleton/singleinstance. When ever you get to the A page, you call a Create() on your provider which can clear the current instance with collected information. The other pages/viewmodels should the use the .Current to add information.

How to hook GWT navigation from a userscript?

I'm writing a userscript for a GWT-based site.
My script uses URL of the page as input. It should be update each page of the site with additional information.
Unfortunately, as view changes in GWT are implemented via rerendering (only location anchor in browser address-bar is being changed), clicks on internal links are not recognized as page loads and Greasemonkey does not invoke my script, leaving new views unmodified.
Is there a way to hook in GWT-based navigation from an userscript? I need a way to modify each "change" Gerrit navigates to.
Complete workflow should look like:
User scans through the list of issues
User clicks on a link . (Address bar will assume a location of a change being clicked, for example https://git.eclipse.org/r/#/c/38781/)
Page is modified by userscript to contain information about new view (in our case /c/38781/)
Greasemonkey is only invoked at the first step of this workflow, and I don't know ho to detect second one to be able to trigger the third.
I've tried to observe DOM changes on the page, but my listeners are never called probably due to the fact GWT renders some parts via innerHTML property, without explicit child manipulation.

Detect if there is a modal form showing

Is there some method of detecting if there is a modal form showing in my VB6 application.
I want to show another form modally if there is a modal form showing and modeless if there isn't a modal form showing.
I know I can do some error handling to detect this and show modally if the error occurs:
Public Sub ShowFormModeless(frm As Form, Optional ownerForm As Form = Nothing)
On Error GoTo ShowModal
Call frm.Show(, ownerForm)
Exit Sub
ShowModal:
Call frm.Show(vbModal, ownerForm)
End Sub
But I want to be able to detect this without the error being thrown.
Try checking App.NonModalAllowed. Note that this property does not detect modal forms being shown from other (than current module) projects, i.e. if your application consists of main executable and several ActiveX dlls each of these projects will have a separate App object and Forms collection.
The result is that if a dll is showing a modal form only its own project's App.NonModalAllowed is flagged. So once again, App.NonModalAllowed is not a process-wide flag but a per project one.
Note that this flag tracks VB6 only forms, so if you are using API dialogs (open/save file, color picker, etc) this does not enter VB6 runtime's modal loop, so nothing is flagged.
If you application is a single exe then using this flag works as expected.