Thursday, August 5, 2010

GWT: Extend The DatePicker/CalendarView

We're going to start this series of articles related with GWT with a tutorial about extending the DatePicker/CalendarView.

With the DatePicker you can choose any date in a Calendar and browse through it. The DatePicker uses internally the CalendarView class to configure the way the Dates are showed.

The nice thing about the DatePicker is that is really simple to use, but this simplicity comes with a high cost for Enterprise developments: It's really hard to extend, since is highly dependent of internal classes.

One of the most requested features is the ability to limit the valid dates, basically configuring a minimum and a maximum date.

To accomplish that we need to extend the DefaultCalendarView class.

In you GWT Project create a new com.google.gwt.user.datepicker.client package in your /src directory

Go to the GWT subversion repository and copy the DefaultCalendarView file to your code.

Now we're going to start doing our changes:

Create a new constructor adding support for the minimum and maximum dates and define the new variables

private Date minDate = null;
 private Date maxDate = null;

 /**
  * Constructor.
  */
 public DefaultCalendarView() {
 }

 /**
  * Constructor.
  * 
  * @param minDate
  *            Minimum allowed date.
  * @param maxDate
  *            Maximum allowed date.
  */
 public DefaultCalendarView(Date minDate, Date maxDate) {
  this.minDate = minDate;
  this.maxDate = maxDate;
 }

Ok that was easy, now we can define which are the minimum and maximum valid dates, but that's still doing nothing by itself

The easiest way to accomplish our objective is to disable the non-valid dates in the calendar, so let's modify the ......

@Override
 public boolean isDateEnabled(Date d) {
  if (minDate != null && maxDate != null) {
   if (d.after(minDate) && d.before(maxDate)) {
    return true;
   } else {
    return false;
   }
  }
  return getCell(d).isEnabled();
 }

We are almost done. Now let's modify the update method of the CellGrid subclass.

public void update(Date current) {
    // * Another Tweak *//
    setEnabled(getDatePicker().isDateEnabled(current));
    getValue().setTime(current.getTime());
    String value = getModel().formatDayOfMonth(getValue());
    setText(value);
    dateStyle = cellStyle;
    if (isFiller()) {
     dateStyle += " " + css().dayIsFiller();
    } else {
     String extraStyle = getDatePicker().getStyleOfDate(current);
     if (extraStyle != null) {
      dateStyle += " " + extraStyle;
     }
    }
    // We want to certify that all date styles have " " before and
    // after
    // them for ease of adding to and replacing them.
    dateStyle += " ";
    updateStyle();
   }

Note that we only changed the first line of the method, so we are not enabling the cell by default anymore, but we're checking if should be enabled.

The last missing part is that the DatePicker class needs also to be extended to use our new code:

public class DatePickerEx extends DatePicker {

 public DatePickerEx(Date minimum, Date maximum) {
  super(new DefaultMonthSelector(),
    new DefaultCalendarView(minimum, maximum), new CalendarModel());
 }

 public DatePickerEx(MonthSelector monthSelector, CalendarView view,
   CalendarModel model) {
  super(monthSelector, view, model);
 }
}

For your convenience you can also download the code in this archive

We're done. Enjoy your new DatePicker.

Introduction to GWT

This is the Part 1 of what I expect will become a series of articles about my personal experiences when developing with GWT.

Some months ago I started a project with GWT for my current employee. This was my first GWT project, so I needed to do some research and quite a lot of proof of concept, to make sure I could cover all the requested features.

What’s and what’s not GWT
 

That’s what Google says about GWT in their official page. 
Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. GWT is used by many products at Google, including Google Wave and Google AdWords. It's open source, completely free, and used by thousands of developers around the world. 
In this paragraph we have the first key about what’s GWT “is a development toolkit for building complex browser-based applications”. GWT is not the toolkit to use in your homepage or a simple website. For those tasks it’s much better to use pure Javascript toolkits (like JQuery) or maybe some PHP backend. 

GWT is useful when you want to create complex enterprise browser-based applications. But “what’s a complex enterprise browser-based application”? 

Well, I imagine that really depends, but I would say that any browser-based application that requires support for multiple simultaneous users, access to some backend with complex rules and wants to use a rich user interface. 

GWT only solves the rich user interface part, but is a perfect complement for a J2EE backend, allowing an easy integration and a rich experience. 

How is different GWT from other web toolkits? 

I would say that the most important difference is that when developing you only need to known Java, there’s no need to known anything about HTML or Javascript (even when it helps when you need to do really complex features) 

Ok, but JSP or IceFaces/RichFaces also allow to do that. Yes and no. JSP is the Java equivalent to PHP. That means that you need to known HTML and Javascript and inject the PHP in the middle. IceFaces/RichFaces are a really good alternative. In fact I almost choose IceFaces for my project, but the widgets and the flexibility of the components where not matching my expectations. 

