arcgissamples\geodatabase\classextension\RelatedObjectEventHandler.java—ArcObjects 10.4 Help for Java | ArcGIS for Desktop
Related Object Event Handler custom Java class extension
arcgissamples\geodatabase\classextension\RelatedObjectEventHandler.java
/* Copyright 2015 ESRI
* 
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
* 
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* 
* See the use restrictions at <your ArcGIS install location>/DeveloperKit10.4/userestrictions.txt.
* 
*/
package arcgissamples.geodatabase.classextension;

import java.io.IOException;

import com.esri.arcgis.geodatabase.*;
import com.esri.arcgis.geometry.ILine;
import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.interop.extn.ArcGISCategories;
import com.esri.arcgis.interop.extn.ArcGISExtension;
import com.esri.arcgis.system.*;

/**
 * 
 * A class extension that listens to relationship class messages to provide a variation
 * on the behavior of a composite relationship class. Designed to be applied to a feature
 * class of transformers that participates in a relationship class with a feature class
 * of utility poles, this extension ensures that the transformers will be moved or rotated
 * whenever a related pole is moved or rotated, but cascaded deletion (as it occurs in
 * a composite relationship class) is excluded.
 * 
 * For this extension to work properly, the poles-transformers relationship class used must
 * have (at a minimum) messaging enabled from the poles class to the transformers class, and
 * it is assumed that the relationship class is named "POLES_XFORMERS".
 */
@ArcGISExtension(categories = { ArcGISCategories.GeoObjectClassExtensions })
public class RelatedObjectEventHandler implements IClassExtension, IObjectClassExtension, IFeatureClassExtension,
  IConfirmSendRelatedObjectEvents, IRelatedObjectClassEvents2
{
  private static final long serialVersionUID = -710303671934006089L;
  
  /**
   * The name of the relationship class that the custom behavior applies to.
   */
  private final String REL_CLASS_NAME = "POLES_XFORMERS"; 
  
  /************************************************************************************************
   * IClassExtension members
   ************************************************************************************************/
  /**
   * Initializes the extension, passing in a reference to its class helper and its extension properties.
   */  
  public void init(IClassHelper classHelper, IPropertySet extensionProperties)
  {
      //get indexes for all fields here.
  }
  
  /**
   * Called when the extension's class is being disposed of from memory.
   */
  public void shutdown()
  {
  }
  
  /************************************************************************************************
   * IRelatedObjectClassEvents2 members - 
   * This is an optional interface used to receive messages when features in related feature classes 
   * that are related to the Feature Class are rotated, moved or changed and handle such events. So, this is used 
   * mainly in conjunction with Relationship classes.
   ************************************************************************************************/
  /**
   * Called when one or more poles are moved.
   */  
  public void relatedObjectSetMoved(IRelationshipClass relationshipClass, ISet relatedObjects,
    ISet movedObjects, ILine moveVector) throws IOException, AutomationException
  {      
    // Get the first related object.
    relatedObjects.reset();
    //IFeatureEdit featureEdit = new IFeatureEditProxy(relatedObjects.next());
    Feature feature = (Feature) relatedObjects.next();
    
    // Move the set of related objects.
    relatedObjects.reset();
    feature.moveSet(relatedObjects, moveVector);
  }

  /**
   * Called when one or more poles are rotated.
   */
  public void relatedObjectSetRotated(IRelationshipClass relationshipClass, ISet relatedObjects,
    ISet movedObjects, IPoint origin, double rotationAngle) throws IOException, AutomationException
  {
    // Get the first related object.
    relatedObjects.reset();
    Feature feature = (Feature) relatedObjects.next();
    
    // Rotate the set of related objects.
    relatedObjects.reset();
    feature.rotateSet(relatedObjects, origin, rotationAngle);
  }
  
  /**
   * Called when the geometry or attributes of a pole are changed.
   */
  public void relatedObjectChanged(IRelationshipClass relationshipClass, IObject changedObject, IObject relatedObject)
    throws IOException, AutomationException
  {

  }

  /**
   * This method is currently reserved and is not called.
   */
  public void relatedObjectMoved(IRelationshipClass relationshipClass, IObject changedObject, ILine moveVector, IObject relatedObject)
    throws IOException, AutomationException
  {

  }

  /**
   * This method is currently reserved and is not called.
   */
  public void relatedObjectRotated(IRelationshipClass relationshipClass, IObject changedObject,
    IPoint origin, double rotationAngle, IObject relatedObject) throws IOException, AutomationException
  {

  }

  /************************************************************************************************
   * IConfirmSendRelatedObjectEvents members
   ************************************************************************************************/
  /**
   * Called when one or more poles are moved to determine whether further events should occur.
   */  
  public boolean confirmSendRelatedObjectSetMoved(IRelationshipClass relationshipClass,
    ISet movedObjects, ILine moveVector) throws IOException, AutomationException
  {
    // Get the relationship class name.
    IDataset dataset = new IDatasetProxy(relationshipClass);
    String datasetName = dataset.getName();
    return datasetName.equalsIgnoreCase(REL_CLASS_NAME);
  }

  /**
   * Called when one or more poles are rotated to determine whether further events should occur.
   */  
  public boolean confirmSendRelatedObjectSetRotated(IRelationshipClass relationshipClass,
    ISet movedObjects, IPoint origin, double rotationAngle) throws IOException, AutomationException
  {
    // Get the relationship class name.
    IDataset dataset = new IDatasetProxy(relationshipClass);
    String datasetName = dataset.getName();
    return datasetName.equalsIgnoreCase(REL_CLASS_NAME);
  }

  /**
   * Called when the geometry or attributes of a pole are changed to determine whether further events should occur.
   */
  public boolean confirmSendRelatedObjectChanged(IRelationshipClass relationshipClass, IObject changedObject)
    throws IOException, AutomationException
  {
      return false;
  }

  /**
   * This method is currently reserved and is not called.
   */
  public boolean confirmSendRelatedObjectMoved(IRelationshipClass relationshipClass, IObject changedObject, ILine moveVector)
    throws IOException, AutomationException
  {
    return false;
  }

  /**
   * This method is currently reserved and is not called.
   */
  public boolean confirmSendRelatedObjectRotated(IRelationshipClass relationshipClass, IObject changedObject,
    IPoint origin, double rotationAngle) throws IOException, AutomationException
  {
    return false;
  }
}