Search in sources :

Example 16 with TreeParent

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent in project convertigo by convertigo.

the class ChangeToSingleValuedVariableAction 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();
            TreeParent treeParent = treeObject.getParent();
            DatabaseObjectTreeObject parentTreeObject = null;
            if (treeParent instanceof DatabaseObjectTreeObject)
                parentTreeObject = (DatabaseObjectTreeObject) treeParent;
            else
                parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
            if (parentTreeObject != null) {
                Object databaseObject = treeObject.getObject();
                if (databaseObject != null) {
                    Variable multi = (Variable) databaseObject;
                    Variable simple = null;
                    if (databaseObject instanceof TestCaseMultiValuedVariable)
                        simple = new TestCaseVariable();
                    if (databaseObject instanceof StepMultiValuedVariable)
                        simple = new StepVariable();
                    if (databaseObject instanceof RequestableMultiValuedVariable)
                        simple = new RequestableVariable();
                    if (databaseObject instanceof RequestableHttpMultiValuedVariable)
                        simple = new RequestableHttpVariable();
                    if (databaseObject instanceof HttpStatementMultiValuedVariable)
                        simple = new HttpStatementVariable();
                    if (simple != null) {
                        if (multi instanceof StepMultiValuedVariable) {
                            ((StepVariable) simple).setSourceDefinition(((StepVariable) multi).getSourceDefinition());
                        }
                        if (multi instanceof RequestableVariable) {
                            ((RequestableVariable) simple).setXmlTypeAffectation(((RequestableVariable) multi).getXmlTypeAffectation());
                        }
                        if (multi instanceof RequestableHttpVariable) {
                            // HttpName
                            ((RequestableHttpVariable) simple).setHttpName(((RequestableHttpVariable) multi).getHttpName());
                            // HttpMethod
                            ((RequestableHttpVariable) simple).setHttpMethod(((RequestableHttpVariable) multi).getHttpMethod());
                        }
                        XMLVector<Object> xmlv = GenericUtils.cast(multi.getValueOrNull());
                        Object value = (xmlv == null) ? null : (xmlv.isEmpty() ? "" : xmlv.get(0).toString());
                        simple.setValueOrNull(value);
                        simple.setVisibility(multi.getVisibility());
                        // Comment
                        simple.setComment(multi.getComment());
                        // Description
                        simple.setDescription(multi.getDescription());
                        // Required
                        simple.setRequired(multi.isRequired());
                        simple.bNew = true;
                        simple.hasChanged = true;
                        // Add new variable to parent
                        DatabaseObject parentDbo = multi.getParent();
                        parentDbo.add(simple);
                        // Set correct order
                        if (parentDbo instanceof TestCase)
                            ((TestCase) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof RequestableStep)
                            ((RequestableStep) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof TransactionWithVariables)
                            ((TransactionWithVariables) parentDbo).insertAtOrder(simple, multi.priority);
                        if (parentDbo instanceof HTTPStatement)
                            ((HTTPStatement) parentDbo).insertAtOrder(simple, multi.priority);
                        // Add new variable in Tree
                        VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, simple);
                        treeParent.addChild(varTreeObject);
                        // Delete simple variable
                        multi.delete();
                        // Set correct name
                        simple.setName(multi.getName());
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(simple));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change simple variable to multi valuated variable!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) RequestableHttpVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpVariable) HttpStatementVariable(com.twinsoft.convertigo.beans.variables.HttpStatementVariable) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable) HttpStatementMultiValuedVariable(com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable) Variable(com.twinsoft.convertigo.beans.core.Variable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) TestCaseMultiValuedVariable(com.twinsoft.convertigo.beans.variables.TestCaseMultiValuedVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) HttpStatementMultiValuedVariable(com.twinsoft.convertigo.beans.variables.HttpStatementMultiValuedVariable) StepVariable(com.twinsoft.convertigo.beans.variables.StepVariable) Cursor(org.eclipse.swt.graphics.Cursor) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) StepMultiValuedVariable(com.twinsoft.convertigo.beans.variables.StepMultiValuedVariable) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) VariableTreeObject2(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject2) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) HttpStatementVariable(com.twinsoft.convertigo.beans.variables.HttpStatementVariable) TestCaseVariable(com.twinsoft.convertigo.beans.variables.TestCaseVariable) TestCaseMultiValuedVariable(com.twinsoft.convertigo.beans.variables.TestCaseMultiValuedVariable) RequestableHttpMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableHttpMultiValuedVariable) TestCase(com.twinsoft.convertigo.beans.core.TestCase) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) RequestableMultiValuedVariable(com.twinsoft.convertigo.beans.variables.RequestableMultiValuedVariable) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) TransactionWithVariables(com.twinsoft.convertigo.beans.core.TransactionWithVariables) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 17 with TreeParent

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent 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();
    }
}
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) 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) HeaderParameter(com.twinsoft.convertigo.beans.rest.HeaderParameter) UrlMappingParameterTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.UrlMappingParameterTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 18 with TreeParent

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent in project convertigo by convertigo.

