Search in sources :

Example 46 with Step

use of com.twinsoft.convertigo.beans.core.Step 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 47 with Step

use of com.twinsoft.convertigo.beans.core.Step 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)

Example 48 with Step

use of com.twinsoft.convertigo.beans.core.Step in project convertigo by convertigo.

the class ChangeToIfExistThenElseStepAction 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 IfExist step
            if ((databaseObject != null) && (databaseObject instanceof IfExistStep)) {
                IfExistStep ifStep = (IfExistStep) 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
                    IfExistThenElseStep ifThenElseStep = new IfExistThenElseStep();
                    // Set properties
                    ifThenElseStep.setSourceDefinition(ifStep.getSourceDefinition());
                    ifThenElseStep.setComment(ifStep.getComment());
                    ifThenElseStep.setCondition(ifStep.getCondition());
                    ifThenElseStep.setEnabled(ifStep.isEnabled());
                    ifThenElseStep.setOutput(ifStep.isOutput());
                    ifThenElseStep.setName(ifStep.getName());
                    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;
                    // Save oldName
                    String oldName = ifStep.getName();
                    // Now delete
                    ifStep.delete();
                    // Set name after deletion
                    ifThenElseStep.setName(oldName);
                    // 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));
                }
            }
            // For IsInThenElse step
            if ((databaseObject != null) && (databaseObject instanceof IsInThenElseStep)) {
                IsInThenElseStep isInThenElseStep = (IsInThenElseStep) databaseObject;
                if (isInThenElseStep.hasThenElseSteps()) {
                    TreeParent treeParent = treeObject.getParent();
                    DatabaseObjectTreeObject parentTreeObject = null;
                    if (treeParent instanceof DatabaseObjectTreeObject)
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                    else
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                    if (parentTreeObject != null) {
                        // New IfExistThenElse step
                        IfExistThenElseStep ifThenElseStep = new IfExistThenElseStep();
                        // Set properties
                        ifThenElseStep.setSourceDefinition(isInThenElseStep.getSourceDefinition());
                        ifThenElseStep.setComment(isInThenElseStep.getComment());
                        ifThenElseStep.setCondition(isInThenElseStep.getCondition());
                        ifThenElseStep.setEnabled(isInThenElseStep.isEnabled());
                        ifThenElseStep.setOutput(isInThenElseStep.isOutput());
                        ifThenElseStep.setName(isInThenElseStep.getName());
                        ifThenElseStep.bNew = true;
                        ifThenElseStep.hasChanged = true;
                        // Add new IfExistThenElse step to parent
                        DatabaseObject parentDbo = isInThenElseStep.getParent();
                        parentDbo.add(ifThenElseStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(ifThenElseStep, isInThenElseStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(ifThenElseStep, isInThenElseStep.priority);
                        // Add Then/Else steps
                        ThenStep thenStep = isInThenElseStep.getThenStep();
                        ElseStep elseStep = isInThenElseStep.getElseStep();
                        thenStep.bNew = true;
                        elseStep.bNew = true;
                        ifThenElseStep.addStep(thenStep);
                        ifThenElseStep.addStep(elseStep);
                        // Add new IfExistThenElse step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, ifThenElseStep);
                        treeParent.addChild(stepTreeObject);
                        stepTreeObject.addChild(new StepTreeObject(explorerView.viewer, thenStep));
                        stepTreeObject.addChild(new StepTreeObject(explorerView.viewer, elseStep));
                        // Delete IsInThenElse step
                        long oldPriority = isInThenElseStep.priority;
                        // Save oldName
                        String oldName = isInThenElseStep.getName();
                        // Now delete
                        isInThenElseStep.delete();
                        // Set name after deletion
                        ifThenElseStep.setName(oldName);
                        // Simulate move of IsInThenElse to IfExistThenElse step
                        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 IfExistThenElse 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) IsInThenElseStep(com.twinsoft.convertigo.beans.steps.IsInThenElseStep) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) 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) IfExistStep(com.twinsoft.convertigo.beans.steps.IfExistStep) Step(com.twinsoft.convertigo.beans.core.Step) IsInThenElseStep(com.twinsoft.convertigo.beans.steps.IsInThenElseStep) 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) 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 49 with Step

use of com.twinsoft.convertigo.beans.core.Step in project convertigo by convertigo.

the class ClipboardManager method cutAndPaste.

public void cutAndPaste(final DatabaseObject object, DatabaseObject parentDatabaseObject) throws ConvertigoException {
    // Verifying if a sheet with the same browser does not already exist
    if (object instanceof Sheet) {
        String browser = ((Sheet) object).getBrowser();
        Sheet sheet = null;
        if (parentDatabaseObject instanceof ScreenClass) {
            sheet = ((ScreenClass) parentDatabaseObject).getLocalSheet(browser);
        } else if (parentDatabaseObject instanceof RequestableObject) {
            sheet = ((RequestableObject) parentDatabaseObject).getSheet(browser);
        }
        if (sheet != null) {
            throw new EngineException("You cannot cut and paste the sheet because a sheet is already defined for the browser \"" + browser + "\" in the screen class \"" + parentDatabaseObject.getName() + "\".");
        }
    }
    if (object instanceof Step) {
        if (object instanceof ThenStep) {
            throw new EngineException("You cannot cut the \"Then\" step");
        }
        if (object instanceof ElseStep) {
            throw new EngineException("You cannot cut the \"Else\" step");
        }
    }
    if (object instanceof Statement) {
        if (object instanceof ThenStatement)
            throw new EngineException("You cannot cut the \"Then\" statement");
        if (object instanceof ElseStatement)
            throw new EngineException("You cannot cut the \"Else\" statement");
    }
    // Verify object is accepted for paste
    if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
        throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
    }
    if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    }
    // Verify if a child object with same name exist
    boolean bContinue = true;
    boolean bIncName = false;
    String dboName = object.getName();
    while (bContinue) {
        try {
            if (bIncName) {
                dboName = DatabaseObject.incrementName(dboName);
                object.setName(dboName);
            }
            new WalkHelper() {

                boolean root = true;

                boolean find = false;

                @Override
                protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                    boolean isInstance = dboClass.isInstance(object);
                    find |= isInstance;
                    return isInstance;
                }

                @Override
                protected void walk(DatabaseObject databaseObject) throws Exception {
                    if (root) {
                        root = false;
                        if (databaseObject instanceof Project) {
                            if (object instanceof Connector && ((Connector) object).isDefault) {
                                throw new EngineException("You cannot cut the default connector to another project");
                            }
                        } else if (databaseObject instanceof Connector) {
                            if (object instanceof ScreenClass) {
                                throw new EngineException("You cannot cut the default screen class to another connector");
                            } else if (object instanceof Transaction && ((Transaction) object).isDefault) {
                                throw new EngineException("You cannot cut the default transaction to another connector");
                            }
                        } else if (databaseObject instanceof ScreenClass) {
                            if (object instanceof Criteria && databaseObject.getParent() instanceof Connector) {
                                throw new EngineException("You cannot cut the criterion of default screen class");
                            }
                        } else if (databaseObject instanceof MobileObject) {
                            if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
                                if (object instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                                    com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(object);
                                    if (pc.isRoot) {
                                        throw new EngineException("You cannot cut the root page to another application");
                                    }
                                }
                            } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
                                if (object instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                                    com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(object);
                                    if (pc.isRoot) {
                                        throw new EngineException("You cannot cut the root page to another application");
                                    }
                                }
                            }
                        }
                        super.walk(databaseObject);
                        if (!find) {
                            throw new EngineException("You cannot cut and paste to a " + databaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
                        }
                    } else {
                        if (object != databaseObject && object.getName().equalsIgnoreCase(databaseObject.getName())) {
                            throw new ObjectWithSameNameException("Unable to cut the object because an object with the same name already exists in target.");
                        }
                    }
                }
            }.init(parentDatabaseObject);
            bContinue = false;
        } catch (ObjectWithSameNameException e) {
            bIncName = true;
        } catch (EngineException e) {
            throw e;
        } catch (Exception e) {
            throw new EngineException("Exception in cutAndPaste", e);
        }
    }
    move(object, parentDatabaseObject);
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) EngineException(com.twinsoft.convertigo.engine.EngineException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Project(com.twinsoft.convertigo.beans.core.Project) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Example 50 with Step

use of com.twinsoft.convertigo.beans.core.Step in project convertigo by convertigo.

the class ClipboardManager method paste.

public void paste(String xmlData, Object parentObject, boolean bChangeName) throws EngineException, SAXException, IOException {
    Document document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(xmlData)));
    Element rootElement = document.getDocumentElement();
    NodeList nodeList = rootElement.getChildNodes();
    int len = nodeList.getLength();
    Node node;
    pastedSteps.clear();
    pastedComponents.clear();
    pastedObjects = new Object[] {};
    if (len > 0) {
        pastedObjects = new Object[len];
    }
    Object object = null;
    for (int i = 0; i < len; i++) {
        node = (Node) nodeList.item(i);
        if (node.getNodeType() != Node.TEXT_NODE) {
            if (parentObject instanceof IPropertyTreeObject) {
                object = paste(node, (IPropertyTreeObject) parentObject, bChangeName);
            } else if (parentObject instanceof IDesignTreeObject) {
                object = paste(node, (IDesignTreeObject) parentObject, bChangeName);
            } else {
                object = paste(node, (DatabaseObject) parentObject, bChangeName);
            }
            pastedObjects[i] = object;
        }
    }
    for (Entry<String, Step> entry : pastedSteps.entrySet()) {
        Step step = entry.getValue();
        step.getSequence().fireStepCopied(new StepEvent(step, entry.getKey()));
    }
    for (Object ob : pastedObjects) {
        // MOBILE COMPONENTS
        if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
            if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                com.twinsoft.convertigo.beans.mobile.components.PageComponent page = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (page.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        page.markPageAsDirty();
                    }
                }
            } else if (ob instanceof com.twinsoft.convertigo.beans.mobile.components.UIComponent) {
                com.twinsoft.convertigo.beans.mobile.components.UIComponent uic = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (uic.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        uic.markAsDirty();
                    }
                }
            }
        }
        // NGX COMPONENTS
        if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
            if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                com.twinsoft.convertigo.beans.ngx.components.PageComponent page = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (page.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        page.markPageAsDirty();
                    }
                }
            } else if (ob instanceof com.twinsoft.convertigo.beans.ngx.components.UIComponent) {
                com.twinsoft.convertigo.beans.ngx.components.UIComponent uic = GenericUtils.cast(ob);
                for (Entry<String, MobileObject> entry : pastedComponents.entrySet()) {
                    if (uic.updateSmartSources(entry.getKey(), String.valueOf(entry.getValue().priority))) {
                        uic.markAsDirty();
                    }
                }
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) RequestableStep(com.twinsoft.convertigo.beans.core.RequestableStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Document(org.w3c.dom.Document) Entry(java.util.Map.Entry) StringReader(java.io.StringReader) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) NodeList(org.w3c.dom.NodeList) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) JSONObject(org.codehaus.jettison.json.JSONObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IDesignTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IDesignTreeObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject)

Aggregations

Step (com.twinsoft.convertigo.beans.core.Step)70 Sequence (com.twinsoft.convertigo.beans.core.Sequence)36 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)32 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)26 EngineException (com.twinsoft.convertigo.engine.EngineException)26 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)25 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)24 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)24 TransactionStep (com.twinsoft.convertigo.beans.steps.TransactionStep)21 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)21 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)20 SequenceStep (com.twinsoft.convertigo.beans.steps.SequenceStep)19 RequestableStep (com.twinsoft.convertigo.beans.core.RequestableStep)18 Connector (com.twinsoft.convertigo.beans.core.Connector)17 Project (com.twinsoft.convertigo.beans.core.Project)17 Cursor (org.eclipse.swt.graphics.Cursor)17 Display (org.eclipse.swt.widgets.Display)17 Shell (org.eclipse.swt.widgets.Shell)17 Transaction (com.twinsoft.convertigo.beans.core.Transaction)16 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)16