Search in sources :

Example 16 with StepTreeObject

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

the class ChangeToSourceStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
	 */
@Override
public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            if ((databaseObject != null) && (databaseObject instanceof SimpleSourceStep)) {
                SimpleSourceStep jSimpleSourceStep = (SimpleSourceStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New jSource step
                    SourceStep jSourceStep = new SourceStep();
                    // Set properties
                    jSourceStep.setSourceDefinition(jSimpleSourceStep.getSourceDefinition());
                    jSourceStep.setComment(jSimpleSourceStep.getComment());
                    jSourceStep.setVariableName(jSimpleSourceStep.getVariableName());
                    jSourceStep.setEnabled(jSimpleSourceStep.isEnabled());
                    jSourceStep.setOutput(jSimpleSourceStep.isOutput());
                    jSourceStep.setName(jSimpleSourceStep.getName());
                    jSourceStep.bNew = true;
                    jSourceStep.hasChanged = true;
                    // Add new jSource step to parent
                    DatabaseObject parentDbo = jSimpleSourceStep.getParent();
                    parentDbo.add(jSourceStep);
                    // Set correct order
                    if (parentDbo instanceof StepWithExpressions)
                        ((StepWithExpressions) parentDbo).insertAtOrder(jSourceStep, jSimpleSourceStep.priority);
                    else if (parentDbo instanceof Sequence)
                        ((Sequence) parentDbo).insertAtOrder(jSourceStep, jSimpleSourceStep.priority);
                    // Add new jSource step in Tree
                    StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, jSourceStep);
                    treeParent.addChild(stepTreeObject);
                    // Delete jSimpleSource step
                    long oldPriority = jSimpleSourceStep.priority;
                    jSimpleSourceStep.delete();
                    // Simulate move of jSimpleSource to jSource step
                    jSourceStep.getSequence().fireStepMoved(new StepEvent(jSourceStep, String.valueOf(oldPriority)));
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(jSourceStep));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to jSource step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) SimpleSourceStep(com.twinsoft.convertigo.beans.steps.SimpleSourceStep) Shell(org.eclipse.swt.widgets.Shell) SourceStep(com.twinsoft.convertigo.beans.steps.SourceStep) SimpleSourceStep(com.twinsoft.convertigo.beans.steps.SimpleSourceStep) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 17 with StepTreeObject

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

the class ChangeToAttributeStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
	 */
