Archive for the ‘Eclipse’ Category

Distributed Version Control with Git available for the Kindle

Tuesday, November 15th, 2011

Today I released my first book for the Kindle platform: Distributed Version Control with Git.



Git is popular, especially in my main focus areas, Eclipse and Android.

Since a while I’m working in converting my tutorials into offline versions. The Git tutorial is the first one because it has no images. To my surprise it was still a huge amount of work. I hope the second book will be easier, as I learned a lot about epub, mobipocket, design, DocBook, XSLT transformations, Apache Ant, Inkscape and other tools.

You find the Git Book in all Amazon Stores:

Git Book in Amazon Germany
Git Book in Amazon UK
Git Book in Amazon France
Git Book in Amazon USA

Just to set the right expectations, the Distributed Version Control with Git has the same content related material as the online version. I hope that having this material also available for the Kindle is helpful. Is also allows you to read the online version before deciding if you want to get the book offline.

A big thanks goes to Alex Blewitt for writing the foreword and for providing feedback. I would especially thank Jennifer Nerlich de Vogel for their intensive spell checking exercises. Wolfgang Schell who is a power Kindle user gave important feedback for improving the structure of the book to optimize it for the Kindle.

I also got many suggestions or corrections from my readers and other people involved with Git and would I would like to express my deepest gratitude to their contribution including Robert Konigsberg, Elke Schaper, Appaholics, Michael Wiedmann, Joshy Cyriac, Peter Kahle, Jon Svede, Henning Hoefer, Matthias Sohn, Chris Aniszczyk, Stefan Lay, Edwin Kempin, Sasa Zivkov, David Carver.

Also a big thank you to Ralf Ebert who seeded the idea to publish on the Kindle platform.

Now I’m hoping for positve reviews at Amazon. :-)

Eclipse – Setting the default perspective via config.ini

Wednesday, November 2nd, 2011

A quick tip for the Eclipse IDE (and also useful for Eclipse RCP). You can use the “config.ini” (in your Eclipse installation folder) to define a perspective.

For example the following in config.ini will set the default perspective to the resource perspective.

-perspective
org.eclipse.ui.resourcePerspective

Make sure to add this before the JVM options.

For find the perspective ID you can use the Plugin menu spy.

You find all possible startup parameters listed The Eclipse runtime options

Hope this helps.

Eclipse RCP updates with p2 got sooo much easier

Thursday, October 20th, 2011

Eclipse 3.7 introduced a new feature “org.eclipse.equinox.p2.rcp.feature” which makes updating an RCP application super easy.

Have a look at Eclipse RCP updates with p2 where I describe a very basis setup which should get you started.

I hope this helps.

Running Eclipse RCP applications in the e4 compatiblity layer

Tuesday, October 11th, 2011

Eclipse 4.x allow to run Eclipse RCP applications and Eclipse plug-ins which are created based on Eclipse 3.x.

This is valuable as it allows you to reuse your existing code base and evaluate advantages as the live model and CSS based styling. Unfortunately concepts like dependency for views do not work with the compatibility layer.

To run your Eclipse 3.x RCP application on e4 you only have to add a few plug-ins to your product.

org.eclipse.e4.ui.workbench.addons.swt
org.eclipse.equinox.ds
org.eclipse.equinox.event
org.eclipse.equinox.util
org.eclipse.platform
org.eclipse.ui.forms
org.eclipse.ui.intro

After this change you should be able to start your existing application based on e4.

Related bugs:

Quick access should not be hard-coded
[Compatibility] All views now have view menus
Compatibility Layer – Getting services via getViewSite().getServices()
Compatibility Layer – Using @Inject in plugin.xml based contribution

I hope this help. I also updated my Eclipse 4.2 Tutorial.

How to fix your perspective in Eclipse RCP (and potentially a bug…)

Tuesday, October 4th, 2011

A common requirement for Eclipse RCP applications is that the perspective should be fixed so that the user cannot change the layout, e.g. layout parts cannot be moved or zoomed, and the initial set of views cannot be closed.

According to the Javadoc this behavior should happen if the perspective is set to fixed. There seems to be bug in the implementation or in the Javadoc as the position in Perspective.java is important. The following works:


public void createInitialLayout(IPageLayout layout) {
	layout.setEditorAreaVisible(true);
        layout.setFixed(true);
	layout.addView("de.vogella.rcp.fixedperspective.view",
				IPageLayout.LEFT, 0.5f, layout.getEditorArea());
	layout.addView("de.vogella.rcp.fixedperspective.view2",
				IPageLayout.RIGHT, 0.5f, layout.getEditorArea());

}

The following does not fix the perspective:

