if99.net

IF99 ITB

Archive for the ‘eclipse’ Category

? State of Scala IDE on Eclipse

without comments

Even thought Scala is now among the trendy programming languages, it still misses a lot before it is considered as one of the major players.

Most Scala programmers are they who are not satisfied with Java, so it’s natural that most of them were before programming with Java. One of the things Java programmers miss from Scala is a robust and functional IDE. Since I’m a big fans of Eclipse, this means Scala IDE for Eclipse. While surely the improvements have introduced to the plugin, there are many things left out.

So what are still missing? This is my list based on several months experience with Scala IDE. If some missing features are missing (duh…), just comment and I’ll try to update the post.

  • No refactoring. I miss refactoring a lot. I still remember the day I find refactoring features on RefactorIT for JBuilder. It’s like the day you saw sun for the first time. And not long after that, I found Eclipse with its build-in refactoring features. Call me lazy programmer, but programmer should be lazy, isn’t it?
  • The content assist takes (almost) forever. Yesterday I found myself restarting Eclipse about five times just because I’m programming with Scala. And I’ve increase the timeout of content assist ten folds.
  • Content Assist doesn’t show (not nearly) all posibilities. When it works, it doesn’t even show nearly all possibilities I want to have. On some cases, it even can’t show a pretty simple completion for a field. As small example: if I write ‘va’, I hope I can get ‘var’ and ‘val’ as the first entries of the completion suggestion.
  • Limited formatting options. Eclipse’s Java Formatter is the best configurable formatter I’ve ever saw. This Scala formatter doesn’t even come near it.
  • No suggestion, not even correction suggestion. I often use Ctrl+1 in Java editor to assign the statement to a variable. Not possible. If you got errors, you got no correction suggestion.
  • No integration to scala documentation. Weird, but the Scala editor can show Javadoc but no Scala documentation is accessible.
  • No auto import. I ended up importing the whole package everytime I need a class.

But yes, I still put a lot of hope woth Scala IDE. It shouldn’t take a lot of time, because the code is in Scala and Scala means productivity, right?

State of Scala IDE on Eclipse originally appeared on firdau.si on January 28, 2011.

Written by nanda

January 28th, 2011 at 7:19 pm

Posted in eclipse,scala

? Fresh look for your Eclipse editor

without comments

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.

Fresh look for your Eclipse editor originally appeared on firdau.si on January 27, 2011.

Written by nanda

January 27th, 2011 at 9:18 pm

Eclipse Helios is released!

without comments

Yup… Eclipse Helios is released. Download now from here.

The new and noteworthy list can be found here.

Related posts:

  1. Java Formatter Improvement on Eclipse Helios
  2. Eclipse 3.3 Live Rename Refactoring
  3. Maven Plugin: Java Code Formatter

Eclipse Helios is released! originally appeared on satukubik on June 23, 2010.

Written by Nanda Firdausi

June 24th, 2010 at 3:08 am

Posted in eclipse,helios

Eclipse RCP: Opening Certain Preference Page

without comments

The best thing about programming is there are a lot of way to get what you want. But it is desirable that we used the best way to get there. The fastest and clearest solution is what some programmers want. And in that respect, that what makes some programmers artists while the others not.

In this article, I will try to explain the best way to open certain preference page in Eclipse RCP. This shortcut is sometimes needed to avoid questions from users about how to customize certain aspects of the application while in fact the possibility is already offered… via a preference.

To open certain preference page, one can create an entirely new handler by knowing how to do that programmatically. This is a way to do that programmatically:

final PreferenceDialog dialog = PreferencesUtil
				.createPreferenceDialogOn(shell, preferencePageId, null, null);
dialog.open();

A smarter way is to check if Eclipse has provided a handler for that and then create a command for that handler. And indeed, Eclipse has it. The id of the handler is: org.eclipse.ui.internal.handlers.ShowPreferencePageHandler.

The thinking goes further and we need to check also if Eclipse has provided a command for that. While the id is not obvious, the command id for that is: org.eclipse.ui.window.preferences.

After we know that the command is available, what we need is to configure the menu. This is how to do that:

<command
     commandId="org.eclipse.ui.window.preferences"
     label="label you want"
     style="push">
     <parameter
          name="preferencePageId"
          value="idofpreferecepage">
     </parameter>
</command>

And so that is!

Related posts:

  1. Embedding Jetty Server in Eclipse RCP
  2. Eclipse RCP: ISharedImages
  3. Eclipse 3.3 Live Rename Refactoring

Eclipse RCP: Opening Certain Preference Page originally appeared on satukubik on June 14, 2010.

Written by Nanda Firdausi

June 14th, 2010 at 4:41 pm

Posted in eclipse,preference

