Omnis Technical Note TNID0007 June 2016

Creating a custom editor for Schema classes

for Omnis Studio 8.x or above
By Omnis Engineering

You can create custom editors for all types of classes, except system classes, using a new feature in Omnis Studio 8. The editor would be a window class created in Omnis itself which can provide additional functionality beyond that provided by the built-in editor for the class. All classes have a property called $editor which can specify the name of a library containing an alternative editor for the class, plus the $editordata property which can be used to store any additional data for the class. Existing users may note that this feature was available for object classes in previous versions but has been extended to other class types in Omnis Studio 8.

There is an example library to accompany this tech note that provides an alternative editor for schema classes. Download the library from Github: https://github.com/OmnisStudio/Omnis-CustomEditor (requires Studio 8.1.2 or above)
(or the archive myeditor.zip which requires Studio 8.x or above)

Enabling the editor property

To implement your own editor for a class, you need to “turn on” or enable the $editor property, so you can view it in the Property Manager – this property is normally hidden since this is an advanced capability not normally required by developers. To enable the $editor property you need to change a setting in the config.json file, which is located in the ‘studio’ folder in the main Omnis folder (you need to close Omnis Studio to edit this file). Open the file and find the section labelled “show_editor” under the “properties” section and set the setting to true.

"properties": {
  "show_editor": true
  }
}

The $editordata property will only appear in the Property Manager when used in conjunction with the Notation Inspector (for example, when viewing the schema class in the example library via $root.$libs.LIBRARY.$schemas in the Notation Inspector). Note that the specified editor is not used when you open a class from the find and replace results pane, in this case, the normal editor for the class opens.

Custom Schema Editor

The example library contains a schema class called sMySchema which has its $editor property set to ‘MYEDITOR’ (the name of the library), as well as a window class called wMyClassEditor which is loaded when you edit the schema class.

The startup_task of the example library adds the alternative schema editor to the Add-Ons menu using the $installtool method. When you select the schema editor from the add-on menu, Omnis calls the method $exectool() in the tool's startup task which in this case opens the custom schema editor.

Open the wMyClassEditor window class in design mode and examine its $construct() method – this receives a reference to the schema class to be edited, sets up the editor window, and loads the column information of the schema class ready to be edited. Note that the $ignoreexternal property is assigned to true so that any schema class can be edited. The editor stores additional character data in $userinfo for each column and row data in $userinfo for the class. In addition, the $editordata property is used to save the window setup using the loadWindowsetup and saveWindowsetup class methods.

The loadClass method loads the column information about the schema class, adds the userinfo column data, and the data is displayed in the custom schema editor.

Do iColumnList.$define(
      iColName,iColTypeList,iColSubTypeList,iColSubLen,iColDesc,
      iColPrimaryKey,iColNoNull,iColUserInfo,iColIdent)
Do iUserInfoList.$define(iUserInfoColName,iUserInfoColValue)
If len(iClassRef)
  Calculate iServerTableName as iClassRef.$servertablename
  Do iColumnList.$merge(
      iClassRef.$objs.$makelist($ref.$name,$cinst.$getColTypeList($ref.$coltype),
      $cinst.$getColSubTypeList($ref.$coltype,$ref.$colsubtype),$ref.$colsublen,
      pick(len($ref.$desc)>0,'',$ref.$desc),pick($ref.$primarykey=kTrue,1,2),
      pick($ref.$nonull=kTrue,1,2),$ref.$userinfo,$ref.$ident))
  Calculate lRow as iClassRef.$userinfo
  For lCount from 1 to lRow.$colcount step 1
    Do iUserInfoList.$add(lRow.[lCount].$name,lRow.[lCount])
  End For
End If

The saveClass method takes the information from the editor window and writes it back to the schema class if it has changed. The newSchema, openSchema and saveSchemaAs methods set the $editor property of the new or edited schema class so that it is always edited by the custom schema editor.

The data grid in the custom schema editor window (called SchemaColumns) has an $event method that handles the drag and drop actions used at runtime to reorder the rows in the list, as well as context menus and the column type drop lists.

You could use a similar approach to create custom editors for other class types.
  

Search Omnis Developer Resources

 

Hit enter to search

X