Step 3: Editing overview

Intro

With the EMF-based datamodel we have just created, we can already load and save scenario files using Microsoft Excel format.

For bigger scenarios, Excel and other table processing apps come in handy helping to mass-process the initial scenario data, do data search-and-replace operations, filtering, etc.

However, during the model development and debugging stage, smaller scenarios are more common. It would be more convenient to be able to quickly edit such a scenario right from within the application, than to switch back and forth between the application and an external file editing tool.

In this step we will see how editing works in the application. In the next step we will enhance this editing logic.

Scenario tree

Start the application and create a new scenario via the 'File' → 'New' menu item.

The application is in the 'EDITOR' mode, and it displays the scenario contents in the 'Scenario structure' part:

Scenario structure tree

All tree items are enumerated in the The TreeElementType enum located in the located in the …​application.utils package.

Initially this enum contains four items: SCENARIO (for the root scenario tree item), ARC, NODE, and NETWORK (this last one is for the tree item that acts as a parent for 'Arcs' and 'Nodes' items).

Scenario tree structure is defined by the classes located in package …​parts.editor.treeelements that inherit from the TreeElement class. The root tree item is described by the TreeElementScenario class. Its createChildElements() method now returns one item of class TreeElementNetwork (displays the 'Transport network' item), which, in turn, has two child elements: one for nodes and one for arcs (see the createChildElements() method in the TreeElementNetwork class).

When we add new nodes and arcs, their number is updated in the scenario tree. This behavior is enabled in the TreePart.initializeDependentScenarioListFields() method.

Objects table

Most scenario tree items represent a group of objects of the same kind. Initially, there are 'Nodes' or the 'Arcs' tree items. When you click such a tree item, a table is displayed where you can see all the objects of the selected type:

List of nodes

How does the program know what to display in the table?

ObjectsPart class

Find the ObjectsPart class in the …​application.parts.editor package. Its registerPages() method contains all the tables that are shown for the items selected in the scenario tree.

Initially, two tables are registered: for Arcs and for Nodes. Table structure is completely described here, along with the editing capabilities that are available from the object table directly.

Object properties part

Scenario properties

When clicked, the root tree item, 'Scenario', shows the scenario properties in the 'Properties' part:

Scenario properties page

This works as follows:

  1. A ScenarioPage class ( …​application.pages package) is created that contains the property page settings: how to display end edit fields, etc. Its isVisible() method defines when this page should be visible: only if the selected object has the type Scenario.

  2. In the PropertiesPart class ( …​application.parts.editor package), in the registerPages() method, a new ScenarioPage object is registered.

  3. Each time a scenario tree item (such as the root item, or any other tree item) is selected, the TreePart issues a message that contains the selected tree element as its body.

  4. When such a message is sent, it is processed by the PropertiesPart instance: the appropriate property page becomes visible and receives the object to show its properties.

Arc and Node properties

When you select a node or an arc in the respective table, its properties are displayed in the 'Properties' part.

The internal mechanics here is almost the same: ArcPage and NodePage classes are created and registered in the PropertiesPart.registerPages() method; PropertiesPart processes the 'arc/node has been selected' messages.

The only difference is the source of the message that some object is selected: now it is emitted by the objects table. This is set up in the ObjectsPart class (…​application.parts.editor package) that we discussed earlier. In its registerPages() method, an object table is registered for each scenario tree item type (except the root one). When some table row is selected, a message is emitted that contains the object that is represented by the selected table row; this message is caught by the PropertiesPart, and you already know the rest.

Mind the difference:

  • PropertiesPart.registerPages() is for property pages, i.e., pages that contain properties of one object;

  • ObjectsPart.registerPages() is for tables with objects, i.e., tables that can show several objects of the same type.