Creating a module property page

We will now add a property page to the JUnit Module.

In this property page we will simply:

  • add the previously defined “Create a Test case” command
  • display the name of the currently selected element

Property page creation is a two steps process : a declaration in module.xml and a Java class that extends AbstractMdacPropertyPage and redefines appropriate operations.

Property page declaration

A property page is declared within the gui section of the module.xml file.

 1    <Gui>
 2    ...
 3        <Views>
 4            <PropertyPage
 5                label="%JUnitPropertyPage"
 6                image="res/icons/JUnit.png"
 7                class="org.tutosland.junitmodule.JUnitPropertyPage">
 8                <CommandRef refid="CreateTestCase"/>
 9                ...
10            </PropertyPage>
11            ...
12        </Views>
13    </Gui>

Property Page

  • label: the name of the property page as shown in Modelio gui. When this field begins with % then it is a resource label that will be retrieved in the manifest property file (module*.properties).
  • image: a 16x16px image that will be displayed on the gui. It should be stored in resources/… (see §7.4.2) but it can be empty
  • class: value is the name of the Java class that will be activaed to manage the property page. This class should extend AbstractMdacPropertyPage class to be suitable for command activation.

Associate commands with the property page

To make commands appear in the property page, add a CommandRef tag. Its refid attribute should be set as the needed command’s identifier. For more information on commands see §7.5.

Coding the property page behavior

Coding property page behavior is quite simple, only two method implementations have to be provided.

1public void update(ObList<IElement> elements, MdacPropertyTable table)

This method is called by Modelio each time the current selection changes in the tool, therefore potentially requiring an update of the property box contents.

The “elements” parameter contains the list of the newly selected elements.

The “table” parameter is the table that must be filled with the updated contents of the property box before returning.

1public void changeProperty(ObList<IElement> elements, int row, String value)

This method is called by Modelio whenever the end-user changes a value in the property box.

The “elements” parameter contains the list of the currently selected elements.

The “row” parameter is the row number of the modified value.

The “value” parameter is the new value the user has set to the given row.

Typical code in this method consists in implementing a switch on the row number, transforming the string value into the proper internal type and setting the proper attribute of the selected element(s) to the new value.

Remember that in case of model changes, a transaction is required.

Here is an example of the JUnitPropertyPage class contents, which only displays and updates the name of an element:

 1package org.tutosland.junitmodule;
 2class JUnitPropertyPage extends AbstractMdacPropertyPage
 3{
 4  // This method is called when the current selection changes and that the
 5  // property box contents requires an update.
 6  // In this example, simply add one property (the Name of the currently selected element)
 7  public void update(ObList<IElement> elements, IMdacPropertyTable table)
 8  {
 9    IModelElement modelElement = ((IModelElement)elements.get(0));
10    table.addProperty ("Name", modelElement.getName());
11  }
12  // This method is called when a value has been edited
13  // in the property box in the row
14  // Here we simply have to update the currently selected element name
15  // Note the use of a Transaction to modify the model.
16  public void changeProperty(ObList<IElement> elements, int row, String value)
17  {
18    ITransaction t = Modelio.getInstance().getModelingSession().createTransaction("Change a property");
19    for ( IElement element : elements )
20    {
21      if ( element instanceof IModelElement )
22      {
23        IModelElement modelElement = (IModelElement)element;
24        switch (row)
25        {
26          case 0: // Name
27            modelElement.setName (value);
28            break;
29        }
30      }
31    }
32    Modelio.getInstance().getModelingSession().commit(t);
33  }
34}

<< Previous Index Next >>