Tag Archives: eclipse

Fresh look for your Eclipse editor

The default theme of Eclipse is good, but I must admit that with some configuration, Vim can show code better. And this is pretty easy, just go to Google and search for ‘vim color’.

I know from a long time ago that Eclipse allows us to change the color preference of our editor. Hence I never change the default since it is just too much hassle to do that. Not counting that when I reinstall Eclipse, I might have to reconfigure all that stuffs.

So when I found this plugin Eclipse Color Theme, I know I will like the plugin. But God, how I’m still surprised to see the result.

Do you like it? There are even more themes you can download here.

Eclipse Tips: Open Implementation

Eclipse Helios has another subtle enhancement to the JDT. It is called as Open Implementation. So what’s that? Before we play around with the feature, let’s create some classes.

interface IProcessor {
	void process();
}
public class Processor1 implements IProcessor {

	@Override
	public void process() {
		// TODO Auto-generated method stub
	}

}
public class Processor2 implements IProcessor {

	@Override
	public void process() {
	}

}
public class Main {

	public static void main(String[] args) {
		new Processor1().process();
	}

	public static void a(IProcessor p) {
		p.process();
	}
}

Before Open Implementation is implemented, we have only Open Declaration with F3 as default keybinding. Try this on Eclipse before Helios. Put your text cursor on method process on statement p.process(); in class Main. Click F3. You’ll be brought to the process method in IProcessor.

But what we need often is not the declaration, we need the implementation of the method. Before Helios, what I do is to go the declaration, click Ctrl+T and pick the implementation I want.

Helios shortens this. Put your text cursor again on the method and click menu Navigate → Open Implementation. Now if you have more than one implementation of the method, you will get choice to pick which implementation to open.

By defining a keybinding on Preferences → General → Keys you can even use the feature easier, but before you do that, see if this shortcut is fast enough for you.

Click Ctrl and hold it. Now move your mouse over the same method. Tadam… you will get choice.

If you pick Open Implementation you’ll get the same choice as before.

So that’s it. Hopefully this tips helps you a lot.

Eclipse's Quick Diff: See What Changes You've Made Since Last Checkout

A new morning. You’ve checked out the last code from SVN. Stand up and prepare a coffee and when you were back to the computer, Eclipse had loaded the newest code. You ready to code. And you code. Until afternoon and you need to check-in the changes you’ve made. Now you wonder, what have you changed? You know the file you’ve changed, it’s decorated by Eclipse after all. But which lines?

This question is always arisen to most of us. Unfortunately, as default, Eclipse didn’t easily show which lines have you added since last check out. Before I know this feature, I usually compare my code with the latest code in repository. How annoying is that?

It turns out that Eclipse actually already have functionality for that. See this picture.

This feature is called Quick Diff. It is turned on as default but the reference source is the last saved version. If your project use SVN (or CVS, Mercurial, Git as long as you use the Eclipse plugin for that SCM), you can change the Quick Diff behavior to compare the code on your machine with the latest code in the SCM. How nice is that? If you delete lines, you’ll get something like this.

How to do that? As you can guess, go to Preferences and select General → Editors → Text Editors → Quick Diff. Then change the last combo box to SCM you used. That’s it. Now close the main screen and close all opened files. You’ll get the information about which lines have you changed once you open any files.

There is another option in the preference to ‘Show differences in overview ruler’. If you activate this, you’ll get something like in on the right side of the editor.

Now there is still problem with this quick diff functionality. If you have several projects that come from different SCMs, you can’t set the source project based. It’s so not nice and I have filed a enhancement request for that. Vote it up if you also want that functionality!

Eclipse's Team Project Set: Easier Collaboration

Eclipse has this feature Team Project Set which is rarely used. Really rarely I must say.

The point of Team Project Set is when you have many projects on your workspace that build the entire application. People often ask new developers to just check out each project from CVS/SVN. While this works, it is certainly not efficient. With Team Project Set, you will get the same result just by several mouse clicks.

To use Team Project Set, first you have to have a workspace fully configured for your application. Now, click anywhere the Package View and select Export. Select Team Project Set from the list. You should get this dialog window.

Now select the projects you want to include in the Team Project Set and click Next. Select the target file and click finish. Your job is done. Now you can share the project set file to the new developers.

In the new workspace, you can do the reversed step that you do before. Do Import and select Team Project Set.

The next step is self-explanatory, select the project set file you’ve created before and click finish. Depends on the size of your projects, the process will take time anywhere from couple of seconds until several hours. And there you go, the complete projects of your application configured with the SCM.

Limit Your Access to Java API for More Productivity

Simplify your work environment to get more jobs done. One example here is to limit your access to the Java API so you won’t be distracted by proposals that you don’t need.

RCP/SWT developers are facing this all the time. Point is a class in org.eclipse.swt.graphics, but it is also a class in java.awt. When you start to autocomplete, you will get at least two proposals of Point and alas, the Point from java.awt is usually put in the first place. The same with MouseListener. You will get at least one from java.awt.event and one from org.eclipse.swt.events.

You can solve the problem by limiting your access to Java API. To do this, you need to open the Build Path properties of your project.

Here you can double click the Access rules to get the Type Access Rules dialog.

Click Add… to add a rule. For the example I gave before, you may need to set rule to access type java/awt/** as forbidden. You can set many rules as you like and after that close the dialog.

Now if you try to get proposal for Point, you’ll get only the class from SWT and nothing from AWT. This will surely help you choose the right class that you intended.

Introduction to Eclipse Command

Command in Eclipse represents task. Anything can be a task. In the example in the picture above, I used ‘delete’ as example. A command can have several handlers, which are active on different conditions. In the previous example, I used three handlers which active depend on the type of the object.

Commands can be triggered from one or more place(s). We can define a menu that call a command or define a context menu for that. We can also bind a keyboard shortcut to call a command and we can as well programmatically call a command from our code. And that’s just some examples.

Command, architecturally, is representation of controller. Using command should made it easy for developer to get a big picture of what an application does. Just list all the command and that should be it.

You can find more about command in these links.

What is Eclipse-RCP-based Application?

To get the answer of that question, we need to take a look at the global architecture of an Eclipse-RCP-based application. This picture below can summarize the information.

SWT is Standard Widget Toolkit for Java. Developed by IBM and later by Eclipse Foundation, the purpose of SWT is to give native performance and look to Java application. SWT is implemented using JNI and so is not write-once-run-anywhere-library (WORA). This mean that each OS need specific SWT distribution.

JFaces is a layer above SWT which provides more convenience classes for generic application. JFaces is a WORA library.

OSGi is a standard developed by consortium with the same name to provide Java environment that is more dynamic. The goal is extensible, loosely-coupled applications with modules behind it.

Equinox is Eclipse implementation of OSGi.

Eclipse Core and Eclipse UI are classes that form the platform of Eclipse. All Eclipse-RCP-based applications will use this classes. Among other things, it provides extension framework, command framework (and somewhat-deprecated Action framework), and basic application-window management.