Moving Inspector From the Old Config to the OpenAPI

In version 4.0 OpenAPI calls are used to build custom inspectors. This paragraph describes how to create your own page in an existing inspector or add a field to an existing page of an existing inspector. For the users of Together 3.x who used to use config files for inspector customization this chapter contains mapping of old config parameters to new OpenAPI calls.

For detailed information on inspector API follow this link.

To illustrate the material of this chapter there are two examples in the installation of Together. Take the directory modules/com/togethersoft/modules/inspector/examples. In this directory you can see two manifest (.def) files declaring the examples: Page.def and Field.def.

Inside each of those files there is a line commented out. That line looks like:

# MainClassName = <Main module class name>
Given that this line in file Page.def is uncommented, autorun() method of corresponding module will be executed upon next startup of Together. Then, after inspector is called on a class of a class diagram you will see additional page with three fields called "My page". Or/and 3 additional fields at the bottom of the existing page called "Properties". Those are the results of work of the modules that you just have enabled.

Now let's give a detailed look to how those modules work inside.

How to add fields to the existing inspector

Please see the complete sample codes with the comments:
modules/source/com/togethersoft/modules/inspector/examples/AddFieldsToInspector.java
and the complete example of corresponding config of version 3.2.

Creates a string property.
config inspector.node.element.*.Class.item.Properties.item.myStringProperty = StringField
Java property = new RwiInspectorStringProperty(rwiElements, "myStringProperty");

Sets the name to be shown in the UI.
config inspector.node.element.*.Class.item.Properties.item.myStringProperty.name = "My string property"
Java property.setName("My string property");

Creates a string property.
config inspector.node.element.*.Class.item.Properties.item.myStringProperty = StringField
Java property = new RwiInspectorStringProperty(rwiElements, "myStringProperty");

Creates a boolean property
config inspector.node.element.*.Class.item.Properties.item.myBooleanProperty = BooleanField
Java property = new RwiInspectorBooleanProperty(rwiElements, "myBooleanProperty");

Sets the name to be shown in the UI
config inspector.node.element.*.Class.item.Properties.item.myBooleanProperty.name = "My boolean property"
Java property.setName("My boolean property");

Creates a string property
config inspector.node.element.*.Class.item.Properties.item.myChoiceProperty = ComboboxField(
\ {
\ values := { "value1", "value2", "value3" }
\ }
\ )
inspector.node.element.*.Class.item.Properties.item.myChoiceProperty.name = "My choice property"
Java
property.setName("My choice property");
    SwingComboBoxEditor editor = new SwingComboBoxEditor(
        new DefaultComboBoxModel(
            new String[] {"value1", "value2", "value3"}
        )
    );
property.setPropertyEditor(editor);

Creates a string property, which will be shown, when some condition is met
config inspector.node.element.*.Class.item.Properties.item.myConditionalProperty = StringField
inspector.node.element.*.Class.item.Properties.item.myConditionalProperty.name = "My conditional property"
inspector.node.element.*.Class.item.Properties.item.myConditionalProperty.condition = hasProperty("myBooleanProperty")
Java
property = new RwiInspectorStringProperty(rwiElements, "myConditionalProperty");
property.setName("My conditional property");
Condition condition = new Condition() {
    public boolean execute(IdeContext context) {
        RwiElement[] rwiElements = RwiElementsUtil.getRwiElements(context);
        return RwiElementsUtil.checkProperty(context, "myBooleanProperty", true);
      }
    };
propertiesPage.addProperty(property, condition);

How to add page to the inspector

Please see the complete sample codes with the comments:
modules/source/com/togethersoft/modules/inspector/examples/AddPageToInspector.java
and the complete example of corresponding config of version 3.2.

Set service - class which will be used to visualize this component
config inspector.node.element.*.Class.item.My page.view.UI = treeTableNodeUI
inspector.node.element.*.Class.item.My page.view.expandLevel = all
Java page.setService(UIComponentService.class, new PropertyTableComponentUI(page));
inspector.addComponent(page, null);

Creates a string property
config inspector.node.element.*.Class.item.My page.item.myStringProperty = StringField
Java property = new RwiInspectorStringProperty(rwiElements, "myStringProperty");

