Search in sources :

Example 1 with ACLNptuiWindow

use of com.eicon.iConnect.acl.ACLNptuiWindow in project convertigo by convertigo.

the class Nptui method execute.

/**
 * Applies the extraction rule to the current iJavelin object.
 *
 * @param javelin the Javelin object.
 * @param block the current block to analyze.
 * @param blockFactory the block context of the current block.
 *
 * @return an ExtractionRuleResult object containing the result of
 * the query.
 */
public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
    JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
    int screenWidth = javelin.getScreenWidth();
    if (bFirstTime) {
        bFirstTime = false;
        ACLNptuiScreen mptuiScreen = null;
        try {
            mptuiScreen = (ACLNptuiScreen) javelin.getInternalDataStructure();
        } catch (ClassCastException e) {
            xrs.hasMatched = false;
            xrs.newCurrentBlock = block;
            return (xrs);
        }
        ACLNptuiComponent[] components = mptuiScreen.getComponents();
        if (components.length == 0) {
            // no Nptui component on this screen
            xrs.hasMatched = false;
            xrs.newCurrentBlock = block;
            return (xrs);
        }
        ACLNptuiWindow[] windows = mptuiScreen.getWindows();
        // inspect all windows to handle them first
        for (int i = 0; i < windows.length; i++) {
            Engine.logBeans.trace("Treating window " + i + " : z-order " + windows[i].getZOrder());
            treatAndAddComponent(windows[i], screenWidth, dom, blockFactory, null, javelin);
        }
        // inspect all other components
        for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof ACLNptuiWindow) {
                Engine.logBeans.trace("Not treating component " + i + " : " + components[i].getClass());
            } else {
                Engine.logBeans.trace("Treating component " + i + " : " + components[i].getClass());
                treatAndAddComponent(components[i], screenWidth, dom, blockFactory, null, javelin);
            }
        }
        xrs.hasMatched = true;
        xrs.newCurrentBlock = block;
        return (xrs);
    } else {
        xrs.hasMatched = false;
        xrs.newCurrentBlock = block;
        return (xrs);
    }
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult) ACLNptuiScreen(com.eicon.iConnect.acl.ACLNptuiScreen) ACLNptuiComponent(com.eicon.iConnect.acl.ACLNptuiComponent) ACLNptuiWindow(com.eicon.iConnect.acl.ACLNptuiWindow)

Example 2 with ACLNptuiWindow

use of com.eicon.iConnect.acl.ACLNptuiWindow in project convertigo by convertigo.

the class Nptui method treatAndAddComponent.

/**
 * Treat a NPTUI component, create a block corresponding to it,
 * add this block to the block factory,
 * remove old blocks corresponding to it from block factory,
 * treat window's children components,
 * copy window's children blocks in optionnal children,
 * etc.
 *
 * @param component : the NPTUI component to treat
 * @param screenWidth : the screen width
 * @param dom : the DOM
 * @param blockFactory : the block factory
 * @param parent : the parent Block, the window to which add the component if it is a window's child, null if no parent window exists.
 * @param javelin : the javelin emulator object
 */