the class ChangeToIfFileExistStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#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 IfFileExistThenElseStep)) {
                IfFileExistThenElseStep ifFileExistThenElseStep = (IfFileExistThenElseStep) databaseObject;
                if (ifFileExistThenElseStep.hasThenElseSteps()) {
                    ThenStep thenStep = ifFileExistThenElseStep.getThenStep();
                    List<Step> list = thenStep.getSteps();
                    TreePath[] selectedPaths = new TreePath[list.size()];
                    for (int i = 0; i < list.size(); i++) {
                        StepTreeObject stepTreeObject = (StepTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                        selectedPaths[i] = new TreePath(stepTreeObject);
                    }
                    TreeParent treeParent = treeObject.getParent();
                    DatabaseObjectTreeObject parentTreeObject = null;
                    if (treeParent instanceof DatabaseObjectTreeObject)
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                    else
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                    if (parentTreeObject != null) {
                        // New jIf step
                        IfFileExistStep ifFileExistStep = new IfFileExistStep(ifFileExistThenElseStep.getCondition());
                        ifFileExistStep.bNew = true;
                        ifFileExistStep.hasChanged = true;
                        // Add new jIf step to parent
                        DatabaseObject parentDbo = ifFileExistThenElseStep.getParent();
                        parentDbo.add(ifFileExistStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(ifFileExistStep, ifFileExistThenElseStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(ifFileExistStep, ifFileExistThenElseStep.priority);
                        // Add new jIf step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifFileExistStep);
                        treeParent.addChild(stepTreeObject);
                        // Cut/Paste steps under jIf step
                        if (selectedPaths.length > 0) {
                            new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
                            for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
                                ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], stepTreeObject);
                            }
                            ConvertigoPlugin.clipboardManagerDND.reset();
                        }
                        // Delete IfThenElse step
                        long oldPriority = ifFileExistThenElseStep.priority;
                        ifFileExistThenElseStep.delete();
                        // Simulate move of IfThenElse to If
                        ifFileExistStep.getSequence().fireStepMoved(new StepEvent(ifFileExistStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifFileExistStep));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to IfFileExist step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfFileExistStep(com.twinsoft.convertigo.beans.steps.IfFileExistStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) IfFileExistStep(com.twinsoft.convertigo.beans.steps.IfFileExistStep) Step(com.twinsoft.convertigo.beans.core.Step) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Shell(org.eclipse.swt.widgets.Shell) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 19 with TreeParent

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent in project convertigo by convertigo.

the class ChangeToIfFileExistThenElseStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#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 IfFileExistStep)) {
                IfFileExistStep ifFileExistStep = (IfFileExistStep) databaseObject;
                List<Step> list = ifFileExistStep.getSteps();
                TreePath[] selectedPaths = new TreePath[list.size()];
                for (int i = 0; i < list.size(); i++) {
                    StepTreeObject stepTreeObject = (StepTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                    selectedPaths[i] = new TreePath(stepTreeObject);
                }
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New IfFileExistThenElseStep step
                    IfFileExistThenElseStep ifFileExistThenElseStep = new IfFileExistThenElseStep(ifFileExistStep.getCondition());
                    ifFileExistThenElseStep.bNew = true;
                    ifFileExistThenElseStep.hasChanged = true;
                    // Add new IfFileExistThenElseStep step to parent
                    DatabaseObject parentDbo = ifFileExistStep.getParent();
                    parentDbo.add(ifFileExistThenElseStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(ifFileExistThenElseStep, ifFileExistStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(ifFileExistThenElseStep, ifFileExistStep.priority);
                    // Add Then/Else steps
                    ThenStep thenStep = new ThenStep();
                    thenStep.bNew = true;
                    ifFileExistThenElseStep.addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    elseStep.bNew = true;
                    ifFileExistThenElseStep.addStep(elseStep);
                    // Add new IfFileExistThenElseStep step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifFileExistThenElseStep);
                    treeParent.addChild(stepTreeObject);
                    StepTreeObject thenTreeObject = new StepTreeObject(explorerView.viewer, thenStep);
                    stepTreeObject.addChild(thenTreeObject);
                    StepTreeObject elseTreeObject = new StepTreeObject(explorerView.viewer, elseStep);
                    stepTreeObject.addChild(elseTreeObject);
                    // Cut/Paste steps under Then step
                    if (selectedPaths.length > 0) {
                        new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
                        for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
                            ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], thenTreeObject);
                        }
                        ConvertigoPlugin.clipboardManagerDND.reset();
                    }
                    // Delete If step
                    long oldPriority = ifFileExistStep.priority;
                    ifFileExistStep.delete();
                    // Simulate move of If to IfThenElse
                    ifFileExistThenElseStep.getSequence().fireStepMoved(new StepEvent(ifFileExistThenElseStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifFileExistThenElseStep));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to IfFileExistThenElse step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : IfFileExistStep(com.twinsoft.convertigo.beans.steps.IfFileExistStep) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) IfFileExistStep(com.twinsoft.convertigo.beans.steps.IfFileExistStep) Step(com.twinsoft.convertigo.beans.core.Step) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) Cursor(org.eclipse.swt.graphics.Cursor) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Sequence(com.twinsoft.convertigo.beans.core.Sequence) IfFileExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfFileExistThenElseStep) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 20 with TreeParent

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent in project convertigo by convertigo.

