Tuesday, December 16, 2008

Enceladus - Sixth Largest Moon of Saturn


Saturn, the sixth planet from the sun and one of the gas giants in our solar system has 7 moons in addition to a prominent system of rings. One of these moons, Enceladus, is especially interesting to us humans because it is made mostly of water-ice and could possibly support life. It's diameter is roughly 500 km (15% of the moon's) and has a mass of about 0.2% of the moon's mass. Certain areas of the moon's surface lack craters indicating a dynamic surface similar to the floating ice sheets in the Earth's arctic regions. Water vapor has also been observed spewing from the surface. I found the image here and it is licensed under a Creative Commons liscence.

Optical Illusion - "Shifting Almonds"

I found this image in cyberspace here. It's just a plain ol' PNG, and one of the coolest optical illusions I've ever seen.

See also: Home-made and Bio-inspired Wind Power

Verify User Intent Before Closing an Eclipse RCP Application

Have you ever accidentally closed an application only to lose all the data you were working with or abort some long running calculation half way through? On one particular application I was working on, it would have been devastating to accidentally close the application so I needed to add a dialog box that asked the user to verify that s/he really wanted to close the application. I've also used some applications before with this feature, and found it annoying when I was asked every single time whether or not I was really sure I wanted to close the application. Use it sparingly. The best solution would be to add a preference to the application where the user could decide if s/he wanted the reminder or not. I'll add a tutorial on how to do that soon. Anyway, It took me a while to figure out how to add a confirmation dialog box, but it's actually quite easy. Here's how...



Step 0: Create a Hello World Application.

Step 1: Add code to create the dialog box when the close application action is triggered. In the ApplicationWorkbenchAdvisor class that was automatically generated when you created a hello world application using the new RCP application wizard in Eclipse, you need to override the preShutdown() method. The method returns a boolean where, if true, the application will shut down, and if false, the application will continue running. You need to add code in that method that opens up a dialog box, gets user input, and returns what the user selected. Eclipse's JFace library contains a nice little class called MessageDialog where we can easily make a dialog box pop up, ask a question, and get the answer. We use the MessageDialog.openQuestion() method and pass it three parameters: a Shell, the dialog box's title, and the question we want to ask.


package com.blogspot.obscuredclarity;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {

private static final String PERSPECTIVE_ID = "com.timmolter.helloWorld.perspective";

public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
return new ApplicationWorkbenchWindowAdvisor(configurer);
}

public String getInitialWindowPerspectiveId() {
return PERSPECTIVE_ID;
}

public boolean preShutdown(){

Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
String dialogBoxTitle = "Question";
String question = "Are you sure you want to close this application?";
return MessageDialog.openQuestion(shell, dialogBoxTitle, question);

}
}




Step 2: Run the application and test if everything worked. Your application should now have a dialog box that verifies user intent when the application is closed and look something like this:


Piece of Cake!

Next ---> Add Nested Menu Items and Custom Actions to an Eclipse RCP Application
<--- Previous - Add a Menu to an Eclipse RCP Application
Also see: Eclipse RCP Tutorial Table of Contents

Thursday, December 11, 2008

Add a Menu to an Eclipse RCP Application

As shown in the article Hello World with Eclipse RCP - Your First Application, it is quite simple to create and run your own very basic Java RCP application using Eclipse. In this article I will show you how to add a "Menu" to your application. In particular, I will add the "Exit" action to a "File" menu, and it is very simple. It only requires a few lines of code in one class. The application's menu is used to provide the user with a logical and organized interface to access all the global functions of the application. For example, almost all applications have a File--->Exit or a Help---> About menu. An Eclipse RCP application menu can be as simple or elaborate as needed, and it can contain icons, dividers, and expanding submenus. The following steps demonstrate how to add the Exit action to a File menu to an Eclipse RCP application.



