Search in sources :

Example 11 with TreePath

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath 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)11 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)11 TreePath (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreePath)11 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)11 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)11 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)10 Cursor (org.eclipse.swt.graphics.Cursor)10 Display (org.eclipse.swt.widgets.Display)10 Shell (org.eclipse.swt.widgets.Shell)10 Sequence (com.twinsoft.convertigo.beans.core.Sequence)8 Step (com.twinsoft.convertigo.beans.core.Step)8 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)8 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)8 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)8 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)8 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)4 IfExistStep (com.twinsoft.convertigo.beans.steps.IfExistStep)3 IfExistThenElseStep (com.twinsoft.convertigo.beans.steps.IfExistThenElseStep)3 IsInStep (com.twinsoft.convertigo.beans.steps.IsInStep)3 IsInThenElseStep (com.twinsoft.convertigo.beans.steps.IsInThenElseStep)3