Search in sources :

Example 1 with IfStatement

use of com.twinsoft.convertigo.beans.statements.IfStatement in project convertigo by convertigo.

the class ChangeToIfStatementAction 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 IfThenElseStatement)) {
                IfThenElseStatement ifThenElseStatement = (IfThenElseStatement) databaseObject;
                if (ifThenElseStatement.hasThenElseStatements()) {
                    ThenStatement thenStatement = ifThenElseStatement.getThenStatement();
                    List<Statement> list = thenStatement.getStatements();
                    TreePath[] selectedPaths = new TreePath[list.size()];
                    for (int i = 0; i < list.size(); i++) {
                        StatementTreeObject statementTreeObject = (StatementTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                        selectedPaths[i] = new TreePath(statementTreeObject);
                    }
                    TreeParent treeParent = treeObject.getParent();
                    DatabaseObjectTreeObject parentTreeObject = null;
                    if (treeParent instanceof DatabaseObjectTreeObject)
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                    else
                        parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                    if (parentTreeObject != null) {
                        // New If statement
                        IfStatement ifStatement = new IfStatement(ifThenElseStatement.getCondition());
                        ifStatement.bNew = true;
                        ifStatement.hasChanged = true;
                        // Add new If statement to parent
                        DatabaseObject parentDbo = ifThenElseStatement.getParent();
                        parentDbo.add(ifStatement);
                        // Set correct order
                        if (parentDbo instanceof StatementWithExpressions) {
                            int index = ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).indexOf(ifThenElseStatement.priority);
                            ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).add(index, ifStatement.priority);
                        }
                        // Add new If statement in Tree
                        StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, ifStatement);
                        treeParent.addChild(statementTreeObject);
                        // Cut/Paste steps under If statement
                        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], statementTreeObject);
                            }
                            ConvertigoPlugin.clipboardManagerDND.reset();
                        }
                        // Delete IfThenElse statement
                        ifThenElseStatement.delete();
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifStatement));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change statement to If statement!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfThenElseStatement(com.twinsoft.convertigo.beans.statements.IfThenElseStatement) IfStatement(com.twinsoft.convertigo.beans.statements.IfStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) IfThenElseStatement(com.twinsoft.convertigo.beans.statements.IfThenElseStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Cursor(org.eclipse.swt.graphics.Cursor) IfStatement(com.twinsoft.convertigo.beans.statements.IfStatement) Shell(org.eclipse.swt.widgets.Shell) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) StatementWithExpressions(com.twinsoft.convertigo.beans.core.StatementWithExpressions) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) 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) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 2 with IfStatement

use of com.twinsoft.convertigo.beans.statements.IfStatement in project convertigo by convertigo.

the class ChangeToIfThenElseStatementAction 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 IfStatement)) {
                IfStatement ifStatement = (IfStatement) databaseObject;
                List<Statement> list = ifStatement.getStatements();
                TreePath[] selectedPaths = new TreePath[list.size()];
                for (int i = 0; i < list.size(); i++) {
                    StatementTreeObject statementTreeObject = (StatementTreeObject) explorerView.findTreeObjectByUserObject(list.get(i));
                    selectedPaths[i] = new TreePath(statementTreeObject);
                }
                TreeParent treeParent = treeObject.getParent();
                DatabaseObjectTreeObject parentTreeObject = null;
                if (treeParent instanceof DatabaseObjectTreeObject)
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent;
                else
                    parentTreeObject = (DatabaseObjectTreeObject) treeParent.getParent();
                if (parentTreeObject != null) {
                    // New IfThenElseStatement statement
                    IfThenElseStatement ifThenElseStatement = new IfThenElseStatement(ifStatement.getCondition());
                    ifThenElseStatement.bNew = true;
                    ifThenElseStatement.hasChanged = true;
                    // Add new IfThenElseStatement statement to parent
                    DatabaseObject parentDbo = ifStatement.getParent();
                    parentDbo.add(ifThenElseStatement);
                    // Set correct order
                    if (parentDbo instanceof StatementWithExpressions) {
                        int index = ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).indexOf(ifStatement.priority);
                        ((StatementWithExpressions) parentDbo).getOrderedStatements().get(0).add(index, ifThenElseStatement.priority);
                    }
                    // Add Then/Else statement
                    ThenStatement thenStatement = new ThenStatement();
                    thenStatement.bNew = true;
                    ifThenElseStatement.addStatement(thenStatement);
                    ElseStatement elseStatement = new ElseStatement();
                    elseStatement.bNew = true;
                    ifThenElseStatement.addStatement(elseStatement);
                    // Add new IfThenElseStep statement in Tree
                    StatementTreeObject statementTreeObject = new StatementTreeObject(explorerView.viewer, ifThenElseStatement);
                    treeParent.addChild(statementTreeObject);
                    StatementTreeObject thenTreeObject = new StatementTreeObject(explorerView.viewer, thenStatement);
                    statementTreeObject.addChild(thenTreeObject);
                    StatementTreeObject elseTreeObject = new StatementTreeObject(explorerView.viewer, elseStatement);
                    statementTreeObject.addChild(elseTreeObject);
                    // Cut/Paste steps under Then statement
                    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 statement
                    ifStatement.delete();
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(explorerView.findTreeObjectByUserObject(ifThenElseStatement));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change statement to IfThenElse statement!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) IfThenElseStatement(com.twinsoft.convertigo.beans.statements.IfThenElseStatement) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) IfStatement(com.twinsoft.convertigo.beans.statements.IfStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) IfThenElseStatement(com.twinsoft.convertigo.beans.statements.IfThenElseStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Cursor(org.eclipse.swt.graphics.Cursor) IfStatement(com.twinsoft.convertigo.beans.statements.IfStatement) Shell(org.eclipse.swt.widgets.Shell) TreePath(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath) StatementWithExpressions(com.twinsoft.convertigo.beans.core.StatementWithExpressions) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) IfThenElseStatement(com.twinsoft.convertigo.beans.statements.IfThenElseStatement) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) 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) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) Display(org.eclipse.swt.widgets.Display)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)2 Statement (com.twinsoft.convertigo.beans.core.Statement)2 StatementWithExpressions (com.twinsoft.convertigo.beans.core.StatementWithExpressions)2 IfStatement (com.twinsoft.convertigo.beans.statements.IfStatement)2 IfThenElseStatement (com.twinsoft.convertigo.beans.statements.IfThenElseStatement)2 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)2 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)2 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)2 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)2 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)2 StatementTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject)2 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)2 Cursor (org.eclipse.swt.graphics.Cursor)2 Display (org.eclipse.swt.widgets.Display)2 Shell (org.eclipse.swt.widgets.Shell)2 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)1