Step 1: Add code to create the File menu and the Exit action. When you created a hello world application using the new RCP application wizard in Eclipse (which I always do to create a skeleton RCP project to build off of for a new application), Eclipse created a ApplicationActionBarAdvisor class that extends ActionBarAdvisor. You need to override 2 of the methods to configure the application's menu to suit the needs of the particular application. During certain strategic points in the workbench's lifecycle, these methods are called and your complete menu is created. In makeActions() the Exit action is created and registered. In fillMenuBar() the File menu is created, the Exit action is added to the File menu, and the File menu is added to the application's menu bar.

package com.blogspot.obscuredcalrity;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

IWorkbenchAction exitAction;

public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
}

protected void makeActions(IWorkbenchWindow window) {

exitAction = ActionFactory.QUIT.create(window); //the ActionFactory defines a set of common actions and can be used in the application.
register(exitAction);  //register the action so they are deleted when the Workbench window is closed

}

protected void fillMenuBar(IMenuManager menuBar) {

MenuManager fileMenu = new MenuManager("&File", "file"); //create a menuManager to take care of all submenus in "File"
fileMenu.add(exitAction); //Add the "exit" action
menuBar.add(fileMenu);//Add the "File" menu to the menuBar

}

}




Step 2: Run the application and test if everything worked. Your application should now have a File menu with an Exit action and look something like this:



Piece of Cake!

Next ---> Verify User Intent Before Closing an Eclipse RCP Application
<--- Previous - Add an Icon to an Eclipse RCP Application View
Also see: Eclipse RCP Tutorial Table of Contents

Wednesday, December 3, 2008

Add an Icon to an Eclipse RCP Application View

In the last Java Eclipse RCP tutorial, Adding a View to an Eclipse RCP Application, I demonstrated how to add a view to a simple RCP application. In RCP applications, views are where you put things like tables, buttons, combo boxes, labels, charts, etc. - all the graphical interfaces that a user will interact with when using your application. In this article I will show where to get icons and how to add an icon to a view, which is placed on a tab corresponding to that view. I will also show how to label that tab with some custom text.



Step 1: Get some icons. Mark James at www.famfamfam.com has graciously created and made available over 1000 icons suitable for Eclipse RCP applications. His work is licensed under a Creative Commons Attribution 2.5 License, so you can use the icons any way you like. Download the icons, browse through them, and choose one that you'd like to use for your view.





Step 2: Add the icon to your RCP application. With Eclipse open and the Package Explorer showing the contents of your project, drag and drop an icon into the "icons" folder. For this example, I put the bomb.png icon into the icons folder.



Step 3: Add the icon to the view. Make sure the View is highlighted in the All Extensions list. To the right are the properties of the view. To the right of the icon property, click on the "Browse..." button. In the dialog box that pops up, choose the icon that you just added. The icon should show up next to the view's name in the "All Extensions" list.




Step 4: Specify that the view's title should be shown. Now that the icon is added to the application project and associated with the view, some code is needed to tie everything together. In Perspective.java set the boolean flag for the second argument in the "addStandAloneView" method to true. This is the "showTitle" flag which tells the RCP application to show a tab for the view containing the icon and a title for the view.

package com.blogspot.obscuredclarity.addicon;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

 public void createInitialLayout(IPageLayout layout) {

  layout.addStandaloneView(MainView.ID, true, IPageLayout.LEFT, 1.0f,   layout.getEditorArea());
  layout.setEditorAreaVisible(false); //hide the editor in the perspective

 }
}


Step 5: Give the view's tab a name. In the view's class, add the line "this.setPartName("Hello!");" to the createPartControl method (line 16). Change the "Hello!" String to whatever you want.

package com.blogspot.obscuredclarity.addicon;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

public class MainView extends ViewPart {

 public static final String ID = "com.blogspot.eclipsercptutorials.addicon.mainView"; //the ID needs to match the id set in the view's properties

 public MainView() {    }

 public void createPartControl(Composite parent) {

  this.setPartName("Hello!");

  Label label = new Label(parent, SWT.None); //new up a Label widget
  label.setText("  All this program does is display this text in a view."); //set the label's text

 }

 public void setFocus() { }

}


Step 6: Run the application and test if everything worked. Your application should now look something like this:



