use of com.twinsoft.convertigo.beans.rest.HeaderParameter in project convertigo by convertigo.
the class ChangeToHeaderParameterAction 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 Header parameter
HeaderParameter headerParameter = new HeaderParameter();
if (DatabaseObjectsManager.acceptDatabaseObjects(parameter.getParent(), headerParameter)) {
headerParameter.setComment(parameter.getComment());
headerParameter.setInputType(parameter.getInputType());
headerParameter.setArray(parameter.isArray());
headerParameter.setExposed(parameter.isExposed());
headerParameter.setMultiValued(parameter.isMultiValued());
headerParameter.setRequired(parameter.isRequired());
headerParameter.setValueOrNull(parameter.getValueOrNull());
headerParameter.setMappedVariableName(parameter.getMappedVariableName());
headerParameter.bNew = true;
headerParameter.hasChanged = true;
// Add new parameter to parent operation
UrlMappingOperation operation = (UrlMappingOperation) parameter.getParent();
operation.changeTo(headerParameter);
// Add new parameter in Tree
UrlMappingParameterTreeObject parameterTreeObject = new UrlMappingParameterTreeObject(explorerView.viewer, headerParameter);
treeParent.addChild(parameterTreeObject);
// Delete old parameter
parameter.delete();
// Rename new parameter
headerParameter.setName(parameter.getName());
// Reload in tree
parentTreeObject.hasBeenModified(true);
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(headerParameter));
} else {
throw new EngineException("You cannot paste to a " + parameter.getParent().getClass().getSimpleName() + " a database object of type " + headerParameter.getClass().getSimpleName());
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to change to Header parameter!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations