Monday, 5 September 2011

Love Money Management Even For Nationwide

Two blog posts in one day! You might be thinking what the heck?!?

Love Money have just released an online service to budget and manage your finances. Due to the nightmare that is the IFA in the UK automation for these kind of services is pretty terrible but they have somehow done it. Genius! I can now even connect to my Nationwide account without having to upload OFX's, CSV's and the like.

It really is looking promising, make sure you give this find of the day a go!

GWT Dialog Box With Close Button

Due to the internals of the GWT Dialog Box, extending it to add support for a close button can be a little tricky if you dont understand what your looking for. Alas below demonstrates adding an anchor to the caption area of the dialog, all that's left to do is for you to style the anchor. Happy GWT'ing.

Some people will moan that adding a library such as Smart GWT will add this functionality. Whilst true it also adds a boat load of library code you may never need. Keep compile times short and sweet and use the minimum amount necessary.

  1. // Create anchor we want to accept click events  
  2. final Anchor myAnchor = new Anchor("My Anchor");  
  3.   
  4. // Add handler to anchor  
  5. myAnchor.addClickHandler(new ClickHandler() {  
  6.   @Override  
  7.   public void onClick(ClickEvent event) {  
  8.     Window.alert("Anchor was clicked");  
  9.   }  
  10. });  
  11.   
  12. // Create dialog  
  13. final DialogBox myDialog = new DialogBox();  
  14. myDialog.setText("My Dialog");  
  15.   
  16. // Get caption element  
  17. final HTML caption = ((HTML)myDialog.getCaption());  
  18.   
  19. // Add anchor to caption  
  20. caption.getElement().appendChild(myAnchor.getElement());  
  21.   
  22. // Add click handler to caption  
  23. caption.addClickHandler(new ClickHandler() {  
  24.   @Override  
  25.   public void onClick(ClickEvent event) {  
  26.     // Get x,y caption click relative to the anchor  
  27.     final int x = event.getRelativeX(myAnchor.getElement());  
  28.     final int y = event.getRelativeY(myAnchor.getElement());  
  29.   
  30.     // Check click was within bounds of anchor  
  31.     if(x >= 0 && y >= 0 &&   
  32.       x <= myAnchor.getOffsetWidth() &&   
  33.       y <= myAnchor.getOffsetHeight()) {  
  34.         // Raise event on anchor  
  35.         myAnchor.fireEvent(event);  
  36.     }  
  37.   }  
  38. });  
  39.   
  40. // Show the dialog  
  41. myDialog.show();