Search in sources :

Example 1 with BodyParameter

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();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) UrlMappingOperation(com.twinsoft.convertigo.beans.core.UrlMappingOperation) UrlMappingParameter(com.twinsoft.convertigo.beans.core.UrlMappingParameter) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) EngineException(com.twinsoft.convertigo.engine.EngineException) Cursor(org.eclipse.swt.graphics.Cursor) BodyParameter(com.twinsoft.convertigo.beans.rest.BodyParameter) Shell(org.eclipse.swt.widgets.Shell) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) UrlMappingParameterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) UrlMappingParameterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) UrlMappingParameterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 UrlMappingOperation (com.twinsoft.convertigo.beans.core.UrlMappingOperation)1 UrlMappingParameter (com.twinsoft.convertigo.beans.core.UrlMappingParameter)1 BodyParameter (com.twinsoft.convertigo.beans.rest.BodyParameter)1 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)1 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)1 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)1 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)1 UrlMappingParameterTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 Cursor (org.eclipse.swt.graphics.Cursor)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1