Posts Tagged ‘Eclipse RCP’

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 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 RCP Tutorial updated to Helios

Monday, June 21st, 2010

I’m happy to announce that I updated the Eclipse RCP Tutorial to Helios. Looking at the revision history I was (again) surprised that I maintain this tutorial since Sep. 2007.

This time I made a full cycle; I tried not only to adjust the tutorial to the minor UI changes in Eclipse Helios but also to re-structure the tutorial and the text to improve it’s readability. I added more pictures which hopefully make the Plugin concept easier to understand.

Please note that the URL has changed to http://www.vogella.de/articles/EclipseRCP/article.html so in case you have saved this link I encourage you to update this to the new URL. But URL forwarding is setup so don’t worry to much.

I hope this tutorial continue to help new RCP developers to find their way into the fascinating world of plugin and RCP development.

Have fun hacking Eclipse RCP! :-)


Switch to our mobile site