use of com.twinsoft.convertigo.beans.rest.BodyParameter in project convertigo by convertigo.
the class ChangeToBodyParameterAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof UrlMappingParameter)) {
UrlMappingParameter parameter = (UrlMappingParameter) databaseObject;
TreeParent treeParent = treeObject.getParent();
DatabaseObjectTreeObject parentTreeObject = null;
if (treeParent instanceof DatabaseObjectTreeObject)
parentTreeObject = (DatabaseObjectTreeObject) treeParent;
else
parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
if (parentTreeObject != null) {
// Create new Body parameter
BodyParameter bodyParameter = new BodyParameter();
if (DatabaseObjectsManager.acceptDatabaseObjects(parameter.getParent(), bodyParameter)) {
bodyParameter.setComment(parameter.getComment());
bodyParameter.setArray(false);
bodyParameter.setExposed(parameter.isExposed());
bodyParameter.setMultiValued(false);
bodyParameter.setRequired(parameter.isRequired());
bodyParameter.setMappedVariableName(parameter.getMappedVariableName());
bodyParameter.bNew = true;
bodyParameter.hasChanged = true;
// Add new parameter to parent operation
UrlMappingOperation operation = (UrlMappingOperation) parameter.getParent();
operation.changeTo(bodyParameter);
// Add new parameter in Tree
UrlMappingParameterTreeObject parameterTreeObject = new UrlMappingParameterTreeObject(explorerView.viewer, bodyParameter);
treeParent.addChild(parameterTreeObject);
// Delete old parameter
parameter.delete();
// Rename new parameter
bodyParameter.setName(parameter.getName());
// Reload in tree
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(bodyParameter));
} else {
throw new EngineException("You cannot paste to a " + parameter.getParent().getClass().getSimpleName() + " a database object of type " + bodyParameter.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change to Body parameter!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations