I'm new to GWT and I need to get a right click working. The doco I've read suggests that I need to override the onBrowserEvent() method. I'm just experimenting at this stage. the event is processed and my pop-up appears. However, as soon as I close the pop-up, the usual browser drop down menu appears (with options like "Bookmark this page" and such).
I'm using IceWeasel 24.5.0 (FireFox clone for Debian) and, obviously, Debian (wheezy).
Here's the relevant code:
public ActivityTextCell() {
super(BrowserEvents.MOUSEDOWN, BrowserEvents.MOUSEUP);
}
#Override
public void onBrowserEvent(
com.google.gwt.cell.client.Cell.Context context,
Element parent,
ActivityDTO value,
NativeEvent event,
ValueUpdater<ActivityDTO> valueUpdater) {
super.onBrowserEvent(context, parent, value, event, valueUpdater);
event.preventDefault();
event.stopPropagation();
if (event.getType().equals(BrowserEvents.MOUSEUP)) {
Window.alert("mouse up event");
}
else {
switch ( event.getButton()){
case NativeEvent.BUTTON_RIGHT:
Window.alert("right mouseclick");
break;
case NativeEvent.BUTTON_LEFT:
Window.alert("left mouseclick");
break;
case NativeEvent.BUTTON_MIDDLE:
default:
break; // Do nothing
}
}
The class ActivityTextCell extends AbstractCell.
So what am I missing? How do I stop the browser from reaticng to the mouse click?
Well it certainly wasn't a matter of a few minutes (as can be seen by the fact that it has taken me a week to get back to this), but I have a solution. I tried reversing the order of the the event.preventDefault() and super.onBrowserEvent() but it didn't really help.
I tried a little experiment on a normal web page. It turns out, that the MOUSEDOWN event doesn't do anything in that context and the usual browser selection menu appears on the MOUSEUP. So the if/else logic sort of fell by the wayside.
What did the trick is to include the following in the top level GUI class immediately after adding the main page:
RootLayoutPanel.get().addDomHandler(new ContextMenuHandler() {
#Override
public void onContextMenu(ContextMenuEvent event) {
event.preventDefault();
event.stopPropagation();
}
}, ContextMenuEvent.getType());
This has the additional benefit (for my purposes, at least) of preventing the Browser from reacting to a right click anywhere in the application view.
As an aside: The purpose of preventing the default action is to stop the Browser doing its own thing Stopping propagation is possibly not required, but I left it in anyway (propagation goes fro the node up to the root, not the other way around). The purpose of overridinging onBrowserEvent() is to enable your own application to handel that event. The use of super.onBrowserEvent() is to allow the event to be handled by your code in the first place. I've given the relevant reference in my previous comment. The book "GWT in Action" is well worth a read if you're likely to be doing a lot of GWT coding.
You call super.onBrowserEvent() which triggers the standard browser response.
You should move event.preventDefault() to the if part of your code, and super.onBrowserEvent() to the else part. You want one of them executed depending on a browser event, but not both.
Related
In my project I use simple JavaFX browser, that works in background and do some stuff without displaying it.
More precisely it submitted some form to one online page.
So, I ran into a problem: when this page doesn't available, I can't figure it out from my Java code, it looks like form wasn't submitted and clicks on Submit button do nothing, but in Chrome for example I see that the page isn't available.
So, is there an option to check from Java code if page is available?
Thanks in advance and sorry for bad English.
So, I found an answer.
There is Worker class in JavaFX that associates with WebEngine and it has a field with State type.
State is enum that has 6 options:
READY
SCHEDULED
RUNNING
SUCCEEDED
CANCELLED
FAILED
So State.FAILED can be used for handling errors.
For example, something like that (we'll assume we have WebEngine instance):
webEngine.getLoadWorker().stateProperty().addListener((observable, oldState, newState) -> {
if (newState == Worker.State.FAILED) {
doOnError();
return;
}
doOnSuccess();
});
webEndgine.load("example.com");
So, every time state is changed ObservableValue#changed will be called with new State value as one of parameteres and if state become FAILED we do some error processing.
I'm wondering if there is a simple way in GWT to forbid History.back() (or .forward()) to lead to an external site, and define a fallback url if one of this happen.
For example :
Assuming that mysite.com#token, contains a component triggering a History.back().
I am on stackoverflow.com, I paste mysite.com#token in my browser, then click on my component which move me back to stackoverflow, is it possible that click goes in mysite.com instead as a back exit my site?
Thanks for your help!
Use this approach
Window.addWindowClosingHandler(new ClosingHandler() {
public void onWindowClosing(ClosingEvent event) {
event.setMessage("Do you want to leave this site");
}
});
In a CTabFolder, I'd like to check the content for unsaved data before the user can switch from one tab to another. SWT does not provide a PreSelection event, as stated here.
I found a workaround, suggesting to switch back to the old tab when a selection is triggered, validate the data and then perform the desired switch again, if data is valid.
I do understand the general idea of this workaround, however, it is not working for me. oldPageIndex and newPageIndex do always have the same value, though I did not click on the same tab.
this.tabContainer.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent event) {
int oldPageIndex = tabContainer.getSelectionIndex();
int newPageIndex = tabContainer.indexOf((CTabItem)event.item);
// Here: oldPageIndex == newPageIndex
...
}
});
Is this workaround still working or is there anything I could possibly be doing wrong? Or maybe, has there been any fix for a real PreSelection event in the meantime? I tried using event.doit, but the SelectionEvent is fired, when the tabs have been switched already.
You can use the selection listener but as you have found the getSelectionIndex() does not give you the old tab. So you will have to maintain the old tab index yourself.
This is the technique used by the Eclipse FormEditor.
I'm using a viewpager which is made up of some number of relative layout siblings which are quite complex.
If I click on the relative layout, it will highlight the entire page and read the title and a few textviews one after the other as expected.
If I scroll the viewpager I'd like talkback to read the next page in the same way it reads the first if I click. Secondly, if I scroll to the second, third, etc. pages and click on those layouts, talkback will read as expected.
I am trying to achieve the click behavior after the scroll event has completed.
Here is what I have for the accessibilityDelegate.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
View page = viewPager.getCurrentPageView();
performAccessibilityAction(page, AccessibilityNodeInfo.ACTION_CLICK, Bundle.EMPTY);
}
return super.onRequestSendAccessibilityEvent(host, child, event);
}
});
I've verified that 'page' is the RelativeLayout parent that I think it is. I've also confirmed that the onRequestSendAccessibilityEvent is being fired, but it doesn't read the contents of its children. Am I missing something?
Updated
I've also tried using
viewpager.getCurrentPageView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
The above worked for another example when I needed to force talkback to reread a single item but does not have any affect if I try it on the page.
Thanks
Some background -- When you tap on the relative layout, TalkBack generates speech based on the layout's contents. On ICS, this is triggered by a HOVER_ENTER event. On Jelly Bean, it's triggered by an ACCESSIBILITY_FOCUS event. These events are sent automatically by the framework and should, generally speaking, never be sent manually from an app. The same goes for FOCUS events, except in the special case of custom views (see Accessibility talk from Google I/O 2013 for more details).
So, back on topic.
You can control the speech for SCROLLED events by populating the outgoing event with the text you want read. The down side of this is that you'll need to manually generate the text you want read, and it's very likely that this text will differ from what TalkBack will read if the user touches the layout.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
event.setContentDescription(/** your text */);
}
}
});
Another option is to do nothing and let the user explore the view on their own. This is the preferred interaction model for Android accessibility.
Edit: Video URL is broken, Changed.
This issue was reported on google check
where ViewPager does not set AccessibilityEvent parameters properly
when scrolling.
But after releas of Android Support Library, revision 23.2.1 (March 2016) This issue has been resolved.
update Support Library to Android Support Library to 23.2.1
I had the same issue before. And now I add android:focusable="true" to the ViewGroup, the TalkBalk will read the ViewGroup, instead of its children
I am working on eclipse form based editor. I have given support of handling of Undo Redo and dirty flag to my editor.Both of these feature working fine for single instances of plugin. Problem is coming when i open it with 2 or more files (2 or more instances of eclipse plugin). Now, undo redo starts working weird. They work only for instances that is opened at last.
for eg: Suppose my editor supports '.xeb' file. if i open test1.xeb and test2.xeb files one by one using with my editor. then undo redo only works for instances that is opened for test2.xeb file. If i switch back to other instances, then undo redo of first instance gets appear.
i have below entries in my editor's plugin.xml:
<plugin><extension
point="org.eclipse.ui.editors">
<editor
class="Testeditor"
default="true"
extensions="xeb"
icon="icons/sample.gif"
id="testeditor"
name="editor">
</editor>
</plugin>
i debugged the code and found that this weird behavior is happening due to handling of global action in wrong way.I used below code to set global action handler:
public void setUndoRedoActionHandlers() {
final IActionBars actionBars = getEditorSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
mUndoAction);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
mRedoAction);
actionBars.updateActionBars();
}
i went through some links related to this issue. but couldn't understood the concept to implement this behavior.
http://wiki.eclipse.org/FAQ_How_do_I_find_out_what_view_or_editor_is_selected%3F
http://wiki.eclipse.org/FAQ_How_do_I_hook_into_global_actions,_such_as_Copy_and_Delete%3F
Can any one look into this issue. Thanks in advance.
only override the setFocus() method of MultiPageEditorPart in you editor class and call the appropriate method of setting the global action handler,like this way:
#Override
public void setFocus() {
switch (getActivePage()) {
case 0:
pageOne.setUndoRedoActionHandlers();
break;
case 1:
pageTwo.setUndoRedoActionHandlers();
break;
}
super.setFocus();
}