Skip to main content
Jump to: navigation, search

Difference between revisions of "Creating a new Disease Model Plug-in"

(Customizing the Disease Model Implementation Class (''your code goes here!!''))
(Final Configuration of plugin.xml)
Line 347: Line 347:
  
 
save the plugin.xml
 
save the plugin.xml
 +
 +
 +
[[Image:emf8.png|800px]]
 +
 +
'''Figure 8: Configuring the RUNTIME tab in plugin.xml ''Click twice to see high resolution screenshot.'' '''
 +
  
  
Line 532: Line 538:
  
 
Organize the plug-in using '''"Organize the Manifest Wizard"''' and configure the wizard as shown in figure 10.
 
Organize the plug-in using '''"Organize the Manifest Wizard"''' and configure the wizard as shown in figure 10.
 
 
  
 
= Plugging in Your Plug-In=
 
= Plugging in Your Plug-In=

Revision as of 20:12, 18 December 2007

Back

PreRequisites

You must first have your development environment set up and have the STEM sourcecode installed and running. Make sure you have the latest version of EMF installed.


Create a new Project For your Plug-in

> File>new>other>Eclipse Modeling Framework>Empty EMF Project

The NEW EMPTY EMF PROJECT wizard will open

enter

Project Name: org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel

click on the project

right click

Emf1.png Emf2.png

Figures 1 & 2: Creating an Empty EMF Project

Creating the Required Packages

and create four new packages:

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.impl

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.provider

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.util


Defining your Disease Model Interface

Select the package:

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel

right click, >New > Interface

Edit the Interface so your model extends the appropriate STEM build in Model (e.g., StochasticSEIRDiseaseModel) as

shown below:

import org.eclipse.ohf.stem.diseasemodels.standard.StochasticSEIRDiseaseModel;

/**

* This interface is an EMF Model.

*

* @model

*/

public interface YourDiseaseModel extends StochasticSEIRDiseaseModel {

}

NOTE: The Java doc above the interface declaration is required. This is used by the Eclipse Modeling Framework to generate code for your model.

Emf3.png

Figure 3: After Creating the Interface your Workspace will appear as shown above. Click twice to see high resolution screenshot.

Adding required Dependencies to your plug-in MANIFEST

Having now created the Interface, you will see errors (see the red indicators in figure 3) indicating that the class extended cannot be resolved.

To fix this, in the Eclipse Package Explored, open the META-INF folder and double click the

MANIFEST.MF file to open it.

Below the edit window it will probably open, by default, in the OVERVIEW view. Click on the DEPENDENCIES tab.

you will have to add several dependencies.

Click >add

select org.eclipse.core.runtime

Click >add

select org.eclipse.ohf.stem.core

Click >add

select org.eclipse.ohf.stem.definitions

Click >add

select org.eclipse.ohf.stem.diseasemodels

This last dependency assumes you are extending a build in disease model (almost certainly the case). If you are extending your own existing extension then you much also add that dependency.

hit <ctrl S> to save your changes


Emf4.png

Figure 4: Required Dependencies in Manifest.mf Click twice to see high resolution screenshot.

Generating the EMF Model

Click on your package

right click

select >new>other>Eclipse Modeling Framework>New EMF Model

in the EMF Model wizare, open the folder org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel

and select the model subfolder.

under filename type:

yourdiseasemodel.genmodel

click next

select annoted Java

click Finish


Emf5.png

Figure 5: Creating the new EMF model

Using the EMF Model to Generate Model Code

Look at the package explorer.

EMF will have generate two files in the model subfolder

yourdieasemodel.ecore

and

yourdiseasemodel.genmodel


open yourdiseasemodel.genmodel

right click

you will see a tree appear in the editor window


Emf6.png

Figure 6: yourdiseasemodel.genmodel shown in the editor window. Click twice to see high resolution screenshot.


select the top node

right click

select Generate Model Code


Note:

You should now see a file plugin.xml below the 'model' folder in the package explorer for your new EMF project.

Close the MANIFEST.MF file and open plugin.xml

notice that they now provide the same information for your plugin.


Emf7.png

Figure 7: Having generated your model code the plugin.xml file should appear in the project explorer. The generated code is shown in the editor. Click twice to see high resolution screenshot.

Customizing the Disease Model Implementation Class (your code goes here!!)

open the .impl project and edit the file

YourDiseaseModelImpl.java