Maven Plugin: Java Code Formatter

without comments

Enforcing code format in an organization needs discipline. And the best way to do that is by doing some automation. A plugin for Maven will be a easy decision if your organization has used Maven to manage the build.

This plugin is one plugin that exactly does that. The backbone on the plugin comes from Eclipse Java Formatter, which I still endorse as the best in the industry.

Compared to Jalopy, which is now not free, I find Eclipse formatter has the flexibility we often needed. Although it is not bug-free, for most cases it is more than enough.

However, I concerned by the fact that official maven doesn’t have the latest jar of Eclipse JDT. It still only has version 3.3 of it. Hopefully they will have it soon, especially after Helios is released, which bring a lot of improvement to the Java formatter.

Related posts:

  1. Java Formatter Improvement on Eclipse Helios
  2. My Eclipse Code Formatter
  3. Eclipse plugin: Introduce Static Imports

Maven Plugin: Java Code Formatter originally appeared on satukubik on June 10, 2010.

Written by Nanda Firdausi

June 10th, 2010 at 3:30 pm

Eclipse: Copy Qualified Java Name

without comments

Eclipse has a nice feature to copy qualified name from a resource and this is very useful to create documentation or working with XML. For example:

Say that I need the full qualified name from class CaseFormat. What I have to do is:

  1. Click on + beside CaseFormat.java.
  2. Right click on CaseFormat (not CaseFormat.java).
  3. Select Copy Qualified Name.
  4. There you go, you can paste the full qualified name of class CaseFormat anywhere you want.

But that’s kind of a lot of steps, isn’t it?

OK… you can create a keyboard shortcut for Copy Qualified Name but still you have to expand CaseFormat.java before you can do that. If you don’t expand the *.java node what you’ll get is: ‘/guava/src/com/google/common/base/CaseFormat.java’ instead of ‘com.google.common.base.CaseFormat’.

This problem is kind of annoying and if you have to do this a lot of time, will certainly damage your productivity.

So here is a tiny plugin to solve the problem.

com.satukubik.copyqualifiedname_1.0.0

You can download it, save it to your dropins folder, and restart Eclipse. After that a shortcut Ctrl+Shift+C is available for you to copy qualified java name without having to expand the *.java node.

For those who are curious, I’ve put the source code of the plugin here: http://code.google.com/a/eclipselabs.org/p/copyqualifiedjavaname/. Feel free to clone, suggest improvement, or report a bug.

Related posts:

  1. My top Eclipse keyboard shortcut
  2. Eclipse plugin: Introduce Static Imports
  3. Maven Plugin: Java Code Formatter

Eclipse: Copy Qualified Java Name originally appeared on satukubik on May 26, 2010.

Written by Nanda Firdausi

May 26th, 2010 at 5:44 pm

Hello World… Using Spring Roo 1.1.0M1 under STS 2.3.3M1

without comments

The first day’s Google I/O keynote shows how much work has been done to integrate Spring Roo with GWT. Despite the fact that the demo is not smoothly done, this is kind of interesting combination. If before we have to do all the work to integrate Spring + Hibernate + GWT manually, now the work has already been done. Even nicer, it has tight integration with Eclipse, my favorite Java IDE :D .

Unfortunately the information on how to start creating and playing is not integrated and I spent quite some times to finally run a very simple application using all the technologies. Let me share my experience here…

  1. What you need first is an STS 2.3.3M1. It’s not that easy to find, so here is the link: http://www.springsource.com/products/springsource-google-download. Unfortunately, you have to fill the forms as I can’t find another way to download it without filling the form. Warning, you need STS 2.3.3M1 not release 2.3.2.
  2. Next you have to run the installer. I had no problem for this and at the end, the STS is nicely installed on my computer.
  3. Run the STS and put the workspace location as you like.
  4. If you start a new workspace you’ll get something like this:
  5. Just close the Welcome page and you will get something like this:
  6. You’ll need to install DataNucleus Eclipse Plugin and Google Plugin for Eclipse. To do so, go the third tab under the dashboard and select both extensions. Install it and restart the STS.
  7. We can start creating a new project. Create a Roo project with name ‘hello’ and top level package ‘com.hello’. Wait a bit for Maven to download all the dependencies.
  8. You can use Roo Shell to start adding entities to the project. Do following command:
    persistence setup --provider DATANUCLEUS --database HYPERSONIC_IN_MEMORY
    entity --class ~.server.domain.Employee --testAutomatically
    field string --fieldName userName --sizeMin 3 --sizeMax 30
    gwt setup
    

  9. After that, you should right click on the project and select Google -> Web Toolkit Settings…. And then just click OK. I don’t know what happens but without it the application complain that it can’t find GWT SDK.
  10. Again, right click on the project. Select Maven -> Enable Dependency Management.
  11. Now you can run the application by right click on it and select Run -> Web Application. There you go you got the GWT version of the application.
  12. Alternatively is to run mvn gwt:run from console or from Eclipse.