Step 7: If you want the view to be non-closeable, add layout.getViewLayout(MainView.ID).setCloseable(false);" to the createInitialLayout" method (line 12). This will hide the little "X" on the tab and not allow the tab to be closed, which you probably want to do if your program only has one view.

package com.blogspot.obscuredclarity.addicon;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

 public void createInitialLayout(IPageLayout layout) {

  layout.addStandaloneView(MainView.ID, true, IPageLayout.LEFT, 1.0f,   layout.getEditorArea());
  layout.setEditorAreaVisible(false); //hide the editor in the perspective
  layout.getViewLayout(MainView.ID).setCloseable(false);
 }
}




Piece of cake!

Next ---> Add a Menu to an Eclipse RCP Application
<--- Previous - Adding a View to an Eclipse RCP Application
Also see: Eclipse RCP Tutorial Table of Contents

Sunday, November 30, 2008

Import a CD into iTunes when Artist, Album, and Track Info is Missing

Every now and then, when I buy a new CD and import the music into iTunes, the artist, album, and track names don't come with the music. Instead I would get something like unknown artist, unknown album, and track 01, track2, track 3, etc after the import. Of course, when I search my library for my new music, it cannot find it, which is very irritating. After much googling and trial and error, I eventually figured out how to import the CD and add all the information so that the music shows up in iTunes with all of the important information. I thought since it was difficult for me to figure out how to do it, I would make this post to help other people. The trick is actually quite simple...



Step 1: Insert the CD. iTunes should display all the tracks (Track 01, Track 02...) and the duration of each. Highlight all the tracks by typing CTRL+A or command+A on a Mac.


Step 2: Add the album information. With all the tracks highlighted, choose on File--->"Get Info" or command+I on a Mac. This brings up a dialog box in which you can add the artist and album information as well as the year, genre, and album artwork if you want. After you type in all the information, click "OK". When viewing the track list, the new information should be displayed next to all the tracks.



Step 3: Enter the track names. Highlight the first track and choose File--->"Get Info" or command+I on a Mac. This brings up a dialog box in which you can add the track names one by one. I usually find the track names for the album somewhere online, so I don't have to type them all, but rather just copy and paste them. So copy the first track name from a website, and paste it in the "Name" text box. Don't click OK quite yet. Instead click "Next" and then enter the second track name, clicking "Next" until you fill in all the names. Finally click OK after all the track names have been entered.


Step 4: Choose the file type that the music should be converted to during the import. I usually choose the MP3 format. Go to the iTunes preferences, and under the "General" tab, click "Import Settings...". A dialog box will pop up. Choose "MP3 Encoder" next to "Import Using:". Choose the quality you'd like. Also, if the CD didn't show up in iTunes when you inserted it, make sure "Show CD" is selected in this dialog box.


Step 5: Import the CD. By now, all the information about the CD has been entered, and you can import the tracks. In the bottom right hand corner of the iTunes window click on "Import CD".


Step 6: After the CD is imported, you can verify that the CD and all the correct information has been saved in your file system properly. By default, the music will be imported in the iTunes folder usually in the My Music folder on your hard drive. Doing a search in iTunes should also bring up your newly imported music!


Piece of cake!

Please comment if you found this useful or if something is inaccurate. :)

Friday, November 21, 2008

How to Add an Amazon Widget to Your Blog to Make Some Extra Cash

Amazon.com allows you to place customizable product advertising widgets on your website or blog, and in return splits the profits with you any time someone clicks on your widget and buys something within 24 hours. There are a million ways to earn revenue from your website or blog, but most of them can be quite annoying and spammy in my opinion. Flashy animated banner ads or the ones that grow in size and cover up what you're trying to read are the worst, while textual Google AdSense ads, and relevant Amazon product ads, while still advertisements, are the least obtrusive. Amazon gives you 4% of the product's price as a referral fee once the item is ordered and shipped, and the bonus increases the more items you refer to Amazon. Anyway, why not earn a couple bucks from the effort it takes to post helpful information on your website? I think people are willing to put up with a bit of advertising if the content of the website or blog is substantial.

