Search in sources :

Example 11 with Statement

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

the class FunctionStatement method executeNextStatement.

@Override
public boolean executeNextStatement(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (hasStatements()) {
            List<Statement> v = getStatements();
            if (currentChildStatement < v.size()) {
                Statement st = (Statement) v.get(currentChildStatement);
                executeNextStatement(st, javascriptContext, scope);
                if (bContinue)
                    return executeNextStatement(javascriptContext, scope);
            }
        }
        return true;
    }
    return false;
}
Also used : Statement(com.twinsoft.convertigo.beans.core.Statement)

Example 12 with Statement

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

the class BlockStatement method executeNextStatement.

public boolean executeNextStatement(Context javascriptContext, Scriptable scope) throws EngineException {
    if (isEnabled()) {
        if (hasStatements()) {
            if (currentChildStatement < numberOfStatements()) {
                Statement st = (Statement) getStatements().get(currentChildStatement);
                executeNextStatement(st, javascriptContext, scope);
                if (bContinue)
                    return executeNextStatement(javascriptContext, scope);
            } else {
                if (isLoop) {
                    currentChildStatement = 0;
                    if (bContinue)
                        return doLoop(javascriptContext, scope);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Statement(com.twinsoft.convertigo.beans.core.Statement)

Example 13 with Statement

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

the class DatabaseObjectDeleteAction method delete.

private void delete(DatabaseObject databaseObject, boolean deleteProjectOnDisk) throws EngineException, CoreException {
    if (databaseObject instanceof Connector) {
        if (((Connector) databaseObject).isDefault) {
            throw new EngineException("Cannot delete the default connector!");
        }
        String dirPath, projectName;
        File dir;
        projectName = databaseObject.getParent().getName();
        MessageBox messageBox = new MessageBox(getParentShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
        messageBox.setText("Also delete linked resources?");
        // Delete soap templates for this connector
        dirPath = Engine.projectDir(projectName) + "/soap-templates/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
        // Delete directory corresponding to connector under Traces directory
        dirPath = Engine.projectDir(projectName) + "/Traces/" + databaseObject.getName();
        dir = new File(dirPath);
        if (dir.exists()) {
            messageBox.setMessage("Some resources are linked to the deleted connector.\n\n" + "Do you also want to delete folder:\n\n\"" + dirPath + "\"");
            if (messageBox.open() == SWT.YES) {
                try {
                    DatabaseObjectsManager.deleteDir(dir);
                } catch (IOException e) {
                    ConvertigoPlugin.logDebug("Unable to delete directory \"" + dirPath + "\"!");
                }
            }
        }
    } 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!");
        }
    }
    String dboQName = databaseObject.getQName();
    if (databaseObject instanceof Project) {
        // Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName());
        if (deleteProjectOnDisk) {
            Engine.theApp.databaseObjectsManager.deleteProjectAndCar(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        } else {
            Engine.theApp.databaseObjectsManager.deleteProject(databaseObject.getName(), DeleteProjectOption.unloadOnly);
        }
        ConvertigoPlugin.getDefault().deleteProjectPluginResource(deleteProjectOnDisk, 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 \"" + dboQName + "\" has been deleted from the database repository!");
}
Also used : CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) ElseStatement(com.twinsoft.convertigo.beans.statements.ElseStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) EngineException(com.twinsoft.convertigo.engine.EngineException) ThenStatement(com.twinsoft.convertigo.beans.statements.ThenStatement) IOException(java.io.IOException) Step(com.twinsoft.convertigo.beans.core.Step) ElseStep(com.twinsoft.convertigo.beans.steps.ElseStep) ThenStep(com.twinsoft.convertigo.beans.steps.ThenStep) SimpleStep(com.twinsoft.convertigo.beans.steps.SimpleStep) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) PageComponent(com.twinsoft.convertigo.beans.mobile.components.PageComponent) MessageBox(org.eclipse.swt.widgets.MessageBox) 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)

Example 14 with Statement

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

the class DisableStatementAction method run.

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 = null;
            Statement statement = null;
            TreeObject[] treeObjects = explorerView.getSelectedTreeObjects();
            for (int i = treeObjects.length - 1; i >= 0; i--) {
                treeObject = (DatabaseObjectTreeObject) treeObjects[i];
                if (treeObject instanceof StatementTreeObject) {
                    StatementTreeObject statementTreeObject = (StatementTreeObject) treeObject;
                    statement = (Statement) statementTreeObject.getObject();
                    statement.setEnabled(false);
                    statementTreeObject.setEnabled(false);
                    statementTreeObject.hasBeenModified(true);
                }
            }
            explorerView.refreshSelectedTreeObjects();
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to disable 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) StatementTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StatementTreeObject) Statement(com.twinsoft.convertigo.beans.core.Statement) 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) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display)

