Integration Widget (GWT) with DynamicForm (Smartgwt) - com.google.gwt.user.client.ui.AttachDetachException - gwt

I had this problem when I created a Window (Smartgwt) and put a DynamicForm (Smartgwt) in this Window, In this DynamicForm, I have a CanvasItem (Smartgwt) in which I put a RichTextArea (GWT). And when I press "ESC", I can quit the Window (Smartgwt) without probleme. But when I press "F5" to refresh my application, the browser pops up a exception saying "com.google.gwt.user.client.ui.AttachDetachException". To solve this problem, I do the following:
public class MailWindow extends Window {
public MailWindow(){
this.addCloseClickHandler(new CloseClickHandler() {
public void onCloseClick(CloseClientEvent event) {
form.getRichTextArea().removeFromParent();
MailWindow.this.destroy();
}
});
}
}
Which solved my problem! :)
Kewei

Thanks for posting this. We'll try to incorporate the logic in SmartGWT itself so that you don't need to explicitly call removeFromParent()

Related

GWT: Back Button working twice, both by browser and my GWT code

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.

Mouse wheel event does not fire on GWT FocusPanel, if FocusPanel is on GWT PopupPanel (only in Chrome and Safari)

Here's the code:
public class MyEntryPoint implements EntryPoint {
PopupPanel popupPanel = new PopupPanel(false,true);
FocusPanel focusPanel = new FocusPanel();
VerticalPanel popupContent = new VerticalPanel();
public void onModuleLoad() {
popupContent.add(new Label("Simple popup test"));
popupContent.add(new Label("_"));
focusPanel.add(popupContent);
popupPanel.setWidget(focusPanel);
popupPanel.center();
focusPanel.addMouseWheelHandler(new MouseWheelHandler(){
public void onMouseWheel(MouseWheelEvent event) {
System.out.println("deltaY = " + event.getDeltaY());
}
});
}
}
If you run a GWT app in Firefox, move your mouse over the text "Simple popup test" and scroll the mouse wheel, then onMouseWheel will be called.
If this application is running in Chrome or Safari, place your mouse over the text "Simple popup test" and scroll the mouse wheel, then onMouseWheel not called. If you place the mouse cursor is not on the GWT Label and scroll the mouse wheel, the event will be called onMouseWheel.
Maybe someone has already corrected this? Thank you very much.
The Bug can be found on the GWT issue tracker:
http://code.google.com/p/google-web-toolkit/issues/detail?id=7349
There is a link to a Google goups discussion in the issue text.
I solved the problem by set the popup to modal = false.

Hide Dialog from inside in LWUIT

I have created a Dialog with two buttons Yes, No, and then I have add action listener to them, my problem is that I want no button to hide the Dialog that I have created
the code is looks like:
dialog = new Dialog(title);
dialog.setDialogType(Dialog.TYPE_CONFIRMATION);
ta = new TextArea(text);
ta.getStyle().setBorder(Border.createEmpty());
ta.setEditable(false);
yesCommand = new Button("YES");
noCommand = new Button("NO");
yesCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
LGBMainMidlet.getLGBMidlet().notifyDestroyed();
}
});
noCommand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
Logger.Log("Bye Bye");
dialog = null;
System.gc();
}
});
dialog.addComponent(ta);
dialog.addComponent(yesCommand);
dialog.addComponent(noCommand);
dialog.show();
the code is not working for me, can anyone told me what is the problem?
B.N. I have used dialog.dispose(), but it exit the whole application
It is better to use
dialog.setTimeout(1000); the number show the time limit the dialog box wait in milliseconds. So by doing this you can exit the dialog form automatically.
Dialog.dispose() does not exit the whole application, it just closes the dialog.
If you have nothing in your application you might see nothing if you dispose the dialog.

Block gwt DisclosurePanel on open state

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);
}
});

GWT, disable autoclose MenuBar when clicking on MenuItem?

I want to if it is possible to disable the auto-close MenuBar when I click on a MenuItem?
I have several MenuItem that are like checkboxes, so I can check more than one MenuItem and don't want my menu close everytime I checked one.
Thanks.
I was facing same problem and I will share with you my solution:
1) Create new class MyMenuItemWithCheckBox that extends the MenuItem.
In the constructor set element ID to (forexample) menuItemWIthCheckBox + Unique text.
this.getElement().setId("menuItemWithCheckBox_" + menuItemLabel);
2) Create new class MyMenuBar that extends the MenuBar.
Override the onBrowserEvent method by following:
Override
public void onBrowserEvent(Event event) {
if (DOM.eventGetType(event) == Event.ONCLICK && getSelectedItem().getElement().getId().contains("CheckBox")) {
Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
#Override
public void execute() {
getSelectedItem().getScheduledCommand().execute();
}
});
event.stopPropagation();
} else {
super.onBrowserEvent(event);
}
}
Now scheduled command of MenuItem is always called, but in the case of your
menu checkBox item there is no close of a menubar.
I hope this help you, I spend more than day to create this solution. :-)
First, directly it's not possible because the popup-panel which displays the submenu is private in the MenuBar class.
Buuut, there is a way to do so ...
Simpley fetch the current MenuBar.java code out of googles code repository and include it in your eclipse gwt-project.
You don't have to change anything e.g. package deklaration or something. Just put your source in your project and it will simply replace the original MenuBar-class from the gwt-sdk during compilation (works also with hosted development mode).
Then you can simply set the property autoHide of the popup-Panel to false and the popup shouldn't disappear after clicking.
You can set hideOnClick to false on the menuItems
See here.