Now, let’s 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

Create the Property page

  1. Go to Junit dev module property page studio16 JUnit module

  2. Open the contextual menu and select:
    Junit dev module property page studio16 Modelio Studio –> Junit dev module property page createmenu16 Create element –> Junit dev module property page propertypage16 Property Page

  3. In the "Create a Property page" dialog box, fill in the field with the following:

  4. Enter ‘JUnit’ as label

  5. Enter ‘JUnitPropertyPage’ as Id

  6. Enter ‘JUnitPropertyPage’ for the Java class

  7. In the "Available commands" list, select the "Create a test case" command

  8. Add it to the toolbar using the Junit dev module property page right arrow righ arrow button.

  9. The "Create a test case" command will appear under the toolbar container.
    Junit dev module property page CreateJUnitPropertyPage dlg

  10. Click on OK

The "Property page" container has been created in:
Junit dev module property page studio16 JUnit / Junit dev module property page interfacecontainer16 gui / Junit dev module property page viewcontainer16 views / Junit dev module property page propertypage16 JUnitPropertyPage

If you expand Junit dev module property page propertypage16 JUnitPropertyPage, you’ll see a dependency link to Junit dev module property page JavaClass JUnitPropertyPage class.
(CTRL + ALT + left-clic on the dependency to select the target element)

Coding the property page behavior

  1. Go to Junit dev module property page studio16 JUnit / Junit dev module property page implementationcontainer16 implementation / Junit dev module property page JavaComponent java / Junit dev module property page JavaPackage org.sample.junit / Junit dev module property page JavaPackage handlers / Junit dev module property page JavaPackage propertypage / Junit dev module property page JavaClass JUnitPropertyPage

  2. Click on the Junit dev module property page generate Generate command, and then on the Junit dev module property page edit Edit command to edit the generated JUnitPropertyPage.java source.

  3. Complete the update and changeProperty methods with the following content:
    (JUnitPropertyPage.java source file)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.sample.junit.handlers.propertypage;

import java.util.List;
import com.modeliosoft.modelio.javadesigner.annotations.objid;
import org.modelio.api.module.IModule;
import org.modelio.api.module.propertiesPage.AbstractModulePropertyPage;
import org.modelio.api.module.propertiesPage.IModulePropertyTable;
import org.modelio.metamodel.uml.infrastructure.ModelElement;
import org.modelio.vcore.smkernel.mapi.MObject;


public class JUnitPropertyPage extends AbstractModulePropertyPage {

    public JUnitPropertyPage(IModule module, String name, String label, String bitmap) {
        super(module, name, label, bitmap);
    }

    /**
     * This method is called when the current selection
     * changes and that the property box contents requires
     * an update.
     * In this example, simply add one property (the Name of
     * the currently selected element)
     */

    @Override
    public void update(List<MObject> elements, IModulePropertyTable table) {
        if (elements.size() == 1 && elements.get(0) instanceof ModelElement) {
            ModelElement modelElement = ((ModelElement)elements.get(0));
            table.addProperty ("Name", modelElement.getName());
        }
    }

    /**
     * This method is called when a value has been edited
     * in the property box in the row.
     * Here we simply have to update the currently selected
     * element name.
     * Note: One transaction is already open. So it is not
     * necessary to create another one.
     */

    @Override
    public void changeProperty(List<MObject> elements, int row, String value) {
        if (elements.size() == 1 && elements.get(0) instanceof ModelElement) {
            ModelElement modelElement = ((ModelElement)elements.get(0));
            switch (row) {
            case 1: // First line is row == 1
                modelElement.setName (value);
                break;
            }
        }
    }
}

<< Catching modeling events

Index

Packaging the module >>