Why should I choose GWT? 

For me GWT was the correct solution due to multiple factors:
  • Google is putting quite some efforts in this toolkit and the community around it is really active
  • GWT can be easily customized using CSS and even with direct DOM interaction
  • There are some really interesting extensions for GWT
    • GWT-Cal: Covert one of my main requisites and the developers are really friendly and helpful
    • GWT-Mosaic: Perfectly complements some missing feature and widgets in GWT
    • GWT-Log: Nice and easy integrated logging system
    • GWT-DND: Wonderful Drag&Drop API
Is everything that good? Really?
Well, not really. When I started my project I used SmartGWT. At the beginning it was awesome, everything was really simple, tons of widgets and a lot of people giving good reviews.
I was decided to use it, in fact I even started my project using SmartGWT, but not everything was that perfect.
When using SmartGWT I started finding problems, some were more annoyances than bugs, others required tons of extra work. My first disappointment came from the lack of help in the official forums. In fact I was even surprised by the hard reaction of some of the developers with some users questions. The next problem came when I tried to modify the theme. Was a complete nightmare, everything seemed like a problem and I found myself investing too much time in something that should be really simple.
By then I knew enough to create my own components and libraries like GWT-Mosaic only made everything easier. So I took the way that I wanted to avoid using SmartGWT, but at the end was easier than expected. And now I could use simple CSS and PNGs to create my UI.
Conclusion
Here I finish the first part of these tour through GWT. As you saw GWT is easy enough to use, but powerful enough to tweak it as you want. The ecosystem of libraries is rich enough, but keep always in mind what to you want to achieve.
In the Part 2 I will show you how to create some nice effects and widgets in GWT.
See you soon.

Wednesday, July 28, 2010

Switching Experience (I finally moved to Mac)

I finally did it, I´m finally a switcher. Last month I bought my first Mac (a new MacBook Pro 17” i5) I have been playing with the idea of buying a Mac since some time ago, but I never found a good excuse or reason. When last month my laptop start dying (a 4 years old Fujitsu) I decided it was the proper time to jump to OSX. I was a Windows user for more than 10 years (I started with Windows 3.0), 5 years ago I started to use Linux seriously and 3 years ago was already my main working environment. I must say that I´m a happy Linux user, but the idea of doing some iPhone/iPad application  was the final push to move to Mac.


My first 5 minutes
I always though that all the buzz around the Apple products was exaggerated. As you may known, I got an iPod in Christmas and I´m really happy about it, but I didn’t felt what was owning an Apple product until now.
The box design was beautiful, there is a magic sensation when un-boxing the computer. I saw a nice box with the CDs and some simplified manual, but I took the shortcut. I simply put the MacBook at the table, I connected the power adapter and turned it on.
My kids where playing around, without paying attention to Daddy (in fact there’s nothing weird if Dad is in his computer, right?). But at the moment the MacBook turned on the first time, the speakers started playing a nice music, the screen was filled with a great welcome presentation and both of them came to see what was that. My 2 years old kid directly sit down saying “Daddy, it’s cooool”.
The whole OSX configuration took 5 minutes, asking from time to time for some information. Everything was really easy and straight forward, without any complex stuff. When it finished I had a completely working OS running.
Ok, what do I do now?
Perfect, it’s working, and now what? That was not my first time using an OSX, so probably for me was faster to start playing around that for a normal Windows user. Anyway I really felt at home. Everything was responding really fast and things where really intuitive. I went to Preferences to configure the multitouch trackpad and I was simply wordless when I saw the way the different gestures are explained.
Then I playing a little bit with my kids and the “Photo Booth” application. OSX doesn’t come with games, but I can say that the “Photo Booth” application can be really funny :)
Time to get serious, where are my apps?
The first thing I did was to install all my usual communication, browsing and other common applications. So I started installing Firefox, Google Chrome, Skype, DropBox, OpenOffice, VirtualBox, VLC, FileZilla, Transmission and TrueCrypt (see Essential List of the Best Mac Free Downloads for more recommendations). But I was still missing some functionalities from my Linux/Windows machines.
My first problem was to find a proper replacement for 7Zip. After some googling I found a really nice project which solved my needs perfectly: Keka.
Next problem, I wanted to properly play my DivX and Xvid files using QuickTime. VLC is really great, but I’m always looking for the best integrated solution. This time the answer came from the Perian project.
Ok, now I can browse, execute my virtual machines, use my compressed files and play my  video files.
My first surprise came when I tried to access my external drives. Both of them are formatted using NTFS, I simply connected them and I could access my files perfectly .... but I was not able to modify them !!!! Back to Google and I find that there’s no NTFS writing support in OSX. The solution came from Tuxera, but I find it really slow, so I’m still looking for an optimal solution
Time for the Developer
Until now I was able to cover all my basic needs, but now was time to configure my future development environment.
As I already said, I always try to use the best tool for my projects, so I don’t hesitate to install different IDEs and tools if I get some benefits.
So I first started with my NetBeans installation. Then I followed with Eclipse 64bits and I must say that the speed difference with my Linux Eclipse is amazing. The version in OSX runs like a breeze and feels much faster. Then I followed with “Komodo Edit” which is quite powerful when working with scripting languages and finally I got the XCode from Apple, just to start learning Cocoa and Objective-C.
So I can now continue working with my different projects, but I’m still missing a good way of working with my Subversion repositories. I known, both Eclipse and Netbeans have SVN plugins, but I always feel limited when using them, compared to the power of TortoiseSVN + WinMerger.
Back to Google and my second problem. There’s nothing that can be compared with my Windows TortoiseSVN + WinMerge or my Linux RabbiVCS + Merger. After some search and testing I found CornerStone, Versions and Kaleidoscope. Even when from a visual point of view these are amazing tools, from a functionality point of view I’m missing some basic features, like branch merging. So far I’m using my bellowed command-line svn, using the CollabNet installers.
Conclusions
Casual / Home Users: The MacBook Pro is a great tool, really intuitive and gives all the needed tools out-of-the-box
Advanced Users: Again, a great system that you can tweak as needed
Developers: I miss some of my Windows / Linux tools. The options in OSX are great and maybe I just need to change the way I do some stuff, but right now I would say that’s a good system, but needs some extra effort to make it great. 

