Search in sources :

Example 6 with StepTreeObject

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

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

Example 7 with StepTreeObject

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

the class ChangeToIfFileExistStepAction method run.

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

Example 8 with StepTreeObject

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

the class ChangeToIfFileExistThenElseStepAction method run.

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

Example 9 with StepTreeObject

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject 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 10 with StepTreeObject

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject 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)

Aggregations

StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)23 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)22 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)22 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)20 Cursor (org.eclipse.swt.graphics.Cursor)19 Display (org.eclipse.swt.widgets.Display)19 Shell (org.eclipse.swt.widgets.Shell)19 Sequence (com.twinsoft.convertigo.beans.core.Sequence)18 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)16 Step (com.twinsoft.convertigo.beans.core.Step)15 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)15 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)15 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)15 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)9 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)8 EngineException (com.twinsoft.convertigo.engine.EngineException)6 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)5 AttributeStep (com.twinsoft.convertigo.beans.steps.AttributeStep)4 IfExistStep (com.twinsoft.convertigo.beans.steps.IfExistStep)3 XMLAttributeStep (com.twinsoft.convertigo.beans.steps.XMLAttributeStep)3