Search in sources :

Example 6 with StepEvent

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

the class ChangeToIfThenElseStepAction method run.

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

Example 7 with StepEvent

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

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

Example 8 with StepEvent

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

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

Example 9 with StepEvent

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

the class ChangeToXMLConcatStepAction 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 XMLElementStep)) {
                XMLElementStep elementStep = (XMLElementStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New XMLConcatStep step
                    XMLConcatStep concatStep = new XMLConcatStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(elementStep.getParent(), concatStep)) {
                        XMLVector<XMLVector<Object>> sources = new XMLVector<XMLVector<Object>>();
                        XMLVector<Object> source = new XMLVector<Object>();
                        source.add("description");
                        source.add(elementStep.getSourceDefinition());
                        source.add(elementStep.getNodeText());
                        sources.add(source);
                        concatStep.setOutput(elementStep.isOutput());
                        concatStep.setEnabled(elementStep.isEnabled());
                        concatStep.setComment(elementStep.getComment());
                        // elementStep.getNodeText();
                        concatStep.setNodeName(elementStep.getNodeName());
                        concatStep.setSourcesDefinition(sources);
                        concatStep.bNew = true;
                        concatStep.hasChanged = true;
                        // Add new XMLConcatStep step to parent
                        DatabaseObject parentDbo = elementStep.getParent();
                        parentDbo.add(concatStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(concatStep, elementStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(concatStep, elementStep.priority);
                        // Add new XMLConcatStep step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, concatStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete XMLElementStep step
                        long oldPriority = elementStep.priority;
                        elementStep.delete();
                        concatStep.getSequence().fireStepMoved(new StepEvent(concatStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(concatStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + elementStep.getParent().getClass().getSimpleName() + " a database object of type " + concatStep.getClass().getSimpleName());
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change XMLElement to XMLConcat 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) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) 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) XMLConcatStep(com.twinsoft.convertigo.beans.steps.XMLConcatStep) Sequence(com.twinsoft.convertigo.beans.core.Sequence) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) 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 10 with StepEvent

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

the class ChangeToXMLElementStepAction method run.

/* (non-Javadoc)
	 * @see com.twinsoft.convertigo.eclipse.popup.actions.MyAbstractAction#run()
	 */
@SuppressWarnings("unchecked")
@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();
            // XML Concat step
            if ((databaseObject != null) && (databaseObject instanceof XMLConcatStep)) {
                XMLConcatStep concatStep = (XMLConcatStep) databaseObject;
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New XMLElementStep step
                    XMLElementStep elementStep = new XMLElementStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(concatStep.getParent(), elementStep)) {
                        if (concatStep.getSourcesDefinition().toString().equals("[[]]")) {
                            elementStep.setSourceDefinition(new XMLVector<String>());
                        } else {
                            // Set properties (Default value and Source)
                            XMLVector<XMLVector<Object>> sources = concatStep.getSourcesDefinition();
                            XMLVector<String> sourceDefinition = new XMLVector<String>();
                            String defaultValue = "";
                            for (XMLVector<Object> source : sources) {
                                if (sources.lastElement() == source) {
                                    defaultValue += source.get(2);
                                } else {
                                    defaultValue += source.get(2) + concatStep.getSeparator();
                                }
                                if (sourceDefinition.toString().equals("[]") && (!source.get(1).toString().equals("") && !source.get(1).toString().equals("[]"))) {
                                    sourceDefinition = (XMLVector<String>) source.get(1);
                                }
                            }
                            elementStep.setOutput(concatStep.isOutput());
                            elementStep.setEnabled(concatStep.isEnabled());
                            elementStep.setComment(concatStep.getComment());
                            elementStep.setNodeName(concatStep.getNodeName());
                            elementStep.setNodeText(defaultValue);
                            elementStep.setSourceDefinition(sourceDefinition);
                        }
                        elementStep.bNew = true;
                        elementStep.hasChanged = true;
                        // Add new XMLElementStep step to parent
                        DatabaseObject parentDbo = concatStep.getParent();
                        parentDbo.add(elementStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(elementStep, concatStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(elementStep, concatStep.priority);
                        // Add new XMLElementStep step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, elementStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete XMLConcatStep step
                        long oldPriority = concatStep.priority;
                        concatStep.delete();
                        elementStep.getSequence().fireStepMoved(new StepEvent(elementStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(elementStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + concatStep.getParent().getClass().getSimpleName() + " a database object of type " + elementStep.getClass().getSimpleName());
                    }
                }
            }
            // XML Attribute
            if ((databaseObject != null) && (databaseObject instanceof XMLAttributeStep)) {
                XMLAttributeStep attributeStep = (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 XMLElement step
                    XMLElementStep elementStep = new XMLElementStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(attributeStep.getParent(), elementStep)) {
                        // Set properties
                        elementStep.setOutput(attributeStep.isOutput());
                        elementStep.setEnabled(attributeStep.isEnabled());
                        elementStep.setComment(attributeStep.getComment());
                        elementStep.setSourceDefinition(attributeStep.getSourceDefinition());
                        elementStep.setNodeText(attributeStep.getNodeText());
                        elementStep.setNodeName(attributeStep.getNodeName());
                        elementStep.bNew = true;
                        elementStep.hasChanged = true;
                        // Add new XMLElement step to parent
                        DatabaseObject parentDbo = attributeStep.getParent();
                        parentDbo.add(elementStep);
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(elementStep, attributeStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(elementStep, attributeStep.priority);
                        // Add new XMLElement step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, attributeStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete XMLAttribute step
                        long oldPriority = attributeStep.priority;
                        attributeStep.delete();
                        elementStep.getSequence().fireStepMoved(new StepEvent(elementStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(elementStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + attributeStep.getParent().getClass().getSimpleName() + " a database object of type " + elementStep.getClass().getSimpleName());
                    }
                }
            }
            // JElement
            if ((databaseObject != null) && (databaseObject instanceof ElementStep)) {
                ElementStep jelementStep = (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 XMLElement step
                    XMLElementStep elementStep = new XMLElementStep();
                    if (DatabaseObjectsManager.acceptDatabaseObjects(jelementStep.getParent(), elementStep)) {
                        // Set properties
                        elementStep.setOutput(jelementStep.isOutput());
                        elementStep.setEnabled(jelementStep.isEnabled());
                        elementStep.setComment(jelementStep.getComment());
                        // elementStep.setSourceDefinition(jelementStep.getSourceDefinition());
                        elementStep.setNodeText(jelementStep.getNodeText());
                        elementStep.setNodeName(jelementStep.getNodeName());
                        elementStep.bNew = true;
                        elementStep.hasChanged = true;
                        // Add new XMLElement step to parent
                        DatabaseObject parentDbo = jelementStep.getParent();
                        parentDbo.add(elementStep);
                        for (Step step : jelementStep.getAllSteps()) {
                            try {
                                elementStep.addStep(step);
                            } catch (Throwable t) {
                            }
                        }
                        // Set correct order
                        if (parentDbo instanceof StepWithExpressions)
                            ((StepWithExpressions) parentDbo).insertAtOrder(elementStep, jelementStep.priority);
                        else if (parentDbo instanceof Sequence)
                            ((Sequence) parentDbo).insertAtOrder(elementStep, jelementStep.priority);
                        // Add new XMLElement step in Tree
                        StepTreeObject stepTreeObject = new StepTreeObject(explorerView.viewer, jelementStep);
                        treeParent.addChild(stepTreeObject);
                        // Delete XMLAttribute step
                        long oldPriority = jelementStep.priority;
                        jelementStep.delete();
                        elementStep.getSequence().fireStepMoved(new StepEvent(elementStep, String.valueOf(oldPriority)));
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(elementStep));
                    } else {
                        throw new EngineException("You cannot paste to a " + jelementStep.getParent().getClass().getSimpleName() + " a database object of type " + elementStep.getClass().getSimpleName());
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change step to XMLElement step!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) StepWithExpressions(com.twinsoft.convertigo.beans.core.StepWithExpressions) EngineException(com.twinsoft.convertigo.engine.EngineException) XMLConcatStep(com.twinsoft.convertigo.beans.steps.XMLConcatStep) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) Step(com.twinsoft.convertigo.beans.core.Step) ElementStep(com.twinsoft.convertigo.beans.steps.ElementStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) XMLConcatStep(com.twinsoft.convertigo.beans.steps.XMLConcatStep) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ElementStep(com.twinsoft.convertigo.beans.steps.ElementStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) StepEvent(com.twinsoft.convertigo.beans.core.StepEvent) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Sequence(com.twinsoft.convertigo.beans.core.Sequence) XMLAttributeStep(com.twinsoft.convertigo.beans.steps.XMLAttributeStep) StepTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject) 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) Display(org.eclipse.swt.widgets.Display)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)16 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)16 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)16 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)16 Sequence (com.twinsoft.convertigo.beans.core.Sequence)15 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)15 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)15 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)15 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)15 Cursor (org.eclipse.swt.graphics.Cursor)15 Display (org.eclipse.swt.widgets.Display)15 Shell (org.eclipse.swt.widgets.Shell)15 Step (com.twinsoft.convertigo.beans.core.Step)11 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)9 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)8 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)5 EngineException (com.twinsoft.convertigo.engine.EngineException)5 XMLElementStep (com.twinsoft.convertigo.beans.steps.XMLElementStep)4 AttributeStep (com.twinsoft.convertigo.beans.steps.AttributeStep)3 ElementStep (com.twinsoft.convertigo.beans.steps.ElementStep)3