Thursday, March 11, 2010

The True Behind the Software Patents

Finally someone said the true about the Software Patents. Since yesterday all the blogosphere is talking about the latest Jonathan Schwartz (former Sun CEO) post "Good Artists Copy, Great Artists Steal".

For years I've seen the big companies (Microsoft, Apple, Nokia, Adobe, ....) defending the need of software patents. The main reason, the excuse, was always to protect the intellectual property, the investments these companies where doing in research and development. And that's the point that was never clear to me.

Let's see. If you create a chip, or an engine, or a car, there's always a big amount of work, design, engineering, models, tests, .... The same could be said about a software package. Any Operating System (Windows, OSX, Linux) or production software like the ones created by Adobe, Microsoft, .... All of those cannot be pirated or illegally copied, since there was a huge amount of work to create them.

But what happens with the Software Patents? Most of them are only ideas, and the patent owner is not always the one that had the idea. Patents like Amazon's "1-Click", or some of the crazy Microsoft patents like "the sudo command", "XML", or "the click". In Amazon's case, the "1-Click" is an obvious choice if you want a nice user experience in your online shop. Regarding Microsoft patents ... well I think it's quite obvious that they where only trolling.

Now finally someone said the true. The software patents are nothing else that a way to protect your company against trolls. The software patent alone has no value, the real value appears when you can use it to do a deal with another company so you can use the others ideas for free.

Guys, do you known something? You can do the same using some of the Open Source licenses laying around. I would really prefer more investment in real technology: new protocols (someone said IPV6 support?), better languages (HTML5 before 2015?) or simply more stable, secure and mature software.

What's clear is that Jonathan Schwartz won a new fan in me. I'm waiting to see what else he couldn't say...

See you soon.

Thursday, January 28, 2010

iPad: What can we do with it?

After months of rumors the iPad is finally here. It's a great device, but is also missing some great features, that for sure will be included in iPad v2. But right now we have a first version opening a new way (or as Apple usually does, converting an existing market).


Worldwide the media is talking about this new device, saying things like "The future is here", "The best device for ....". But, what's really the iPad? What we will do with it? How is it going to change our way of working?


Let's see different examples:


iPad in the Education


That's the first situation that comes to my mind. Maybe because I've children, maybe because in Spain the government is starting to invest in netbooks for the schools.


The iPad looks like the perfect solution for the 21st century education. Some countries are investing in netbooks (like Spain) to introduce the new technologies to our kids. But looks like the iPad is a much better choice.


The main objective of the netbook is that the children can learn how to use internet, read the text books and write their works. The problem appears when the netbook is hit by a virus, someone needs to install the applications, configure the computer, ......


The iPad can do everything that the netbook needs to do, but is also easier to manage, safer, everything can be installed easily and the UI is really intuitive. 


In fact, the iPad seems to be a winner as an educational tool.



iPad in the Company


I see the iPad in the company doing mainly 2 different jobs. 


The first one is again in substitution of a netbook. If you need to travel a lot, but you need to be always in touch, a netbook is a good option, but probably an iPad with a bigger screen and a lighter weight is a better partner. If you need a tool to write email, surf the web and read the latest news the iPad is a good solution. If you add a 3G connection and a GPS is a winner. I can foresee different scenarios where a GPS can be an extra benefit. Simply looking for the closest restaurant or hotel for a meeting is an example.


