GWT Anchor Image Link

In my project, I need to display image link in GXT grid with the cursor changed to pointer when the cursor hover on the image. When clicked, it will open a new window.

Here is the code :

Anchor anchor =new Anchor();
final Image image = new Image("../resources/images/pdf.png");

anchor.addMouseOverHandler(new MouseOverHandler() {
    
    @Override
    public void onMouseOver(MouseOverEvent event) {
        DOM.setStyleAttribute(image.getElement(), "cursor", "pointer");
    }
});
                
anchor.addMouseOutHandler(new MouseOutHandler() {
    
    @Override
    public void onMouseOut(MouseOutEvent event) {
        DOM.setStyleAttribute(image.getElement(), "cursor", "default");                        
    }
});
anchor.addClickHandler(new ClickHandler() {
    
    @Override
    public void onClick(ClickEvent event) {
        String url="upload/" + model.get(property).toString();
        Window.open(url, "_blank", "");
        Info.display("Hardware", "Show Datasheet");
    }
});                
anchor.getElement().appendChild(image.getElement());            
return anchor;

0 comments:

 
Copyright © peyotest