add mousewheel event to absolute panel - gwt

can we add a mousewheel event to absolute panel in GWT. I have added a mousewheel event to absolute panel but it is not working .Why this problem is there but if I add it to label then its working properly.
Thanks,

It is because the AbsolutePanel does not implements the HasAllMouseHandlers interface specifically HasMouseWheelHandlers. Label implements HasMouseWheelHandlers interface. So it works for Label.
You have to extend AbsolutePanel and implement HasMouseWheelHandlers interface to make it work with AbsolutePanel. And behavior you have to define.
public class MyAbsolutePanel extends AbsolutePanel implements HasMouseWheelHandlers
{
public HandlerRegistration addMouseWheelHandler(MouseWheelHandler handler)
{
// Define the behavior here.
return addDomHandler(handler, MouseOutEvent.getType());
}
}

Related

how to create Graphiti shapes with scroll bar

My Graphiti editor has shape that represents db table with it rows.. i am looking for a way to add scroll bar to my shape. any one know how to do that?
I've found an answer to this question.
This is the link to use: https://www.eclipse.org/forums/index.php/t/1071551/
I've created my own ScrollFigure, which extends draw2d ScrollPane and implements IGraphicsAlgorithmRenderer.
public class ScrollFigure extends ScrollPane implements IGraphicsAlgorithmRenderer {
#Override
public void setLayoutManager(LayoutManager manager) {
super.setLayoutManager(new ScrollPaneLayout());
}
}
Next you just have to adjust sizes of your figures in your custom factory, which instantiates your ScrollFigure, and scrollbars will be shown.

GWT switching between panels/views

Here is my Entry point class
public class TestUI implements EntryPoint
{
Panel1 panel1 = new Panel1();
public void onModuleLoad()
{
final RootPanel rootPanel = RootPanel.get();
Button btnButtonOnRoot = new Button("Go to next view");
btnButtonOnRoot.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
rootPanel.clear();
rootPanel.add( panel1 );
}
});
rootPanel.add(btnButtonOnRoot, 72, 40);
}
}
Works ok but I want to use something other than a Panel as the view to load when I click the button.
In Eclipse when I click on my client package I get the option to add a Panel, A Composite among other things. Problem is when I go to edit these with my UI designer I can only put a single widget on each one. What I would like to do is have the ability to clear the rootpanel and add an EntryPoint type class to it as I can edit EntryPoint classes with my UI designer. What other type of Classes can I add to a panel that would be editable in a UI designer?
Dont use that WYSIWYG-editors. They are nice to get you started, but building UIs in GWT really is no magic. You have a panel A and add components aa, ab and ac. Then you have another panel and so on.
And one more advice: Try not to use the rootpanel. It behaves a little different than other panels as it actually is no panel. Try to add a ContentPanel to the RootPanel and add elements to that ContentPanel. The ContentPanel then is added to the RootPanel.

GWT 2.4 customized ListBox doesn't fire Change event

I have added some extra functionality to the standard GWT ListBox by extending it like so:
public class FeatureListBox extends ListBox
{
public FeatureListBox()
{
}
public FeatureListBox(boolean isMultipleSelect)
{
super(isMultipleSelect);
}
public FeatureListBox(Element element)
{
super(element);
}
}
Nothing fancy here. However, the Change event is not firing now, or at least the handler (attached per below) is not getting invoked.
FeatureListBox listBox = new FeatureListBox();
listBox.addChangeHandler(new ChangeHandler()
{
public void onChange(ChangeEvent event)
{
// Do something here...
}
});
Any ideas why?
Either remove the no-argument constructor from FeatureListBox or call super() inside it, otherwise the initialization in the superclasses won't happen, which would probably result in what you're seeing.
The problem was in the way I was using my custom list box. In my application I wrap GWT Widgets around existing DOM elements on the page using the static wrap() methods of their widget classes in which the widgets get marked as attached, making them fire events. I didn't do that with my custom list box class originally, so I ended up implementing a static wrap() method similar to the one of the regular ListBox widget and using it in my code. Everything works like a charm now.

GWT adding a ClickHandler to a DOM element

