Skip to main content

Display a model in the editor

This explains how to display a model in the main editor and sub editor.

Display in the main editor

Change the model navigator selection as follows:

public void ShowInEditor(ICommandContext c, ICommandParams p) 
{
//Get the model to display in the editor
IModel model = ...;

//Activate and select the model navigator
IEditorPage editorPage = c.App.Window.EditorPage;
editorPage.ActiveNavigator = "Model";
editorPage.CurrentNavigator.Select(model);

//To further switch view definitions, use the following
var viewDefinitionName = "Detail"; //Example of view definition named "Detail"
IEditorDef viewDef = model.OwnerProject.Profile.ViewDefinitions.Editors.FirstOrDefault(e => e.ModelClass.Id == model.Metaclass.Id && e.Name == viewDefinitionName);
editorPage.MainEditorView.SelectViewDefinition(viewDef);
}
info

The above sample code uses the following APIs, which have been experimentally implemented.

  • IEditorDef.Name property

These APIs are not guaranteed to be of high quality and are not listed in the API specifications. Use them at your own risk.

Display in a subeditor

To display a specific model in a subeditor, display the subeditor and then specify the model in Manual mode.

public void ShowInSubEditor(ICommandContext c, ICommandParams p) 
{
//Get the model to display in the subeditor
IModel model = ...;

//Show the subeditor
IEditorPage editorPage = c.App.Window.EditorPage;
editorPage.IsSubEditorVisible = true;
//Switch to manual subeditor mode and specify the model to display
editorPage.SetSubEditorMode(SubEditorMode.Manual, model);
}

Reference: Extension method

It is useful to prepare this as an extension method like the following.

IEditorPageExtension.cs
public static class IEditorPageExtension 
{
///<summary>
///Display the model in the main editor.
///</summary>
///<param name="self">Editor page. </param>
///<param name="model">The model to display in the main editor. </param>
///<param name="viewDefinitionName">The name of the view definition to display. </param>
public static void SelectMainEditorView(this IEditorPage self, IModel model, string viewDefinitionName = null)
{
//Activate the model navigator
self.ActiveNavigator = "Model";

//Select a model
self.CurrentNavigator.Select(model);

//Select a view definition
if (!string.IsNullOrEmpty(viewDefinitionName))
{
var viewDef = model.OwnerProject.Profile.ViewDefinitions.Editors.FirstOrDefault(e => e.ModelClass.Id == model.Metaclass.Id && e.Name == viewDefinitionName);
self.MainEditorView.SelectViewDefinition(viewDef);
}
}

///<summary>
///Display the model in the subeditor.
///</summary>
///<param name="self">The editor page. </param>
///<param name="model">The model to display in the subeditor. </param>
///<param name="viewDefinitionName">The view definition name to display. </param>
public static void SelectSubEditorView(this IEditorPage self, IModel model, string viewDefinitionName = null)
{
self.IsSubEditorVisible = true;
self.SetSubEditorMode(SubEditorMode.Manual, model);

//Select the view definition
if (!string.IsNullOrEmpty(viewDefinitionName))
{
var viewDef = model.OwnerProject.Profile.ViewDefinitions.Editors.FirstOrDefault(e => e.ModelClass.Id == model.Metaclass.Id && e.Name == viewDefinitionName);
self.SubEditorView.SelectViewDefinition(viewDef);
}
}
}
info

The above sample code uses the following API, which has been experimentally implemented.

  • IEditorDef.Name property

These APIs are not guaranteed to be of high quality and are not listed in the API specifications. Use them at your own risk.

You can operate them intuitively as follows.

Example of use

public void SomeCommand(ICommandContext c, ICommandParams p)

{
IModel model = ...;
IEditorPage editorPage = c.App.Window.EditorPage;

//Select in the main editor
editorPage.SelectMainEditorView(model);

//Display the "Diagram" view in the subeditor
editorPage.SelectSubEditorView(model, "Diagram");

}