Search in sources :

Example 26 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector 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 27 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class TransactionWriteVariableAction 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();
                    ConvertigoPlugin.logDebug("Analyzing screen class '" + currentScreenClass.getName() + "'...");
                    String normalizedScreenClassName = StringUtils.normalize(currentScreenClass.getName());
                    int i;
                    String handlerName = "on" + normalizedScreenClassName + JavelinTransaction.EVENT_ENTRY_HANDLER;
                    ConvertigoPlugin.logDebug("Handlers:\n" + transaction.handlers);
                    ConvertigoPlugin.logDebug("Searching for handler '" + handlerName + "'...");
                    if ((i = transaction.handlers.indexOf(handlerName)) == -1) {
                        display.beep();
                        ConvertigoPlugin.logDebug("No handler found for the current screen class!");
                    } else {
                        ConvertigoPlugin.logDebug("Handler found!");
                        // Delimit the function
                        int bof, eof;
                        bof = transaction.handlers.indexOf('{', i) + 1;
                        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);
                        int c = javelin.getCurrentColumn();
                        int l = javelin.getCurrentLine();
                        String line1 = "\tjavelin.moveCursor(" + c + ", " + l + ");\n";
                        // We must remove the default value of the variable if any
                        String variableName = variable.toString();
                        int ii;
                        if ((ii = variableName.indexOf(' ')) != -1) {
                            variableName = variableName.substring(0, ii);
                        }
                        String line2 = "\tjavelin.send(" + variableName + ");\n";
                        // Delimit the marker for generated input variables code
                        String code = "";
                        int idxMarker = function.indexOf("\t// begin-of-variables");
                        if (idxMarker == -1) {
                            code = "\n\t// begin-of-variables: DO NOT EDIT OR MODIFY\n";
                            code += line1 + line2;
                            code += "\t// end-of-variables\n";
                            function = code + function;
                        } else {
                            idxMarker = function.indexOf("\t// end-of-variables");
                            // Update previous definition if any
                            int idxPreviousDefinition = function.indexOf(line2);
                            if (idxPreviousDefinition != -1) {
                                int i1 = function.lastIndexOf("moveCursor(", idxPreviousDefinition) + 11;
                                // Search for moveCursor only inside the variables block
                                if (i1 < idxMarker) {
                                    int i2 = function.indexOf(')', i1);
                                    function = function.substring(0, i1) + c + ", " + l + function.substring(i2);
                                }
                            } else // Add definition otherwise
                            {
                                code += line1 + line2;
                            }
                            function = function.substring(0, idxMarker) + code + function.substring(idxMarker);
                        }
                        transaction.handlers = transaction.handlers.substring(0, bof) + function + transaction.handlers.substring(eof);
                        transaction.hasChanged = true;
                        ConvertigoPlugin.logDebug("Code added:\n" + code);
                        explorerView.updateDatabaseObject(transaction);
                        // Update the opened handlers editor if any
                        JScriptEditorInput jsinput = ConvertigoPlugin.getDefault().getJScriptEditorInput(transaction);
                        if (jsinput != null) {
                            jsinput.reload();
                        }
                    }
                    javelin.requestFocus();
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to write variable from Javelin!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) 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 28 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class ColumnEditor method addPropertyElementFromSelectionZone.

/**
 * Add a column to the property according to the current selected zone.
 * @param databaseObject
 * @param connector
 * @param setter
 */
public static void addPropertyElementFromSelectionZone(DatabaseObject databaseObject, Connector connector, Method propertySetter) {
    if (connector == null) {
        throw new IllegalArgumentException("The connector object is null");
    }
    JavelinConnector jTmp = null;
    try {
        jTmp = (JavelinConnector) connector;
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("The connector object is not a JavelinConnector");
    }
    XMLRectangle zone = jTmp.getSelectionZone();
    if ((zone.width < 1) || (zone.height < 1))
        return;
    XMLVector<XMLVector<Object>> vTmp = null;
    if (Table.class.isAssignableFrom(databaseObject.getClass())) {
        vTmp = ((Table) databaseObject).getColumns();
    } else // not a table => no columns
    {
    }
    XMLVector<Object> v = new XMLVector<Object>();
    v.add(jTmp.javelin.getString(zone.x, zone.y, zone.width).trim());
    v.add(Integer.valueOf(zone.x));
    v.add(Integer.valueOf(zone.x + zone.width - 1));
    v.add(Integer.valueOf(0));
    vTmp.add(v);
    try {
        propertySetter.invoke(databaseObject, new Object[] { vTmp });
    } catch (Throwable e) {
        String message = "Error : " + e.getMessage();
        ConvertigoPlugin.logException(e, message);
    }
    jTmp.javelin.setSelectionZone(new XMLRectangle(zone.x, 0, zone.width, jTmp.javelin.getScreenHeight()));
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) XMLVector(com.twinsoft.convertigo.beans.common.XMLVector) XMLRectangle(com.twinsoft.convertigo.beans.common.XMLRectangle) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 29 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class CreateHandlerDialogComposite method createTreeScreenClasses.

/**
 * This method initializes jComboBoxScreenClasses
 */
private void createTreeScreenClasses() {
    tree = new Tree(this, SWT.MULTI | SWT.BORDER);
    tree.setHeaderVisible(false);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.verticalSpan = 20;
    tree.setLayoutData(gridData);
    if (isScreenClassAware) {
        Connector connector = (Connector) transaction.getParent();
        if (connector instanceof HtmlConnector) {
            HtmlConnector htmlConnector = (HtmlConnector) connector;
            ScreenClass defaultScreenClass = htmlConnector.getDefaultScreenClass();
            TreeItem branch = new TreeItem(tree, SWT.NONE);
            branch.setText(defaultScreenClass.getName());
            List<ScreenClass> screenClasses = defaultScreenClass.getInheritedScreenClasses();
            for (ScreenClass screenClass : screenClasses) {
                getInHeritedScreenClass(screenClass, branch);
            }
        } else if (connector instanceof JavelinConnector) {
            JavelinConnector javelinConnector = (JavelinConnector) connector;
            ScreenClass defaultScreenClass = javelinConnector.getDefaultScreenClass();
            TreeItem branch = new TreeItem(tree, SWT.NONE);
            branch.setText(defaultScreenClass.getName());
            List<ScreenClass> screenClasses = defaultScreenClass.getInheritedScreenClasses();
            for (ScreenClass screenClass : screenClasses) {
                getInHeritedScreenClass(screenClass, branch);
            }
        }
    }
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) Connector(com.twinsoft.convertigo.beans.core.Connector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) TreeItem(org.eclipse.swt.widgets.TreeItem) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) ArrayList(java.util.ArrayList) List(java.util.List)

Example 30 with JavelinConnector

use of com.twinsoft.convertigo.beans.connectors.JavelinConnector in project convertigo by convertigo.

the class ZoneEditor method displayPropertyValueFromSelectionZone.

/**
 * Displays the value of the selected property if it is a screen zone.
 * @param databaseObject
 * @param connector
 * @param getter
 */
public static void displayPropertyValueFromSelectionZone(DatabaseObject databaseObject, Connector connector, Method propertyGetter) {
    if (connector == null) {
        throw new IllegalArgumentException("The connector object is null");
    }
    XMLRectangle zone = null;
    try {
        zone = (XMLRectangle) propertyGetter.invoke(databaseObject, (Object[]) null);
    } catch (Throwable e) {
        String message = "Error : " + e.getMessage();
        ConvertigoPlugin.logException(e, message);
    }
    JavelinConnector jTmp = null;
    try {
        jTmp = (JavelinConnector) connector;
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("The connector object is not a iJavelin");
    }
    jTmp.javelin.setSelectionZone(zone);
}
Also used : JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) XMLRectangle(com.twinsoft.convertigo.beans.common.XMLRectangle) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Aggregations

JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)50 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)17 Javelin (com.twinsoft.twinj.Javelin)12 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)11 Connector (com.twinsoft.convertigo.beans.core.Connector)11 EngineException (com.twinsoft.convertigo.engine.EngineException)10 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 Transaction (com.twinsoft.convertigo.beans.core.Transaction)8 JavelinTransaction (com.twinsoft.convertigo.beans.transactions.JavelinTransaction)8 XMLRectangle (com.twinsoft.convertigo.beans.common.XMLRectangle)7 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)7 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)7 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)6 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)6 com.twinsoft.twinj.iJavelin (com.twinsoft.twinj.iJavelin)6 Project (com.twinsoft.convertigo.beans.core.Project)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)5 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)5 AbstractConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite)5 ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)5