Search in sources :

Example 6 with ThenStep

use of com.twinsoft.convertigo.beans.steps.ThenStep in project convertigo by convertigo.

the class ChangeToIfStepAction 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 IfThenElseStep)) {
                IfThenElseStep ifThenElseStep = (IfThenElseStep) 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
                        IfStep ifStep = new IfStep(ifThenElseStep.getCondition());
                        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;
                        ifThenElseStep.delete();
                        // 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 jIf 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) 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) Step(com.twinsoft.convertigo.beans.core.Step) IfStep(com.twinsoft.convertigo.beans.steps.IfStep) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) 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) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) 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) IfStep(com.twinsoft.convertigo.beans.steps.IfStep)

Example 7 with ThenStep

use of com.twinsoft.convertigo.beans.steps.ThenStep in project convertigo by convertigo.

the class ChangeToIfThenElseStepAction 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 IfStep)) {
                IfStep ifStep = (IfStep) databaseObject;
                List<Step> list = ifStep.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 IfThenElseStep step
                    IfThenElseStep ifThenElseStep = new IfThenElseStep(ifStep.getCondition());
                    ifThenElseStep.bNew = true;
                    ifThenElseStep.hasChanged = true;
                    // Add new IfThenElseStep step to parent
                    DatabaseObject parentDbo = ifStep.getParent();
                    parentDbo.add(ifThenElseStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(ifThenElseStep, ifStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(ifThenElseStep, ifStep.priority);
                    // Add Then/Else steps
                    ThenStep thenStep = new ThenStep();
                    thenStep.bNew = true;
                    ifThenElseStep.addStep(thenStep);
                    ElseStep elseStep = new ElseStep();
                    elseStep.bNew = true;
                    ifThenElseStep.addStep(elseStep);
                    // Add new IfThenElseStep step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifThenElseStep);
                    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 = ifStep.priority;
                    ifStep.delete();
                    // Simulate move of If to IfThenElse
                    ifThenElseStep.getSequence().fireStepMoved(new StepEvent(ifThenElseStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifThenElseStep));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to jIfThenElse step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) 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) Step(com.twinsoft.convertigo.beans.core.Step) IfStep(com.twinsoft.convertigo.beans.steps.IfStep) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) 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) IfThenElseStep(com.twinsoft.convertigo.beans.steps.IfThenElseStep) 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) IfStep(com.twinsoft.convertigo.beans.steps.IfStep)

Example 8 with ThenStep

use of com.twinsoft.convertigo.beans.steps.ThenStep in project convertigo by convertigo.

the class ClipboardAction method pasteStep.

private Object pasteStep(Shell shell, String source, DatabaseObject targetObject) throws ParserConfigurationException, SAXException, IOException {
    // Can only paste on Sequence or Step
    if (targetObject instanceof Sequence)
        return targetObject;
    else if (!(targetObject instanceof Step))
        return null;
    // cannot paste to IThenElseContainer
    if (targetObject instanceof IThenElseContainer)
        return null;
    else {
        List<Object> objects = clipboardManager.read(source);
        int size = objects.size();
        for (Object ob : objects) {
            // Can only paste step objects
            if (!(ob instanceof Step))
                return null;
            // Can paste only on step which may contain children
            if ((ob instanceof StepWithExpressions) && (!(targetObject instanceof StepWithExpressions)))
                return null;
            // cannot paste a ThenStep
            if (ob instanceof ThenStep)
                return null;
            // cannot paste a ElseStep
            if (ob instanceof ElseStep)
                return null;
            // cannot paste a ThenStatement
            if (ob instanceof ThenStatement)
                return null;
            // cannot paste a ElseStatement
            if (ob instanceof ElseStatement)
                return null;
            // Special case of XMLElementStep, ElementStep
            if ((targetObject instanceof XMLElementStep) || (targetObject instanceof ElementStep)) {
                // Case paste on itself -> target is changed to parent
                if ((size == 1) && ((ob instanceof XMLElementStep) || (ob instanceof ElementStep))) {
                    if (((Step) ob).getName().equals(targetObject.getName())) {
                        return targetObject.getParent();
                    }
                    return null;
                } else // Else, only accept paste of XMLAttributeStep
                if (!(ob instanceof XMLAttributeStep || ob instanceof AttributeStep)) {
                    return null;
                }
            } else // Case of step which may contain children
            if (targetObject instanceof StepWithExpressions) {
                // Case paste on itself -> ask user what to do
                if ((size == 1) && (ob.getClass().equals(targetObject.getClass()))) {
                    if (((Step) ob).getName().equals(targetObject.getName())) {
                        CustomDialog customDialog = new CustomDialog(shell, "Paste a step", "Do you want to paste the step as a sibling or a child step?", 500, 150, new ButtonSpec("As a sibling", true), new ButtonSpec("As a child", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
                        int response = customDialog.open();
                        if (response == 0) {
                            return targetObject.getParent();
                        } else if (response == 2) {
                            return null;
                        } else
                            break;
                    }
                }
                // Else, paste
                break;
            } else // Other case
            {
                // Case paste on itself -> target is changed to parent
                if ((size == 1) && (ob.getClass().equals(targetObject.getClass()))) {
                    if (((Step) ob).getName().equals(targetObject.getName())) {
                        return targetObject.getParent();
                    }
                    return null;
                }
                // Else, not permitted
                return null;
            }
        }
    }
    return targetObject;
}
Also used : IThenElseContainer(com.twinsoft.convertigo.beans.steps.IThenElseContainer) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Sequence(com.twinsoft.convertigo.beans.core.Sequence) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) Step(com.twinsoft.convertigo.beans.core.Step) ElementStep(com.twinsoft.convertigo.beans.steps.ElementStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) AttributeStep(com.twinsoft.convertigo.beans.steps.AttributeStep) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) CustomDialog(com.twinsoft.convertigo.eclipse.dialogs.CustomDialog) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) AttributeStep(com.twinsoft.convertigo.beans.steps.AttributeStep) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) 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) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) ElementStep(com.twinsoft.convertigo.beans.steps.ElementStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) ButtonSpec(com.twinsoft.convertigo.eclipse.dialogs.ButtonSpec)