@Override
public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            Object databaseObject = treeObject.getObject();
            // XMLAttribute
            if ((databaseObject != null) && (databaseObject instanceof XMLAttributeStep)) {
                XMLAttributeStep xmlAttributeStep = (XMLAttributeStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New Attribute step
                    AttributeStep attributeStep = new AttributeStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(xmlAttributeStep.getParent(), attributeStep)) {
                        // Set properties
                        attributeStep.setOutput(xmlAttributeStep.isOutput());
                        attributeStep.setEnabled(xmlAttributeStep.isEnabled());
                        attributeStep.setComment(xmlAttributeStep.getComment());
                        // attributeStep.setExpression(elementStep.getExpression());
                        attributeStep.setNodeText(xmlAttributeStep.getNodeText());
                        attributeStep.setNodeName(xmlAttributeStep.getNodeName());
                        attributeStep.bNew = true;
                        attributeStep.hasChanged = true;
                        // Add new Attribute step to parent
                        DatabaseObject parentDbo = xmlAttributeStep.getParent();
                        parentDbo.add(attributeStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(attributeStep, xmlAttributeStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(attributeStep, xmlAttributeStep.priority);
                        // Add new Attribute step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, xmlAttributeStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete Element step
                        long oldPriority = xmlAttributeStep.priority;
                        xmlAttributeStep.delete();
                        attributeStep.getSequence().fireStepMoved(new StepEvent(attributeStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(attributeStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + xmlAttributeStep.getParent().getClass().getSimpleName() + " a database object of type " + attributeStep.getClass().getSimpleName());
                    }
                }
            }
            // Element
            if ((databaseObject != null) && (databaseObject instanceof ElementStep)) {
                ElementStep elementStep = (ElementStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New Attribute step
                    AttributeStep attributeStep = new AttributeStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(elementStep.getParent(), attributeStep)) {
                        // Set properties
                        attributeStep.setOutput(elementStep.isOutput());
                        attributeStep.setEnabled(elementStep.isEnabled());
                        attributeStep.setComment(elementStep.getComment());
                        attributeStep.setExpression(elementStep.getExpression());
                        attributeStep.setNodeText(elementStep.getNodeText());
                        attributeStep.setNodeName(elementStep.getNodeName());
                        attributeStep.bNew = true;
                        attributeStep.hasChanged = true;
                        // Add new Attribute step to parent
                        DatabaseObject parentDbo = elementStep.getParent();
                        parentDbo.add(attributeStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(attributeStep, elementStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(attributeStep, elementStep.priority);
                        // Add new Attribute step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, elementStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete Element step
                        long oldPriority = elementStep.priority;
                        elementStep.delete();
                        attributeStep.getSequence().fireStepMoved(new StepEvent(attributeStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(attributeStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + elementStep.getParent().getClass().getSimpleName() + " a database object of type " + attributeStep.getClass().getSimpleName());
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change to Attribute step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) EngineException(com.twinsoft.convertigo.engine.EngineException) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) AttributeStep(com.twinsoft.convertigo.beans.steps.AttributeStep) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) ElementStep(com.twinsoft.convertigo.beans.steps.ElementStep) Display(org.eclipse.swt.widgets.Display)

Example 18 with StepTreeObject

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

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

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

the class ReferencesView method handleCallStepselection.

private void handleCallStepselection(Object firstElement) {
    try {
        ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
        StepTreeObject stepTreeObject = (StepTreeObject) firstElement;
        Step step = stepTreeObject.getObject();
        RootNode root = new RootNode();
        if (step instanceof TransactionStep) {
            TransactionStep transactionStep = (TransactionStep) step;
            String transactionStepName = transactionStep.getName();
            TransactionStepNode transactionStepNode = new TransactionStepNode(root, transactionStepName, transactionStep);
            RequiresNode requiresNode = new RequiresNode(transactionStepNode, "Requires");
            String transactionName = transactionStep.getTransactionName();
            String connectorName = transactionStep.getConnectorName();
            String projectName = transactionStep.getProjectName();
            Project project = getProject(projectName, projectExplorerView);
            ProjectNode projectNode = new ProjectNode(requiresNode, projectName, project);
            Connector connector = null;
            Transaction transaction = null;
            try {
                if (project != null) {
                    connector = project.getConnectorByName(connectorName);
                    if (connector != null) {
                        transaction = connector.getTransactionByName(transactionName);
                    }
                }
            } catch (EngineException e) {
                connector = null;
                transaction = null;
            }
            ConnectorNode connectorNode = getConnectorNode(projectNode, connector);
            if (connectorNode == null)
                connectorNode = new ConnectorNode(projectNode, connectorName, connector);
            projectNode.addChild(connectorNode);
            TransactionNode transactionNode = new TransactionNode(projectNode, transactionName, transaction);
            connectorNode.addChild(transactionNode);
            requiresNode.addChild(projectNode);
            transactionStepNode.addChild(requiresNode);
            root.addChild(transactionStepNode);
        } else if (step instanceof SequenceStep) {
            SequenceStep sequenceStep = (SequenceStep) step;
            String sequenceStepName = sequenceStep.getName();
            SequenceStepNode sequenceStepNode = new SequenceStepNode(root, sequenceStepName, sequenceStep);
            RequiresNode requiresNode = new RequiresNode(sequenceStepNode, "Requires");
            String sequenceName = sequenceStep.getSequenceName();
            String projectName = sequenceStep.getProjectName();
            Project project = getProject(projectName, projectExplorerView);
            ProjectNode projectNode = new ProjectNode(requiresNode, projectName, project);
            Sequence sequence = null;
            try {
                if (project != null)
                    sequence = project.getSequenceByName(sequenceName);
            } catch (EngineException e) {
                sequence = null;
            }
            projectNode.addChild(new SequenceNode(projectNode, sequenceName, sequence));
            requiresNode.addChild(projectNode);
            sequenceStepNode.addChild(requiresNode);
            root.addChild(sequenceStepNode);
        } else {
            root.addChild(new InformationNode(root, "References are not handled for this object"));
            treeViewer.setInput(root);
        }
        treeViewer.setInput(root);
        treeViewer.expandAll();
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Error while analyzing the projects hierarchy", true);
    }
}
Also used : RootNode(com.twinsoft.convertigo.eclipse.views.references.model.RootNode) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) ProxyHttpConnector(com.twinsoft.convertigo.beans.connectors.ProxyHttpConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) 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) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) BranchStep(com.twinsoft.convertigo.beans.steps.BranchStep) XMLComplexStep(com.twinsoft.convertigo.beans.steps.XMLComplexStep) BlockStep(com.twinsoft.convertigo.beans.steps.BlockStep) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SequenceStepNode(com.twinsoft.convertigo.eclipse.views.references.model.SequenceStepNode) ConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.ConnectorNode) SiteClipperConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.SiteClipperConnectorNode) HtmlConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.HtmlConnectorNode) JavelinConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.JavelinConnectorNode) CicsConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.CicsConnectorNode) SqlConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.SqlConnectorNode) ProxyHttpConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.ProxyHttpConnectorNode) HttpConnectorNode(com.twinsoft.convertigo.eclipse.views.references.model.HttpConnectorNode) SequenceNode(com.twinsoft.convertigo.eclipse.views.references.model.SequenceNode) EngineException(com.twinsoft.convertigo.engine.EngineException) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) Project(com.twinsoft.convertigo.beans.core.Project) TransactionStepNode(com.twinsoft.convertigo.eclipse.views.references.model.TransactionStepNode) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) RequiresNode(com.twinsoft.convertigo.eclipse.views.references.model.RequiresNode) TransactionNode(com.twinsoft.convertigo.eclipse.views.references.model.TransactionNode) InformationNode(com.twinsoft.convertigo.eclipse.views.references.model.InformationNode) ProjectNode(com.twinsoft.convertigo.eclipse.views.references.model.ProjectNode)

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