public void createInitialLayout(IPageLayout layout) {
        layout.setEditorAreaVisible(false);
        // does not work
	layout.addView("de.vogella.rcp.fixedperspective.view",
				IPageLayout.LEFT, 0.5f, layout.getEditorArea());
	layout.addView("de.vogella.rcp.fixedperspective.view2",
				IPageLayout.RIGHT, 0.5f, layout.getEditorArea());
	layout.setFixed(true);
}

Does anyone know if that is a bug or a feature?

Another question which sometimes comes up is how to fix a specific view which is added via the Perspective.java. This is possible by getting IViewLayout from the layout.

public void createInitialLayout(IPageLayout layout) {
		layout.addView("com.example.view.view", IPageLayout.LEFT, 0.95f, layout.getEditorArea());
		IViewLayout viewLayout = layout.getViewLayout("com.example.view.view");
		viewLayout.setCloseable(false);
		viewLayout.setMoveable(false);
		layout.setEditorAreaVisible(true);
	}

Eclipse Secure storage of preferences

Thursday, September 22nd, 2011

Eclipse allows to encrypt preference values via the plugin “org.eclipse.equinox.security”. The key/ value pairs will be stored in the file “secure.storage” in the folder “.eclipse/org.eclipse.equinox.security” of the user directory.

Eclipse uses a PasswordProvider for encrypting the preferences. Via the extension point “org.eclipse.equinox.security.secureStorage” you can register your own PasswordProvider.

To test the secure storage create the project “de.vogella.preferences.security” with a view and add “org.eclipse.equinox.security” as a dependency to this.

Change the code of your view to the following.

package de.vogella.preferences.security;

import org.eclipse.equinox.security.storage.ISecurePreferences;
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

public class View extends ViewPart {
	public void createPartControl(Composite parent) {
		Button buttonPut = new Button(parent, SWT.PUSH);
		buttonPut.setText("Save values");
		buttonPut.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ISecurePreferences preferences = SecurePreferencesFactory
						.getDefault();
				ISecurePreferences node = preferences.node("info");
				try {
					node.put("user", "vogella", true);
					node.put("password", "123", true);
				} catch (StorageException e1) {
					e1.printStackTrace();
				}
			}
		});
		Button buttonGet = new Button(parent, SWT.PUSH);
		buttonGet.setText("Get values");
		buttonGet.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ISecurePreferences preferences = SecurePreferencesFactory
						.getDefault();
				if (preferences.nodeExists("info")) {
					ISecurePreferences node = preferences.node("info");
					try {
						String user = node.get("user", "n/a");
						String password = node.get("password", "n/a");
						System.out.println(user);
						System.out.println(password);
					} catch (StorageException e1) {
						e1.printStackTrace();
					}
				}
			}
		});

	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
	}
}

I hope this helps. For more details please see Eclipse Preference Tutorial.

I hope this blog entry helps. You find me also on Twitter. My G+ profile can be found Lars Vogels Google+.

Eclipse default line length of 80 chars outdated?

Tuesday, September 6th, 2011

Today I write to get your opinion.

I believe defaults are important as few developers take the time to change them and in a distributed team it is often the easiest to stay with the default settings.

As we all know Eclipse defaults to 80 chars per line. After that the “Format Source” command will break the line.

A quick poll on Twitter indicated that people would like to see that limit increased.

What do you think about this setting? Wouldn’t it make sense to increase this? Is this even possible or would this change create too much noice in the version control systems of the existing code base?

Eclipse SWT – Creating an email in the default email client

Tuesday, August 30th, 2011

As many of you properly know SWT has the nice Program.launch() method which allows to start programs associated with an URI.

Example:

// This works for Windows
	public void openMailWindows(String to, String subject,String body, List<File> attachments) {
		String mailto = "mailto:" + enc(to) + "?subject=" + enc(subject) + "&body=" + enc(body);
		for (File f : attachments) {
			mailto += "&attach=" + f.getAbsolutePath();
		}
		Program.launch(mailto);
	}

	private String enc(String p) {
		if (p == null)
			p = "";
		try {
			return URLEncoder.encode(p, "UTF-8").replace("+", "%20");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException();
		}
	}

Unfortunately this does not seem to be working on Linux. So if you are working under Linux you have to use the Java runtime directly. Unfortunately this requires you in my humble opinion to code against a a specific application.

// This works for Linux with Thunderbird
	public void openMailLinux(String to, String subject,String body, List<File> attachments) {
		String mailto = "mailto:" + enc(to) + "?subject=" + enc(subject) + "&body=" + enc(body);
		for (File f : attachments) {
			mailto += "&attach=" + f.getAbsolutePath();
		}
		Program.launch(mailto);
		try {
			// For using the parameters check the following description
			// http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29
			Runtime.getRuntime().exec("thunderbird -compose");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

I hope this helps.

You find me also on Twitter and Google+.

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+.


Switch to our mobile site