How to listen to edit events

This topic describes how to listen to IEngineEditEvents using the OnStartEditing event as an example.

In this topic

About listening to IEngineEditEvents

The IEngineEditEvents interface is an outbound interface on the EngineEditor singleton object that notifies listeners of editing actions. Events can be fired in response to end user interaction or program logic. For example, the IEngineEditEvents.OnStartEditing event will be raised by using the out-of-the-box ControlsEditingStartCommand or when IEngineEditor.StartEditing is called.
To listen for specific IEngineEditEvents, a listener must be registered with the EngineEditor object. This listener is notified whenever the events are fired. If you are not interested in all the events on the interface, you can subclass the corresponding Adapter class and only override the methods for the events you are interested in.

Listening to IEngineEditEvents

In the following code example, a listener is created to determine when an editing session has started. 
private EngineEditor editor;
public void someMethod()throws Exception{
    ... if (editor == null)
        editor = new EngineEditor();
    editor.addIEngineEditEventsListener(new IEngineEditEventsAdapter(){
        public void onStartEditing(IEngineEditEventsOnStartEditingEvent arg0)throws
            IOException, AutomationException{
            System.out.println("Started Editing"); 
The EngineEditor is a singleton. Hold a reference to it in an instance or a class variable to prevent it from being destroyed during garbage collection. This is also true for other ArcObjects singletons.

Event order

One editing command or method can fire a number of specific IEngineEditEvents. For example, see the following:
  1. The OnStartEditing, OnSelectionChanged, then OnSketchModified events are fired when the IEngineEditor.StartEditing method is called, or when a user executes the ControlsEditingStartCommand.
  2. The OnSketchModified, OnAfterDrawSketch and OnCurrentTaskChanged events are fired when the IEngineEditor.CurrentTask method is called, or when a user a user selects a new edit task from ControlsEditingTaskToolControl.
  3. The OnTargetLayerChanged and OnStopEditing events are fired when the IEngineEditor.StopEditing method is called, or when a user uses the ControlsEditingStopCommand.
It is important for a developer to understand the order in which events are fired so that the customized code associated with the events, is executed in the correct order.

See Also:

How to start an edit session
How to create a sketch operation
How to work with the operation stack
Sample: Edit events life cycle

Development licensingDeployment licensing
Engine Developer KitEngine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced