Search in sources :

Example 6 with ConnectorEditor

use of com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor in project convertigo by convertigo.

the class TransactionExecuteSelectedFromStubAction 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) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            if ((treeObject != null) && (treeObject instanceof TransactionTreeObject)) {
                TransactionTreeObject transactionTreeObject = (TransactionTreeObject) treeObject;
                Transaction transaction = transactionTreeObject.getObject();
                transactionTreeObject.getConnectorTreeObject().openConnectorEditor();
                Connector connector = (Connector) transaction.getParent();
                ProjectTreeObject projectTreeObject = transactionTreeObject.getProjectTreeObject();
                ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                if (connectorEditor != null) {
                    getActivePage().activate(connectorEditor);
                    connectorEditor.getDocument(transaction.getName(), true);
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected transaction!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) Connector(com.twinsoft.convertigo.beans.core.Connector) Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) Display(org.eclipse.swt.widgets.Display)

Example 7 with ConnectorEditor

use of com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor in project convertigo by convertigo.

the class TransactionExecuteSelectedAction method 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();
            if ((treeObject != null) && (treeObject instanceof TransactionTreeObject)) {
                TransactionTreeObject transactionTreeObject = (TransactionTreeObject) treeObject;
                Transaction transaction = transactionTreeObject.getObject();
                transactionTreeObject.getConnectorTreeObject().openConnectorEditor();
                Connector connector = (Connector) transaction.getParent();
                ProjectTreeObject projectTreeObject = transactionTreeObject.getProjectTreeObject();
                ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                if (connectorEditor != null) {
                    getActivePage().activate(connectorEditor);
                    connectorEditor.getDocument(transaction.getName(), isStubRequested());
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected transaction!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) Connector(com.twinsoft.convertigo.beans.core.Connector) Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Transaction(com.twinsoft.convertigo.beans.core.Transaction) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) TransactionTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TransactionTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) Display(org.eclipse.swt.widgets.Display)

Example 8 with ConnectorEditor

use of com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor in project convertigo by convertigo.

the class ViewExecuteSelectedAction method 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();
            if ((treeObject != null) && (treeObject instanceof DesignDocumentViewTreeObject)) {
                DesignDocumentViewTreeObject viewTreeObject = (DesignDocumentViewTreeObject) treeObject;
                DesignDocumentTreeObject ddto = (DesignDocumentTreeObject) viewTreeObject.getTreeObjectOwner();
                ConnectorTreeObject cto = (ConnectorTreeObject) ddto.getOwnerDatabaseObjectTreeObject();
                ProjectTreeObject projectTreeObject = cto.getProjectTreeObject();
                CouchDbConnector connector = (CouchDbConnector) cto.getObject();
                cto.openConnectorEditor();
                ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                if (connectorEditor != null) {
                    // activate connector's editor
                    getActivePage().activate(connectorEditor);
                    // set transaction's parameters
                    Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
                    ((GetViewTransaction) transaction).setViewname(viewTreeObject.getDocViewName());
                    Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
                    view_reduce.setValueOrNull(viewTreeObject.hasReduce() ? isReduceRequested() : false);
                    // execute view transaction
                    connectorEditor.getDocument(CouchDbConnector.internalView, isStubRequested());
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to execute the selected view!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Variable(com.twinsoft.convertigo.beans.core.Variable) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) CouchDbConnector(com.twinsoft.convertigo.beans.connectors.CouchDbConnector) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) Shell(org.eclipse.swt.widgets.Shell) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) GetViewTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.GetViewTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) DesignDocumentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentTreeObject) DesignDocumentViewTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DesignDocumentViewTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ConnectorTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ConnectorTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 9 with ConnectorEditor

use of com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor in project convertigo by convertigo.

