Event subscription
Extension points are defined in the extension's OnActivate
method, just like the ribbon.
You can define a subscription for an event by accessing the Events
property of the ExtensionPoints
property.
Overview of events you can subscribe to
ExtensionPoints is a codebase implementation of manifest event subscriptions. See Manifest File Events for events that you can subscribe to.
Implementation of event subscription
public class SampleExtensionEntryPoint: ExtensionBase
{
///<summary>
///This is the process at the time of activation.
///</summary>
protected override void OnActivate ()
{
//event
ExtensionPoints.Events.Application.RegisterOnAfterStart <ApplicationAfterStartEvent> ();
}
}
Subscribed events are processed by implementing the OnHandle
method in the event handler class derived from the base class.
///<summary>
///Application execution event
///</summary>
public class ApplicationAfterStartEvent: ApplicationAfterStartEventHandlerBase
{
///<summary>
///Event handler processing.
///</summary>
///<param name = "c"> </param>
///<param name = "p"> </param>
protected override void OnHandle (IEventContext c, AfterStartEventParams p)
{
//Implement event handling.
Output.WriteLine (ExtensionName, $ "Events: ApplicationAfterStart Event. Version: {App.Version}");
}
}
Events you can subscribe to
Application
You can subscribe to events before the application starts and ends.
//event
ExtensionPoints.Events.Application.RegisterOnAfterStart <ApplicationAfterStartEvent> ();
ExtensionPoints.Events.Application.RegisterOnBeforeQuit <ApplicationBeforeQuitEvent> ();
Project
You can subscribe to events such as creating, opening, and saving projects.
ExtensionPoints.Events.Project.RegisterOnAfterNew <ApplicationAfterStartEvent> ();
ExtensionPoints.Events.Project.RegisterOnBeforeOpen <ProjectBeforeOpenEvent> ();
ExtensionPoints.Events.Project.RegisterOnAfterOpen <ProjectAfterOpenEvent> ();
ExtensionPoints.Events.Project.RegisterOnBeforeOpen <ProjectBeforeSaveEvent> ();
//...
Model
You can subscribe to events related to model creation and editing. The AddModelEvent
method specifies the class to subscribe to the event, and theRegisterOn ...
method specifies the model editing event to subscribe to.
//Add post-modeling events to the "SoftwareComponent" metamodel
ExtensionPoints.Events.AddModelEvent ("SoftwareComponent"). RegisterOnAfterNew <SoftwareComponentAfterNewEvent> ();
Use the following method to subscribe to the event.
- RegisterOnBeforeNew
- RegisterOnAfterNew
- RegisterOnAfterNewRelation
- RegisterOnModelEdited
- RegisterOnFieldChanged
- RegisterOnBeforeDelete
- Such
The event handler is implemented by deriving from the base class provided as follows.
public class SoftwareComponentAfterNewEvent: ModelsAfterNewEventHandlerBase
{
protected override void OnHandle (IEventContext c, ModelAfterNewEventParams p)
{
Output.WriteLine (ExtensionName, $ "SoftwareComponent created.");
}
}
You can specify multiple class names separated by commas.
ExtensionPoints.Events.AddModelEvent ("Actor, UseCase, UseCaseStep"). RegisterOnAfterNew <UseCaseModelAfterNewEvent> ();
If you omit the metamodel name, you will subscribe to the event for all models. This has the same meaning as *
in the manifest file.
ExtensionPoints.Events.AddModelEvent (). RegisterOnAfterNew <ModelAfterNewEvent> ();
Command
Subscribe to events before and after executing the Next Design command.
//For the command registered in the extension
ExtensionPoints.Events.AddCommandEvent ("MyExtensionCommand"). RegisterOnAfterExecute <MyExtensionCommandsAfterExecuteEvent> ();
//For system commands
ExtensionPoints.Events.AddCommandEvent (NextDesignAppCommands.Home_CheckError) .RegisterOnBeforeExecute <CheckErrorCommandBeforeExecuteEvent> ();
The event handler implements the derived class as follows:
public class CheckErrorCommandBeforeExecuteEvent: CommandsBeforeExecuteEventHandlerBase
{
protected override void OnHandle (IEventContext c, BeforeExecuteEventParams p)
{
//...
}
}
Page
You can subscribe to events before and after page changes.
ExtensionPoints.Events.Pages.RegisterOnBeforeChange <PagesBeforeChangeEvent> ();
ExtensionPoints.Events.Pages.RegisterOnAfterChange <PagesAfterChangeEvent> ();
The event handler implements the derived class as follows:
public class PagesBeforeChangeEvent: PagesBeforeChangeEventHandlerBase
{
protected override void OnHandle (IEventContext c, PageBeforeChangeEventParams p)
{
//...
}
}
public class PagesAfterChangeEvent: PagesAfterChangeEventHandlerBase
{
protected override void OnHandle (IEventContext c, PageAfterChangeEventParams p)
{
//...
}
}
Navigator
You can subscribe to change events in the navigator. Register the event handler with the AddNavigatorEvent
method.
ExtensionPoints.Events.AddNavigatorEvent (). RegisterOnShow <NavigatorShowEvent> ();
The event handler implements the derived class as follows:
public class NavigatorShowEvent: NavigatorsShowEventHandlerBase
{
protected override void OnHandle (IEventContext c, NavigatorOnShowEventParams p)
{
Output.WriteLine (ExtensionName, $ "Navigator: {p.TargetNavigatorName}");
}
}
To specify the type of navigator to subscribe to, specify the navigator type in the EventTargetNavigatorType
enumeration as follows.
//Subscribe to the model navigator display event
ExtensionPoints.Events.AddNavigatorEvent (EventTargetNavigatorType.Model) .RegisterOnShow <NavigatorShowEvent> ();
Editor
You can subscribe to the editor view and selection events.
ExtensionPoints.Events.AddEditorEvent (). RegisterOnShow <EditorShowEvent> ();
If you want to subscribe to the event only for a specific view definition, specify the view definition name as follows:
ExtensionPoints.Events.AddEditorEvent ("MyViewDefenition"). RegisterOnShow <MyViewDefenitionEditorShowEvent> ();
You can also subscribe to model selection change events in the editor.
ExtensionPoints.Events.AddEditorEvent ("MyViewDefenition"). RegisterOnSelectionChanged <EditorsSelectionChangedEvent> ();
Information window
You can show/hide the information window, change the selection, and subscribe to double-clicking. The subscription has the following methods.
- RegisterOnShow
- RegisterOnHide
- RegisterOnSelectionChanged
- RegisterOnDoubleClick
ExtensionPoints.Events.AddInformationEvent (EventTargetInformationAreaType.Error) .RegisterOnDoubleClick <ErrorDoubleClickEvent> ();
The event handler implements the derived class as follows:
public class ErrorDoubleClickEvent: InformationsDoubleClickEventHandlerBase
{
protected override void OnHandle (IEventContext c, InformationOnDoubleClickEventParams p)
{
Output.WriteLine (ExtensionName, $ "Model: {p.Model.Name}");
//Prevent standard double-click behavior
p.Consume ();
}
}
Event handler definition
To define event handlers for subscribed events, see Implement event handlers.