Search in sources :

Example 1 with IfXpathExistsThenElseStatement

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

the class ChangeToIfXpathExistsThenElseStatementAction 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) {
            DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
            DatabaseObject databaseObject = treeObject.getObject();
            // IfXpathExists
            if ((databaseObject != null) && (databaseObject instanceof IfXpathExistsStatement)) {
                IfXpathExistsStatement ifStatement = (IfXpathExistsStatement) databaseObject;
                DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
                if (parentTreeObject != null) {
                    // New IfXpathExistsThenElseStatement statement
                    IfXpathExistsThenElseStatement ifThenElseStatement = new IfXpathExistsThenElseStatement();
                    ifThenElseStatement.bNew = true;
                    ifThenElseStatement.hasChanged = true;
                    // Add new IfThenElseStatement statement to parent
                    StatementWithExpressions parentDbo = (StatementWithExpressions) ifStatement.getParent();
                    parentDbo.addStatementAfter(ifThenElseStatement, ifStatement);
                    // Add Then/Else statement
                    ThenStatement thenStatement = new ThenStatement();
                    thenStatement.bNew = true;
                    ifThenElseStatement.addStatement(thenStatement);
                    ElseStatement elseStatement = new ElseStatement();
                    elseStatement.bNew = true;
                    ifThenElseStatement.addStatement(elseStatement);
                    for (Statement statement : ifStatement.getStatements()) {
                        thenStatement.addStatement(statement);
                    }
                    String name = ifStatement.getName();
                    // Set properties
                    ifThenElseStatement.setCondition(ifStatement.getCondition());
                    ifThenElseStatement.setComment(ifStatement.getComment());
                    ifThenElseStatement.setEnabled(ifStatement.isEnabled());
                    ifThenElseStatement.setVersion(ifStatement.getVersion());
                    // Delete If statement
                    ifStatement.delete();
                    ifThenElseStatement.setName(name);
                    parentTreeObject.hasBeenModified(true);
                    explorerView.reloadTreeObject(parentTreeObject);
                    explorerView.setSelectedTreeObject(parentTreeObject.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) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) IfXpathExistsThenElseStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsThenElseStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) IfXpathExistsStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsStatement) IfXpathExistsThenElseStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsThenElseStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) StatementWithExpressions(com.twinsoft.convertigo.beans.core.StatementWithExpressions) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) IfXpathExistsThenElseStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsThenElseStatement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) IfXpathExistsStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsStatement) Display(org.eclipse.swt.widgets.Display)

Example 2 with IfXpathExistsThenElseStatement

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

the class ChangeToIfXpathExistsStatementAction 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) {
            DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) explorerView.getFirstSelectedTreeObject();
            DatabaseObject databaseObject = treeObject.getObject();
            if ((databaseObject != null) && (databaseObject instanceof IfXpathExistsThenElseStatement)) {
                IfXpathExistsThenElseStatement ifThenElseStatement = (IfXpathExistsThenElseStatement) databaseObject;
                // IfXpathExistsThenElse statement
                if (ifThenElseStatement.hasThenElseStatements()) {
                    DatabaseObjectTreeObject parentTreeObject = treeObject.getOwnerDatabaseObjectTreeObject();
                    if (parentTreeObject != null) {
                        // New IfXpathExistsStatement statement
                        IfXpathExistsStatement ifStatement = new IfXpathExistsStatement();
                        ifStatement.bNew = true;
                        ifStatement.hasChanged = true;
                        // Add new If statement to parent
                        StatementWithExpressions parentDbo = (StatementWithExpressions) ifThenElseStatement.getParent();
                        parentDbo.addStatementAfter(ifStatement, ifThenElseStatement);
                        for (Statement statement : ifThenElseStatement.getThenStatement().getStatements()) {
                            ifStatement.addStatement(statement);
                        }
                        // Set properties
                        ifStatement.setCondition(ifThenElseStatement.getCondition());
                        ifStatement.setComment(ifThenElseStatement.getComment());
                        ifStatement.setEnabled(ifThenElseStatement.isEnabled());
                        ifStatement.setVersion(ifThenElseStatement.getVersion());
                        String name = ifThenElseStatement.getName();
                        // Delete IfThenElse statement
                        ifThenElseStatement.delete();
                        ifStatement.setName(name);
                        parentTreeObject.hasBeenModified(true);
                        explorerView.reloadTreeObject(parentTreeObject);
                        explorerView.setSelectedTreeObject(parentTreeObject.findTreeObjectByUserObject(ifStatement));
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to change statement to If statement!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) StatementWithExpressions(com.twinsoft.convertigo.beans.core.StatementWithExpressions) IfXpathExistsThenElseStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsThenElseStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) IfXpathExistsStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsStatement) IfXpathExistsThenElseStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsThenElseStatement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Cursor(org.eclipse.swt.graphics.Cursor) IfXpathExistsStatement(com.twinsoft.convertigo.beans.statements.IfXpathExistsStatement) 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 IfXpathExistsStatement (com.twinsoft.convertigo.beans.statements.IfXpathExistsStatement)2 IfXpathExistsThenElseStatement (com.twinsoft.convertigo.beans.statements.IfXpathExistsThenElseStatement)2 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)2 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)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 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)1