nodes.add(selection.getSelected());
}
else {
nodes.addAll(selection.getSelection());
}
final MModeController modeController = (MModeController) Controller.getCurrentModeController();
modeController.startTransaction();
for (final NodeModel node : nodes) {
try {
if (mode == ExecutionMode.ON_SELECTED_NODE_RECURSIVELY) {
// TODO: ensure that a script is invoked only once on every node?
// (might be a problem with recursive actions if parent and child
// are selected.)
executeScriptRecursive(node);
}
else {
script.execute(node);
}
}
catch (ExecuteScriptException ex) {
final String cause;
// The ExecuteScriptException should have a cause. Print
// that, it is what we want to know.
if (ex.getCause() != null) {
if (ex.getCause().getCause() != null) {
LogUtils.warn("ExecuteScriptAction failed:", ex.getCause().getCause());
cause = ex.getCause().getCause().toString();
} else {
LogUtils.warn("ExecuteScriptAction failed:", ex.getCause());
cause = ex.getCause().toString();
}
}
else {
LogUtils.warn("ExecuteScriptAction failed:", ex);
cause = ex.toString();
}
LogUtils.warn("error executing script " + scriptFile + " - giving up\n" + cause);
modeController.delayedRollback();
ScriptingEngine.showScriptExceptionErrorMessage(ex);
return;
}
}
modeController.delayedCommit();
}
finally {
Controller.getCurrentController().getViewController().setWaitingCursor(false);
}
}