private void treatAndAddComponent(ACLNptuiComponent component, int screenWidth, org.w3c.dom.Document dom, BlockFactory blockFactory, Block parent, iJavelin javelin) {
    int offset = component.getScreenOffset();
    int compLine, compCol;
    if (offset % screenWidth != 0) {
        compLine = offset / screenWidth;
        compCol = offset % screenWidth;
    } else {
        compLine = (offset / screenWidth) - 1;
        compCol = 0;
    }
    int cursorLine = javelin.getCurrentLine();
    int cursorColumn = javelin.getCurrentColumn();
    if (blockFactory == null) {
        // no parent block defined and no blockFactory
        Engine.logBeans.trace("(treatAndAddComponent) no parent block defined and no blockFactory");
        return;
    }
    // look for the object place in blockFactory
    Block beginBlock = blockFactory.getFirstBlock();
    Block afterBlock = null;
    if (beginBlock == null) {
        // no block in blockFactory
        Engine.logBeans.trace("(treatAndAddComponent) no block in blockFactory");
        return;
    }
    // there is at least one block in blockFactory
    if (beginBlock.line == compLine && beginBlock.column >= compCol) {
        // the block matching component's line and column is the first block of blockFactory
        afterBlock = null;
    } else {
        while (// while beginBlock is on a line inferior to compLine
        beginBlock.line < compLine || (beginBlock.line == compLine && beginBlock.column < compCol)) {
            // or beginBlock is on the good line but on a column inferior to compCol
            afterBlock = beginBlock;
            beginBlock = blockFactory.getNextBlock(beginBlock);
            if (beginBlock == null) {
                // no block in blockFactory is matching component's line and column
                Engine.logBeans.trace("(treatAndAddComponent) no block in blockFactory is matching component's line and column");
                return;
            }
        }
    }
    if (component instanceof ACLNptuiWindow) {
        if (bWindow) {
            Engine.logBeans.trace("(treatAndAddComponent) window detected and extraction allowed");
            ACLNptuiWindow comp = (ACLNptuiWindow) component;
            Block myPanel = new Block();
            myPanel.name = "untitled";
            myPanel.type = "panel";
            myPanel.setText("");
            myPanel.bRender = true;
            myPanel.line = compLine;
            myPanel.column = compCol;
            int height = comp.getHeight() - 1;
            myPanel.setOptionalAttribute("width", "" + comp.getWidth());
            myPanel.setOptionalAttribute("height", "" + height);
            myPanel.setOptionalAttribute("shadow", "" + comp.isShadow());
            if (comp.getHeader() != null) {
                myPanel.setOptionalAttribute("topTitle", "" + comp.getHeader());
                myPanel.setOptionalAttribute("topTitleColumn", "" + comp.getHeaderJustification());
            } else {
                myPanel.setOptionalAttribute("topTitle", "");
                myPanel.setOptionalAttribute("topTitleColumn", "");
            }
            if (comp.getFooter() != null) {
                myPanel.setOptionalAttribute("bottomTitle", "" + comp.getFooter());
                myPanel.setOptionalAttribute("bottomTitleColumn", "" + comp.getFooterJustification());
            } else {
                myPanel.setOptionalAttribute("bottomTitle", "");
                myPanel.setOptionalAttribute("bottomTitleColumn", "");
            }
            myPanel.setOptionalAttribute("zOrder", "" + comp.getZOrder());
            // comp.isPullDownMenu());
            // treat every contained components
            ACLNptuiComponent[] childrenComp = comp.getComponents();
            for (int i = 0; i < childrenComp.length; i++) {
                Engine.logBeans.trace("Treating window child component " + i + " : " + childrenComp[i].getClass());
                treatAndAddComponent(childrenComp[i], screenWidth, dom, blockFactory, myPanel, javelin);
            }
            // remove blocks from the existant window, and copy the content blocks to the new window
            removeBlocksFromWindow(blockFactory, afterBlock, compCol, compLine, comp.getWidth() + 2, comp.getHeight(), myPanel, dom);
            if (parent == null) {
                blockFactory.insertBlock(myPanel, afterBlock);
            } else {
                // window in another component : impossible
                Engine.logBeans.trace("(treatAndAddComponent) window in another component : error, don't add this component");
            }
        } else {
            Engine.logBeans.trace("(treatAndAddComponent) window detected but extraction not allowed");
        }
    } else if (component instanceof ACLNptuiScrollBar) {
        if (bScrollBar) {
            Engine.logBeans.trace("(treatAndAddComponent) scrollbar detected and extraction allowed");
            ACLNptuiScrollBar comp = (ACLNptuiScrollBar) component;
            Block mySlider = new Block();
            mySlider.name = "untitled";
            mySlider.type = "slider";
            mySlider.setText("");
            mySlider.line = compLine;
            mySlider.column = compCol;
            if (comp.isHorizontal()) {
                mySlider.setOptionalAttribute("width", "" + comp.getSize());
                mySlider.setOptionalAttribute("height", "1");
            } else {
                mySlider.setOptionalAttribute("width", "1");
                mySlider.setOptionalAttribute("height", "" + comp.getSize());
            }
            mySlider.setOptionalAttribute("shadow", "" + comp.isShadow());
            mySlider.setOptionalAttribute("hasArrows", "" + comp.hasArrows());
            mySlider.setOptionalAttribute("itemsCount", "" + comp.getItemsCount());
            mySlider.setOptionalAttribute("itemsCountBeforeSlider", "" + comp.getItemsCountBeforeSlider());
            mySlider.setOptionalAttribute("sliderSize", "" + comp.getSliderSize());
            mySlider.setOptionalAttribute("sliderPos", "" + comp.getSliderPosInShaft());
            // remove blocks from blockFactory
            if (comp.isHorizontal()) {
                removeBlocksHorizontaly(blockFactory, afterBlock, compCol, compLine, comp.getSize());
            } else {
                removeBlocksVerticaly(blockFactory, afterBlock, compCol, compLine, comp.getSize());
            }
            // add generated blocks
            if (parent == null) {
                blockFactory.insertBlock(mySlider, afterBlock);
            } else {
                // scrollbar in window
                parent.addOptionalChildren(mySlider);
            }
        } else {
            Engine.logBeans.trace("(treatAndAddComponent) scrollbar detected but extraction not allowed");
        }
    } else if (component instanceof ACLNptuiSelectionField) {
        ACLNptuiSelectionField comp = (ACLNptuiSelectionField) component;
        Block myContainer = new Block();
        myContainer.name = "untitled";
        myContainer.setText("");
        myContainer.line = compLine;
        myContainer.column = compCol;
        myContainer.setOptionalAttribute("shadow", "" + comp.isShadow());
        myContainer.setOptionalAttribute("choicesTextSize", "" + comp.getChoiceTextSize());
        myContainer.setOptionalAttribute("choicesCols", "" + comp.getChoiceColumns());
        myContainer.setOptionalAttribute("choicesRows", "" + comp.getChoiceRows());
        if (comp.isAutoEnter())
            myContainer.setOptionalAttribute("autoEnter", "" + comp.isAutoEnter());
        if (comp.isAutoSelect())
            myContainer.setOptionalAttribute("autoSelect", "" + comp.isAutoSelect());
        ACLNptuiChoice[] choices = comp.getChoices();
        int type = ((ACLNptuiSelectionField) component).getType();
        if (type == ACLNptuiSelectionField.TYPE_BUTTONS) {
            if (bButton) {
                Engine.logBeans.trace("(treatAndAddComponent) buttons detected and extraction allowed");
                myContainer.type = "buttonsPanel";
                for (int j = 0; j < choices.length; j++) {
                    ACLNptuiChoice choice = choices[j];
                    int choiceOffset = choice.getScreenOffset();
                    Element element = dom.createElement("block");
                    element.setAttribute("name", "untitled");
                    element.setAttribute("type", "keyword");
                    Text textNode = dom.createTextNode(choice.getText());
                    element.appendChild(textNode);
                    int choiceLine, choiceColumn;
                    if (choiceOffset % screenWidth != 0) {
                        choiceLine = choiceOffset / screenWidth;
                        choiceColumn = choiceOffset % screenWidth;
                    } else {
                        choiceLine = (choiceOffset / screenWidth) - 1;
                        choiceColumn = 0;
                    }
                    element.setAttribute("line", "" + choiceLine);
                    element.setAttribute("column", "" + choiceColumn);
                    element.setAttribute("action", "KEY_NPTUI");
                    element.setAttribute("width", "" + choice.getLength());
                    element.setAttribute("height", "1");
                    element.setAttribute("dotransaction", "false");
                    element.setAttribute("available", "" + choice.isAvailable());
                    // handle cursor focus
                    if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
                        element.setAttribute("hasFocus", "true");
                    // handle attributes and remove old blocks from block factory
                    int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
                    addAttributes(attribute, element);
                    // add the element to container
                    myContainer.addOptionalChildren(element);
                }
            } else {
                Engine.logBeans.trace("(treatAndAddComponent) buttons detected but extraction not allowed");
            }
        } else if (type == ACLNptuiSelectionField.TYPE_CHECK) {
            if (bCheckbox) {
                Engine.logBeans.trace("(treatAndAddComponent) checkboxes detected and extraction allowed");
                myContainer.type = "checkboxesPanel";
                for (int j = 0; j < choices.length; j++) {
                    ACLNptuiChoice choice = choices[j];
                    int choiceOffset = choice.getScreenOffset();
                    Element element = dom.createElement("item");
                    element.setAttribute("name", "untitled");
                    element.setAttribute("type", "checkbox");
                    Text textNode = dom.createTextNode(choice.getText());
                    element.appendChild(textNode);
                    int choiceLine, choiceColumn;
                    if (choiceOffset % screenWidth != 0) {
                        choiceLine = choiceOffset / screenWidth;
                        choiceColumn = choiceOffset % screenWidth;
                    } else {
                        choiceLine = (choiceOffset / screenWidth) - 1;
                        choiceColumn = 0;
                    }
                    element.setAttribute("line", "" + choiceLine);
                    element.setAttribute("column", "" + choiceColumn);
                    element.setAttribute("checked", "" + choice.isSelected());
                    // handle cursor focus
                    if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
                        element.setAttribute("hasFocus", "true");
                    // handle attributes and remove old blocks from block factory
                    int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
                    addAttributes(attribute, element);
                    // add the element to container
                    myContainer.addOptionalChildren(element);
                }
            } else {
                Engine.logBeans.trace("(treatAndAddComponent) checkboxes detected but extraction not allowed");
            }
        } else if (type == ACLNptuiSelectionField.TYPE_MENU) {
            if (bMenu) {
                Engine.logBeans.trace("(treatAndAddComponent) menu detected and extraction allowed");
                myContainer.type = "menu";
                for (int j = 0; j < choices.length; j++) {
                    ACLNptuiChoice choice = choices[j];
                    int choiceOffset = choice.getScreenOffset();
                    Element element = dom.createElement("item");
                    element.setAttribute("name", "untitled");
                    element.setAttribute("type", "menuItem");
                    element.setAttribute("value", choice.getText());
                    int choiceLine, choiceColumn;
                    if (choiceOffset % screenWidth != 0) {
                        choiceLine = choiceOffset / screenWidth;
                        choiceColumn = choiceOffset % screenWidth;
                    } else {
                        choiceLine = (choiceOffset / screenWidth) - 1;
                        choiceColumn = 0;
                    }
                    element.setAttribute("line", "" + choiceLine);
                    element.setAttribute("column", "" + choiceColumn);
                    element.setAttribute("selected", "" + choice.isSelected());
                    element.setAttribute("available", "" + choice.isAvailable());
                    element.setAttribute("hilighted", "" + choice.isHilighted());
                    // handle cursor focus
                    if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
                        element.setAttribute("hasFocus", "true");
                    // handle attributes and remove old blocks from block factory
                    int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
                    addAttributes(attribute, element);
                    // add the element to container
                    myContainer.addOptionalChildren(element);
                }
            } else {
                Engine.logBeans.trace("(treatAndAddComponent) menu detected but extraction not allowed");
            }
        } else if (type == ACLNptuiSelectionField.TYPE_RADIO) {
            if (bRadio) {
                Engine.logBeans.trace("(treatAndAddComponent) radio buttons detected and extraction allowed");
                myContainer.type = "radioPanel";
                for (int j = 0; j < choices.length; j++) {
                    ACLNptuiChoice choice = choices[j];
                    int choiceOffset = choice.getScreenOffset();
                    Element element = dom.createElement("item");
                    element.setAttribute("name", "untitled");
                    element.setAttribute("type", "radio");
                    element.setAttribute("value", choice.getText());
                    int choiceLine, choiceColumn;
                    if (choiceOffset % screenWidth != 0) {
                        choiceLine = choiceOffset / screenWidth;
                        choiceColumn = choiceOffset % screenWidth;
                    } else {
                        choiceLine = (choiceOffset / screenWidth) - 1;
                        choiceColumn = 0;
                    }
                    element.setAttribute("line", "" + choiceLine);
                    element.setAttribute("column", "" + choiceColumn);
                    element.setAttribute("selected", "" + choice.isSelected());
                    // handle cursor focus
                    if (cursorLine == choiceLine && cursorColumn >= choiceColumn && cursorColumn < choiceColumn + choice.getLength())
                        element.setAttribute("hasFocus", "true");
                    // handle attributes and remove old blocks from block factory
                    int attribute = removeBlocksHorizontaly(blockFactory, afterBlock, choiceColumn, choiceLine, choice.getLength());
                    addAttributes(attribute, element);
                    // add the element to container
                    myContainer.addOptionalChildren(element);
                }
            } else {
                Engine.logBeans.trace("(treatAndAddComponent) radio buttons detected but extraction not allowed");
            }
        } else {
            // type is unknown or not handled
            Engine.logBeans.trace("(treatAndAddComponent) Type is unknown or not handled");
            return;
        }
        // if the children have been added (if the boolean was true)
        if (myContainer.hasOptionalChildren()) {
            // add generated blocks
            if (parent == null) {
                blockFactory.insertBlock(myContainer, afterBlock);
            } else {
                // SelectionField in window
                parent.addOptionalChildren(myContainer);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) Block(com.twinsoft.convertigo.beans.core.Block) ACLNptuiChoice(com.eicon.iConnect.acl.ACLNptuiChoice) Text(org.w3c.dom.Text) ACLNptuiComponent(com.eicon.iConnect.acl.ACLNptuiComponent) ACLNptuiWindow(com.eicon.iConnect.acl.ACLNptuiWindow) ACLNptuiScrollBar(com.eicon.iConnect.acl.ACLNptuiScrollBar) ACLNptuiSelectionField(com.eicon.iConnect.acl.ACLNptuiSelectionField)

Aggregations

ACLNptuiComponent (com.eicon.iConnect.acl.ACLNptuiComponent)2 ACLNptuiWindow (com.eicon.iConnect.acl.ACLNptuiWindow)2 ACLNptuiChoice (com.eicon.iConnect.acl.ACLNptuiChoice)1 ACLNptuiScreen (com.eicon.iConnect.acl.ACLNptuiScreen)1 ACLNptuiScrollBar (com.eicon.iConnect.acl.ACLNptuiScrollBar)1 ACLNptuiSelectionField (com.eicon.iConnect.acl.ACLNptuiSelectionField)1 Block (com.twinsoft.convertigo.beans.core.Block)1 JavelinExtractionRuleResult (com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)1 Element (org.w3c.dom.Element)1 Text (org.w3c.dom.Text)1