hovering HTML help page over a link in GWT - gwt

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

Related

Gwt DragStartHandler does not work in IE and Firefox

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.

wicket download link clear feedback panel

I have couple of drop downdowns and a download link button. Based on the user selection, i get the file to be downloaded. if the user did not make a selection I show an error on the feedback panel. if the user then makes a selection and clicks on download link it works fine, but the previous feedback message is still visible. How do I clear it.
onclick of the download link, i tried the following, but no use
FeedbackMessages me = Session.get().getFeedbackMessages();
me.clear();
Probably it is
Session.get().cleanupFeedbackMessages()
even it has been changed in Wicket 6.x
I've found this post and I think it is time to share the way for Wicket 6.x and for Wicket 7.x, because Session.get().cleanupFeedbackMessages() was deprecated already.
To do it for Wicket 6.x you have to implement additional filter for the feedback panel. Where to do it, it is your decision to decide.
Create a new FeedbackPanel implementation by extending from the existing FeedBackPanel class
private class MessagesFeedbackPanel extends FeedbackPanel{
private MessageFilter filter = new MessageFilter();
public MessagesFeedbackPanel(String id){
super(id);
setFilter(filter);
}
#Override
protected void onBeforeRender(){
super.onBeforeRender();
// clear old messages
filter.clearMessages();
}
}
Provide a new Filter implementation, by implementing the existing IFeedbackMessageFilter interface
public class MessageFilter implements IFeedbackMessageFilter{
List<FeedbackMessage> messages = new ArrayList<FeedbackMessage>();
public void clearMessages(){
messages.clear();
}
#Override
public boolean accept(FeedbackMessage currentMessage){
for(FeedbackMessage message: messages){
if(message.getMessage().toString().equals(currentMessage.getMessage().toString()))
return false;
}
messages.add(currentMessage);
return true;
}
}
Following code works for me in Wicket 6:
public class MyComponent extends Panel {
...
FeedbackMessages feedback = getFeedbackMessages();
feedback.clear();

Possible bug with GWT gwtquery .live() method

I'm trying to do the following:
I want to add a specific handler for some links, denoted by a class.
$("a.link_list").live("click", new ListLinkHandler());
I need .live() instead of .bind() because new such links will be generated. (I know jQuery's .live() is deprecated in favor of .on(), but gwt-query doesn't have a .on() yet.)
I defined the handler like this (just as the gwtquery example does):
public class ListLinkHandler extends Function {
#Override
public boolean f(Event e) { [...] }
}
However, the handler method is never called when I click the links.
I can see the event listener in Chrome Dev Tools: http://screencloud.net/v/bV5V. I think it's on the body because it's a .live().
I tried using .bind() and it worked fine. The body event listener changed in a a.link_list and the handler does what it's supposed to do, but (as documented, I didn't test) not for newly created links.
I filed a bug for the .live() method, but maybe I'm doing something wrong.
Also, I have no idea how to do it without gwtquery, GWT doesn't seem to have a method for selecting elements by class, neither to continually add the listener to new elements.
It seems you are doing something wrong, but I need more code to be sure. Could you send the complete onModuleLoad code which demonstrates this wrong behavior?
I have written a quick example using live, and it works either when adding new gwt widgets or dom elements with gquery, in both Chrome and FF
public void onModuleLoad() {
$("a.link_list").live("click", new ListLinkHandler());
// Add a new link via gquery
$("<a class='link_list' href=javascript:alert('href') onClick=alert('onClick')>Click </a>").appendTo(document);
// Add a new link via gwt widgets
Anchor a = new Anchor("click");
a.setStyleName("link_list");
a.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Window.alert("clickHandler");
}
});
RootPanel.get().add(a);
}
public class ListLinkHandler extends Function {
#Override
public boolean f(Event e) {
Window.alert("live");
return true;
}
}

How to add a double-click listener to my GEF editor?

I'm using GEF. I have a graphical editor with some "boxes" implemented. Now, I want to add a double-click listener to each box (Rectangle).
I tried to add a listener to the GraphicalViewer but it did not work.
In the GraphicalEditPart of the "box" for which you want to add the listener, you have to override the performRequest(Request req) method. When the framework identifies a double-click on the part's figure, it calls this method with a request that has req.getType()==RequestConstants.REQ_OPEN. You can take over from here.
Complete code to test that his works:
#Override
public void performRequest(Request req) {
if(req.getType() == RequestConstants.REQ_OPEN) {
System.out.println("requested double-click.");
}
}
Hope this does the trick.
I am not familiar with GEF myself, however I found this in documentation:
GraphicalEditor abstraction sets the EditDomain - handler for editing events
EditDomain interface with methods for handling events - e.g. double click
Tutorial on how to implement editing of models through GUI in GEF (using EditDomain)
viewer.getControl().addListener(SWT.MouseDoubleClick, new Listener() {
#Override
public void handleEvent(Event event) {
//write the double click action
});

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.