Elaboration idea movement ajax wicket elements - ajax

I am trying to optimize a webapplication for ipad use. I am now implementing the user interaction and related action / feedback. I have the following idea and was wondering if it is possible to achieve this.
Detect the user-interaction with javascript
Determine what element is touched.
Determine the movement.
Communicate with Wicket
Send the movement to the touched element if it implements a certain interface, i.e., touchable.
The element reacts to the user-interaction by implementing, in the interface, defined methods.
An example of a touchable element could be the following:
public class MyPanel extends Panel implements TouchableElement
#Override
public void react(int x, int y, int movement) {
....
}
}
Could someone tell me if this is possible and/or give me some tips, drawbacks et cetera. Every piece of feedback is helpfull.

Could someone tell me if this is possible and/or give me some tips, drawbacks et cetera.
This would certainly be possible by creating your own AJAX Behavior extending AbstractDefaultAjaxBehavior that "listens" on the user's clicks via javascript and sends any information you calculated within the javascript to the server, where you can react to it in the Behavior's respond() method. A tutorial on how to create your own AJAX Behavior can be found here.
The code would look something like this then:
MyPanel panel = new MyPanel("panel");
panel.add(new MyAjaxBehavior());
However, if all you want is drag and drop you might find existing solutions like Sven Meiers wicket-dnd.

Related

Prism navigation- finding out origin of navigation request?

I have a viewmodel tied to a view used in a region. I'm trying to find a way that when that view is navigated to from a particular view (say view A), it does some work internally, like initializing some lists, setting some stuff, whatever. But if it has been navigated to from view B, it needs to NOT reinitialize everything, and just display the data it already has.
I could pass a parameter I suppose, saying whether this is a new operation or if we are going back to work on the old one, but I thought it would be nicer to be able to state that if we came from this view, we do one thing, and if we came from that one we do another.
If that makes sense :)
You can implement the INavigationAware interface which contains 3 methods. One of these methods is the OnNavigatedTo method. There you can access the journal and check the current entry. From there you should be able to determine if it came from View A or View B.
public void OnNavigatedTo(NavigationContext navigationContext)
{
var journal = navigationContext.NavigationService.Journal;
//use journal.CurrentEntry
}

What controls "loading" feedback in MVP?

I see two basic ways to implement "loading" feedback (e.g. swirly loading icon):
In the presenter:
void displayData()
{
display.startShowingLoadingIcon();
startLoadingData();
}
void onDataLoaded()
{
display.stopShowingLoadingIconAndDisplayData(data);
}
In the display:
void showData()
{
startShowingLoadingIcon();
presenter.getData(callback);
}
Callback callback(data)
{
stopShowingLoadingIconAndDisplayData(data);
}
I like the second solution because it seems like loading feedback is clearly a user interface decision. I don't want my presenter to have to know about any kind of user interaction. Also, the first solution allows the display some flexibility for the case that the user cancels a request, something else comes up, etc. On the other hand, the first solution is simpler to implement, and doesn't require the display to know about the presenter.
What do you do?
I think it belongs in the view because:
1: The reason you'd take things out of the view is so you can more easily test it. A simple start/ stop showing loading doesn't seem like a lot of logic worth writing tests for.
2: This feature is so specific to the view, that it feels the presenter shouldn't even have to know about it.
3: Since the view is responsible for knowing how to render itself, it makes sense that it should know how to display a loading icon when needed.

MVVM Light: Where do I instantiate a class from a model and how do I update/access it?

Right now, I'm working on my first WP7 app and have run into some questions, which I haven't been able to answer despite reading what I could find online. Please consider an app that has a main page, a parameters page and a results page. In the parameters page, the user can enter or update numbers in various textboxes. Hitting the back button takes the user back to the main page, where there is a button called "Calculate". Hitting that button should take the data, perform a calculation with it and take the user to the results page presenting a grid with the results.
In a file called Calculator.cs I have a class called Calculator inside a folder called Models. I also have my MainViewModel.cs, ParametersViewModel.cs, and ResultsViewModel.cs files inside the ViewModels folder and the corresponding MainPage.xaml, along with Parameters.xaml and Results.xaml inside a folder called Views. I'm assuming that all the data will be manipulated within the instance of the Calculator class and then a results set will be returned and directed to Results.xaml. I'm just at a loss as to where to instantiate the Calculator class, pass it data, then retrieve the results. I'm also somewhat puzzled how I will trigger the automatic navigation to the Results page when the calculation is done.
Any help with this would be greatly appreciated.
UPDATE: Passing a complex object to a page while navigating in a WP7 Silverlight application has some more info on the same subject. I can go into App.xaml.cs and add something like this:
public class Foobar
{
public string barfoo = "hah!";
}
public static Foobar myfoob = new Foobar();
Then access it from a ViewModel page, e.g. AboutViewModel.cs, like this:
public AboutViewModel()
{
string goo = App.myfoob.barfoo;
}
But at this point I'm still uncertain what unforseen effects that might have. I'm going to tackle serialization/tombstoning at this point to see what happens with either this approach or by using the same DataContext across pages. Otherwise, one of the posters in the link above mentioned serializing the params and passing them between pages. My concern there would be whether or not there is a character limit as with HTTP GET. Seems there is: URI Limits in Silverlight
There are of course lots of possible designs - and lots of them are correct in different ways!
Here's one I might use:
The Calculate button press should trigger the Navigate to the Results page
On navigate to, the Results page should show some animation (maybe just a progress bar)
On navigate to, the Results page should create a new ResultsViewModel, passing in the MainViewModel as parameters
the constructor (or some init method) of the ResultsViewModel should spark up a thread to do the calculation
when this calculation is complete, then the relevant properties of the ResultsViewModel will get set
at which point the databinding on the Results page will clear the animation and show the results
Other solutions are definitely available - will be interested to read what other people suggest and prefer.
As an aside, one thing to watch out for on your Results page is tombstoning - could be an interesting challenge!

