Geirr Winnem's Blog

Blogging about development

  • Categories

  • Archives

  • Follow me

Building a PureMvc Multicore eclipse plugin, Creating a preference page.

Posted by gwinnem on November 14, 2009

I have been using puremvc multicore for quite a while now.
One of the things im missing is a plugin in eclipse for creating new classes like:

  1. Facade
  2. Mediator
  3. SimpleCommand
  4. MacroCommand
  5. Proxy


Since im quite the lazy developer i hate programming repetitive code all the time.
I have been using the CFeclipse plugin’s snippet functionality but it’s not good enough since it only allows you to insert code into the code editor.

After doing quite a lot of research and also posted this into the forums at the puremvc website i have to admit i was
quite surprised to learn that no one had developed one before. So i decided to doit by myself, although im not an expert in eclipse plugin development.

I will start this tutorial by creating a simple preference page where the path to the puremvc multicore swc file is stored, so that the Add PureMvcMulticore Nature can copy the swc file into the default lib folder, and also update the project settings so that the swc is included in the project.

First we have to create a new plugin project.
Doing this is quite easy. Just press ctrl+N and this will bring up the meny, select other so that we can select the project type to create.
This will bring up a new dialog.
Project type
Find the Plug-in Development category and select: Plug-in Project.

In the next dialog you give your project a meaningfull name and also set the location for the project.
Project name

Data required for the plugin dialog:
If you already have given the project a meaningfull name, then you can use the default settings for:

  • Plug-in ID:
  • Plug-in Version:
  • Plug-in Name:

The Plug-in Provider is optional so feel free to fill in an appropiate value here.
I have set the Execution environment to JRE-1.1, so that the developer dont need to have the newest JRE or SDK installed.
Since a preference page is part of the UI we also have to mark the This plug-in will make contributions to the UI.
default settings

Next up is to select the template to use for the plug-in.
Select the Custom plug-in Wizard and press next.
Plug-in template

Since we selected the Custom Wizard we can select from all the available templates, and we can also select multiple templates to include in the project.
I prefer developing a plugin in separate projects so it’s easy to debug and test the different parts of a plug-in.
In the next dialog press Deselect All And then select: Preference Page.
Plugin Template selection

The final step is to define the package name, page class name and page name(This is the name that will show up in the preference’s window in eclipse).
Page settings

The project will have a structure like the below image:
project structure

Now we are ready todo some coding:
Open up the PreferenceConstants.java file, and do the following changes to it:

package testplugin.preferences;

/**
 * Constant definitions for plug-in preferences
 */
public class PreferenceConstants {

	public static final String P_PATH = "pathPreference";

/*	public static final String P_BOOLEAN = "booleanPreference";

	public static final String P_CHOICE = "choicePreference";

	public static final String P_STRING = "stringPreference";*/

}

Next up is the PreferenceInitializer.java This file is used to initialize the fields in the preference page with default values.

package testplugin.preferences;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;

import testplugin.Activator;

/**
 * Class used to initialize default preference values.
 */
public class PreferenceInitializer extends AbstractPreferenceInitializer {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
	 */
	public void initializeDefaultPreferences() {
		//We leave this empty for now.
		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
		
		//We commented these out in PreferenceConstants.java
		/*store.setDefault(PreferenceConstants.P_BOOLEAN, true);
		store.setDefault(PreferenceConstants.P_CHOICE, "choice2");
		store.setDefault(PreferenceConstants.P_STRING,
				"Default value");*/
	}

}

Next up is the SamplePreferencePage.java If you named this something else in the wizard, the file will have the same name.
We only modify the function createFieldEditors

	public void createFieldEditors() {
		addField(new DirectoryFieldEditor(PreferenceConstants.P_PATH, 
				"&Directory preference:", getFieldEditorParent()));
/*		addField(
			new BooleanFieldEditor(
				PreferenceConstants.P_BOOLEAN,
				"&An example of a boolean preference",
				getFieldEditorParent()));

		addField(new RadioGroupFieldEditor(
				PreferenceConstants.P_CHOICE,
			"An example of a multiple-choice preference",
			1,
			new String[][] { { "&Choice 1", "choice1" }, {
				"C&hoice 2", "choice2" }
		}, getFieldEditorParent()));
		addField(
			new StringFieldEditor(PreferenceConstants.P_STRING, "A &text preference:", getFieldEditorParent()));*/
	}

Now we are ready to export the plugin as a jar file.
Select the project in the package explorer and then goto File-Export.
This will bring up:
Export to jar

Select Jar file and then next.
Next step is to define the JAR File Specification details:
JAR File Specification

Leave it with default values and press next to get to the packaging options.
JAR Packaging Options

Next screen is the JAR Manifest Specifiction.
JARManifest
Select Use Existing Manifest From Workspace, and press the Browse button.
Then expand your project in the Manifest Selection dialog.
In the META-INF directory select the MANIFEST.MF
ManifestSelection

Find the jar file and copy it to the eclipse plugins folder, then restart eclipse, select Window-Preferences. Look for your page there 🙂

Resources:

3 Responses to “Building a PureMvc Multicore eclipse plugin, Creating a preference page.”

  1. Just a question what theme do you use? Is it a expensive template? Did you hire a freelancer to make this? I like that design. My web log is http://www.wordpressrobot.com/

  2. Sander said

    Nice post. Interesting to see where this is going.

Leave a comment