What I like about the Amazon widgets is that they are customizable and can contain products relevant to your blog post. While it's an advertisement, I feel placing an
Amazon widget on a relevant blog post can also be seen as a service for the people looking for a quick link to buy that product from a trusted vendor.

The appearance of the widgets can be customized to match the look and feel of your website. There are also many different types of widgets you can use, giving you several choices. I discovered the Amazon widgets on someone else's blog, but it took me forever to figure out how to put them on my own blog. In this article I hope to save some of you the time it took me to get Amazon widgets on your website!

Step 1: First off, here are four different examples of widgets. There are a bunch of different ones available in addition to this.

Search Box Link:




Deals:




MP3 Clips:




My Favorites:



The My Favorites widget is the only one I really use on my blog. I embed it in the text of some of my articles so that the recommendation for the product is right where the product is talked about in most cases. Since I have been a customer of Amazon.com for quite a while now, I can feel guilt free when sending readers of my blog to their website because I know it's a reputable company.

Step 2: To get an Amazon widget for yourself, just click on the "Get Widget" button on the My Favorites widget above. This will take you to the Amazon.com Associates Central website where you can sign up for an associates account and start building your own widgets and get the code to embed in your website. Doing so is pretty easy after you have an account. Just for the sake of completeness, I'll show you how easy it is to build a My Favorites widget and embed it in your blog.

Step 3: After logged into your Amazon associates account, click on the "Widgets" tab and click "Add to Your Webpage" for the "My Favorites" widget.


Step 4: Search for the type of product you would like to advertise and add one or more. I just typed "widget" because this article is about Amazon widgets. Click "Add Product" for the products you like and they will show up in the right hand column. You can remove them and/or sort the order. When you're done, click "Next Step". You can always add or remove products later, even without re-embedding the widget code in your website.



Step 5: Customize the visual display of your widget. Give it a title, choose whether or not to randomly shuffle the products, and choose colors, etc. If you want to add more columns, you might have to change the width of the widget first in units of pixels. When you are done customizing it, click "Add to My Webpage".


Step 6: Add the widget code to your webpage. Click "Copy" in the small box that popped up to copy the HTML code that defines your new widget. This code will need to be pasted into your webpage.


Step 7: Paste your widget HTML code into your webpage. With a blogger blog you have to click on the "Edit HTML" tab and paste your code there where ever you want the widget to appear between the article text.

Piece of cake!

See also: Add an HTML Footer to Every Post of Your Blogger Blog
and Place an Inline Link to an Amazon Product with Your Associates ID



Monday, November 10, 2008

Eclipse RCP Tutorial Table of Contents

Following is a list of the Eclipse RCP tutorials found on this blog (obscuredclarity.blogspot.com). More articles will be added so please bookmark or subscribe to the RSS feed. Please leave a short comment if you find anything inaccurate with any of the tutorials. I would also love to know if this was useful to you or if you'd like to see a tutorial on something in particular that you're having problems with. Thanks! :)

1. Using Eclipse for RCP Application Development
2. Hello World with Eclipse RCP - Your First Application
3. Adding a View to an Eclipse RCP Application
4. Add an Icon to an Eclipse RCP Application View
5. Add a Menu to an Eclipse RCP Application
6. Verify User Intent Before Closing an Eclipse RCP Application
7. Add Nested Menu Items to an Eclipse RCP Application
8. Add a Custom Menu Action to an Eclipse RCP Application
9. Add an Image to an Eclipse RCP Application
10. Import and Export an Eclipse RCP Application Project
11. Updating a Widget in an Eclipse RCP Application from a Worker Thread
12. Animation in Eclipse RCP Applications - A Bouncing Ball
13. Add a Toolbar to a View in an Eclipse RCP Application
14. Add a Menu to a View in an Eclipse RCP Application
15. Using Simple JFace Message Boxes in an Eclipse RCP Application

These Eclipse RCP tutorial examples were done on a Mac, but should be identical for a Windows or Linux machine. The only difference is the look of Eclipse and your application.

Saturday, November 8, 2008

Adding a View to an Eclipse RCP Application

