How to listen to edit events


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

In this topic

 

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.OnStartEditingevent will be raised by using the out of the box ControlsEditingStartCommandor whenIEngineEditor.StartEditingis called.
 
In order 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're interested in.

Steps to listen to IEngineEditEvents

In the following example a listener is created to determine when an editing session has started. 
[Java]
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, and you should hold a reference to it in an instance or a class variable to prevent it from being destroyed during garbage collection. This holds true for other arcobject singletons too.

Event order

One editing command or method may fire a number of specific IEngineEditEvents. For example:
 
(1) The OnStartEditing, OnSelectionChanged and then OnSketchModified events are fired when the IEngineEditor.StartEditing method is called or when a user executes the ControlsEditingStartCommand.
(2) The OnSketchModifiedOnAfterDrawSketch and then OnCurrentTaskChanged events are fired when the IEngineEditor.CurrentTask method is called or when a user a user selects a new edit task from the ControlsEditingTaskToolControl.
(3) The OnTargetLayerChanged and then 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 operationstack
Sample: Edit Events Life Cycle




Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo