IMPORTANT: Be VERY careful to get the URI right here. Observe the three slashes (///). Eclipse uses the URI string in a map to retrieve adapter factories for different purposes, and a typo can be very tricky to debug later. If you are unsure, look at the java class YourDiseaseModelPackage.java and the eNS_URI variable.

click the checkbox to: "Activate this plug-in when one of its classes is loaded"

under Execution Environments (if it is not already there) click add

select J2SE1.5 (or above)

click on the dependencies tab again

order the dependencies top to bottom as follows

org.eclipse.core.runtime

org.eclipse.emf.ecore

org.eclipse.emf.ecore.edit

org.eclipse.stem.diseasemodel

org.eclipse.stem.core

org.eclipse.stem.definitions

org.eclipse.stem.populationmodels

With the single exception of the org.eclipse.core.runtime dependency, all of these should be Rexported.
If they are not (as indicated by a small black arrow), click on each one in turn, click Properties, and then
make sure that the checkbox "Re-export this dependency" is selected.

Check the classpath. To do this, open the MANIFEST.MF Tab

If it is missing, under Bundle-Verion: add a line

Bundle-ClassPath: .

make sure the bundle activator line has $Implementation at the end of it.

Plugging in Your Plug-In

Providing custom parameters for your disease model

You will most likely want to add custom parameters to your disease model. You do this by opening the ecore editor for your new model (yourdiseasemodel.ecore). Select the EMF class representing your new disease model, right click and select "New Child->EAttribute". In the Properties view, specify a name and the EType (e.g. EDouble). Make sure that your new attribute is marked 'editable' in the .genmodel. Next, regenerate the code (open the .genmodel, rightclick and select Generate All

To allow the user to enter values for your new parameter when your disease model is selected from the dropdown provided by the new disease wizard, there are a few steps you need to follow.

First, you need to create the necessary support for national language (NLS) so that the names and descriptions of your parameter are shown on the new disease model wizard. You do this by extending the generated class YourDiseaseModelAdapterFactory and implementing the PropertyStringProviderAdapterFactory as well as the IStartup interface. The easiest way to do this is to copy an existing java class and modify it. For instance, the org.eclipse.stem.ui.diseasemodels.example project has this class:

Copy this class to your existing project (IMPORTANT: This is the "editor" project generated by EMF, it has the .ui in the path):

org.eclipse.stem.ui.diseasemodels.yourdiseasemodel.

You can use the package that has already been pre-generated (org.eclipse.stem.ui.diseasemodels.yourdiseasemodel.presentation) or you can create a new (more descriptive) package.

Rename the class to e.g. YourDiseaseModelPropertyStringProviderAdapterFactory

The class won't compile. You need to add a dependency in the plugin.xml to the org.eclipse.stem.ui project. Open the plugin.xml and the Dependencies tab, click Add and select org.eclipse.stem.ui. Also add org.eclipse.stem.ui.diseasemodels to the dependencies.

Next, change the superclass to YourDiseaseModelAdapterFactory. Now change the method "createExampleDiseaseModelAdapter" to "createYourDiseaseModelAdapter" (it MUST override the superclass method)

The class still won't compile, since it needs to be provided a message class that will be used to do the translation of NLS strings for natural language support. You will notice that the class refers to a class ExampleDiseaseWizardMessages. Copy this class from the example disease model project and rename (e.g. to YourDiseaseModelWizardMessages)

Change the BUNDLE_NAME variable in this class to point to a new .properties file that will contain the NLS resources for your new disease model. For instance, set it to:

Next, create an empty text file yourdiseasemessages.properties in the package (as pointed to by the BUNDLE_NAME).

Now you need to make sure "YourDiseaseModelPropertyStringProviderAdapterFactory" is loaded when the STEM launches. This will register your new string provider (the code in the constructor ensures this) and make it available to do the translation when needed. Open the plugin.xml in your new plugin (the one with .ui in it) and select the Extensions tab. Click "Add..." and enter org.eclipse.ui.startup in the "Extension Point Filter" text box. Pick org.eclipse.ui.startup from the list and then Finish. You'll see the new Extension under in the Extensions tab. Expand org.eclipse.ui.startup and select the (startup) element underneath. On the right side, click Browse and select "YourDiseaseModelPropertyStringProviderAdapterFactory". Save the plugin. If you look at the plugin.xml in a text file, you should see something like:

Now, if you've done everything right and select your new disease model from the STEM New Disease Model wizard dropdown, you will see your new custom attribute displayed and waiting for the user to specify a value. You will also see that the name and the unit strings have exclamation marks (!) around them. This means that an attempt was made to retrieve a translated name and unit (and tooltip) for your attribute but it wasn't found. If your new attribute was named "test", you'll see the strings "!test!", "!testUNIT!" and "!testTT!" (the last one is for the tooltip). This is where you enter those 3 NLS strings in your yourdiseasemessages.properties file, e.g.:

test = Test
testUNIT = ms (or whatever the unit is for your new attribute)
testTT = Here is a more detailed description shown in the tooltip

Now that you've added the ability for the user to specify values for your new attribute, you also want to validate that such values are valid. To do this, you start by copying (and renaming) 4 files from the example disease model project:

The files won't compile. Start by editing YourDiseaseModelPropertyEditorAdapterFactory.java and change the superclass so that it is correct (YourDiseaseModelAdapter). Change the "createExampleDiseaseModelAdapter" method to "createYourDiseaseModelAdapter" and make sure it returns a new instance of YourDiseaseModelAdapter.

Next, in "YourDiseaseModelPropertyEditorAdapter", make sure the method "createDiseaseModelPropertyEditor" returns a new instance of "YourDiseaseModelPropertyEditor"

Finally, in YourDiseaseModelPropertyEditor, change the constructor to simply this:

This will reuse the superclass method for creating the actual widgets needed to enter parameter values for your disease model.

In the populate() method (which is called when it is time to create a new instance of your disease model when the user has finished with the wizard), replace the case statements with the new parameter(s) that are unique for your disease model.

In the validate() method, you add code to validate the values entered by the user for your new disease parameters.

Finally, an important step is needed. In the class YourDiseaseModelEditorPlugin.java, which is a generated class, add a new method in the Implementation inner class that will make sure your new property editor adapter is registered with the factory. This is how the method looks like:

To make sure this method is invoked when the plugin is started, check the plugin.xml and the Overview tab. For activator, YourDiseaseModelEditorPlugin$Implementation should be specified.

Make sure that the two plugins you just created are checked in the run configuration for STEM (org.eclipse.stem.diseasemodels.yourdiseasemodel and org.eclipse.stem.ui.diseasemodels.yourdiseasemodel) and you should be able to create and validate new instances of your disease model, and drag them into your custom models.