Found difficulties in some versions of Opera with exercising CSS properties like .myclass[disabled] {...}. Also I haven't found any solution how to sink events for disabled widgets. Seems like they are totally non-interactive (however :hover property still does some effect) speaking in terms of standard events, available for handling. Manually implemented enabled/disabled state has been the only suitable solution, which I'd found till present.
In some singleton filter class (e.g. NativePreviewHandlerForHasEnabled):
*************************
private final Map<Element, HasEnabled> elementToWidgetMap = new HashMap<Element, HasEnabled>();
private NativePreviewHandlerForHasEnabled() {
assert instance == null : "Only one instance is allowed.";
elementToWidgetMap = new HashMap<Element, HasEnabled>();
Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
public void onPreviewNativeEvent(NativePreviewEvent pEvent) {
final Element target = pEvent.getNativeEvent().getEventTarget().cast();
HasEnabled widget = elementToWidgetMap.get(target);
if (widget != null && !widget.isEnabled()) {
// Let it work, cause we may need to e.g. hide tool tip when mouse is out
if (pEvent.getTypeInt() != Event.ONMOUSEOUT) {
pEvent.cancel();
}
}
}
}); }
public <T extends Widget & HasEnabled> void registerWidget(T widget) {
elementToWidgetMap.put(widget.getElement(), widget);
}
*************************
For our widget:
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
// super.setEnabled(enabled); // don't do this!
}
It's not perfect. Map can grow up fast depending on scale of your app. To enhance the performance store HandlerRegistration objects upon Event.addNativePreviewHandler call for later disposing, when the time comes.
On Thursday, June 17, 2010 10:27:26 PM UTC+5, Magnus wrote:
Hi,
how can I enable/disable a widget (TextBox, Button, etc.)?
I would like to iterate all Widgets of a form and set this status. I
found no appropriate methods in the Widget class...
Magnus
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/c29e6HJ34ecJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment