Search in sources :

Example 11 with ConnectorEditor

use of com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor 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 12 with ConnectorEditor

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

the class ConvertigoPlugin method getConnectorEditor.

/**
 * Gets the editor associated with given connector.
 * !!MUST BE CALLED IN A UI-THREAD!!
 * @return ConnectorEditor : the found connector editor or null
 */
public ConnectorEditor getConnectorEditor(Connector connector) {
    ConnectorEditor connectorEditor = null;
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (activePage != null) {
        if (connector != null) {
            IEditorReference[] editorRefs = activePage.getEditorReferences();
            for (int i = 0; i < editorRefs.length; i++) {
                IEditorReference editorRef = (IEditorReference) editorRefs[i];
                try {
                    IEditorInput editorInput = editorRef.getEditorInput();
                    if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) {
                        if (((ConnectorEditorInput) editorInput).is(connector)) {
                            connectorEditor = (ConnectorEditor) editorRef.getEditor(true);
                            break;
                        }
                    }
                } catch (PartInitException e) {
                    ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'");
                }
            }
        }
    }
    return connectorEditor;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ConnectorEditorInput(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditorInput) IEditorInput(org.eclipse.ui.IEditorInput)

Example 13 with ConnectorEditor

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

the class ConvertigoPartListener method partClosed.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
	 */
public void partClosed(IWorkbenchPart part) {
    if (part instanceof ConnectorEditor) {
        // close editor properly
        ((ConnectorEditor) part).close();
    }
    if (part instanceof SequenceEditor) {
        // close editor properly
        ((SequenceEditor) part).close();
    }
    if (part instanceof ProjectExplorerView) {
        // close view properly
        ((ProjectExplorerView) part).close();
    }
    if (part instanceof SourcePickerView) {
        // close view properly
        ((SourcePickerView) part).close();
    }
    if (part instanceof ConsoleView) {
        ConvertigoPlugin convertigoPlugin = ConvertigoPlugin.getDefault();
        boolean shuttingDown = convertigoPlugin.isShuttingDown();
        if (shuttingDown) {
            IConsole[] tabConsoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles();
            String openedConsoles = "";
            for (IConsole console : tabConsoles) {
                if (console instanceof MessageConsole) {
                    if ((console.equals(convertigoPlugin.engineConsole)) && (openedConsoles.indexOf("engine") == -1))
                        openedConsoles += (openedConsoles.equals("") ? "" : ",") + "engine";
                    else if ((console.equals(convertigoPlugin.stdoutConsole)) && (openedConsoles.indexOf("stdout") == -1))
                        openedConsoles += (openedConsoles.equals("") ? "" : ",") + "stdout";
                }
            }
            ConvertigoPlugin.setProperty(ConvertigoPlugin.PREFERENCE_OPENED_CONSOLES, openedConsoles);
        }
    }
    if (part instanceof EditorPart) {
        IEditorInput input = ((EditorPart) part).getEditorInput();
        if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
            try {
                com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput acei = GenericUtils.cast(input);
                MobileBuilder mb = acei.getApplication().getProject().getMobileBuilder();
                mb.removeMobileEventListener((com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditor) part);
                mb.setAutoBuild(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
            try {
                com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput acei = GenericUtils.cast(input);
                MobileBuilder mb = acei.getApplication().getProject().getMobileBuilder();
                mb.removeMobileEventListener((com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditor) part);
                mb.setAutoBuild(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (input instanceof JScriptEditorInput) {
            try {
                ((JScriptEditorInput) input).getFile().getParent().delete(true, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput) {
            try {
                ((com.twinsoft.convertigo.eclipse.editors.mobile.ComponentFileEditorInput) input).getFile().delete(true, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) {
            try {
                ((com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) input).getFile().delete(true, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : SourcePickerView(com.twinsoft.convertigo.eclipse.views.sourcepicker.SourcePickerView) JScriptEditorInput(com.twinsoft.convertigo.eclipse.editors.jscript.JScriptEditorInput) ConnectorEditor(com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) MessageConsole(org.eclipse.ui.console.MessageConsole) ConsoleView(org.eclipse.ui.internal.console.ConsoleView) SequenceEditor(com.twinsoft.convertigo.eclipse.editors.sequence.SequenceEditor) IConsole(org.eclipse.ui.console.IConsole) EditorPart(org.eclipse.ui.part.EditorPart) MobileBuilder(com.twinsoft.convertigo.engine.mobile.MobileBuilder) IEditorInput(org.eclipse.ui.IEditorInput)

Example 14 with ConnectorEditor

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

the class CreateTagNameFromSelectionZoneAction method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        final 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)) {
                final Javelin javelin = ((JavelinConnectorComposite) connectorComposite).getJavelin();
                ScreenClass currentScreenClass = ((JavelinConnector) connectorEditorPart.getConnector()).getCurrentScreenClass();
                Engine.theApp.fireObjectDetected(new EngineEvent(currentScreenClass));
                final ScreenClassTreeObject lastDetectedScreenClassTreeObject = explorerView.getLastDetectedScreenClassTreeObject();
                if (lastDetectedScreenClassTreeObject != null) {
                    final ScreenClass lastDetectedScreenClass = (ScreenClass) lastDetectedScreenClassTreeObject.getObject();
                    final TagName tagName = new TagName();
                    final InputDialog dlg = new InputDialog(shell, "New TagName", "Please enter a tag name :", "_configure_a_tag_name_", null);
                    if (dlg.open() == Window.OK) {
                        display.asyncExec(new Runnable() {

                            public void run() {
                                try {
                                    String name = dlg.getValue();
                                    Rectangle zone = javelin.getSelectionZone();
                                    tagName.setTagName(StringUtils.normalize(name));
                                    tagName.setSelectionScreenZone(new XMLRectangle(zone.x, zone.y, zone.width, zone.height));
                                    tagName.setSelectionAttribute(javelin.getCharAttribute(zone.x, zone.y));
                                    tagName.setSelectionType("");
                                    tagName.hasChanged = true;
                                    tagName.bNew = true;
                                    lastDetectedScreenClass.addExtractionRule(tagName);
                                    explorerView.reloadTreeObject(lastDetectedScreenClassTreeObject);
                                } catch (Exception e) {
                                    ConvertigoPlugin.logException(e, "Unable to create screen class from selection zone!");
                                }
                                javelin.setSelectionZone(new Rectangle(0, 0, 0, 0));
                            }
                        });
                    } else {
                        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 : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) InputDialog(org.eclipse.jface.dialogs.InputDialog) TagName(com.twinsoft.convertigo.beans.common.TagName) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) AbstractConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.AbstractConnectorComposite) JavelinConnectorComposite(com.twinsoft.convertigo.eclipse.editors.connector.JavelinConnectorComposite) Rectangle(java.awt.Rectangle) XMLRectangle(com.twinsoft.convertigo.beans.common.XMLRectangle) Javelin(com.twinsoft.twinj.Javelin) 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) XMLRectangle(com.twinsoft.convertigo.beans.common.XMLRectangle) EngineEvent(com.twinsoft.convertigo.engine.EngineEvent) Display(org.eclipse.swt.widgets.Display)

Example 15 with ConnectorEditor

use of com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor 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

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