Insert Event(creat a new link and undo)

When I creat a new Link in jgoView, and undo a deleted link, both of the actions produce JGoDocumentEvent.INSERTED event in the jgo_Document_changed method. I want to distinguish the two event, how to do it?
By the way, I noticed that jgoview_changed method. JGoViewEvent.linkCreated and JGoViewEvent.linkInserted are generated at the same time if I creat a link. How to distinguish a new link created and a deleted link is undone, those two event?
Thanks.
Li

You could look at JGoUndoManager.isUndoing() or isRedoing().
Note also the difference between a JGoViewEvent.LINK_CREATED and a JGoDocumentEvent.INSERTED: the former happens only because the user drew a new link (or some code called JGoView.newLink); the latter happens for all programmatic additions of a link or other object to a document.

Yes, I understand. Another question: I noticed that if I create a new link, the document.insert is called twice. I can see it from my System.out.println code, the message got printed twice.
void jGoView_documentChanged(JGoDocumentEvent evt) {
if
(evt.getHint() == JGoDocumentEvent.INSERTED) {
System.out.println"jGoView_WorkFlow_documentChanged ) :JGoDocuemnt Event inserted.");
}
}
Thanks a lot.
Li

I just tried that, and I only got a single message printed out when I as a user drew a new link.
Now there is a temporary link that is created by the view and added to the view (not to the document) as the user is drawing a new link. However adding an object to a view will not cause a document event.


I tested my program again and again, the result is still the same. when I simulate a user to draw a new link on the view,
System.out.println(“DocumentChanged, event is JGoDocumentEvent.INSERTED”);
this line gets executed multiple times, not only once, but System.out.println(“Link inserted”);
this line gets only executed once. because the if condition narrows down the insertion to labledLink insert.
when a node is inserted, the following code does get executed only once.
System.out.println(“DocumentChanged, event is JGoDocumentEvent.INSERTED”);
Thanks a lot.
my method’s snap shot is just as following:
void
jGoView_WorkFlow_documentChanged(JGoDocumentEvent evt) {
if (evt.getHint() == JGoDocumentEvent.INSERTED) {
System.out.println(“DocumentChanged, event is JGoDocumentEvent.INSERTED”);
if(evt.getJGoObject() instanceof JGoLabeledLink){
System.out.println(“Link inserted”);
}
if(evt.getJGoObject() instanceof JGoNode){
System.out.println(“Workflow node inserted.”);
}
return;
}
if(evt.getHint()== JGoDocumentEvent.REMOVED){
JGoObject obj = evt.getJGoObject();
if(obj ==null)
System.out.println(“null object get reported.”);
if(obj instanceof JGoLink){
System.out.println(“Link gets removed Transition”);
}
if(obj instanceof WorkflowStateNode){
System.out.println(“workflowstate node deleted”);
}
return;
}
super.documentChanged(evt);
}

I just tried this again, modifying the MinimalApp example.
I added this method to MinimalApp JApplet:
void jGoView_documentChanged(JGoDocumentEvent evt) {
if (evt.getHint() == JGoDocumentEvent.INSERTED) {
System.out.println(“JGoDocuemntEvent.INSERTED.”);
}
}
And I added this statement to the MinimalApp constructor:
myView.getDocument().addDocumentListener(new JGoDocumentListener() {
public void documentChanged(JGoDocumentEvent e) {
jGoView_documentChanged(e);
}
});
Everything works fine–there is only a single INSERTED message when the user draws a new link. Perhaps you have two document listeners defined?