Search in sources :

Example 21 with Statement

use of com.twinsoft.convertigo.beans.core.Statement 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 22 with Statement

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

the class TreeDropAdapter method paste.

public DatabaseObject paste(Node node, DatabaseObject parentDatabaseObject, boolean bChangeName) throws EngineException {
    Object object = ConvertigoPlugin.clipboardManagerDND.read(node);
    if (object instanceof DatabaseObject) {
        DatabaseObject databaseObject = (DatabaseObject) object;
        String dboName = databaseObject.getName();
        String name = null;
        boolean bContinue = true;
        int index = 0;
        while (bContinue) {
            if (bChangeName) {
                if (index == 0)
                    name = dboName;
                else
                    name = dboName + index;
                databaseObject.setName(name);
            }
            databaseObject.hasChanged = true;
            databaseObject.bNew = true;
            try {
                if (parentDatabaseObject != null)
                    parentDatabaseObject.add(databaseObject);
                bContinue = false;
            } catch (ObjectWithSameNameException owsne) {
                if ((parentDatabaseObject instanceof HtmlTransaction) && (databaseObject instanceof Statement))
                    throw new EngineException("HtmlTransaction already contains a statement named \"" + name + "\".", owsne);
                if ((parentDatabaseObject instanceof Sequence) && (databaseObject instanceof Step))
                    throw new EngineException("Sequence already contains a step named \"" + name + "\".", owsne);
                // Silently ignore
                index++;
            }
        }
        NodeList childNodes = node.getChildNodes();
        int len = childNodes.getLength();
        Node childNode;
        String childNodeName;
        for (int i = 0; i < len; i++) {
            childNode = childNodes.item(i);
            if (childNode.getNodeType() != Node.ELEMENT_NODE)
                continue;
            childNodeName = childNode.getNodeName();
            if (!(childNodeName.equalsIgnoreCase("property")) && !(childNodeName.equalsIgnoreCase("handlers")) && !(childNodeName.equalsIgnoreCase("wsdltype")) && !(childNodeName.equalsIgnoreCase("docdata")) && !(childNodeName.equalsIgnoreCase("beandata")) && !(childNodeName.equalsIgnoreCase("dnd"))) {
                paste(childNode, databaseObject, bChangeName);
            }
        }
        // needed !
        databaseObject.isImporting = false;
        databaseObject.isSubLoaded = true;
        return databaseObject;
    }
    return null;
}
Also used : XpathableStatement(com.twinsoft.convertigo.beans.statements.XpathableStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) EngineException(com.twinsoft.convertigo.engine.EngineException) Sequence(com.twinsoft.convertigo.beans.core.Sequence) SequenceStep(com.twinsoft.convertigo.beans.steps.SequenceStep) XMLElementStep(com.twinsoft.convertigo.beans.steps.XMLElementStep) Step(com.twinsoft.convertigo.beans.core.Step) TransactionStep(com.twinsoft.convertigo.beans.steps.TransactionStep) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) NgxComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxComponentTreeObject) IOrderableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IOrderableTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) ObjectsFolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject) NgxUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxUIComponentTreeObject) MobileUIComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileUIComponentTreeObject) IPropertyTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.IPropertyTreeObject) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) MobileComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.MobileComponentTreeObject)

Example 23 with Statement

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

the class HtmlConnectorDesignComposite method createStatementFromSelection.

public void createStatementFromSelection() {
    String className = "com.twinsoft.convertigo.beans.core.Statement";
    // Retrieve selected statement xpath
    String statementXpath = xpathEvaluator.getSelectionXpath();
    // Retrieve parent Statement
    Statement parentObject = getParentStatement();
    if (parentObject == null) {
        ConvertigoPlugin.errorMessageBox("Unable to create a new statement.\nThe selected handler belongs to a different HTML connector.");
        return;
    }
    // Add statement to parent statement
    NewObjectWizard newObjectWizard = new NewObjectWizard(parentObject, className, statementXpath, null);
    WizardDialog wzdlg = new WizardDialog(Display.getCurrent().getActiveShell(), newObjectWizard);
    wzdlg.setPageSize(850, 650);
    wzdlg.open();
    if (wzdlg.getReturnCode() != Window.CANCEL) {
        Statement statement = (Statement) newObjectWizard.newBean;
        // Reload parent statement in Tree
        fireObjectChanged(new CompositeEvent(parentObject));
        // Set selection on new statement (will expand tree to new statement)
        if (statement != null)
            fireObjectSelected(new CompositeEvent(statement));
        // Set back selection on parent statement
        fireObjectSelected(new CompositeEvent(parentObject));
    }
}
Also used : HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) ScEntryHandlerStatement(com.twinsoft.convertigo.beans.statements.ScEntryHandlerStatement) ScExitHandlerStatement(com.twinsoft.convertigo.beans.statements.ScExitHandlerStatement) ScHandlerStatement(com.twinsoft.convertigo.beans.statements.ScHandlerStatement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) NewObjectWizard(com.twinsoft.convertigo.eclipse.wizards.new_object.NewObjectWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent)

Example 24 with Statement

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

the class EventStatementGenerator method addStatement.

protected void addStatement(AbstractEventStatement stat) {
    if (stat != null) {
        try {
            List<Statement> stats = block.getStatements();
            boolean goodName = false;
            String currentName = stat.getName();
            while (!goodName) {
                goodName = true;
                for (int i = 0; i < stats.size() && goodName; i++) {
                    DatabaseObject obj = (DatabaseObject) stats.get(i);
                    goodName = !(obj.getName().equals(currentName));
                }
                if (!goodName) {
                    String base = currentName;
                    int count = 1;
                    int i_ = currentName.lastIndexOf("_");
                    if (i_ != -1 && i_ + 1 < currentName.length()) {
                        String end = currentName.substring(i_ + 1);
                        try {
                            count = Integer.parseInt(end) + 1;
                            base = currentName.substring(0, i_);
                        } catch (NumberFormatException e) {
                        }
                    }
                    currentName = base + "_" + count;
                }
            }
            if (!StringUtils.isNormalized(currentName))
                throw new EngineException("Statement name is not normalized : \"" + currentName + "\"");
            stat.setName(currentName);
            stat.hasChanged = true;
            stat.bNew = true;
            block.addStatement(stat);
            block.hasChanged = true;
        } catch (EngineException e) {
            ConvertigoPlugin.logException(e, "Error when adding an '" + stat.getClass().getName() + "' statement.");
        }
    }
}
Also used : MouseStatement(com.twinsoft.convertigo.beans.statements.MouseStatement) InputHtmlSetValueStatement(com.twinsoft.convertigo.beans.statements.InputHtmlSetValueStatement) InputHtmlSetSelectedStatement(com.twinsoft.convertigo.beans.statements.InputHtmlSetSelectedStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) InputHtmlSetCheckedStatement(com.twinsoft.convertigo.beans.statements.InputHtmlSetCheckedStatement) AbstractEventStatement(com.twinsoft.convertigo.beans.statements.AbstractEventStatement) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 25 with Statement

use of com.twinsoft.convertigo.beans.core.Statement 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

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