The second example is when you're always at the office, but your work request continuous walks inside the company (think of a secretary or a warehouse worker) The iPad is a good way to have all your worksheets, documents and email always with you.


Another situation (I known, I said "2 different jobs") is when your work requires an specific image. Design or Media companies are just an example of companies that are alway looking for the cooler device for their receptions, for a device that says "we care about how things look". And right now, the iPad is the best way of saying it.


iPad at Home


And of course, the iPad is also a great device to have at home. The iPhone has already proven itself as a great gaming platform, just imagine with a bigger screen. 


At home, the iPad, can be ideal as a family device for "quick tasks". Checking your email, twitter or social network is just an example. Using it as a photo album or contacts manager is just another. You can also watch your movies or series or listen your favorite music. And now you can also read books.


Most of these things were already possible with the iPhone/iPod Touch, but the screen is making here all the difference. I'm the owner of an iPod Touch, and even when I use it a lot, I cannot write more than a short answer to an email, or do a quick check to a website. I cannot imagine myself working hours with this tiny screen. But I can see myself perfectly working with the iPad, in fact, I can see myself writing in this blog with the iPad in a couple of months.


Conclusion


The iPad is far away from being perfect. The fact that doesn't have a camera is, from my point of view, an error. The apparent lack of multitasking is also a problem, the fact that the screen is 4:3 is another drawback.


It's clear that the iPad is not a computer, is not a portable console, is not an MP3 player and is not an ebook reader. 


We can only wait that the next generation will solve all these negative points. But the iPad is also a bit of everything, and that's its strength.


See you soon.

Friday, January 1, 2010

Is Desktop Development Dying?

After the Oracle/Sun issue and the poor Java 7 announcement, a lot of people has been talking about the "Java is Dead" issue. I completely disagree with this statement, but I really think that something is dying: desktop development.

Last year's improvements in languages and frameworks related with desktop development can be easily reduced to CUDA and OpenCL (please tell me if I'm missing something else). The improvements in frameworks for desktop applications was null (at least in the Java world). On the other hand, let's check other technologies and see the consolidation of the "App Store" and the whole iPhone OS world, how well Android is doing (maybe slower than expected), the quality jump in the Google WebToolkit, Google Chrome OS, the consolidation of Cloud Computing, ....

All these technologies are related with mobile development, web development, ... but desktop development is not following. From my point of view, desktop development is stuck at the same place since some years ago. Let's see what will bring the next year, but so far all the buzz seems to point to the same place, again mobile development.

Not so many years ago a lot of people was looking the whole HTML/JavaScript coding as "second class development" (well maybe was not that many), but nowadays it's an essential part of any developer work. Almost all the restrictions that we had 10 years ago to do "web applications" are gone. And the rest will disappear when HTML 5 finally arrives. So if there's any of you that's still not looking into this new world, it's about time to jump into it ;)

See you soon,

Tuesday, December 22, 2009

The iPhone/iPod As an IT Tool

It's not Christmas, but I've already got my present :) Some days ago, my current employee, gave me an iPod Touch 2G. It was not a simple present, but also a tool to work with a new iPhone application that we're developing.

As many of you, I'm working in a small company. My main job is as developer, but I'm also doing some IT and technical support work, so I was curious to see how could the iPod help me with these tasks.

As I said, I have an iPod, but everything explained here is also applicable to the iPhone. In fact the iPhone is even more useful since you don't need to look for a WIFI connection ;)

Let's start:

A Communication Tool

Here we will see how can we use the iPhone as a communication tool:

  • Mail: Configure your e-mail accounts (check here for the documentation to setup your email accounts)
  • Skype: Even if you have an iPod, you can use Skype to stay in contact with your friends and colleagues. If you also want to talk, you'll need to buy a headphone+microphone kit.
  • Social Networks: Almost all the social networks have an iPhone widget. In my case I installed Facebook, LinkedIn and Twitter (Twitterrific). But you can also find widgets for Xing, MySpaces, ...
An Administrator Tool

Let's see what do we need to have control over our computers and network:
  • Network Ping Lite: It's a simple application that gives you the power of ping, traceroute and telnet commands
  • Mocha VNC: With this tool we can control any computer with a VNC Server installed.
  • iSSH: Another great application. With this one I've all the power of an SSH console, but I can also do remote X connections
  • VPN: Integrated in you iPhone is a cool VPN client, so you are never outside your network.
  • iNet Pro: With this one you can ping, scan ports, scan network, ...

Other Useful Tools

That's the miscellaneous section where I list other tools that I feel are really useful
  • DropBox: Does it even need a presentation?
  • GoodReader: A really good PDF reader
  • AppBox Pro: It's a useful package with different applications.

I'm still investigating what other cool things I can do, but what's your preferred iPhone application?