I have a FocusPanel in which contains a Label.
And then I add the DragStartHandler to FocusPanel like the code below:
focusPanel.addDomHandler(new DragStartHandler() {
#Override
public void onDragStart(DragStartEvent event)
{
focusPanel.getElement().getStyle().setBackgroundColor("yellow");
event.getDataTransfer().setDragImage(focusPanel.getElement(), 10, 10);
dragSourceIndex = getFocusPanelIndex(focusPanel);
}
}, DragStartEvent.getType());
I can drag this in Chrome, but cannot do this in IE and Firefox. Moreover, if I highlight the focuspanel's text first, then I can drag when it's highlighted.
Does anyone know what is wrong?
Thanks.
I make a go-around by adding highlight on MouseDownEvent.
focusPanel.addMouseDownHandler(new MouseDownHandler() {
#Override
public void onMouseDown(MouseDownEvent event)
{
markText(focusPanel.getWidget().getElement());
}
});
The markText method is learn from here:
Set selected text in GWT (in order to make copy paste easier)
This is a hacking but at least works.
Now the issue is, the "drop" events are not happening in IE. I use IE 11.
Related
Is there a way in JavaFX8 to select date (as text) in DatePicker from Java code? I want to activate a control with DatePicker in such a way, a user could edit a date without using a mouse.
The similar problem was described here Is there a way to select a text field in code without clicking on it (javafx)?, but the problem was about TextField.
I've tried the solution given in the above question:
Platform.runLater(new Runnable() {
#Override
public void run() {
datePicker.requestFocus();
}
});
In result, the datePicker control is focused, but the text is not selected - typing a new date causes appending new characters to the default one.
Any suggestions?
Thanks in advance.
The problem has been solved according to kleopatra's hint in the following way:
Platform.runLater(new Runnable() {
#Override
public void run() {
datePicker.requestFocus();
datePicker.getEditor().selectAll();
}
});
Thanks for that.
Add the following code after calling stage.show();:
datePicker.getEditor().requestFocus();
datePicker.getEditor().positionCaret(0);
datePicker.getEditor().selectNextWord();
I have an editable GWT Label which shows a strange behavior. That is if I click the text “Add note…” the cursor does not appear until I click a second time. But if I click on the label outside the text the cursor appears on first click. How do I solve that? My guess is that replacing the text also removes the cursor when the cursor is in the text. So how can I get the cursor back on first click?
public class EditableLabel extends Label implements FocusHandler {
public EditableLabel() {
super();
getElement().setAttribute("contenteditable", "true");
getElement().setAttribute("tabindex", "1");
this.sinkEvents(Event.ONBLUR);
this.sinkEvents(Event.ONFOCUS);
addHandler(this, FocusEvent.getType());
setText("Add note...");
}
#Override
public void onFocus(FocusEvent event) {
setText("");
}
}
I think your problem depends on the browser. On FF it works fine for me.
I assume you want to write something, if so try to change Label for TextBox, it should work.
The Scenario:
In my GWT webapp, I'm using KeyDownHandler to capture the event of user hitting backspace.
Say, I'm using it on widget 'B', and hitting the backpsace when widget 'B' is focused should take me to widget 'A'.
The Problem:
On hitting backspace, I'm taken to widget 'A', BUT only for a moment before the Browser takes me back to the previous page! I want my backspace event to be used only by my (GWT) code, not the browser.
final TextBox txtA = new TextBox();
TextBox txtB = new TextBox();
VerticalPanel testPanel = new VerticalPanel();
testPanel.add(txtA);
testPanel.add(txtB);
txtB.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent event) {
if(event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE){
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
txtA.setFocus(true);
}
});
}
}
});
RootPanel.get().add(testPanel);
This SO post might be usefull to you. However its still better to use shift+tab to navigate backwards in a web-based form IMHO.
You might have to prevent the default action from happening. And you might have to do it for some or all of the key events (keydown, keypress –in Firefox–, keyup); be sure to test as many browsers as possible!
That being said, hijacking global keyboard shortcuts is seen my many users as being too intrusive; and it might have consequences on accessibility of your app.
I'm trying to implement a hovering HTML help page over a link or widget in a GWT GUI.
I tried to do something similar to change image on hover using gwt and ui-binder and http://examples.roughian.com/index.htm#Listeners~PopupListener
ui.xml
<layout:cell horizontalAlign="LEFT">
<widget:ButtonLink ui:field="manageApps" text="Applications"/>
</layout:cell>
ui.java
PopupPanel popup = new PopupPanel(true);
HTML html = new HTML("<p>Hello</p>");
//popup.setStyleName("demo-popup");
popup.add(html);
#UiHandler("manageApps")
public void onMouseOver(MouseOverEvent event) {
popup.center();
}
However compilation fails on the #UiHandler with the message: Field manageApps doesn't have 'addHandler' method for com...MouseOverHandler.
Any idea or pointer helps. Thanks.
I have a solution so far that can be improved later:
ui.java
#Override
public void onMouseOver(MouseOverEvent mouseOverEvent) {
//To change body of implemented methods use File | Settings | File Templates.
popup.center();
}
manageApps.addHandler(this, MouseOverEvent.getType());
What is a ButtonLink? If you made it yourself, did you implement HasMouseOverHandlers? Chances are the problem is that the widget doesn't know how to throw a MouseOverEvent, but you're trying to catch them anyway.
I have a solution so far that can be improved later:
ui.java
#Override
public void onMouseOver(MouseOverEvent mouseOverEvent) {
//To change body of implemented methods use File | Settings | File Templates.
popup.center();
}
manageApps.addHandler(this, MouseOverEvent.getType());
How may I block a gwt DisclosurePanel on the open state ?
I mean, how can I prevent this DisclosurePanel to close if the user click the header more than once ?
(My header is a textBox, I want the user to enter a text, and the panel should remain open if the user unfocus the textBox and focus newly by clicking it. The DisclosurePanel content has a "cancel" button that closes the panel)
Thank you very much.
I edit my question after 2 first answers: I would like to avoid to reopen the DisclosurePanel once closed to avoid flashing effect. I actually want to prevent the DisclosurePanel to close. Maybe sinkEvents can help me... if so, how? Thanks.
A NativePreviewHandler receives all events before they are fired to their handlers. By registering a nativePreviewHandler the first time your disclosurePanel is opened, you can cancel the click event. You can later decide to remove this handler by preventClose.removeHandler();
HandlerRegistration preventClose = null;
....
panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
if (preventClose == null){
preventClose = Event.addNativePreviewHandler(new NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt()==Event.ONCLICK && event.getNativeEvent().getEventTarget() == panel.getHeader().getElement().cast())
event.cancel();
}
});
}
}
});
The obvious answer is review the javadoc here: https://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/DisclosurePanel.html
There is a setOpen() method that: Changes the visible state of this DisclosurePanel.
Set it to false from a click event to capture the user action.
The JavaDoc is right here: https://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/DisclosurePanel.html
jamesDrinkard pointed the old 1.5 javadoc.
You can use the addCloseHandler(CloseHandler<DisclosurePanel> handler) method to add a handler so when the user tries to close it you can reopen it again with setOpen().
Maybe not the best way, but it worked for me (maybe just one of both will work too):
dPanel.setOpen(true);
dPanel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});
dPanel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
#Override
public void onClose(CloseEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});