That’s that!

Related posts:

  1. Maven Plugin: Java Code Formatter
  2. Using Eclipse WTP for developing application under Websphere Application Server Community Edition (WAS CE)
  3. Spring Tips: Initializing bean using EasyMock for unit test

Hello World… Using Spring Roo 1.1.0M1 under STS 2.3.3M1 originally appeared on satukubik on May 21, 2010.

Written by Nanda Firdausi

May 21st, 2010 at 9:46 pm

Posted in eclipse,gwt,roo,spring,sts

Java Formatter Improvement on Eclipse Helios

without comments

A new milestone of Eclipse 3.6 just released with a long new and noteworthy list.

Instead of discussing what’s new from this release, I want to discuss a set of improvement from its Java Formatter. I still love Eclipse’s Java Formatter and with these new improvements, I even love it more. This improvements unfortunately didn’t make their way to list of new and noteworthy, hence the reason why I wrote this blog post.

First, we can now turn off the formatter for some part of your code that you don’t want to format automatically. This is achieved by defining special tags.

This is very useful to format a part of your code that will if formatted will be uglier. For example:

		// [format off]
		foo(           "|------------|\n"            +
		    "-----------|------------|-----------\n" +
	         "----------|   FORMAT   |----------\n"  +
	          "--------- |          | ---------\n"  +
	            "-------  |        |  -------\n"  +
	                      "--------");

No tools can keep this formatting no matter what are you trying, right? ;)

The next improvement is very beautiful. This is result of bug entry 59891 which is posted five years ago (! just to make sure that you understand its complexity).

Basically the problem is if you have nested method calls, Eclipse can’t group the arguments based on their call level. So if you have something like:

public class Main {
    public static void main(
            String[] args) {
        foo(bar(1, 2, 3), baz(4, 5, 6, 7));
    }
}

In case the editor set to wrap on 40th characters, you will get:

public class Main {
    public static void main(
            String[] args) {
        foo(bar(1, 2, 3), baz(4, 5, 6,
                7));
    }
}

With the improvement, you will get:

public class Main {
    public static void main(
            String[] args) {
        foo(bar(1, 2, 3),
                baz(4, 5, 6, 7));
    }
}

Very nice!

A longer example (based on post on StackOverflow.com).

With old formatter, the best you can get is:

		Options options = new Options().addOption(OPTION_HELP_SHORT,
				OPTION_HELP, false, "print usage information").addOption(
				OPTION_VERSION_SHORT, OPTION_VERSION, false,
				"print version and exit").addOption(
				OptionBuilder.withLongOpt(OPTION_PROPERTIES)
						.hasArg()
						.withArgName("FILE")
						.withType(File.class)
						.withDescription("specify a user properties file")
						.create());

Or anything explained on the original post. With the new improvement, you can set the formatter to get something like this:

		Options options = new Options()
				.addOption(OPTION_HELP_SHORT, OPTION_HELP, false, "print usage information")
				.addOption(OPTION_VERSION_SHORT, OPTION_VERSION, false, "print version")
				.addOption(	OptionBuilder
									.withLongOpt(OPTION_PROPERTIES)
									.hasArg()
									.withArgName("FILE")
									.withType(File.class)
									.withDescription("specify a user properties file")
									.create());

Beautiful, isn’t it? Just one bug maybe since there is a white space before OptionBuilder.

Beside those two, Helios also bring further supports for formatting annotations and various bug fixes. You can check the whole list by clicking this link.

Related posts:

  1. My Eclipse Code Formatter
  2. Performance benchmark for logging
  3. Be extremely careful when you initialize a non-final field in the declaration!

Java Formatter Improvement on Eclipse Helios originally appeared on satukubik on May 3, 2010.

Written by Nanda Firdausi

May 3rd, 2010 at 10:05 pm

Visual Editor in Eclipse Galileo

without comments

For a long time I have tried to install Visual Editor into my Eclipse Galileo and never get it work until recently.

The secret is explained in the Wiki:

With “Eclipse IDE for Java EE Developers”, you should NOT check the Java EMF Model Utilities (org.eclipse.jem.util) plugins since there are already installed.

Ugh… I think I have tried it before but why only now it is working? Anyway, I’m glad that I have it.

For those who are not aware, Visual Editor is an GUI editor for Eclipse. It can be used to assist Swing or SWT application creation. I never like Netbeans Matisse or SWT Designer because I can’t modify the code like I want. I know that Visual Editor is pretty slow, but to get a code that I can enhance manually tastes better than the alternative.

