Search in sources :

Example 31 with TreeParent

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

the class ChangeToIsInStepAction 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();
            // For IsInThenElse step
            if ((databaseObject != null) && (databaseObject instanceof IsInThenElseStep)) {
                IsInThenElseStep ifThenElseStep = (IsInThenElseStep) databaseObject;
                if (ifThenElseStep.hasThenElseSteps()) {
                    ThenStep thenStep = ifThenElseStep.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
                        IsInStep ifStep = new IsInStep();
                        // Set properties
                        ifStep.setSourceDefinition(ifThenElseStep.getSourceDefinition());
                        ifStep.setTestDefinition(ifThenElseStep.getTestDefinition());
                        ifStep.setComment(ifThenElseStep.getComment());
                        ifStep.setCondition(ifThenElseStep.getCondition());
                        ifStep.setEnabled(ifThenElseStep.isEnabled());
                        ifStep.setOutput(ifThenElseStep.isOutput());
                        ifStep.setName(ifThenElseStep.getName());
                        ifStep.bNew = true;
                        ifStep.hasChanged = true;
                        // Add new jIf step to parent
                        DatabaseObject parentDbo = ifThenElseStep.getParent();
                        parentDbo.add(ifStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(ifStep, ifThenElseStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(ifStep, ifThenElseStep.priority);
                        // Add new jIf step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifStep);
                        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 = ifThenElseStep.priority;
                        // Save oldName
                        String oldName = ifThenElseStep.getName();
                        // Now delete
                        ifThenElseStep.delete();
                        // Set name after deletion
                        ifStep.setName(oldName);
                        // Simulate move of IfThenElse to If
                        ifStep.getSequence().fireStepMoved(new StepEvent(ifStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifStep));
                    }
                }
            }
            // For IfExist step
            if ((databaseObject != null) && (databaseObject instanceof IfExistStep)) {
                IfExistStep ifExistStep = (IfExistStep) databaseObject;
                List<Step> list = ifExistStep.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
                    IsInStep ifStep = new IsInStep();
                    // Set properties
                    ifStep.setSourceDefinition(ifExistStep.getSourceDefinition());
                    ifStep.setComment(ifExistStep.getComment());
                    ifStep.setCondition(ifExistStep.getCondition());
                    ifStep.setEnabled(ifExistStep.isEnabled());
                    ifStep.setOutput(ifExistStep.isOutput());
                    ifStep.setName(ifExistStep.getName());
                    ifStep.bNew = true;
                    ifStep.hasChanged = true;
                    // Add new jIf step to parent
                    DatabaseObject parentDbo = ifExistStep.getParent();
                    parentDbo.add(ifStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(ifStep, ifExistStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(ifStep, ifExistStep.priority);
                    // Add new jIf step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifStep);
                    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 = ifExistStep.priority;
                    // Save oldName
                    String oldName = ifExistStep.getName();
                    // Now delete
                    ifExistStep.delete();
                    // Set name after deletion
                    ifStep.setName(oldName);
                    // Simulate move of IfThenElse to If
                    ifStep.getSequence().fireStepMoved(new StepEvent(ifStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifStep));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to IsIn step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) IfExistStep(com.twinsoft.convertigo.beans.steps.IfExistStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) IsInStep(com.twinsoft.convertigo.beans.steps.IsInStep) IfExistStep(com.twinsoft.convertigo.beans.steps.IfExistStep) Step(com.twinsoft.convertigo.beans.core.Step) IsInThenElseStep(com.twinsoft.convertigo.beans.steps.IsInThenElseStep) Cursor(org.eclipse.swt.graphics.Cursor) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Shell(org.eclipse.swt.widgets.Shell) IsInStep(com.twinsoft.convertigo.beans.steps.IsInStep) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IsInThenElseStep(com.twinsoft.convertigo.beans.steps.IsInThenElseStep) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Sequence(com.twinsoft.convertigo.beans.core.Sequence) 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 32 with TreeParent

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

the class ChangeToMultiValuedVariableAction 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 simple = (Variable) databaseObject;
                    Variable multi = null;
                    if (databaseObject instanceof TestCaseVariable)
                        multi = new TestCaseMultiValuedVariable();
                    if (databaseObject instanceof StepVariable)
                        multi = new StepMultiValuedVariable();
                    if (databaseObject instanceof RequestableVariable)
                        multi = new RequestableMultiValuedVariable();
                    if (databaseObject instanceof RequestableHttpVariable)
                        multi = new RequestableHttpMultiValuedVariable();
                    if (databaseObject instanceof HttpStatementVariable)
                        multi = new HttpStatementMultiValuedVariable();
                    if (multi != null) {
                        if (multi instanceof StepVariable) {
                            ((StepVariable) multi).setSourceDefinition(((StepVariable) simple).getSourceDefinition());
                        }
                        if (multi instanceof RequestableVariable) {
                            ((RequestableVariable) multi).setXmlTypeAffectation(((RequestableVariable) simple).getXmlTypeAffectation());
                        }
                        if (multi instanceof RequestableHttpVariable) {
                            // HttpName
                            ((RequestableHttpVariable) multi).setHttpName(((RequestableHttpVariable) simple).getHttpName());
                            // HttpMethod
                            ((RequestableHttpVariable) multi).setHttpMethod(((RequestableHttpVariable) simple).getHttpMethod());
                        }
                        Object value = simple.getValueOrNull();
                        multi.setValueOrNull(value);
                        multi.setVisibility(simple.getVisibility());
                        // Comment
                        multi.setComment(simple.getComment());
                        // Description
                        multi.setDescription(simple.getDescription());
                        // Required
                        multi.setRequired(simple.isRequired());
                        multi.bNew = true;
                        multi.hasChanged = true;
                        // Add new variable to parent
                        DatabaseObject parentDbo = simple.getParent();
                        parentDbo.add(multi);
                        // Set correct order
                        if (parentDbo instanceof TestCase)
                            ((TestCase) parentDbo).insertAtOrder(multi, simple.priority);
                        if (parentDbo instanceof RequestableStep)
                            ((RequestableStep) parentDbo).insertAtOrder(multi, simple.priority);
                        if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(multi, simple.priority);
                        if (parentDbo instanceof TransactionWithVariables)
                            ((TransactionWithVariables) parentDbo).insertAtOrder(multi, simple.priority);
                        if (parentDbo instanceof HTTPStatement)
                            ((HTTPStatement) parentDbo).insertAtOrder(multi, simple.priority);
                        // Add new variable in Tree
                        VariableTreeObject2 varTreeObject = new VariableTreeObject2(explorerView.viewer, multi);
                        treeParent.addChild(varTreeObject);
                        // Delete simple variable
                        simple.delete();
                        // Set correct name
                        multi.setName(simple.getName());
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(multi));
                    }
                }
            }
        }
    } 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 33 with TreeParent

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

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