As shown in the article Hello World with Eclipse RCP - Your First Application, it is quite simple to create and run your own very basic Java RCP application using Eclipse. This article shows you how to add a "View" to your application. Part of learning how to create RCP applications using Eclipse is to learn the terminology people use. A view is the part of your application where you put things like tables, buttons, combo boxes, labels, charts, etc. - all the graphical interfaces that a user will interact with when using your application. These visible units of interaction are called "widgets" and Eclipse provides us with many customizable widgets in the SWT and JFACE libraries.

When an RCP application starts up, a string of events occurs under the hood that generates a stand-alone window containing all your customized widgets that give your program its unique look and functionality. At the top of the hierarchy is the Application class and contains the application's main method (actually called "start()"). In the start() method, a single Workbench object is created, which is a behind-the-scenes class controlling your RCP application. The Workbench in turn contains one or more WorkbenchWindow objects, which are the visible windows making up your program. In most cases you just have one WorkbenchWindow. A WorkbenchWindow in turn contains a menu (optional), a toolbar (optional), and/or one or more Perspective objects. In most cases you just have one Perspective. A Perspective in turn contains one Editor object and/or one or more View objects. View objects in turn contain one or more Widgets, which are the finest grain visible units of the RCP application. As a visual example of all this, look at the following BitTorrent application called Vuze (aka Azureus). You see a WorkbenchWindow with a menu, a toolbar, and two views called "My Torrents" and "Statistics". The "Statistics" view contains Tab widgets which in turn contain other widgets.





As a review, the hierarchy is like this:

Application
|
Workbench
|
WorkbenchWindow(s)
|
Perspective(s) Menu Toolbar
|
View(s) Editor
|
SWT and/or JFace Widget(s)

When Eclipse set up a HelloWorld RCP application for you with a wizard described here, it generated an Application, a Workbench, and a WorkbenchWindow with a Perspective. This article shows how to build off of that, by adding a View with a Label widget containing some text to the View. Let's get to it...

Step 0: Create a HelloWorld RCP application.

Step 1: Add the "views" extension point to your RCP project. Click on the "Extensions" tab along the bottom of the view in Eclipse that shows all the properties for your RCP project. If you don't see that view, double-click on "MANIFEST.MF" in the "META-INF" folder in your project folder in the Package Explorer. Here, you need to add an extension point to your application. Click "Add..." and a dialog box will pop up for selecting a new extension point. Scroll down and find the extension point called "org.eclipse.ui.views", select it and click "Finish".


Step 2: Add a View to your RCP project. You should now see the org.eclispe.ui.views extension added to the "All Extensions" list for your project. Right-click on "org.eclispe.ui.views" and select New --> view.


Step 3: Set the properties of the View. Make sure the View is highlighted in the All Extensions list. To the right you will be able to set some properties of the view. For right now, just the first two properties need to be set. In this example an id of com.blogspot.eclipsercptutorials.mainView and a name of MainView.


Step 4: Generate the view's class. In the properties list click on the "class" link. This will bring up a wizard. Leave everything at the default values but give it a name that matches the name you entered in the name property before. Click "Finish".

Step 5: Add some code to the MainView class that you generated earlier. You need to make sure a "public static final String" field called ID is defined and set equal to the id that you set in the view's properties editor. Also, in createPartControl() add two lines of code that creates a Label widget and set it's text. You may find that when you add the Label code you get an error "Label cannot be resolved to a type". This is because you haven't added an import statement yet above the class definition. The import statements tell the compiler what classes your class will be using. If you ever get an error like that, you can click on the class name, i.e. "Label", in your code and type ctrl+m (windows or Linux) or command+m (Mac). Make sure to always choose the SWT version of the widget and not the Swing or other type of class with the same name.

package com.blogspot.obscuredclarity.addview;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

public class MainView extends ViewPart {

public static final String ID = "com.blogspot.eclipsercptutorials.mainView"; // the ID needs to match the id set in the view's properties

public MainView() { }

public void createPartControl(Composite parent) {

Label label = new Label(parent, SWT.None); //new up a Label widget
label.setText("  All this program does is display this text in a view."); //set the label's text

}

public void setFocus() { }

}


