Creating an edit
An edit is the lego brick of the modifications commanded by the user: Adding a link, removing it, creating a node and many more. Edits can be combined into more complex modifications like removing a node (which includes removing the node and removing every link it had). The main advantage of the edit structure is the easy implementation of undo/redo history.
To create an edit, write a class with name
WhatYourEditDoesEdit in the
action folder of
org.openmarkov.core. Search for
AddNodeEdit if you have trouble finding it.
Looking at one of those edits will give you an insight of how your edit should be written.
The class should extend
CompoundPNEdit if your edit is a complex action that runs several other edits (like the remove node case). This inheritance will force you to write this three methods:
doEdit(): here you program what the edit does.
undo(): this code should undo
doEdit(), remember to save (in
doEdit()) everything necessary to undo it cleanly.
redo(): redo doEdit, save everything necessary to redo the edit from memory, saving the computations. The redo method should begin with:
setTypicalRedo(false) // Tells OpenMarkov to run your code instead of `doEdit()` again super.redo() // General test to see if a `redo()` can be applied
Note that edits that extend
redo() by themselves using those of its components. You don't need to write a big one.
Once created, you can run the edit using
probnet.doEdit(WhatYourEditDoesEdit). One possibility is when clicked from a menu.