Example 9 with ThenStep

use of com.twinsoft.convertigo.beans.steps.ThenStep 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 10 with ThenStep

use of com.twinsoft.convertigo.beans.steps.ThenStep in project convertigo by convertigo.

the class ChangeToIfExistStepAction 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 IfExistThenElseStep
            if ((databaseObject != null) && (databaseObject instanceof IfExistThenElseStep)) {
                IfExistThenElseStep ifThenElseStep = (IfExistThenElseStep) 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
                        IfExistStep ifStep = new IfExistStep();
                        // Set properties
                        ifStep.setSourceDefinition(ifThenElseStep.getSourceDefinition());
                        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 IsInStep
            if ((databaseObject != null) && (databaseObject instanceof IsInStep)) {
                IsInStep isInStep = (IsInStep) databaseObject;
                List<Step> list = isInStep.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
                    IfExistStep ifStep = new IfExistStep();
                    // Set properties
                    ifStep.setSourceDefinition(isInStep.getSourceDefinition());
                    ifStep.setComment(isInStep.getComment());
                    ifStep.setCondition(isInStep.getCondition());
                    ifStep.setEnabled(isInStep.isEnabled());
                    ifStep.setOutput(isInStep.isOutput());
                    ifStep.setName(isInStep.getName());
                    ifStep.bNew = true;
                    ifStep.hasChanged = true;
                    // Add new jIf step to parent
                    DatabaseObject parentDbo = isInStep.getParent();
                    parentDbo.add(ifStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(ifStep, isInStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(ifStep, isInStep.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 IsIn step
                    long oldPriority = isInStep.priority;
                    // Save oldName
                    String oldName = isInStep.getName();
                    // Now delete
                    isInStep.delete();
                    // Set name after deletion
                    ifStep.setName(oldName);
                    // Simulate move of IsIn 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 IfExist step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfExistThenElseStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) IfExistStep(com.twinsoft.convertigo.beans.steps.IfExistStep) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) IfExistThenElseStep(com.twinsoft.convertigo.beans.steps.IfExistThenElseStep) 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) 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) 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)

Aggregations

ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)13 Step (com.twinsoft.convertigo.beans.core.Step)12 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)11 Sequence (com.twinsoft.convertigo.beans.core.Sequence)9 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)9 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)9 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)9 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)9 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)8 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)8 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)8 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)8 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)8 Cursor (org.eclipse.swt.graphics.Cursor)8 Display (org.eclipse.swt.widgets.Display)8 Shell (org.eclipse.swt.widgets.Shell)8 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)5 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)5 Connector (com.twinsoft.convertigo.beans.core.Connector)4 Project (com.twinsoft.convertigo.beans.core.Project)4