Step 6: Add the view to the application's perspective. Remember how when you used the wizard in Eclipse to create a standalone HelloWrold application and it generated a perspective for you automatically? And remember that views are children of perspectives? The Perspective class in your project should look similar to the following if you want it to add your new view. Open Perspective.java and add the two lines of code shown below in the createInitialLayout method.

package com.blogspot.obscuredclarity.addview;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

public void createInitialLayout(IPageLayout layout) {

layout.addStandaloneView(MainView.ID, false, IPageLayout.LEFT, 1.0f, layout.getEditorArea());
layout.setEditorAreaVisible(false); //hide the editor in the perspective
}
}


Step 7: Run your application. Congrats, you now have an Eclipse RCP application with a view! The view gives you a place to add more widgets and add funtionality to your program. The next things you'll want to add to your program are things like a menu, an editor, more views, status bars, a toolbar, and widgets.




Next ---> Add an Icon to an Eclipse RCP Application View
<--- Previous - Hello World with Eclipse RCP - Your First Application
Also see: Eclipse RCP Tutorial Table of Contents

Friday, November 7, 2008

Hello World with Eclipse RCP - Your First Application

As discussed in the article Using Eclipse for RCP Application Development, Eclipse is free and open-source software that people use to develop Java-based programs called Rich Client Platform (RCP) applications. Using a computer with any operating system (I happen to be using Mac OSX), you can use Eclipse to create an advanced program that can be deployed on Mac, Linux, and/or Windows OS. In this article, I will show how easy it is to get started using Eclipse and make your very own application even if you never wrote a line of code in your life. The program is going to be the classic "Hello World" application that programmers often write as their first program when trying out a new coding language or Integrated Development Environment (IDE). Before following along you'll need to have Eclipse and the Java Runtime Environment (JRE) installed as described here.



Step 1: Launch Eclipse and choose a "workspace". The workspace is where all the files needed for the application, either generated by Eclipse or written by you, will be located. The location I chose for my workspace is in a folder called "workspace" located in the directory that my Eclipse IDE folder resides. Once your application is created, you can navigate to that folder on your hard drive and actually find the files there.
Step 2: Launch the new project wizard in Eclipse. Select "File" from the menu, choose "New" and click "Project".

Step 3: When the new project wizard launches, select "Plugin Project" and click "Next".

