Search in sources :

Example 41 with ScreenClass

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

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

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

the class ScreenClassTreeObject method rename.

public boolean rename(String newName, Boolean bDialog) {
    ScreenClass sc = getObject();
    IScreenClassContainer<?> scc = (IScreenClassContainer<?>) sc.getConnector();
    if (!sc.getName().equalsIgnoreCase(newName) && scc.getScreenClassByName(newName) != null) {
        ConvertigoPlugin.logException(new ConvertigoException("The name \"" + newName + "\" is already used by another screen class."), "Unable to change the object name.", bDialog);
        return false;
    }
    return super.rename(newName, bDialog);
}
Also used : ConvertigoException(com.twinsoft.convertigo.engine.ConvertigoException) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) IScreenClassContainer(com.twinsoft.convertigo.beans.core.IScreenClassContainer)

Example 44 with ScreenClass

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

the class JavelinConnector method getAllScreenClassesNames.

public String[] getAllScreenClassesNames() {
    List<JavelinScreenClass> vScreenClasses = getAllScreenClasses();
    String[] screenClassNames = new String[vScreenClasses.size()];
    int i = 0;
    for (ScreenClass screenClass : vScreenClasses) {
        screenClassNames[i] = screenClass.getName();
        i++;
    }
    return screenClassNames;
}
Also used : JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) FindString(com.twinsoft.convertigo.beans.common.FindString)

Example 45 with ScreenClass

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

the class CreateScreenClassFromSelectionZoneAction 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();
        IWorkbenchPart wpart = getActivePart();
        if ((explorerView != null) && (wpart != null) && (wpart instanceof ConnectorEditor)) {
            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();
                Engine.theApp.fireObjectDetected(new EngineEvent(currentScreenClass));
                ScreenClassTreeObject lastDetectedScreenClassTreeObject = explorerView.getLastDetectedScreenClassTreeObject();
                if (lastDetectedScreenClassTreeObject != null) {
                    Rectangle zone = javelin.getSelectionZone();
                    String strZone = javelin.getString(zone.x, zone.y, zone.width);
                    ScreenClass lastDetectedScreenClass = (ScreenClass) lastDetectedScreenClassTreeObject.getObject();
                    JavelinScreenClass screenClass = new JavelinScreenClass();
                    screenClass.priority = lastDetectedScreenClass.priority + 1;
                    screenClass.hasChanged = true;
                    screenClass.bNew = true;
                    lastDetectedScreenClass.add(screenClass);
                    FindString fs = new FindString();
                    fs.setString(strZone);
                    fs.setX(zone.x);
                    fs.setY(zone.y);
                    fs.hasChanged = true;
                    fs.bNew = true;
                    // Determine whether there is the same attribute for each character
                    boolean isSameAttribute = true;
                    int attribute = javelin.getCharAttribute(zone.x, zone.y);
                    for (int i = 1; (i < zone.width) && isSameAttribute; i++) {
                        isSameAttribute = JavelinUtils.isSameAttribute(attribute, javelin.getCharAttribute(zone.x + i, zone.y));
                    }
                    fs.setAttribute(isSameAttribute ? attribute : -1);
                    screenClass.addCriteria(fs);
                    explorerView.reloadTreeObject(lastDetectedScreenClassTreeObject);
                    Engine.theApp.fireObjectDetected(new EngineEvent(screenClass));
                    javelin.setSelectionZone(new Rectangle(0, 0, 0, 0));
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create screen class from selection zone!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) AbstractConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite) JavelinConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.JavelinConnectorComposite) Rectangle(java.awt.Rectangle) Javelin(com.twinsoft.twinj.Javelin) FindString(com.twinsoft.convertigo.beans.common.FindString) Cursor(org.eclipse.swt.graphics.Cursor) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ConnectorEditorPart(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorPart) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ScreenClassTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) FindString(com.twinsoft.convertigo.beans.common.FindString) Display(org.eclipse.swt.widgets.Display)

Aggregations

ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)47 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)17 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)16 Transaction (com.twinsoft.convertigo.beans.core.Transaction)16 EngineException (com.twinsoft.convertigo.engine.EngineException)15 Connector (com.twinsoft.convertigo.beans.core.Connector)14 HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)13 Statement (com.twinsoft.convertigo.beans.core.Statement)13 JavelinScreenClass (com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass)10 IOException (java.io.IOException)10 Step (com.twinsoft.convertigo.beans.core.Step)9 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)9 Criteria (com.twinsoft.convertigo.beans.core.Criteria)8 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)8 Project (com.twinsoft.convertigo.beans.core.Project)7 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)7 ArrayList (java.util.ArrayList)7 Sheet (com.twinsoft.convertigo.beans.core.Sheet)6 FunctionStatement (com.twinsoft.convertigo.beans.statements.FunctionStatement)6 ElseStep (com.twinsoft.convertigo.beans.steps.ElseStep)6