RIght-Click in GWT?

I am building an AJAX web app with GWT, and I want to use right-click for various things, just like in a desktop app. However, right-click produces the standard Web context menu and void onClick(ClickEvent event) never gets called. Has anyone figured out how to get this to work? thanks!
easy peasy, add a listener on the contextmenuhandler which will display a widget based on where the user right clicks. https://confluence.clazzes.org/pages/viewpage.action?pageId=425996
class MyWidget extends Composite implements ContextMenuHandler {
// just an example, use a meaningful Widget here...
private Widget base;
private PopupPanel contextMenu;
public MyWidget() {
// initialize base widget, etc...
this.contextMenu = new PopupPanel(true);
this.contextMenu.add(new HTML("My Context menu!"));
this.contextMenu.hide();
initWidget(this.base);
// of course it would be better if base would implement HasContextMenuHandlers, but the effect is the same
addDomHandler(this, ContextMenuEvent.getType());
}
public void onContextMenu(ContextMenuEvent event) {
// stop the browser from opening the context menu
event.preventDefault();
event.stopPropagation();
this.contextMenu.setPopupPosition(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
this.contextMenu.show();
}
}
lastly you will want to disable the browsers menu for full overloading of this type of context menu. That should work in all of the browsers except opera. but honestly who uses that these days neways ^_______^
<body oncontextmenu="return false;">
It turns out you can do it by extending DeckPanel. Here's an excellent discussion, along with a nice demo that proves it works.
http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/
Although there are ways of doing it I believe the GWT team had a debate about this and decided enabling right click in a web app was a bad thing and so made the concious decision not to support it. The argument was that right click should continue to work as expected (bring up the host browser's right click context menu) and overriding this was breaking that expected behaviour and that and would be bad practice. While I have had instances where a right click context menu would be useful generally I tend to agree with the GWT team's decision.

Observe event created through an instance of a Winforms UserControl

In my winforms app, I have a UserControl that contains a DataGridView. I instantiate and load this UserControl when needed into a panel in my Main Form (frmMain). My problem is figuring out how to resond to or listen for events raised in my UC's DataGridView. For example, I want to handle the CellDoubleClick event of the DataGridView in my Main Form rather than through the UC.
Is this possible? I had thought of updating a property when the cell in the grid is double-clicked, and then let my Main form do whatever when that property changes - therefore I thought of using INotifyPropertyChanged. Im not heavily clued up on how to use it in m scenario however, and would deeply appreciate some help in this regard, or if anyone can suggest an alternate solution.
Much thanx!
Your user control must encapsulate some logic, so if you want to handle event of the DataGridView that is in your control the way you've described, you probably missing something in idea of user controls and encapsulation. Technically here two ways to do this:
Make a public property in your user control of type DataGridView.
Make an event wrapper. You will need to create an event in your user control that is raised when DataGridView CellDoubleClick (or any) is rased and in your calling code you will handle this event wrapper.
The second approach is more logical, cos internal logic of your control is incapsulated and you can provide end-user of you component with more logical and meaningful event then CellDoubleClidk or else.
thank u 4 your reply. Sorry for not responding earlier. I did manage to sort this issue out by creating a public event in my UC:
public event DataGridViewCellEventHandler GridRowDoubleClick {
add { dgvTasks.CellDoubleClick += value; }
remove { dgvTasks.CellDoubleClick -= value; }
}
and in my main form, after I instantiate and load the UC
_ucTask.GridRowDoubleClick += new DataGridViewCellEventHandler(TasksGrid_CellDoubleClick);
with the following attached event:
private void TasksGrid_CellDoubleClick( object sender, DataGridViewCellEventArgs e ) {
// do work here!
}
This does work, although I don't know if any of u experts out there foresee a problem with this approach.

Resources