RIght-Click in GWT? - ajax

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.

Related

How to specify a particular order of buttons in a JavaFX 8 Alert

I need to ask the user to confirm doing an action. The set of buttons of the confirmation dialog are "Yes", "No" and "Cancel". My code is below:
private ButtonType askYesNoCancel(String question) {
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setContentText(question);
alert.getButtonTypes().setAll(ButtonType.YES,
ButtonType.NO,
ButtonType.CANCEL);
return alert.showAndWait().get();
}
which gives me
The problem I am facing is that regardless in what order I specify the ButtonTypes for an Alert, I get the same button order (No - Cancel - Yes). I took a look at API documentation for Alert, Button and ButtonType, alas, not to find an answer.
What I try to accomplish, is the button order Yes - No - Cancel. Any advice?
Example if you really need to specify button order...
private static class FixedOrderButtonDialog extends DialogPane {
#Override
protected Node createButtonBar() {
ButtonBar node = (ButtonBar) super.createButtonBar();
node.setButtonOrder(ButtonBar.BUTTON_ORDER_NONE);
return node;
}
}
And then when you create your Alert.
alert.setDialogPane(new FixedOrderButtonDialog());
Check the answer to: Enter Key Event Is Not Working On Dialog In Javafx?, though I guess that answer more appropriately belongs with this question and perhaps doesn't fully explain what is going on. Also read the ButtonBar javadoc.
Basically, the button position is determined by a combination of the ButtonType of each button and the ButtonBar's buttonOrder. By changing either of these things, you will end up with different button layouts.
As I recall, customizing the ButtonBar was kind of tricky. You might need to subclass the alert and override createButtonBar.
What I try to accomplish, is the button order Yes - No - Cancel. Any advice?
My advice is: Don't try to customize the button order, but let the system default order be applied. The button order has already been preconfigured to match the standard button layout for dialogs for various operating systems. Reordering the buttons to deviate from that standard may make your application just slightly more confusing for users (that's a pretty subjective opinion though).
This is a modified version of #Adam solution. Advantage - no need in extra class, no need to remove existing dialog pane with all its content.
ButtonBar buttonBar = (ButtonBar) alert.getDialogPane().lookup(".button-bar");
buttonBar.setButtonOrder(ButtonBar.BUTTON_ORDER_NONE);

How go from one UI to another UI on Image button click event in juce introjucer?

can you please tell me How go from one UI to another UI on Image button click event in juce introjucer?
Basically you have to:
1.- Parent component must inherit from ButtonListener, and you must implement the buttonclicked method
void WindowComponent::buttonClicked (Button* activeButton)
{
if (activeButton == &someButton)
{
gotoOtherPage();
}
}
2.- Your "UIs" i must suppose are components, if so just do something like:
component.setVisible(false),
otherComponent.setVisible(true),
Or perhaps stash them in a TabbedComponent, hide the tabs or overlap some buttons and then just do:
tabbedComponent.setCurrentTabIndex(someIndex);
That should get you going, in case you need help to draw a button just do something like:
addAndMakeVisible (&someButton);
someButton.setBounds(...);
someButton.addListener(this);
Check out the doxygen docs, they are quite helpful.

Elaboration idea movement ajax wicket elements

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.

Handling Asynchronous operations in Windows Phone7

I am developing a Windows Phone7 application in which I have two App bar buttons both when clicked makes Asynchronous calls to Web and Callbacks will be performed upon the Web response.
Now my problem is, if I click on one button and as the Async operation is going on in the background ans meanwhile if I click on another button both callbacks are executing one after the other, which is not good for obvious reasons. Could any one help me on how to handle this???
First I thought to disable other buttons when 1 Async operation is going. But it doesnt give good feel for user. So what will be the best way to handle this problem??
You can use a Flag variable and check its value within the async call complete method. Based on your requirement you can choose to update or not update the view.
I was looking for the same answer.
I have found the solution, If you initialize an object inside a constructor like this, you will get multiple loops when you call a service function:
public partial class MainPage : PhoneApplicationPage
{
MovieServiceClient mov;
public MainPage()
{
mov = new MovieServiceClient(); //Don't do this.
InitializeComponent();
}
}
Avoid that.

Eclipse RCP: How can I update a view when the selected editor changes?

This should be quite a common problem, but I couldn't find anything helpful on the topic.
We are developing an application with Eclipse RCP. The application shows data in an editor of which usually multiple instances are open. In an additional view you can edit the editor-values. When the values are changed in the view they are updated in the editor and it's dirty flag is set.
So far it works fine. What we're missing is: When another editor instance gets the focus, our view should show the data of this editor.
I managed to do that for two views. The second view is sucessfully updated using a TableViewer as selection Provider and registering a SelectionListener in the other view. I tried the same thing for the editor using a Viewer I subclassed from ContentViewer, but it didn't work.
Can this approach be working?
Or do I need a different approach on the problem?
May be you can subclass your view from PageBookView and then provide special adapter for your editor. Outline View is implemented using this approach.
Thank you cerealk, that was exactly what I needed. :-)
Update the View when another Editor is selected
public class myView {
// Create an IPartListener2
IPartListener2 pl = new IPartListener2() {
// If the Editor I'm interested in was updated ...
public void partActivated(IWorkbenchPartReference ref) {
IWorkbenchPart part = ref.getPart(true);
if (part instanceof DetailEditor) {
// ... update the view
Contact contactFromSelectedEditor = ((DetailEditor) part).detailComposite.contact;
detailComposite.update(contactFromSelectedEditor);
}
}
...
}
// Add the IPartListener2 to the page
IWorkbenchPage page = this.getSite().getPage();
page.addPartListener(pl);
}
Why use an IPartListener2 instead of an IPartListener
The IPartListener2 replaces IPartListener with 3.5.
As explained in this this answer:
You should always use IPartListener2 as it can handle part-change events on parts that have not yet been
created because they are hidden in a stack behind another part.
This
listener will also tell you when a part is made visible or hidden or
when an editor's input is changed.

Resources