Archive for the ‘Eclipse’ Category

Eclipse RCP Tutorial updated to Indigo

Wednesday, August 10th, 2011

Just a quick note, I updated my Eclipse RCP Tutorial to Eclipse Indigo.

Contentwise no big changes, but I tried to structure everything a little bit more, e.g. the first RCP example is used in several chapters and is also finally deployed.

Would be great if you use the “+1″ button on the tutorial, if you like it.

You find more information about Eclipse in the Eclipse Tutorials section of http://www.vogella.de. You might be interested in my Eclipse RCP Training.

You find me also on Twitter. My G+ profile can be found Lars Vogels Google+.

Eclipse Launcher – command line statement for starting your program

Tuesday, July 5th, 2011

Eclipse allow you to start your program via the launcher framework which is very powerful and makes life simple.

Sometimes you want to see the command line which Eclipse uses to start your program. Especially if the program does not want to start and you want to know why. To get the command line statement, run your program and switch to the debug perspective. Here you see your running programs.

Right click on the process and select properties. The next window show you the command line statement the launcher created and used.

I hope this help. Thank to Frederic Conrotte for pointing this out to me.

You find me also on Twitter and Google+.

Eclipse Indigo – My top 5 minor features

Wednesday, June 29th, 2011

Ian Bull did his Top 10 Features where he discuss the great new stuff in Eclipse Indigo.

I tend to value the little things which makes my life easier. So here is my list of things which will help me in my daily work:

1.) Lightweight resource refresh on access

This is big for me. Nothing was more annoying then the “File did change, press F5″ to refresh” you received once you tried to open a file which had been changed. Now you can tell Eclipse to do this automatically for you via Preferences > General > Workspace and select Refresh on access.

2.) Mylyns Alt+click Replacement

Mylyn makes it not much easier to display the filtered children via a plug button. Very nice and helpful for my daily work as I use Mylyn a lot.

3.) Allow Actions to retire

Bug report fixed the necessity to use the ActionFactory to make certain commands usable. While this is may sound like a tiny thing, I personally believe it will make learing and teaching Eclipse RCP easier for the participants. Special thanks to Prakash G. R. for fixing this.

4.) JDT Unavoidable generic type problems

It is really annoying to see warnings for things you cannot not change. A new compiler option has been added that suppresses unavoidable generic type problems.

5.) Improved spelling

Dani Megert picked up lots of spelling suggestions for Eclipse 3.7 so that Eclipse doesn’t show these words as incorrect. Please see the
Bug report for details. Again this seem like just like a tiny thing, but I found it annoying that Eclipse wasn’t aware of terms like “Internet” or “Android”. We still miss “Committer”, lets hope for the next release.

So in total not necessary the biggest changes but all things will help me or make me feel better about using Eclipse.

Thanks to everyone who was involved in these changes.

Mylyn Github Connector

Tuesday, May 10th, 2011

Just in case you missed it, there is a prototype for a Mylyn and Github connector available. Please see https://github.com/blog/852-github-mylyn-connector-for-eclipse for the official announcement.

Installing the connector is pretty straight forward you can directly install it from the Eclipse Marketplace client. The only pre-requisite is that you add the Orbit repository http://download.eclipse.org/tools/orbit/downloads/drops/S20110422041657/repository/ and install “Gson” from the com.google.* category (thanks to Christian Trutz for the tip on twitter).

Importing your issues is as easy as File -> Import -> Tasks -> Github Task Repositories and then you can define new queries for this repository.

The first test unfortunately failed. During a submit of a new issue with the error “Submit failed: Unexpected error: Unprocessable Entry”.

Still the connector looks very promissing. Git is my favorite version control system and I love Github. Its great that soon Mylyn will also to share issues and ther context via GitHub.

I suggest you give it a test run. If you find issues you can report them in bugzilla: Mylyn EGit Connector.

Update: The bug is already fixed, looks like testing will get your bugs solved fast. :-)

Importing existing Java Project into Eclipse – “Create project from existing source”

Tuesday, April 19th, 2011

Are you trying to import a non-Eclipse based Java project into Eclipse?

You find a lot of tips in the internet which tell you that you should create a new Java Project and then use the “Create project from existing source” option.

For example on the Google Plugin for Eclipse webpage.

Unfortunately this option does not exists. To my knowlegge the correct (and unfortunately a bit complex way) is to create a nwe Java project, select the project, right-click on it and select Import -> File System.

On the following dialog you can select the directory from which you want to import and also if existing resources should be overriden.

I hope this helps.

Remark: For Google App Engine with Java you also need to set the output path (bin folder) of the project to “projectname/war/WEB-INF/classes”.

Registering for Android Intents – Being a crappy browser

Monday, February 21st, 2011

One of the most powerful concepts of Android Development is that you can send asynchronously messages to other activities and services via Intents. The standard case is that you specify the intent you want to call and then Android starts the corresponding activity.

You can also register yourself to existing events. For example if you writing an browser application you can register yourself in “AndroidManifest.mf” via the following intent filter as a browser.

  <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".BrowserActivitiy"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="http"/>
            </intent-filter>
        </activity>

    </application>

If you install this application and open an URL in another application you should get a popup asking which application should be opened. As now two application have registered for the same intent the user have to choose which one should be used.

Once your activity is called you can use getIntent() to access the intent. The method getActivity() provides you the action and getData() let you access the data which was pasted. In this example we will simply read the HTML data and load it into a text view.

For more information please see Android Intents and Android Networking.

SWT Style Bits – Bitwise Or and Bitwise And

Tuesday, January 25th, 2011

Ever wondered how SWT Style bits work? It is actually very simple. The style bits are a multitud of 2

SWT.NONE = 0, // 00000000 binary
SWT.MULTI = 2, // 00000010 binary
SWT.SINGLE = 4; // 00000100 binary
SWT.READ_ONLY = 8; // 00001000 binary