the class TransactionShowVariableAction 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) {
            TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
            String variable = (String) ((VariableTreeObject) treeObject).getObject();
            JavelinTransaction transaction = (JavelinTransaction) treeObject.getParent().getParent().getObject();
            JavelinConnector javelinConnector = (JavelinConnector) transaction.getParent();
            IEditorPart wpart = getConnectorEditor(javelinConnector);
            if ((wpart != null) && (wpart instanceof ConnectorEditor)) {
                getActivePage().activate(wpart);
                ConnectorEditor connectorEditor = (ConnectorEditor) wpart;
                ConnectorEditorPart connectorEditorPart = connectorEditor.getConnectorEditorPart();
                AbstractConnectorComposite connectorComposite = connectorEditorPart.getConnectorComposite();
                if ((connectorComposite != null) && (connectorComposite instanceof JavelinConnectorComposite)) {
                    Javelin javelin = ((JavelinConnectorComposite) connectorComposite).getJavelin();
                    ScreenClass currentScreenClass = ((JavelinConnector) connectorEditorPart.getConnector()).getCurrentScreenClass();
                    String normalizedScreenClassName = StringUtils.normalize(currentScreenClass.getName());
                    int i;
                    String handlerName = "on" + normalizedScreenClassName + JavelinTransaction.EVENT_ENTRY_HANDLER;
                    if ((i = transaction.handlers.indexOf(handlerName)) == -1) {
                        display.beep();
                        ConvertigoPlugin.logWarning("Unable to show the position of the variable \"" + variable + "\": no handler found for the current screen class!");
                    } else {
                        ConvertigoPlugin.logDebug("Found handler: " + handlerName);
                        // Delimit the function
                        int bof, eof;
                        bof = transaction.handlers.indexOf('{', i) + 2;
                        eof = transaction.handlers.indexOf("function", bof);
                        if (eof == -1) {
                            eof = transaction.handlers.lastIndexOf('}') - 1;
                        } else {
                            eof = transaction.handlers.lastIndexOf('}', eof) - 1;
                        }
                        String function = transaction.handlers.substring(bof, eof);
                        // Delimit the marker for generated input variables code
                        int idxMarker = function.indexOf("\t// begin-of-variables");
                        if (idxMarker == -1) {
                            // No variable marker, do nothing
                            display.beep();
                            ConvertigoPlugin.logWarning("Unable to show the position of the variable \"" + variable + "\": no variable marker found for the handler!");
                            return;
                        }
                        int idxMarker2 = function.indexOf("\t// end-of-variables", idxMarker);
                        String code = function.substring(idxMarker, idxMarker2);
                        String line = "\tjavelin.send(" + variable + ");\n";
                        int idxPosition = code.indexOf(line);
                        if (idxPosition == -1) {
                            ConvertigoPlugin.logDebug("No variable '" + variable + "' found into the handler!");
                            return;
                        }
                        idxPosition = code.lastIndexOf("moveCursor(", idxPosition) + 11;
                        int idxComa = code.indexOf(',', idxPosition);
                        int idxClosedParenthesis = code.indexOf(')', idxComa);
                        int x = Integer.parseInt(code.substring(idxPosition, idxComa).trim());
                        int y = Integer.parseInt(code.substring(idxComa + 1, idxClosedParenthesis).trim());
                        ConvertigoPlugin.logDebug("Variable position found: " + x + ", " + y);
                        javelin.moveCursor(x, y);
                    }
                    javelin.requestFocus();
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to show variable to Javelin!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) AbstractConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite) JavelinConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.JavelinConnectorComposite) Javelin(com.twinsoft.twinj.Javelin) IEditorPart(org.eclipse.ui.IEditorPart) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ConnectorEditorPart(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorPart) JavelinTransaction(com.twinsoft.convertigo.beans.transactions.JavelinTransaction) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Shell(org.eclipse.swt.widgets.Shell) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) VariableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.VariableTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 10 with ConnectorEditor

use of com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor in project convertigo by convertigo.

the class UpdateXSDTypesAction method run.

