Search in sources :

Example 6 with ThenStatement

use of com.twinsoft.convertigo.beans.statements.ThenStatement 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)

Example 7 with ThenStatement

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

the class ClipboardManager method cutAndPaste.

public void cutAndPaste(final DatabaseObject object, DatabaseObject parentDatabaseObject) throws ConvertigoException {
    // Verifying if a sheet with the same browser does not already exist
    if (object instanceof Sheet) {
        String browser = ((Sheet) object).getBrowser();
        Sheet sheet = null;
        if (parentDatabaseObject instanceof ScreenClass) {
            sheet = ((ScreenClass) parentDatabaseObject).getLocalSheet(browser);
        } else if (parentDatabaseObject instanceof RequestableObject) {
            sheet = ((RequestableObject) parentDatabaseObject).getSheet(browser);
        }
        if (sheet != null) {
            throw new EngineException("You cannot cut and paste the sheet because a sheet is already defined for the browser \"" + browser + "\" in the screen class \"" + parentDatabaseObject.getName() + "\".");
        }
    }
    if (object instanceof Step) {
        if (object instanceof ThenStep) {
            throw new EngineException("You cannot cut the \"Then\" step");
        }
        if (object instanceof ElseStep) {
            throw new EngineException("You cannot cut the \"Else\" step");
        }
    }
    if (object instanceof Statement) {
        if (object instanceof ThenStatement)
            throw new EngineException("You cannot cut the \"Then\" statement");
        if (object instanceof ElseStatement)
            throw new EngineException("You cannot cut the \"Else\" statement");
    }
    // Verify object is accepted for paste
    if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
        throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
    }
    if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    } else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
            throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
        }
        if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
            String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(object);
            throw new EngineException("Template project " + tplVersion + " compatibility required");
        }
    }
    // Verify if a child object with same name exist
    try {
        new WalkHelper() {

            boolean root = true;

            boolean find = false;

            @Override
            protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
                boolean isInstance = dboClass.isInstance(object);
                find |= isInstance;
                return isInstance;
            }

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                if (root) {
                    root = false;
                    if (databaseObject instanceof Project) {
                        if (object instanceof Connector && ((Connector) object).isDefault) {
                            throw new EngineException("You cannot cut the default connector to another project");
                        }
                    } else if (databaseObject instanceof Connector) {
                        if (object instanceof ScreenClass) {
                            throw new EngineException("You cannot cut the default screen class to another connector");
                        } else if (object instanceof Transaction && ((Transaction) object).isDefault) {
                            throw new EngineException("You cannot cut the default transaction to another connector");
                        }
                    } else if (databaseObject instanceof ScreenClass) {
                        if (object instanceof Criteria && databaseObject.getParent() instanceof Connector) {
                            throw new EngineException("You cannot cut the criterion of default screen class");
                        }
                    } else if (databaseObject instanceof MobileObject) {
                        if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
                            if (object instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
                                com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(object);
                                if (pc.isRoot) {
                                    throw new EngineException("You cannot cut the root page to another application");
                                }
                            }
                        } else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
                            if (object instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
                                com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(object);
                                if (pc.isRoot) {
                                    throw new EngineException("You cannot cut the root page to another application");
                                }
                            }
                        }
                    }
                    super.walk(databaseObject);
                    if (!find) {
                        throw new EngineException("You cannot cut and paste to a " + databaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
                    }
                } else {
                    if (object.getName().equalsIgnoreCase(databaseObject.getName())) {
                        throw new ObjectWithSameNameException("Unable to cut the object because an object with the same name already exists in target.");
                    }
                }
            }
        }.init(parentDatabaseObject);
    } catch (EngineException e) {
        throw e;
    } catch (Exception e) {
        throw new EngineException("Exception in cutAndPaste", e);
    }
    move(object, parentDatabaseObject);
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) 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) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Criteria(com.twinsoft.convertigo.beans.core.Criteria) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) MobileObject(com.twinsoft.convertigo.beans.core.MobileObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) FunctionStatement(com.twinsoft.convertigo.beans.statements.FunctionStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) InvalidOperationException(com.twinsoft.convertigo.engine.InvalidOperationException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Project(com.twinsoft.convertigo.beans.core.Project) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) Transaction(com.twinsoft.convertigo.beans.core.Transaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Sheet(com.twinsoft.convertigo.beans.core.Sheet)

Example 8 with ThenStatement

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

the class DatabaseObjectDeleteAction method delete.

private void delete(DatabaseObject databaseObject) throws EngineException, IOException {
    if (databaseObject instanceof Connector) {
        if (((Connector) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default connector!");
        }
        String projectName = databaseObject.getParent().getName();
        deleteResourcesFolder(projectName, "soap-templates", databaseObject.getName());
        deleteResourcesFolder(projectName, "Traces", databaseObject.getName());
    } else if (databaseObject instanceof Transaction) {
        if (((Transaction) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default transaction!");
        }
    } else if (databaseObject instanceof ScreenClass) {
        if ((databaseObject.getParent()) instanceof Project) {
            throw new EngineException("Cannot delete the root screen class!");
        }
    } else if (databaseObject instanceof Statement) {
        if ((databaseObject instanceof ThenStatement) || (databaseObject instanceof ElseStatement)) {
            throw new EngineException("Cannot delete this statement!");
        }
    } else if (databaseObject instanceof Step) {
        if ((databaseObject instanceof ThenStep) || (databaseObject instanceof ElseStep)) {
            throw new EngineException("Cannot delete this step!");
        }
    } else if (databaseObject instanceof MobilePlatform) {
        MobilePlatform mobilePlatform = (MobilePlatform) databaseObject;
        File resourceFolder = mobilePlatform.getResourceFolder();
        if (resourceFolder.exists()) {
        // MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        // messageBox.setMessage("Do you want to delete the whole resource folder \"" + mobilePlatform.getRelativeResourcePath() + "\"?");
        // messageBox.setText("Delete the \""+resourceFolder.getName()+"\" folder?");
        // if (messageBox.open() == SWT.YES) {
        // FileUtils.deleteQuietly(resourceFolder);
        // }
        }
    } else if (databaseObject instanceof PageComponent) {
        if (((PageComponent) databaseObject).isRoot) {
            throw new EngineException("Cannot delete the root page!");
        }
    }
    if (databaseObject instanceof Project) {
        // Deleted project will be backup, car will be deleted to avoid its deployment at engine restart
        // Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName());
        Engine.theApp.databaseObjectsManager.deleteProjectAndCar(databaseObject.getName());
    // ConvertigoPlugin.getDefault().deleteProjectPluginResource(databaseObject.getName());
    } else {
        databaseObject.delete();
    }
    if (databaseObject instanceof CouchDbConnector) {
        CouchDbConnector couchDbConnector = (CouchDbConnector) databaseObject;
        String db = couchDbConnector.getDatabaseName();
        if (!db.isEmpty()) {
        // MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        // messageBox.setMessage("Do you want to delete the \""+db+"\" database from the CouchDb server?");
        // messageBox.setText("Delete the database?");
        // if (messageBox.open() == SWT.YES) {
        // couchDbConnector.getCouchClient().deleteDatabase(db);
        // }
        }
    }
// ConvertigoPlugin.logDebug("The object \"" + databaseObject.getQName() + "\" has been deleted from the database repository!");
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) EngineException(com.twinsoft.convertigo.engine.EngineException) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) Project(com.twinsoft.convertigo.beans.core.Project) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) File(java.io.File)

Aggregations

ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)8 Statement (com.twinsoft.convertigo.beans.core.Statement)7 ElseStatement (com.twinsoft.convertigo.beans.statements.ElseStatement)7 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)5 ThenStep (com.twinsoft.convertigo.beans.steps.ThenStep)5 Connector (com.twinsoft.convertigo.beans.core.Connector)4 Project (com.twinsoft.convertigo.beans.core.Project)4 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)4 Step (com.twinsoft.convertigo.beans.core.Step)4 Transaction (com.twinsoft.convertigo.beans.core.Transaction)4 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)4 EngineException (com.twinsoft.convertigo.engine.EngineException)4 StatementWithExpressions (com.twinsoft.convertigo.beans.core.StatementWithExpressions)3 PageComponent (com.twinsoft.convertigo.beans.mobile.components.PageComponent)3 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)3 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)3 File (java.io.File)3 IOException (java.io.IOException)3 CouchDbConnector (com.twinsoft.convertigo.beans.connectors.CouchDbConnector)2