skip to main content
Diagrammer > Programmer's documentation > Developing with the JViews Diagrammer SDK > Using and writing interactors > Subclassing view interactors
 
Subclassing view interactors
You can subclass the IlvMakeSDMNodeInteractor and the IlvMakeSDMLinkInteractor to control when a link is created between two nodes, or to perform custom actions when links or nodes are created.
For example, to create a link only between certain types of node, you can subclass IlvMakeSDMLinkInteractor and override the acceptOrigin and acceptDestination methods, see the following code example:
Subclassing the IlvMakeSDMLinkInteractor
 
public class ValidatingLinkInteractor extends IlvMakeSDMLinkInteractor
{
 
  protected boolean acceptOrigin(IlvPoint p, IlvGraphic fromNode) {
    Object o = getEngine().getObject(fromNode);
    if("false".equals(getEngine().getModel().getObjectProperty(o, "okForOrigin")))
      return false;
      return super.acceptOrigin(p, fromNode);
  }
 
  protected boolean acceptDestination(IlvPoint p, IlvGraphic toNode) {
    Object o = getEngine().getObject(toNode);
    if("false".equals(getEngine().getModel().getObjectProperty(o, "okForDestination")))
      return false;
      return super.acceptDestination(p, toNode);
  }
}
In this example, a node whose property "okForOrigin" is false is not accepted as the origin of a link, and a node whose property "okForDestination" is false is not accepted as the destination of a link.
You can also set custom properties when a node or a link is created by overriding setNodeProperties or setLinkProperties. For example, to prompt the user for the "name" property of a node as it is created, you can subclass IlvMakeSDMNodeInteractor and override setNodePorperties as follows:
Subclassing the IlvMakeSDMNodeInteractor
 
public class PromptingNodeInteractor extends IlvMakeSDMNodeInteractor
{
  protected void setNodeProperties(IlvSDMModel model, Object node) {
    String label = JOptionPane.showInputDialog(getManagerView(), "Name:");
    if(label != null)
    model.setObjectProperty(node, "name", label);
  }
}

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.