In this section, you will learn how programmatically veto events.
To veto an event means a listener is able to stop or cancel an event or rather the action
which created it. A special listener interface VetoableGraphListener
defines an object that is able to receive graph events and subsequently call a veto.
In order to veto an event, a veto listener must throw a new instance of class
GraphEventVetoException. A VetoableGraphListener
implementation should never process an event like a normal GraphListener
does.
Example 8.2. Event Veto Source Listing
void registerVetoListeners()
{
// register for graph model events
graphModel.addVetoableGraphListener(new VetoableGraphListener()
{
public void vetoableNodePreRemove(GraphEvent graphevent)
throws GraphEventVetoException
{
logger.logVetoableGraphListener(graphevent);
// now give it a veto
throw new GraphEventVetoException(
"Event work off stopped", graphevent);
}
public void vetoableEdgePreRemove(GraphEvent graphevent)
throws GraphEventVetoException
{
logger.logVetoableGraphListener(graphevent);
}
public void vetoableEdgePreSplit(GraphEvent graphevent)
throws GraphEventVetoException
{
logger.logVetoableGraphListener(graphevent);
}
public void vetoableNodePreAdd(GraphEvent graphevent)
throws GraphEventVetoException
{
logger.logVetoableGraphListener(graphevent);
}
public void vetoableEdgePreAdd(GraphEvent graphevent)
throws GraphEventVetoException
{
logger.logVetoableGraphListener(graphevent);
}
public void vetoableNodePreDeleteEdgeCascade(GraphEvent graphevent)
throws GraphEventVetoException
{
logger.logVetoableGraphListener(graphevent);
}
});
// it's the same for the view ...
}
The above implementation of a new VetoableGraphListener instance
shows the various methods that can throw a veto exception, thereby canceling the atomic
operation taking place in the model.
Since there are also some atomic operations that can be made upon the graph view
you can find a corresponding interface called
VetoableVisualGraphListener. An implementation of this
interface is registered at a VisualGraphView. It should
work in the same way as the model counterpart does except the it throws a
VisualGraphEventVetoException.
© 2004, 2005 Tensegrity Software GmbH