the class ChangeToIfStatementAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#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 IfThenElseStatement)) {
                IfThenElseStatement ifThenElseStatement = (IfThenElseStatement) databaseObject;
                if (ifThenElseStatement.hasThenElseStatements()) {
                    ThenStatement thenStatement = ifThenElseStatement.getThenStatement();
                    List<Statement> list = thenStatement.getStatements();
                    TreePath[] selectedPaths = new TreePath[list.size()];
                    for (int i = 0; i < list.size(); i++) {
                        StatementTreeObject statementTreeObject = (StatementTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                        selectedPaths[i] = new TreePath(statementTreeObject);
                    }
                    TreeParent treeParent = treeObject.getParent();
                    DatabaseObjectTreeObject parentTreeObject = null;
                    if (treeParent instanceof DatabaseObjectTreeObject)
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                    else
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                    if (parentTreeObject != null) {
                        // New If statement
                        IfStatement ifStatement = new IfStatement(ifThenElseStatement.getCondition());
                        ifStatement.bNew = true;
                        ifStatement.hasChanged = true;
                        // Add new If statement to parent
                        DatabaseObject parentDbo = ifThenElseStatement.getParent();
                        parentDbo.add(ifStatement);
                        // Set correct order
                        if (parentDbo instanceof StatementWithExpressions) {
                            int index = ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).indexOf(ifThenElseStatement.priority);
                            ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).add(index, ifStatement.priority);
                        }
                        // Add new If statement in Tree
                        StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, ifStatement);
                        treeParent.addChild(statementTreeObject);
                        // Cut/Paste steps under If statement
                        if (selectedPaths.length > 0) {
                            new ClipboardAction(ConvertigoPlugin.clipboardManagerDND).cut(explorerView, selectedPaths, ProjectExplorerView.TREE_OBJECT_TYPE_DBO_STEP);
                            for (int i = 0; i < ConvertigoPlugin.clipboardManagerDND.objects.length; i++) {
                                ConvertigoPlugin.clipboardManagerDND.cutAndPaste(ConvertigoPlugin.clipboardManagerDND.objects[i], statementTreeObject);
                            }
                            ConvertigoPlugin.clipboardManagerDND.reset();
                        }
                        // Delete IfThenElse statement
                        ifThenElseStatement.delete();
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifStatement));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change statement to If statement!");
    } 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) IfThenElseStatement(com.twinsoft.convertigo.beans.statements.IfThenElseStatement) IfStatement(com.twinsoft.convertigo.beans.statements.IfStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) IfThenElseStatement(com.twinsoft.convertigo.beans.statements.IfThenElseStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Cursor(org.eclipse.swt.graphics.Cursor) IfStatement(com.twinsoft.convertigo.beans.statements.IfStatement) Shell(org.eclipse.swt.widgets.Shell) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) StatementWithExpressions(com.twinsoft.convertigo.beans.core.StatementWithExpressions) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)48 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)40 Shell (org.eclipse.swt.widgets.Shell)39 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)38 Cursor (org.eclipse.swt.graphics.Cursor)37 Display (org.eclipse.swt.widgets.Display)37 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)35 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)31 FolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject)18 Sequence (com.twinsoft.convertigo.beans.core.Sequence)17 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)15 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)15 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)15 EngineException (com.twinsoft.convertigo.engine.EngineException)12 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)11 Step (com.twinsoft.convertigo.beans.core.Step)10 CompositeEvent (com.twinsoft.convertigo.eclipse.editors.CompositeEvent)9 PropertyTableRowTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject)9 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)8 PropertyTableTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject)8