sets the name to be shown in the UI
config inspector.node.element.*.Class.item.My page.item.myStringProperty.name = "My string property"
Java property.setName("My string property");

creates a boolean property
config inspector.node.element.*.Class.item.My page.item.myBooleanProperty = BooleanField
Java property = new RwiInspectorBooleanProperty(rwiElements, "myBooleanProperty");

sets the name to be shown in the UI
config inspector.node.element.*.Class.item.My page.item.myBooleanProperty.name = "My boolean property"
Java property.setName("My boolean property");
page.addProperty(property, null);

creates a string property
config
inspector.node.element.*.Class.item.My page.item.myChoiceProperty = ComboboxField(
\   {
\     values := { "value1", "value2", "value3" }
\   }
\ )
inspector.node.element.*.Class.item.My page.item.myChoiceProperty.name = "My choice property"
Java
property = new RwiInspectorStringProperty(rwiElements, "myChoiceProperty");
property.setName("My choice property");
SwingComboBoxEditor editor = new SwingComboBoxEditor(
  new DefaultComboBoxModel(
    new String[] {
      "value1", "value2", "value3"
    }
  )
);
property.setPropertyEditor(editor);
editor.setValueEditable(true);
page.addProperty(property, null);

creates a string property, which will be shown, when some condition is met
config inspector.node.element.*.Class.item.My page.item.myConditionalProperty = StringField
Java property = new RwiInspectorStringProperty(rwiElements, "myConditionalProperty");

sets the name to be shown in the UI
config inspector.node.element.*.Class.item.My page.item.myConditionalProperty.name = "My conditional property"
Java property.setName("My conditional property");

creates a Condition class
config inspector.node.element.*.Class.item.My page.item.myConditionalProperty.condition = hasProperty("myBooleanProperty")
Java
Condition condition = new Condition() {
  public boolean execute(IdeContext context) {
    RwiElement[] rwiElements = RwiElementsUtil.getRwiElements(context);
    return RwiElementsUtil.checkProperty(context, "myBooleanProperty", true);
  }
};
page.addProperty(property, condition);

Sample config

###### The one, which corresponds to "AddFieldsToInspector.java":

inspector.node.element.*.Class.item.Properties.item.myStringProperty = StringField
inspector.node.element.*.Class.item.Properties.item.myStringProperty.name = "My string property"

inspector.node.element.*.Class.item.Properties.item.myBooleanProperty = BooleanField
inspector.node.element.*.Class.item.Properties.item.myBooleanProperty.name = "My boolean property"

inspector.node.element.*.Class.item.Properties.item.myChoiceProperty = ComboboxField(
\   {
\     values := { "value1", "value2", "value3" }
\   }
\ )
inspector.node.element.*.Class.item.Properties.item.myChoiceProperty.name = "My choice property"

inspector.node.element.*.Class.item.Properties.item.myConditionalProperty = StringField
inspector.node.element.*.Class.item.Properties.item.myConditionalProperty.name = "My conditional property"
inspector.node.element.*.Class.item.Properties.item.myConditionalProperty.condition = hasProperty("myBooleanProperty")

###### The one, which corresponds to "AddPageToInspector.java":

inspector.node.element.*.Class.item.My page.view.UI = treeTableNodeUI
inspector.node.element.*.Class.item.My page.view.expandLevel = all

inspector.node.element.*.Class.item.My page.item.myStringProperty = StringField
inspector.node.element.*.Class.item.My page.item.myStringProperty.name = "My string property"

inspector.node.element.*.Class.item.My page.item.myBooleanProperty = BooleanField
inspector.node.element.*.Class.item.My page.item.myBooleanProperty.name = "My boolean property"

inspector.node.element.*.Class.item.My page.item.myChoiceProperty = ComboboxField(
\   {
\     values := { "value1", "value2", "value3" }
\   }
\ )
inspector.node.element.*.Class.item.My page.item.myChoiceProperty.name = "My choice property"

inspector.node.element.*.Class.item.My page.item.myConditionalProperty = StringField
inspector.node.element.*.Class.item.My page.item.myConditionalProperty.name = "My conditional property"
inspector.node.element.*.Class.item.My page.item.myConditionalProperty.condition = hasProperty("myBooleanProperty")