Example 15 with Statement

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

the class TransactionCreateHandlerAction method run.

@Override
public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    Statement lastStatement = null;
    try {
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            if (treeObject != null) {
                Transaction transaction = null;
                if (treeObject instanceof TransactionTreeObject) {
                    transaction = (Transaction) treeObject.getObject();
                } else if (treeObject instanceof ObjectsFolderTreeObject) {
                    transaction = (Transaction) treeObject.getParent().getObject();
                }
                if (transaction != null) {
                    CreateHandlerDialog createHandlerDialog = new CreateHandlerDialog(shell, transaction);
                    createHandlerDialog.open();
                    if (createHandlerDialog.getReturnCode() != Window.CANCEL) {
                        List<?> result = createHandlerDialog.result;
                        if (result != null) {
                            int len = result.size();
                            if (len > 0) {
                                if (transaction instanceof HtmlTransaction) {
                                    HtmlTransaction htmlTransaction = (HtmlTransaction) transaction;
                                    Statement statement = null;
                                    for (int i = 0; i < len; i++) {
                                        statement = (Statement) result.get(i);
                                        htmlTransaction.addStatement(statement);
                                    }
                                    lastStatement = statement;
                                } else {
                                    String handler = null;
                                    for (int i = 0; i < len; i++) {
                                        handler = (String) result.get(i);
                                        transaction.handlers += handler;
                                        transaction.hasChanged = true;
                                    }
                                    // Update the opened handlers editor if any
                                    JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
                                    if (jsinput != null) {
                                        jsinput.reload();
                                    }
                                }
                                // Reload transaction in tree and select last created Statement.
                                try {
                                    ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
                                    projectExplorerView.reloadDatabaseObject(transaction);
                                    if (transaction instanceof HtmlTransaction) {
                                        if (lastStatement != null) {
                                            projectExplorerView.objectSelected(new CompositeEvent(lastStatement));
                                        }
                                    } else {
                                        projectExplorerView.objectSelected(new CompositeEvent(transaction));
                                    }
                                } catch (IOException e) {
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create new handler for transaction!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Statement(com.twinsoft.convertigo.beans.core.Statement) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) CreateHandlerDialog(com.twinsoft.convertigo.eclipse.dialogs.CreateHandlerDialog) IOException(java.io.IOException) Cursor(org.eclipse.swt.graphics.Cursor) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) Shell(org.eclipse.swt.widgets.Shell) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

Statement (com.twinsoft.convertigo.beans.core.Statement)33 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)16 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)13 EngineException (com.twinsoft.convertigo.engine.EngineException)13 Transaction (com.twinsoft.convertigo.beans.core.Transaction)12 Connector (com.twinsoft.convertigo.beans.core.Connector)11 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)11 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)11 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)11 Step (com.twinsoft.convertigo.beans.core.Step)10 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)10 Cursor (org.eclipse.swt.graphics.Cursor)9 Display (org.eclipse.swt.widgets.Display)9 Shell (org.eclipse.swt.widgets.Shell)9 Project (com.twinsoft.convertigo.beans.core.Project)8 FunctionStatement (com.twinsoft.convertigo.beans.statements.FunctionStatement)8 ThenStatement (com.twinsoft.convertigo.beans.statements.ThenStatement)8 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)8 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)7 Sequence (com.twinsoft.convertigo.beans.core.Sequence)7