0

I'm struggling at finding a way to listen to Editor events in my extension add-in. What am I trying to do is: after user creates a new point feature, extension should populate an attribute of it with its Z value. So I guess my extension needs to be aware of IEditEventsOnCreateFeatureEvent dispatch, but I don't know how to handle it using ArcObjects for Java. Documentation and forums are full of suggestions using VB and C#, and for ArcGIS Engine, but no Java Extension Add-In AFAIK.

Everything I've been able to do until now is getting an IEditor reference (which is not much, I know).

0

Finally I found an answer myself. I guess it can help many other users as well.

Maybe my code is self-explanatory. Remember: it is an ArcObjects Extension Add-In code (Java). See below (with comments):

public class AutoCotar extends Extension {

private Editor m_editor; // IMPORTANT - Use Editor, not IEditor, as the latter does not
                         // have the method addIEditEventsListener!
public IMxDocument mxDoc;

@Override
public void init(IApplication app) throws IOException, AutomationException {
    mxDoc = (IMxDocument) app.getDocument();

    // Get the Editor Extension reference
    IUID extensionID = new UID();
    extensionID.setValue("esriEditor.Editor");
    IExtension editExtension = app.findExtensionByCLSID(extensionID);
    m_editor = (Editor) editExtension;

    // THE TRICK - Create a new IEditEventsAdapter and add it to m_editor
    m_editor.addIEditEventsListener(new IEditEventsAdapter(){

        private static final long serialVersionUID = 1L;

        // Now all you need to do is implement the behaviour
        // of the events you want to deal with!

        public void onCreateFeature(IEditEventsOnCreateFeatureEvent arg0) throws IOException, AutomationException {
            IFeature theFeature = (IFeature) arg0.getObj();
            int atribCota = theFeature.getFields().findField("cota");
            if(atribCota >= 0)
            {
                IGeometry theGeom = theFeature.getShape();
                theFeature.setValue(atribCota, theGeom.getEnvelope().getZMax());
                theFeature.store();

                mxDoc.getActiveView().partialRefresh(esriViewDrawPhase.esriViewGraphics, null, theFeature.getExtent());
            }
        }

        public void onChangeFeature(IEditEventsOnChangeFeatureEvent arg0) throws IOException, AutomationException {
            this.onCreateFeature(new IEditEventsOnCreateFeatureEvent(arg0.getObj()));
        }
    });
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.