Example 34 with TreeParent

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

the class ChangeToSourceStepAction 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 SimpleSourceStep)) {
                SimpleSourceStep jSimpleSourceStep = (SimpleSourceStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New jSource step
                    SourceStep jSourceStep = new SourceStep();
                    // Set properties
                    jSourceStep.setSourceDefinition(jSimpleSourceStep.getSourceDefinition());
                    jSourceStep.setComment(jSimpleSourceStep.getComment());
                    jSourceStep.setVariableName(jSimpleSourceStep.getVariableName());
                    jSourceStep.setEnabled(jSimpleSourceStep.isEnabled());
                    jSourceStep.setOutput(jSimpleSourceStep.isOutput());
                    jSourceStep.setName(jSimpleSourceStep.getName());
                    jSourceStep.bNew = true;
                    jSourceStep.hasChanged = true;
                    // Add new jSource step to parent
                    DatabaseObject parentDbo = jSimpleSourceStep.getParent();
                    parentDbo.add(jSourceStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(jSourceStep, jSimpleSourceStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(jSourceStep, jSimpleSourceStep.priority);
                    // Add new jSource step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, jSourceStep);
                    treeParent.addChild(stepTreeObject);
                    // Delete jSimpleSource step
                    long oldPriority = jSimpleSourceStep.priority;
                    jSimpleSourceStep.delete();
                    // Simulate move of jSimpleSource to jSource step
                    jSourceStep.getSequence().fireStepMoved(new StepEvent(jSourceStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(jSourceStep));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to jSource 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) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) SimpleSourceStep(com.twinsoft.convertigo.beans.steps.SimpleSourceStep) Shell(org.eclipse.swt.widgets.Shell) SourceStep(com.twinsoft.convertigo.beans.steps.SourceStep) SimpleSourceStep(com.twinsoft.convertigo.beans.steps.SimpleSourceStep) 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 35 with TreeParent

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

the class ChangeToAttributeStepAction 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();
            // XMLAttribute
            if ((databaseObject != null) && (databaseObject instanceof XMLAttributeStep)) {
                XMLAttributeStep xmlAttributeStep = (XMLAttributeStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New Attribute step
                    AttributeStep attributeStep = new AttributeStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(xmlAttributeStep.getParent(), attributeStep)) {
                        // Set properties
                        attributeStep.setOutput(xmlAttributeStep.isOutput());
                        attributeStep.setEnabled(xmlAttributeStep.isEnabled());
                        attributeStep.setComment(xmlAttributeStep.getComment());
                        // attributeStep.setExpression(elementStep.getExpression());
                        attributeStep.setNodeText(xmlAttributeStep.getNodeText());
                        attributeStep.setNodeName(xmlAttributeStep.getNodeName());
                        attributeStep.bNew = true;
                        attributeStep.hasChanged = true;
                        // Add new Attribute step to parent
                        DatabaseObject parentDbo = xmlAttributeStep.getParent();
                        parentDbo.add(attributeStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(attributeStep, xmlAttributeStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(attributeStep, xmlAttributeStep.priority);
                        // Add new Attribute step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, xmlAttributeStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete Element step
                        long oldPriority = xmlAttributeStep.priority;
                        xmlAttributeStep.delete();
                        attributeStep.getSequence().fireStepMoved(new StepEvent(attributeStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(attributeStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + xmlAttributeStep.getParent().getClass().getSimpleName() + " a database object of type " + attributeStep.getClass().getSimpleName());
                    }
                }
            }
            // Element
            if ((databaseObject != null) && (databaseObject instanceof ElementStep)) {
                ElementStep elementStep = (ElementStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New Attribute step
                    AttributeStep attributeStep = new AttributeStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(elementStep.getParent(), attributeStep)) {
                        // Set properties
                        attributeStep.setOutput(elementStep.isOutput());
                        attributeStep.setEnabled(elementStep.isEnabled());
                        attributeStep.setComment(elementStep.getComment());
                        attributeStep.setExpression(elementStep.getExpression());
                        attributeStep.setNodeText(elementStep.getNodeText());
                        attributeStep.setNodeName(elementStep.getNodeName());
                        attributeStep.bNew = true;
                        attributeStep.hasChanged = true;
                        // Add new Attribute step to parent
                        DatabaseObject parentDbo = elementStep.getParent();
                        parentDbo.add(attributeStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(attributeStep, elementStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(attributeStep, elementStep.priority);
                        // Add new Attribute step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, elementStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete Element step
                        long oldPriority = elementStep.priority;
                        elementStep.delete();
                        attributeStep.getSequence().fireStepMoved(new StepEvent(attributeStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(attributeStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + elementStep.getParent().getClass().getSimpleName() + " a database object of type " + attributeStep.getClass().getSimpleName());
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change to Attribute 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) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) EngineException(com.twinsoft.convertigo.engine.EngineException) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) AttributeStep(com.twinsoft.convertigo.beans.steps.AttributeStep) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) 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) ElementStep(com.twinsoft.convertigo.beans.steps.ElementStep) 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