Via the bitwise OR operator | you combine the bits

SWT.NONE | SWT.MULTI | SWT.READ_ONLY results in 00001010

To get later the information if a bit was set use the bitwise AND operation &.

if (SWT.WRAP==(result & SWT.WRAP)){
System.out.println(“SWT.WRAP available”);
}

Here is a small code snippets to run a little test.


package de.vogella.swt.widgets;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class SWTbitwiseOr {
	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		new Text(shell, SWT.NONE);
		System.out.println(SWT.NONE);
		System.out.println(SWT.MULTI);
		System.out.println(SWT.SINGLE);
		System.out.println(SWT.READ_ONLY);
		System.out.println(SWT.WRAP);
		System.out.println(SWT.SEARCH);
		System.out.println(SWT.ICON_CANCEL);
		System.out.println(SWT.ICON_SEARCH);
		System.out.println(SWT.LEFT);
		System.out.println(SWT.RIGHT);
		System.out.println(SWT.PASSWORD);
		System.out.println(SWT.CENTER);

		// Lets see what we have 

		int result = SWT.MULTI | SWT.WRAP;
		System.out.println(result);
		if (SWT.MULTI==(result & SWT.MULTI)){
			System.out.println("SWT.MULI available");
		}
		if (SWT.WRAP==(result & SWT.WRAP)){
			System.out.println("SWT.WRAP available");
		}
		if (SWT.SINGLE==(result & SWT.SINGLE)){
			System.out.println("SWT.SINGLE available");
		} else {
			System.out.println("SWT.SINGLE available");
		}

	}
}

For more information please see Bitwise Operators.

If you are located in Germany you may be interested in my Eclipse RCP training which I deliver together with Ralf Ebert.

Eclipse Papercut #7 – Adding the PDE Plugin creation wizard to the Eclipse toolbar

Thursday, January 13th, 2011

Its been a while since I wrote my last Eclipse papercut blog entry.

Today I demonstrate how to add the PDE wizard for creating new plugins to the Eclipse toolbar. I personally create plugin projects on a regular basis therefore it is annoying to select the wizard via File-> New -> blablabla.

I know that I can use Ctrl+3 to select the wizard but I want to be able to select this wizard from the main toolbar.

This is really easily. First find the related Wizard via the Plugin Spy. We see that the wizard is called NewPluginProjectWizard.

Then create a command with the following default handler.


package de.vogella.plugin.pdewizard.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.pde.internal.ui.wizards.plugin.NewPluginProjectWizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;

public class SampleHandler extends AbstractHandler {
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell shell = HandlerUtil.getActiveShell(event);
		WizardDialog wizard = new WizardDialog(shell,
				new NewPluginProjectWizard());
		wizard.open();
		return null;
	}
}

Via the plugin menu spy you also find quickly a nice place to put your new toolitem to the main toobar

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.commands">
      <command
            defaultHandler="de.vogella.plugin.pdewizard.handlers.NewPluginWizardHandler"
            id="de.vogella.plugin.pdewizard.commands.pluginwizard"
            name="New Plugin Wizard">
      </command>
   </extension>
   <extension
         id="toolbar:org.eclipse.ui.workbench.file?after=newWizardDropDown"
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="toolbar:org.eclipse.ui.workbench.file">
            <command
                  commandId="de.vogella.plugin.pdewizard.commands.pluginwizard"
                  icon="icons/sample.gif"
                  tooltip="Create new plugin">
            </command>
      </menuContribution>
   </extension>

</plugin>

If you also add the dependencies to org.eclipse.ui, org.eclipse.pde.ui, org.eclipse.pde.ui.templates and org.eclipse.core.runtime then you should be able to create a new plugin project via your new button in the main toolbar.

I hope this help. You can follow me on Twitter.

EDIT: A simpler solution was proposed by Remy Suen: Since the new/import/export wizards are parameterized commands, the same effect can actually be achieved with pure XML.

<extension
id="toolbar:org.eclipse.ui.workbench.file?after=newWizardDropDown"
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:org.eclipse.ui.workbench.file">
<command
commandId="org.eclipse.ui.newWizard">
<parameter
name="newWizardId"
value="org.eclipse.pde.ui.NewProjectWizard">
</parameter>
</command>
</menuContribution>
</extension>

Git Alias – git add -A and git commit in one command

Saturday, December 25th, 2010

In in 95% of my time I type “git add . -A” directly followed by “git commit -m “message” in the Git version control system.

That is a lot of typing for a very common case. Fortunately git allows to add an alias for the command. To add an alias for git add and git commit to your git configuration, open your .git/config file and add the following.

[alias]
        ac = !git add -A && git commit

Alternative you can use the –global flag from the command line:

git config --global alias.ac '!git add -A && git commit'

You now can add and commit to your Git repository via the command:

git ac -m "message"

Unfortunately alias seems not to be supported on the window implementation of git (msysgit). See the bug report: msysgit does not support alias definition.

I hope this helps. More details can be found in my Git Tutorial. You may want to follow me on Twitter.

Making the Android source code available in Eclipse

Tuesday, December 14th, 2010

One of the annoying things in the Android Development Kit is that it does not include the source code for the standard Android classes. This makes it IMHO unnecessary hard to learn the Android platform.

Of course there is a solution for this. Clone the Android Source Code via Git. Once you have the full source code, switch to the “/frameworks/base/core/java” directory, zip the content of the “android” folder and attach it to your Android jar.

For those of you who don’t want to clone the full Android repoI have attached the source from the current version of Android (Android 2.2) here: Android Source Code zip .

I hope this helps.

For further info check my Android tutorial or if you are based in Germany visit my Android Training.


Switch to our mobile site