public void run() {
    final 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();
            ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
            MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION | SWT.APPLICATION_MODAL);
            String message = "Do you really want to extract the schema?\nWarning: the previous one will be replaced.";
            messageBox.setMessage(message);
            if (messageBox.open() == SWT.YES) {
                RequestableObject requestable = (RequestableObject) treeObject.getObject();
                String requestableName = StringUtils.normalize(requestable.getName(), true);
                Document document = null;
                String result = null;
                if (!(requestableName.equals(requestable.getName()))) {
                    throw new Exception("Requestable name should be normalized");
                }
                if (requestable instanceof Transaction) {
                    Connector connector = (Connector) requestable.getParent();
                    String connectorName = StringUtils.normalize(connector.getName(), true);
                    if (!(connectorName.equals(connector.getName()))) {
                        throw new Exception("Connector name should be normalized");
                    }
                    if (connector.getDefaultTransaction() == null) {
                        throw new Exception("Connector must have a default transaction");
                    }
                    if (requestable instanceof HtmlTransaction) {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the XML document before trying to extract the XSD types.");
                                return;
                            }
                            result = requestable.generateXsdTypes(document, extract);
                        } else {
                            HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
                            String defaultTransactionName = StringUtils.normalize(defaultTransaction.getName(), true);
                            if (!(defaultTransactionName.equals(defaultTransaction.getName()))) {
                                throw new Exception("Default transaction name should be normalized");
                            }
                            String defaultXsdTypes = defaultTransaction.generateXsdTypes(null, false);
                            if (requestable.equals(defaultTransaction))
                                result = defaultXsdTypes;
                            else {
                                TransactionXSDTypesDialog dlg = new TransactionXSDTypesDialog(shell, requestable);
                                if (dlg.open() == Window.OK) {
                                    result = dlg.result;
                                    result += defaultXsdTypes;
                                }
                            }
                        }
                    } else {
                        if (extract) {
                            ConnectorEditor connectorEditor = projectTreeObject.getConnectorEditor(connector);
                            if (connectorEditor == null) {
                                ConvertigoPlugin.infoMessageBox("Please open connector first.");
                                return;
                            }
                            document = connectorEditor.getLastGeneratedDocument();
                            if (document == null) {
                                ConvertigoPlugin.infoMessageBox("You should first generate the XML document before trying to extract the XSD types.");
                                return;
                            }
                            String prefix = requestable.getXsdTypePrefix();
                            document.getDocumentElement().setAttribute("transaction", prefix + requestableName);
                        }
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                if (!xmlQName.isEmpty()) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Assigned element QName' property.");
                                    return;
                                }
                                if (!reqn.equals("")) {
                                    ConvertigoPlugin.infoMessageBox("You should first unset 'Schema of XML response root element' property.");
                                    return;
                                }
                            }
                        }
                        result = requestable.generateXsdTypes(document, extract);
                    }
                }
                if ((result != null) && (!result.equals(""))) {
                    String xsdTypes = result;
                    if (requestable instanceof Transaction) {
                        if (requestable instanceof XmlHttpTransaction) {
                            XmlHttpTransaction xmlHttpTransaction = (XmlHttpTransaction) requestable;
                            XmlQName xmlQName = xmlHttpTransaction.getXmlElementRefAffectation();
                            String reqn = xmlHttpTransaction.getResponseElementQName();
                            if (!extract && ((!xmlQName.isEmpty()) || (!reqn.equals("")))) {
                                // ignore
                                ;
                            } else
                                ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                        } else
                            ((Transaction) requestable).writeSchemaToFile(xsdTypes);
                    }
                    requestable.hasChanged = true;
                    Engine.theApp.schemaManager.clearCache(requestable.getProject().getName());
                    explorerView.refreshFirstSelectedTreeObject();
                    explorerView.objectSelected(new CompositeEvent(requestable));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to update schema!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Connector(com.twinsoft.convertigo.beans.core.Connector) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) RequestableObject(com.twinsoft.convertigo.beans.core.RequestableObject) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) Cursor(org.eclipse.swt.graphics.Cursor) Document(org.w3c.dom.Document) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) MessageBox(org.eclipse.swt.widgets.MessageBox) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) Shell(org.eclipse.swt.widgets.Shell) HtmlTransaction(com.twinsoft.convertigo.beans.transactions.HtmlTransaction) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) Transaction(com.twinsoft.convertigo.beans.core.Transaction) TransactionXSDTypesDialog(com.twinsoft.convertigo.eclipse.dialogs.TransactionXSDTypesDialog) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) ProjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject) CompositeEvent(com.twinsoft.convertigo.eclipse.editors.CompositeEvent) Display(org.eclipse.swt.widgets.Display)

Aggregations

ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)17 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)12 Cursor (org.eclipse.swt.graphics.Cursor)10 Display (org.eclipse.swt.widgets.Display)10 Shell (org.eclipse.swt.widgets.Shell)10 Transaction (com.twinsoft.convertigo.beans.core.Transaction)9 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)9 Connector (com.twinsoft.convertigo.beans.core.Connector)7 ProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)7 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)5 AbstractConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite)5 ConnectorEditorPart (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorPart)5 JavelinConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.JavelinConnectorComposite)5 RequestableObject (com.twinsoft.convertigo.beans.core.RequestableObject)4 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)4 ConnectorEditorInput (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorInput)4 Javelin (com.twinsoft.twinj.Javelin)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 PartInitException (org.eclipse.ui.PartInitException)4 Document (org.w3c.dom.Document)4