Using Watson Translation service in an Eclipse SWT application Part 2

The next follow-up to the last article is the code I used to communicate with the Watson Translation service. But first I want to show the flow of the data:

So basically the SWT client sends a JSON string to the server in the body of the message. You can do this as long as you specify application/json as the Content-Type. For JSON, I use the JSON library for Java over at and its been perfect. I have even begun using this library for all of my in memory objects because then I can easily serialize it out for storage or over the network.

Below you will see the primary code to send this message:

JSONObject payload = new JSONObject();
payload.put("toLang", obj.get("to"));
payload.put("text", obj.get("text"));
URL url = new URL(pet_bluemix_translation_service);
URLConnection connection = url.openConnection();
connection.setRequestProperty("Content-Type", "application/json");
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
//Now get the response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String n = in.readLine();
StringBuffer sbValue = new StringBuffer();
while(n != null){
	n = in.readLine();
final String value = sbValue.toString();

Eclipse and SWT to the rescue

For the past week or so I have been able to do some Eclipse and SWT programming. I have a tool here for technical sellers written in Java and what has been requested for a couple of years is a front end UI to that tool. One thing that really stuck out was the Window Builder and the information on the internet. You see, when I started Eclipse development it was very new. Unless you knew where to look it was often difficult to find answers or great examples. Almost 13 years later and its a very different story.

window_builderFirst off, Window Builder is amazing, it works, and the amount of functionality in it is very impressive. I remember early on with was pretty bug ridden and we ended up coding by hand. Now, you can do all kinds of really cool things right in the user interface. I was able to completely use the WindowBuilder editor for all of my windows and dialogs – piece of cake! I especially like the Menu and Table editors – makes creating these things a snap.

Next, I have to mention the internet, StackOverFlow, and all of the blogs and articles out there. It seems no matter what I search for someone has written about it or asked about it. Great job Eclipse Community!.

Eclipse SWT ImageData to the rescue for image resizing!

A little side project I have here at work has taken a life on of its own. Most recently with the launch of the new Aurora storefront I once again enhanced an internal tool to automatically size product images to adhere to the size requirements for the store. I ended up using Eclipses SWT (The Standard Widget Toolkit) that comes with Eclipse to do this. What I wanted to share today was how easy this was using the SWT API’s.

Continue reading

A powerful function…

Many have downloaded, looked at, and have commented on the source code for the attachment viewer project but some may not be aware of a powerful function the SWT Browser brings to the table.  As described in a past post about the architecture, the line where the browser is connected with the embedded browser process (its actually a dotted line) is where this call happens.  The function, or method, is the execute method on the SWT browser.  This allows you to run essentially any JavaScript on a given web page or DOM.  The attachment viewer uses this method to call a JavaScript function named “showAttachments()”.  The Eclipse Java code takes the current selection – which in this case it looks for IAttachment – and then passes a set of URL’s and JSON to that JavaScript function.   This is how easy it is to “connect” the web world with the Eclipse world.

String cmd = "showAttachments(" + jObj.toString() + ");";
 if (browser.execute(cmd) == false){

Tutorial: How to add the Attachment Viewer to your mail file

As promised, here is the step by step tutorial for adding the attachment viewer to your email.  Go ahead and check out the video before you begin so you will get a clear picture of what I am talking about – in case you missed the post.  While these steps are very basic, I am going to explain them using the very technical Eclipse terminology so in the end you will surely know how the Notes 8 client is constructed and especially Mail. 🙂

Continue reading

Demo: Attachment viewer for Notes 8

So I was challenged a couple of days ago by Art Thomas to give him an attachment viewer for when he receives images, movies, etc in mail and he just wants to immediately view them without launching them individually.  I started thinking about how I would implement it and I came to the conclusion that we kind of have the ultimate viewer right at our disposable – the SWT Browser!  So in short, watch the video and let me know what you think.

I gave this out internally for now as a Widget and also showed some people how to change their mail application to have the viewer embedded into Memo and Reply forms (as I demonstrate in the video).  I think this project will be good for OpenNTF and a couple of tutorial videos on how I did it….more to come.

For video click more.

Continue reading

Why SWT/Qt when you have the Lotus platform?

I just read this interesting post about a project for an SWT version based on Qt.  The project argues it is for styling purposes.  What is interesting is the Lotus platform (Lotus Expeditor) which is what Lotus Notes 8.x is based on has had SWidgets since day one.  We even tried to get SWidgets put back into the Eclipse platform but with no success.   You can play with the Lotus Expeditor platform and the toolkit for free.

If you are not familiar with Lotus Notes or Lotus Expeditor you can check out the UI – which is all based on Eclipse/SWT over at the Lotus Notes site.

Here is a screen shot of the Notes email system with styled SWT widgets:

RAP or GWT – Which Java-Based AJAX Technology is for You?

I watched this video recording from EclipseCon 2009 and I think it is a great primer for these two technologies.  Dan and Mark from Instantiations do a great job laying out most of the pros and cons for them.  The recording is 37 minutes long and I think it is more than worth the time.


Reference recording is here.

Automating SWT based applications with SWTBot

Many Lotus customers (and Lotus itself) use Rational Functional Tester(RFT) and in many ways RFT does a great job and in many ways it can be just too much for what you need to do.  If you want to integrate UI testing into your unit testing you might want to check out SWTBot.  I have recently started looking at SWTBot with a serious eye.  I plan on playing around with it for our own team use and I also have some team members looking into it to automate their areas.  I would like to get some feedback from the blogosphere and find out if anyone has actually used this or has integrated it into their ant scripts.  The site has a lot of good pages and articles to get you started running pretty quickly.  I think since its Java/Eclipse based it plays well into the “test driven development” model many companies are moving towards and should feel so daunting to a developer.

Code Snippet: Notify the Property Broker of a property changes

Greg posted a nice little utlility class you can use in your SWT views for publishing basic string based properties to the Property broker.