Search in sources :

Example 1 with FindString

use of com.twinsoft.convertigo.beans.common.FindString in project convertigo by convertigo.

the class JavelinConnector method waitNextPage.

/**
 * Waits for a new page for the same screen class or a new screen class.
 *
 * The method wait for one of the screens described by the screen classes in the
 * project to arrive. We wait for all the screen classes except the current one. In the
 * case of a next page on the same screen class, waitNextPage() will monitor the cursor
 * position. the method will return when the cursor position returns to the same position
 * it was before calling waitNextPage().
 *
 * You can use waitNextPage() method to synchronize your handler before returning
 * "redetect", "accumulate" or "skip".
 *
 * @param context 		the Convertigo context.
 * @param timeout		the time (in ms) we have to wait for the screen class.
 * @param hardDelay		a delay (in ms) added after the nextpage has arrived.
 *
 * @return				true, if we the page did arrive, false otherwise.
 */
public boolean waitNextPage(Context context, String action, int timeout, int hardDelay) throws EngineException {
    if (javelin != null) {
        try {
            List<JavelinScreenClass> vScreenClasses = getAllScreenClasses();
            List<Criteria> vCriterias;
            List<Criteria> vAllCriterias = new ArrayList<Criteria>(128);
            RegularExpression regularExpression;
            FindString findString;
            javelin.deleteWaitAts();
            ScreenClass lastDetectedScreenClass = (ScreenClass) context.lastDetectedObject;
            // Set all screen class criterias observations
            int j = 1;
            for (ScreenClass screenClass : vScreenClasses) {
                Engine.logBeans.debug("(JavelinConnector) Analyzing screen class \"" + screenClass.getName() + "\"");
                // Do not detect the current screen class
                if ((lastDetectedScreenClass != null) && (screenClass.getQName().equals(lastDetectedScreenClass.getQName()))) {
                    Engine.logBeans.debug("(JavelinConnector) Ignoring screen class \"" + screenClass.getName() + "\"");
                    continue;
                }
                vCriterias = screenClass.getLocalCriterias();
                for (Criteria criteria : vCriterias) {
                    if (criteria instanceof RegularExpression) {
                        regularExpression = (RegularExpression) criteria;
                        if ((regularExpression.getX() == -1) || (regularExpression.getX() == -1)) {
                            Engine.logBeans.debug("(JavelinConnector) Ignoring criteria \"" + regularExpression.getRegularExpression() + "\" at (" + regularExpression.getX() + ", " + regularExpression.getY() + ")");
                        } else {
                            Engine.logBeans.debug("(JavelinConnector) Adding a wait at ID: " + j + " \"" + regularExpression.getRegularExpression() + "\" at (" + regularExpression.getX() + ", " + regularExpression.getY() + ")");
                            javelin.waitAtId(j, regularExpression.getRegularExpression(), regularExpression.getX(), regularExpression.getY());
                            vAllCriterias.add(criteria);
                            j++;
                        }
                    }
                }
            }
            // Wait for the cursor to move out from the current location
            int line = javelin.getCurrentLine();
            int col = javelin.getCurrentColumn();
            Engine.logBeans.debug("(JavelinConnector) WaitNextPage(): cursor is now in col: " + col + ", line: " + line);
            javelin.waitCursorAtId(1, col, line, false);
            javelin.doAction(action);
            int ret = javelin.waitTrigger(timeout);
            if (ret == -1) {
                Engine.logBeans.debug("(JavelinConnector) WaitNextPage(): cursor did not move out in time");
                return false;
            }
            // Set one more observation ID on the cursor position
            Engine.logBeans.debug("(JavelinConnector) Adding a waitCursorAt at ID: " + 0 + " in col: " + col + ", line: " + line);
            javelin.waitCursorAtId(0, col, line, true);
            j = javelin.waitTrigger(timeout);
            javelin.deleteWaitAts();
            Criteria criteria;
            if (j != -1) {
                if (j < vAllCriterias.size()) {
                    criteria = (Criteria) vAllCriterias.get(j);
                    String string = "?";
                    int x = -1;
                    int y = -1;
                    if (criteria instanceof FindString) {
                        findString = (FindString) criteria;
                        string = findString.getString();
                        x = findString.getX();
                        y = findString.getY();
                    } else if (criteria instanceof RegularExpression) {
                        regularExpression = (RegularExpression) criteria;
                        string = regularExpression.getRegularExpression();
                        x = regularExpression.getX();
                        y = regularExpression.getY();
                    }
                    Engine.logBeans.debug("(JavelinConnector) WaitNextPage(): found criteria ID:" + j + " \"" + string + "\" at (" + x + ", " + y + ")");
                } else {
                    Engine.logBeans.debug("(JavelinConnector) WaitNextPage(): cursor back in col: " + col + ", line: " + line);
                }
                if (hardDelay > 0) {
                    javelin.waitSync(hardDelay);
                }
                return true;
            }
            Engine.logBeans.debug("(JavelinConnector) WaitNextPage(): automatic data stable event detection aborted because of timeout!");
            return false;
        } catch (Exception e) {
            Engine.logBeans.error("Exception while trying to wait next page", e);
            throw new EngineException("Unable to wait for the next page! See the emulator log for more details...", e);
        }
    } else {
        throw new EngineException("Unable to call the waitNextPage() function without a Javelin emulator!");
    }
}
Also used : RegularExpression(com.twinsoft.convertigo.beans.common.RegularExpression) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException) Criteria(com.twinsoft.convertigo.beans.core.Criteria) FindString(com.twinsoft.convertigo.beans.common.FindString) FindString(com.twinsoft.convertigo.beans.common.FindString) RESyntaxException(org.apache.regexp.RESyntaxException) NoSuchElementException(java.util.NoSuchElementException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 2 with FindString

use of com.twinsoft.convertigo.beans.common.FindString in project convertigo by convertigo.

the class JavelinConnector method waitAtScreenClass.

/**
 * Waits for one of the screens described by the screen classes
 * in the project to arrive. The method waits for all the screen classes
 * except the current one. You can use waitAtScreenClass() method to synchronize
 * your handler before returning "redetect", "accumulate" or "skip".
 *
 * @param context		the Convertigo context.
 * @param timeout		the time (in ms) we have to wait for the screen class.
 * @param hardDelay		a delay (in ms) added after the screen class has arrived.
 *
 * @return				true, if we the screen did arrive, false otherwise.
 */
public boolean waitAtScreenClass(Context context, int timeout, int hardDelay) throws EngineException {
    if (javelin != null) {
        try {
            List<JavelinScreenClass> vScreenClasses = getAllScreenClasses();
            List<Criteria> vCriterias;
            List<Criteria> vAllCriterias = new ArrayList<Criteria>(128);
            RegularExpression regularExpression;
            FindString findString;
            int j = 0;
            ScreenClass lastDetectedScreenClass = (ScreenClass) context.lastDetectedObject;
            for (ScreenClass screenClass : vScreenClasses) {
                // Do not detect the current screen class
                if ((lastDetectedScreenClass != null) && (screenClass.getName().equals(lastDetectedScreenClass.getName()))) {
                    Engine.logBeans.debug("(JavelinConnector) WaitAtScreenClass(): last detected screen class is " + lastDetectedScreenClass.getName());
                    continue;
                }
                vCriterias = screenClass.getLocalCriterias();
                for (Criteria criteria : vCriterias) {
                    if (criteria instanceof FindString) {
                        findString = (FindString) criteria;
                        if ((findString.getX() == -1) || (findString.getX() == -1)) {
                            Engine.logBeans.debug("(JavelinConnector) Ignoring criteria \"" + findString.getString() + "\" at (" + findString.getX() + ", " + findString.getY() + ")");
                        } else {
                            Engine.logBeans.debug("(JavelinConnector) Adding a wait at ID:" + j + " \"" + findString.getString() + "\" at (" + findString.getX() + ", " + findString.getY() + ")");
                            javelin.waitAtId(j, findString.getString(), findString.getX(), findString.getY());
                            vAllCriterias.add(criteria);
                            j++;
                        }
                    } else if (criteria instanceof RegularExpression) {
                        regularExpression = (RegularExpression) criteria;
                        if ((regularExpression.getX() == -1) || (regularExpression.getX() == -1)) {
                            Engine.logBeans.debug("(JavelinConnector) Ignoring criteria \"" + regularExpression.getRegularExpression() + "\" at (" + regularExpression.getX() + ", " + regularExpression.getY() + ")");
                        } else {
                            Engine.logBeans.debug("(JavelinConnector) Adding a wait at ID:" + j + " \"" + regularExpression.getRegularExpression() + "\" at (" + regularExpression.getX() + ", " + regularExpression.getY() + ")");
                            javelin.waitAtId(j, regularExpression.getRegularExpression(), regularExpression.getX(), regularExpression.getY());
                            vAllCriterias.add(criteria);
                            j++;
                        }
                    }
                }
            }
            j = javelin.waitTrigger(timeout);
            javelin.deleteWaitAts();
            Criteria criteria;
            if (j != -1) {
                criteria = (Criteria) vAllCriterias.get(j);
                String string = "?";
                int x = -1;
                int y = -1;
                if (criteria instanceof FindString) {
                    findString = (FindString) criteria;
                    string = findString.getString();
                    x = findString.getX();
                    y = findString.getY();
                } else if (criteria instanceof RegularExpression) {
                    regularExpression = (RegularExpression) criteria;
                    string = regularExpression.getRegularExpression();
                    x = regularExpression.getX();
                    y = regularExpression.getY();
                }
                Engine.logBeans.debug("(JavelinConnector) WaitAtScreenClass(): found criteria ID:" + j + " \"" + string + "\" at (" + x + ", " + y + ")");
                if (hardDelay > 0) {
                    javelin.waitSync(hardDelay);
                }
                return true;
            }
            Engine.logBeans.debug("(JavelinConnector) Automatic data stable event detection aborted because of timeout!");
            return false;
        } catch (Exception e) {
            Engine.logBeans.error("Exception while trying to wait at screen class", e);
            throw new EngineException("Unable to wait at screen class! See the emulator log for more details...", e);
        }
    } else {
        throw new EngineException("Unable to call the waitAtScreenClass() function without a Javelin emulator!");
    }
}
Also used : RegularExpression(com.twinsoft.convertigo.beans.common.RegularExpression) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) JavelinScreenClass(com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass) ArrayList(java.util.ArrayList) EngineException(com.twinsoft.convertigo.engine.EngineException) Criteria(com.twinsoft.convertigo.beans.core.Criteria) FindString(com.twinsoft.convertigo.beans.common.FindString) FindString(com.twinsoft.convertigo.beans.common.FindString) RESyntaxException(org.apache.regexp.RESyntaxException) NoSuchElementException(java.util.NoSuchElementException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) EngineException(com.twinsoft.convertigo.engine.EngineException)

Example 3 with FindString

use of com.twinsoft.convertigo.beans.common.FindString 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

FindString (com.twinsoft.convertigo.beans.common.FindString)3 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)3 JavelinScreenClass (com.twinsoft.convertigo.beans.screenclasses.JavelinScreenClass)3 RegularExpression (com.twinsoft.convertigo.beans.common.RegularExpression)2 Criteria (com.twinsoft.convertigo.beans.core.Criteria)2 EngineException (com.twinsoft.convertigo.engine.EngineException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 RESyntaxException (org.apache.regexp.RESyntaxException)2 EvaluatorException (org.mozilla.javascript.EvaluatorException)2 JavaScriptException (org.mozilla.javascript.JavaScriptException)2 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)1 AbstractConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite)1 ConnectorEditor (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor)1 ConnectorEditorPart (com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorPart)1 JavelinConnectorComposite (com.twinsoft.convertigo.eclipse.editors.connector.JavelinConnectorComposite)1 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)1 ScreenClassTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ScreenClassTreeObject)1 EngineEvent (com.twinsoft.convertigo.engine.EngineEvent)1