Edit the class definition so instead of

  public class YourDiseaseModelImpl extends EObjectImpl implements YourDiseaseModel  {

have it extend the appropriate STEM built in model. For example,

  public class YourDiseaseModelImpl extends StochasticSEIRDiseaseModelImpl implements YourDiseaseModel {

since this is a generated class you must also change constructor the java doc from @generated to @generated NOT


/**

  • An implementation of the model object 'Your Disease Model'.
  • @generated NOT
  • /

change the constructor definition to make it Public (by default EMF makes it Protected).

since this is a generated class you must also change constructor the java doc from @generated to @generated NOT

/**

  • @generated NOT
  • /


and, if needed, add the import for the STEM built in model. e.g.,

import org.eclipse.ohf.stem.diseasemodels.standard.impl.StochasticSEIRDiseaseModelImpl;

Eventually, all of your model code will go in this implementation class by overriding superclass methods such as computeNewDiseaseState() and/or doModelSpecificAdjustments().

Editing the autogenerated genmodel file

This step ensures that the files we are about to autogenerate will go in the right place.

If it is not already open in your environment, go the the toolbar and select

>Window>show view>Other>General>Properties to open the properties view.

Select the properties view.

Once again, double click on the file yourdiseasemodel.genmodel

The .genmodel tree will appear in the editor and the .genmodel properies will appear in the properties view.

Scroll down to the +Edit section and change the Edit Directory to

/org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel/src   (removing the .edit from the path)

Scroll down to the +Editor section and change the Editor Directory to

/org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel/src   (removing the .editor from the path)

Scroll down to the +Tests section and change the Tests Directory to

/org.eclipse.ohf.stem.tests.diseasemodels.yourdiseasemodel/src   

moving the .tests. from the end of the path to just after .stem.


Using EMF to generate the rest of the required code

In the model folder double click on yourdiseasemodel.genmodel

click on the top Yourdiseasemodel node in the editor window

right click

select Generate Edit Code


right click

select Generate Editor Code


Go to the Package Explorer and DELETE the entire generated package entitled

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.presentation

this package is not needed.


Next, Open the file org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.provider.YourDiseaseModelEditPlugin

Eclipse will indicate that the Import

import org.eclipse.ohf.stem.definitions.edges.provider.DefinitionsEditPlugin;

"cannot be resolved". Remove it. hit <ctrl S> to save.

Scroll down to the method

YourdiseasemodelEditPlugin()

DefinitionsEditPlugin.INSTANCE,

will show up as "cannot be resolved". Click on DefinitionsEditPlugin, right click, and select

>source>add import to find the import. hit <ctrl S> to save.


The following steps may not be needed - need to double check this. Go to the file org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.provider.YourDiseaseModelItemProvider

Delete the method public ResourceLocator getResourceLocator()

remove the import import org.eclipse.emf.common.util.ResourceLocator;

The file should now build without errors. The Preceding steps may not be needed - need to double check this.


Final Configuration of plugin.xml

Once again, open plugin.xml file

go to the Runtime tab.

Under Exported Packages click Add

select all of the packages that appear and add them.

save the plugin.xml

On the Right hand side (see figure 8) click the Calculate Uses button.

save the plugin.xml


Emf8.png

Figure 8: Configuring the RUNTIME tab in plugin.xml Click twice to see high resolution screenshot.


Next Click on the Extensions tab

Click Add:

add the extension org.eclipse.ohf.stem.dieseasemodels.diseasemodel

(be careful NOT to select org.eclipse.ohf.stem.dieseasemodels.disease)

click save

save the plugin.xml

Still on the Extensions page click on the extension you just added and

expand it by clicking the (+).

Click on the child node (org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.DiseaseModel1)

On the RHS under Extension Element Details change the class*

to:

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.impl.YourDiseaseModelImpl

click on the child node (dublin_core)

on the RHS fill in at least the first four entries


Follow the same procedure to Add another extension for org.eclipse.emf.edit.itemProviderAdapterFactories

Click on the extension org.eclipse.emf.edit.itemProviderAdapterFactories

expand it by clicking (+)

click on factory

on the RHS change the uri to

http:///org/eclipse/ohf/stem/diseasemodels/yourdiseasemodel.ecore

(note, emf erroneously uses a '.' in the uri. we must be use '/')

under class* change the class to

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.provider.YourdiseasemodelItemProviderAdapterFactory


Next click on the extension org.eclipse.emf.edit.itemProviderAdapterFactories and move it up until the order of

the extensions, top to bottom, is

  • org.eclipse.emf.edit.itemProviderAdapterFactories
  • org.eclise.emf.ecore.generated_package
  • org.eclipse.ohf.stem.dieseasemodels.diseasemodel

Click on the extension

org.eclipse.emf.ecore.genearted_package

expand it by clicking (+)

click on the child node

on the RHS change the uri* to

"http:///org/eclipse/ohf/stem/diseasemodels/yourdiseasemodel.ecore

change the class* to

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.YourdiseasemodelPackage

make sure the genmodel* is

model/yourdieasemodel.genmodel



Adding Supported Types

This is done most easily by editing the xml itself.

click on the plugin.xml tab on the bottom of the window. This is an xml view for your

entire plugin.xml configuration.

in the node:

<extension point="org.eclipse.emf.edit.itemProviderAdapterFactories">

change the factory attribute supportedTypes to be:


<factory ... supportedTypes = "org.eclipse.emf.edit.provider.IEditingDomainItemProvider

        	 org.eclipse.emf.edit.provider.IStructuredItemContentProvider
        	 org.eclipse.emf.edit.provider.ITreeItemContentProvider
        	 org.eclipse.emf.edit.provider.IItemLabelProvider
        	 org.eclipse.emf.edit.provider.IItemPropertySource">

...

</factory>


Leave all the other attributes under factory unchanged


You should now see a total of three extensions listed.


  • org.eclipse.emf.edit.itemProviderAdapterFactories
  • org.eclise.emf.ecore.generated_package
  • org.eclipse.ohf.stem.dieseasemodels.diseasemodel


click on the Build tab

under Binary Build select icons by ckecking the check box.

save the plugin.xml

go to the Overview tab again

under General Information

Under Activator click browse and select

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.provider.YourdiseasemodelEditPlugin$Implementation

set Name: to

%pluginName

set Provider: to

%providerName

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.ohf.stem.diseasemodel
  • org.eclipse.ohf.stem.core
  • org.eclipse.ohf.stem.definitions

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 "Rexeport 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.

Bundle-Activator:

org.eclipse.ohf.stem.diseasemodels.yourdiseasemodel.provider.YourdiseasemodelEditPlugin$Implementation

Go to the Overview Tab

click on "update classpath settings"

on the RHS select:

Organize the plug-in using "Organize the Manifest Wizard" and configure the wizard as shown in figure 10.

Plugging in Your Plug-In

go to the menu bar

click >run>open run dialog

click on the Plug-ins tab

select (check) your plugin org.eclipse.ohf.stem.diseasemodes.yourdiseasemodel

Back to the top