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
-
Go to
JUnit module
-
Open the contextual menu and select:
Modelio Studio –>
Create element –>
Property Page
-
In the "Create a Property page" dialog box, fill in the field with the following:
-
Enter ‘JUnit’ as label
-
Enter ‘JUnitPropertyPage’ as Id
-
Enter ‘JUnitPropertyPage’ for the Java class
-
In the "Available commands" list, select the "Create a test case" command
-
Add it to the toolbar using the
righ arrow button.
-
The "Create a test case" command will appear under the toolbar container.
-
Click on OK
The "Property page" container has been created in:
JUnit /
gui /
views /
JUnitPropertyPage
If you expand JUnitPropertyPage, you’ll see a dependency link to
JUnitPropertyPage class.
(CTRL + ALT + left-clic on the dependency to select the target element)
Coding the property page behavior
-
Go to
JUnit /
implementation /
java /
org.sample.junit /
handlers /
propertypage /
JUnitPropertyPage
-
Click on the
Generate command, and then on the
Edit command to edit the generated JUnitPropertyPage.java source.
-
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;
}
}
}
}