« Back

Before save functionality

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Before save functionality
community documentation adoscript trigger
Answer
27/03/14 12:07
The metamodel shouldn't be save unless the user press "Model >> Save" or "Model >> Save as..." or in the case the user close the tool and the model haven't been saved before. 
In these cases I want to check cardinalities and check that all mandatory attributes have seted a correct value. If exists any errors I want to inform it to the user (all errors cardinalities as shown when "CHECK_CARDINALITIES before-save" is set, and all atributes which have an incorrect value with it respective class) and save the metamodel on the database (only if the user is agree).

RE: Before save functionality
Answer
07/03/14 13:33 as a reply to Anonymous.
I would recommend creating an event handler for the event "BeforeSaveModel". The example below implements a simple event handler that, when the event is triggered, triggers the standard cardinality check of ADOxx. During this check, all cardinality errors will be shown to the user in a separate information box. In the end, if any cardinality errors have been found, a warning box is displayed, asking the user if they still want to save the model. Unfortunately, the current implementation of the cardinality check does not allow the developer catch all the error messages and display them in one single dialog, but we have created a Change Request regarding this issue for a future version of ADOxx.
 1ON_EVENT "BeforeSaveModel"
 2{
 3# modelid, origin: "new"("Model" - "New"), "saveas-new" ("Model"- "Save as" Part 1), "save" ("Model" - "Save")and "saveas-save" ("Model" - "Save as" Part
 42).
 5# Exit Values: 0 - no abortion, -1 - abortion without error, -2 - abortion with error, >0 - abort with core error code.
 6
 7CC "Modeling" CHECK_CARDINALITIES modelid: ( modelid ) nosuccessmessage
 8# --> RESULT ecode: intValue
 9
10IF (ecode) {
11  CC "AdoScript" WARNINGBOX "Cardinality check has failed.\n\nDo you still want to save your model?" title: "Cardinality check failure" yes-no
12  IF ( endbutton = "yes") {
13     EXIT 0
14  }
15  ELSE {
16    EXIT -1
17  }
18}
19}