You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 AbstractModulePropertyPage and redefines appropriate operations.
Property page declaration
A property page is declared within the gui section of the module.xml file.
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 24x24px image that will be displayed on the gui. It should be stored in resources/… 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.
Coding the property page behavior
Go to org.modelio.junit package
Create a new package named: propertypage
Under the propertypage package, create a new class named: JUnitPropertyPage
1package org.modelio.junit.propertypage;
2
3import java.util.List;
4import org.modelio.api.module.IModule;
5import org.modelio.api.module.propertiesPage.AbstractModulePropertyPage;
6import org.modelio.api.module.propertiesPage.IModulePropertyTable;
7import org.modelio.metamodel.uml.infrastructure.ModelElement;
8import org.modelio.vcore.smkernel.mapi.MObject;
9
10
11public class JUnitPropertyPage extends AbstractModulePropertyPage {
12
13 public JUnitPropertyPage(IModule module, String name, String label, String bitmap) {
14 super(module, name, label, bitmap);
15 }
16
17 /**
18 * This method is called when the current selection
19 * changes and that the property box contents requires
20 * an update.
21 * In this example, simply add one property (the Name of
22 * the currently selected element)
23 */
24
25 @Override
26 public void update(List<MObject> elements, IModulePropertyTable table) {
27 if (elements.size() == 1 && elements.get(0) instanceof ModelElement) {
28 ModelElement modelElement = ((ModelElement)elements.get(0));
29 table.addProperty ("Name", modelElement.getName());
30 }
31 }
32
33 /**
34 * This method is called when a value has been edited
35 * in the property box in the row.
36 * Here we simply have to update the currently selected
37 * element name.
38 * Note: One transaction is already open. So it is not
39 * necessary to create another one.
40 */
41
42 @Override
43 public void changeProperty(List<MObject> elements, int row, String value) {
44 if (elements.size() == 1 && elements.get(0) instanceof ModelElement) {
45 ModelElement modelElement = ((ModelElement)elements.get(0));
46 switch (row) {
47 case 1: // First line is row == 1
48 modelElement.setName (value);
49 break;
50 }
51 }
52 }
53}