And more importantly, I like the way it codes my Swing application. Here’s an example:

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class TTT extends JFrame {

   private static final long serialVersionUID = 1L;
   private JPanel jContentPane = null;
   private JLabel jLabel = null;
   private JButton jButton = null;
   private JTextField jTextField = null;
   private JSlider jSlider = null;

   /**
    * This is the default constructor
    */
   public TTT() {
      super();
      initialize();
   }

   /**
    * This method initializes this
    *
    * @return void
    */
   private void initialize() {
      this.setSize(300, 196);
      this.setContentPane(getJContentPane());
      this.setTitle("JFrame");
   }

   /**
    * This method initializes jContentPane
    *
    * @return javax.swing.JPanel
    */
   private JPanel getJContentPane() {
      if (jContentPane == null) {
         jLabel = new JLabel();
         jLabel.setText("JLabel");
         jContentPane = new JPanel();
         jContentPane.setLayout(new BorderLayout());
         jContentPane.add(jLabel, BorderLayout.CENTER);
         jContentPane.add(getJButton(), BorderLayout.EAST);
         jContentPane.add(getJTextField(), BorderLayout.SOUTH);
         jContentPane.add(getJSlider(), BorderLayout.NORTH);
      }
      return jContentPane;
   }

   /**
    * This method initializes jButton
    *
    * @return javax.swing.JButton
    */
   private JButton getJButton() {
      if (jButton == null) {
         jButton = new JButton();
         jButton.setHorizontalAlignment(SwingConstants.TRAILING);
         jButton.setText("Test");
         jButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent e) {
               System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
            }
         });
      }
      return jButton;
   }

   /**
    * This method initializes jTextField
    *
    * @return javax.swing.JTextField
    */
   private JTextField getJTextField() {
      if (jTextField == null) {
         jTextField = new JTextField();
         jTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            @Override public void keyTyped(java.awt.event.KeyEvent e) {
               System.out.println("keyTyped()"); // TODO Auto-generated Event stub keyTyped()
            }
         });
      }
      return jTextField;
   }

   /**
    * This method initializes jSlider
    *
    * @return javax.swing.JSlider
    */
   private JSlider getJSlider() {
      if (jSlider == null) {
         jSlider = new JSlider();
      }
      return jSlider;
   }

} // @jve:decl-index=0:visual-constraint="10,10"

See how it creates a getter for every components? The getter should prepare a component with its properties and also its listener initialization. It makes every method pretty small and readable. There is no long methods with several components and listeners initialization.

Related posts:

  1. Eclipse plugin: Introduce Static Imports
  2. SWT: Composite as filler
  3. What are the important improvements on Eclipse Galileo 3.5 (for me)

Visual Editor in Eclipse Galileo originally appeared on satukubik on April 23, 2010.

Written by Nanda Firdausi

April 23rd, 2010 at 8:04 pm

Why comments are evil…

without comments

We’ve heard a lot of times that comments are considered as an evil. And yet we always found a way to say, ‘but in particular case, comments can be very useful’.

Should we use comments at all?
Of course!!!!!!! My mistake was to name the commandment “Comments are evil”, is just a guideline, as any other principle you apply in software development, sometimes we just produce crappy code, for many reasons, we are under pressure, we don’t know the technology we are working with… Then for the love of god, use comments!! There are other times where we have prodcuded good code wich has a few comments, that’s fine, we cannot always look for the perfection. What “comments are evil” really means is that you should always push yourself to use as few comments as possible, not because you are lazy, but because they are not necessary.

And yet I find it’s hard to take when I explored the code of Eclipse:

...
package org.eclipse.jface.preference;

...

/**
 * A special abstract preference page to host field editors.
 * <p>
 * Subclasses must implement the <code>createFieldEditors</code> method
 * and should override <code>createLayout</code> if a special layout of the field
 * editors is needed.
 * </p>
 */
public abstract class FieldEditorPreferencePage extends PreferencePage
        implements IPropertyChangeListener {
...

Particularly this sentence: and should override createLayout if a special layout of the field editors is needed.

WHY? Because there is no createLayout in the class, not even in the parent class, not in the interface, not anywhere.

So, let’s just code a better code, won’t you?

PS: Just in case anyone curious, the Eclipse version is 3.5.2.
PS 2: Don’t comment this blog post! :P

Related posts:

  1. Don’t be evil
  2. What are the important improvements on Eclipse Galileo 3.5 (for me)
  3. Eclipse plugin: Introduce Static Imports

Why comments are evil… originally appeared on satukubik on April 22, 2010.

Written by Nanda Firdausi

April 22nd, 2010 at 2:13 pm