Step 4: Enter a Project name and click "Next". The nomenclature that Java developers use is [top-level domain.your personal or company's domain name.project or application name]. So for me I entered com.timmolter.helloWorld. The reason for this is to avoid projects with the same name existing elsewhere in the world. If you named your project HelloWorld, there is a chance that there will be other projects out there named the exact same thing, which is bad. Sometimes people share their projects with the world, and having a unique project naming system keeps things in order. The point is to have a unique name that no one else will use.





Step 5: Choose "Yes" for "Would you like to create a rich client application?" and click "Next".

Step 6: Select the "Hello RCP" template and click "Finish".

Step 7: You may be asked if you want to use the Plug-in Development perspective. Choose Yes. This just specifies how you want the Eclipse IDE to be laid out when working on RCP applications.

Step 8: The new project wizard has created a project for you with all the necessary files and settings to make it an RCP Application. On the left side of the IDE you will see a view called "Package Explorer" which contains your new Hello World application files. These files shown in the view match what is found in your workspace folder, which you set up earlier. Navigate to your workspace folder and you should see your new project there.

Step 9: Launch your Hello World application. To do this, you need to be looking at the "Overview" shown in the center view above. This should have been the default thing displayed, but if it is not, just double-click on "MANIFEST.MF" in the "META-INF" folder in your new project folder in the Package Explorer view. On the "Overview" tab, click on the link called "Launch an Eclipse Application" in the "Testing" area. A small window should pop up with "Hello RCP" written at the top. Congrats, you just created and ran your first Eclipse RCP application!


After you close the program, feel free to look around the Overview of your project and also the "src" folder that is part of your project. The "src" folder is where the code that defines your program resides. There should be a package named the same as your project containing a handful of .java files. If you double-click on any of the .java files, they will open up in an editor view in the center of the Eclipse IDE. You may find it satisfying to open up ApplicationWorkbenchWindowAdvisor.java and change the title of your application in the preWindowOpen() method, by changing the "Hello RCP" string to something different and re-running the application.

While the Hello World program is quiet boring, it is nonetheless the first step in creating a real application that actually does something useful.

Next ---> Adding a View to an Eclipse RCP Application
<--- Previous - Using Eclipse for RCP Application Development

Also see: Eclipse RCP Tutorial Table of Contents

Tuesday, November 4, 2008

Using Eclipse for RCP Application Development

Eclipse is free and open-source software that people mainly use to write Java code and develop Java-based programs called Rich Client Platform (RCP) applications. Eclipse is an excellent, if not the best, Integrated Development Environment (IDE) for Java development. The goal of this article it to help anyone who is interested in creating computer applications, even if they never wrote a single line of code in their life before, to decide if Eclipse is right for them.

One popular RCP application created with Eclipse is Vuze, formerly known as Azureus, a BitTorrent client shown at right. A Rich Client Application can be a full-blown program with a menu bar, icons, toolbars, status bars, etc. It can have tabs, tables, buttons, charts, text boxes, wizards, preferences, dialog boxes, and more. It can be multi-threaded and there are virtually no limitations to your creativity. You could create your own version of Photoshop or just simple a program that plays your favorite song when you open it up. Anything is possible.

If you ever used Microsoft's Visual Studio for developing Windows applications with C#, Eclipse is like Java's version of an application used to develop other applications. I started using Microsoft Visual Studio back in 2005, but have since switched to Eclipse. Eclipse matches my programming philosophy and meets my needs much better than VS for the following reasons.
  • With Eclipse, you can develop your application once, and create exports for Windows, Mac, and Linux no matter what operating system (OS) you use as your development computer.
  • I found that creating an exported product with icons and everything to be much easier and intuitive with Eclipse.
  • Eclipse is free and open-source. Microsoft makes you pay for the IDE if you want the full-blown professional version. I like open-source.
I also think VS has its strengths over Eclipse:
  • The learning curve in creating your first application is much steeper with Eclipse. Getting used to the Eclipse IDE can be frustrating because it has many quirks, that until you figure out, you may spend a lot of time banging your head against the wall. I also found the classes used to simplify the layout of your GUI widgets (i.e. buttons, text boxes, graphics) were better designed in VS.
  • Online documentation and available quality books is much better for VS and programming Windows applications in C#.
All in all, I'm very glad I took the plunge and learned how to use Eclipse to develop RCP applications, and I don't miss VS at all. Some people argue that Java is slow, but I personally believe that is wrong. I've run my own similar C# and Java applications on a Windows system and I can't tell a difference. Java on a Mac and Linux is also very fast.

Another observation that I made is that an Eclipse RCP run on a Windows box will be slower than the same exact application run on a Mac or Linux machine with similar specs. After converting a Windows computer to a Linux computer, the application ran twice as fast and caught up to my other Mac and Linux machines. That's not saying Java is slow on Windows, just that Mac and Linux may be superior operating systems for Java applications. But in most cases, the difference will be negligible. The beauty of Eclipse is that you can choose whatever OS you like!

I want to write about my experience with Eclipse and help others avoid some of the frustrations I had getting started. It's my way of giving back to the people involved in making Eclipse possible because I've used it and enjoyed it a lot. So go ahead and download Eclipse and get started on your applications.


You'll want to download "Eclipse for RCP/Plug-in Developers", unzip it, and place it in an easy to access location in your file system. You can double click the Eclipse IDE launcher icon to open up Eclipse. Also make sure your computer has the Java JRE (Java 5 JRE or above) installed. If you have a Mac or a PC running Ubuntu (not sure about other Linux distros), it will already be installed. I like to make a shortcut on my desktop or drag the launcher icon to the dock (Mac).


You should be greeted with a splash screen as Eclipse loads...


and then the Welcome Page.



Next---> Hello World with Eclipse RCP - Your First Application
Also see: Eclipse RCP Tutorial Table of Contents