lets say i have a custom widget which has a ClickHandler. Here's the example:
public class TestWidget extends Composite {
private static TestWidgetUiBinder uiBinder = GWT
.create(TestWidgetUiBinder.class);
interface TestWidgetUiBinder extends UiBinder<Widget, TestWidget> {
}
#UiField
Button button;
public TestWidget(String firstName) {
initWidget(uiBinder.createAndBindUi(this));
button.setText(firstName);
}
#UiHandler("button")
void onClick(ClickEvent e) {
Window.alert("Hello!");
}
}
When i try to add this Widget like this:
TestWidget testWidget = new TestWidget("myTestWidget");
RootPanel.get().add(testWidget);
everything is fine. If i click on my button i get the message i expect.
However if i add it like this:
TestWidget testWidget = new TestWidget("myTestWidget");
RootPanel.getBodyElement().appendChild(testWidget.getElement());
my click event is not being fired. I'm struggeling to understand why.
It would be nice if someone could explain this to me or link me to an resource where i can read this up. Finally i would like to know if it is possible to add the clickhandler afterwards i appended the child event and if that way is recommended. Thanks it advance for help.
kuku
When you call add(), Widget.onAttach() is called on the widget that is being added to the panel. onAttach does some work to register the widget to receive events. appendChild() simply attaches one DOM element to another and does nothing else. You should be able to get events working in the second case by doing this:
Element element = testWidget.getElement();
RootPanel.getBodyElement().appendChild(element);
DOM.sinkEvents(element,
Event.getTypeInt(ClickEvent.getType().getName())
| DOM.getEventsSunk(element);
However, I haven't tested this and I wouldn't recommend that you use it in a real application. Using add() is definitely preferred, using appendChild() in this way has no advantages and may lead to unexpected behaviour.

GWT UiHandler on HTMLPanel

I'm writing a widget with the following markup:
<g:HTMLPanel ui:field="shortcutPanel" styleName="{style.shortcut}">
<g:Image ui:field="shortcutImage"></g:Image>
<span ui:field="shortcutLabel"></span>
</g:HTMLPanel>
So essentially a div that wraps and image and a label. Now, instead of adding the event handlers on the image/span, I'd like an onClick to be associated with the HTMLPanel. My problem however is that gwt tells me that
shortcutPanel doesn't not have an addClickHandler method associated
So I'm assuming the difference is that HTMLPanel doesn't implement HasClickHandlers or something along that line. I'm wondering then what is the standard way to attach a click handler to a Ui element such as an HTMLPanel or even better, is there such a GWT Widget that is essentially a div wrapper that I can easily attach events to with the #UiHandler annotation.
You are probably looking for FocusPanel - it has all the goodies: HasAllFocusHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasBlurHandlers, HasClickHandlers.... to name a few :) I find it to be the easiest and best way to attach click handlers to a Panel.
I haven't done this before, but you could do the following:
Create a custom class MyPanel that extends HTMLPanel and implements HasClickHandlers
Add the following method in MyPanel.java
public HandlerRegistration addClickHandler(ClickHandler handler) {
return addDomHandler(handler, ClickEvent.getType());
}
Then replace HTMLPanel with MyPanel in your ui.xml and its corresponding Java implementation.
You can always look at the implementation of HTMLTable to get an understanding of how the event propagation works. It's a Panel and implements HasClickHandlers.
If you want to use the #UiHandler annotation to register event handlers for your custom widget, you need to re-implement the addXXHandler methods. The GWT compiler doesn't seem to find those in superclasses. e.g. if you want to use
#UiHandler("myCustomWidget")
public void handleWidgetSelectionChangeEvent(final SelectionEvent<CountryDts> event) {
...
}
and your CustomWidget extends a class for which this is working, you might need to add the HasSelectionHandlers interface explicitly to your class:
public class CustomComboBox<D> extends ComboBox<D> implements HasSelectionHandlers<D> {
#Override
#SuppressWarnings("pmd.UselessOverridingMethod")
public HandlerRegistration addSelectionHandler(final SelectionHandler<D> handler) {
// GWT Compile doesn't recognize method in supertype for UIHandler
return super.addSelectionHandler(handler);
}
...
}