Search in sources :

Example 16 with MbengNode

use of com.qwest.mbeng.MbengNode in project mdw-designer by CenturyLinkCloud.

the class FormPanel method performGenericAction.

private void performGenericAction(String action) {
    try {
        datadoc.setAttribute(FormDataDocument.ATTR_ACTION, action);
        datadoc.setAttribute(FormDataDocument.ATTR_FORM, formdoc.getId());
        datadoc.setMetaValue(FormDataDocument.META_PRIVILEGES, privileges);
        datadoc.setMetaValue(FormDataDocument.META_USER, dao.getCuid());
        // clear errors
        datadoc.clearErrors();
        String request = datadoc.format();
        String response = dao.engineCall(request);
        // System.out.println("Response: " + response);
        datadoc.load(response);
        List<String> errors = datadoc.getErrors();
        MbengNode node1;
        if (!datadoc.getRootNode().getKind().equals(FormDataDocument.KIND_FORMDATA)) {
            node1 = datadoc.getRootNode().getFirstChild();
            while (node1 != null && errors.size() == 0) {
                if (node1.getKind().contains("StatusMessage")) {
                    errors.add("SUCCESS".equals(node1.getValue()) ? "Unexpected server response." : node1.getValue());
                }
                node1 = node1.getNextSibling();
            }
            if (errors.size() == 0)
                errors.add("Unknown error from engine");
            // change back to form data document
            datadoc.load(request);
        }
        if (errors.size() > 0) {
            show_errors(errors);
        } else {
            String additionalAction = datadoc.getAttribute(FormDataDocument.ATTR_ACTION);
            CallURL callurl = additionalAction == null ? null : new CallURL(additionalAction);
            if (callurl == null) {
                String newFormName = datadoc.getAttribute(FormDataDocument.ATTR_FORM);
                resetData(newFormName, null);
            } else if (callurl.getAction().equals(FormConstants.ACTION_PROMPT)) {
                String message = datadoc.getMetaValue(FormDataDocument.META_PROMPT);
                if (message != null) {
                    show_info(message);
                }
                String newFormName = datadoc.getAttribute(FormDataDocument.ATTR_FORM);
                resetData(newFormName, null);
            } else if (callurl.getAction().equals(FormConstants.ACTION_DIALOG)) {
                String formName = callurl.getParameter(FormConstants.URLARG_FORMNAME);
                if (formName.startsWith(FormConstants.TABLE_ROW_DIALOG_PREFIX)) {
                    String tableId = formName.substring(FormConstants.TABLE_ROW_DIALOG_PREFIX.length());
                    MbengNode tableNode = canvas.getGenerator().getNodeById(tableId);
                    JTablePlus table = (JTablePlus) canvas.getGenerator().getWidget(tableNode);
                    int row = table.getSelectedRow();
                    if (row < 0)
                        throw new Exception("You need to select a row");
                    TableRowDialog dialog = new TableRowDialog(tableNode, table, row);
                    dialog.setVisible(true);
                } else {
                    show_dialog(formName, true);
                }
            } else if (callurl.getAction().equals(FormConstants.ACTION_OK)) {
                String message = datadoc.getMetaValue(FormDataDocument.META_PROMPT);
                if (message != null)
                    show_info(message);
                frame.setVisible(false);
            } else if (callurl.getAction().equals(FormConstants.ACTION_CANCEL)) {
                exit_copy = false;
                frame.setVisible(false);
            } else {
                String newFormName = datadoc.getAttribute(FormDataDocument.ATTR_FORM);
                resetData(newFormName, null);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        show_error(ex.getMessage());
    }
}
Also used : MbengNode(com.qwest.mbeng.MbengNode) CallURL(com.centurylink.mdw.common.utilities.form.CallURL) JTablePlus(com.centurylink.mdw.designer.utils.JTablePlus) MbengException(com.qwest.mbeng.MbengException)

Example 17 with MbengNode

use of com.qwest.mbeng.MbengNode in project mdw-designer by CenturyLinkCloud.

the class SwingFormGenerator method create_tabbedpane.

private Component create_tabbedpane(final MbengNode node, Rectangle vr) throws Exception {
    String id = node.getAttribute(FormConstants.FORMATTR_ID);
    int activeIndex = 0;
    String assoc_data = node.getAttribute(FormConstants.FORMATTR_DATA);
    if (assoc_data == null || assoc_data.length() == 0)
        assoc_data = "__mdwtabindex__" + id;
    if (atRuntime) {
        String v = dataxml.getValue(assoc_data);
        if (v != null && v.length() > 0)
            activeIndex = Integer.parseInt(v);
    }
    String tabbing_style = node.getAttribute(FormConstants.FORMATTR_TABBING_STYLE);
    boolean readonly = atRuntime ? isReadonlyRegardlessAsssignment(node, id) : false;
    if (readonly) {
        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setBackground(null);
        panel.setBounds(vr);
        int k = 0;
        for (MbengNode child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            if (activeIndex == k) {
                String tablabel = child.getAttribute(FormConstants.FORMATTR_LABEL);
                if (tablabel != null && tablabel.length() > 0) {
                    Border redline = BorderFactory.createLineBorder(Color.DARK_GRAY);
                    TitledBorder border = BorderFactory.createTitledBorder(redline, tablabel);
                    panel.setBorder(border);
                }
                create_children(child, panel);
            }
            k++;
        }
        return panel;
    } else if (atRuntime && (FormConstants.FORMATTRVALUE_TABBINGSTYLE_SERVER.equalsIgnoreCase(tabbing_style) || FormConstants.FORMATTRVALUE_TABBINGSTYLE_AJAX.equalsIgnoreCase(tabbing_style))) {
        final JTabbedPane panel = new JTabbedPane();
        panel.setBackground(null);
        panel.setBounds(vr);
        create_children(node, panel);
        ChangeListener tabChangeListener = new ChangeListener() {

            public void stateChanged(ChangeEvent changeEvent) {
                // JTabbedPane panel = (JTabbedPane) changeEvent.getSource();
                int index = panel.getSelectedIndex();
                ActionEvent e = new ActionEvent(panel, index, ACTION_TABBING);
                formpanel.actionPerformed(e);
            }
        };
        panel.setSelectedIndex(activeIndex);
        panel.addChangeListener(tabChangeListener);
        return panel;
    } else {
        // client/jQUery style, or design time
        JTabbedPane panel = new JTabbedPane();
        panel.setBackground(null);
        panel.setBounds(vr);
        create_children(node, panel);
        panel.setSelectedIndex(activeIndex);
        return panel;
    }
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) ActionEvent(java.awt.event.ActionEvent) MbengNode(com.qwest.mbeng.MbengNode) ChangeListener(javax.swing.event.ChangeListener) TitledBorder(javax.swing.border.TitledBorder) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder)

Example 18 with MbengNode

use of com.qwest.mbeng.MbengNode in project mdw-designer by CenturyLinkCloud.

the class SwingFormGenerator method getChoices.

private SelectOption[] getChoices(MbengNode node) throws Exception {
    SelectOption[] options;
    String av = node.getAttribute(FormConstants.FORMATTR_CHOICES);
    if (av != null && av.length() > 0) {
        if (av.startsWith("$$.")) {
            if (atRuntime) {
                NodeFinder nodeFinder = new NodeFinder();
                String path = av.substring(3).replaceAll("\\.", "/");
                MbengNode choicesNode = nodeFinder.find(dataxml.getRootNode(), path);
                if (choicesNode == null) {
                    options = new SelectOption[0];
                } else {
                    ArrayList<SelectOption> list = new ArrayList<SelectOption>();
                    MbengNode choiceNode = choicesNode.getFirstChild();
                    while (choiceNode != null) {
                        SelectOption o = new SelectOption();
                        String v = choiceNode.getValue();
                        int k = v.indexOf(':');
                        if (k >= 0) {
                            o.value = v.substring(0, k);
                            o.label = v.substring(k + 1);
                        } else
                            o.value = o.label = v;
                        o.selected = false;
                        list.add(o);
                        choiceNode = choiceNode.getNextSibling();
                    }
                    options = list.toArray(new SelectOption[list.size()]);
                }
            } else
                options = string2options("dynamically,generated");
        } else
            options = string2options(av);
    } else {
        options = string2options("red,green,blue");
    }
    return options;
}
Also used : MbengNode(com.qwest.mbeng.MbengNode) ArrayList(java.util.ArrayList) NodeFinder(com.qwest.mbeng.NodeFinder)

Example 19 with MbengNode

use of com.qwest.mbeng.MbengNode in project mdw-designer by CenturyLinkCloud.

the class SwingFormGenerator method generate.

public Rectangle generate(MbengDocument desc_doc, FormDataDocument dataxml) throws Exception {
    this.dataxml = dataxml;
    this.assignStatus = dataxml == null ? FormDataDocument.ASSIGN_STATUS_SELF : dataxml.getAssignStatus();
    labelmap = new HashMap<JLabel, MbengNode>();
    widgetmap = new HashMap<Component, MbengNode>();
    nodelabel = new HashMap<Node, JLabel>();
    nodewidget = new HashMap<Node, Component>();
    idnodemap = new HashMap<String, MbengNode>();
    MbengNode node;
    int max_pw = 0, max_ph = 25;
    // setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    canvas.setLayout(null);
    MbengNode rootnode = desc_doc.getRootNode();
    for (node = rootnode.getFirstChild(); node != null; node = node.getNextSibling()) {
        Rectangle vr = create_component(node, lx_default, vx_default, max_ph, canvas);
        if (vr != null) {
            if (vr.x + vr.width + 5 > max_pw)
                max_pw = vr.x + vr.width + 5;
            if (vr.y + vr.height + 5 > max_ph)
                max_ph = vr.y + vr.height + 5;
        }
    }
    widgetmap.put(canvas, rootnode);
    nodewidget.put(getDomNode(rootnode), canvas);
    // panel.setPreferredSize(new Dimension(max_pw,max_ph));
    return determine_vr(desc_doc.getRootNode(), 0, 0, 800, 600);
}
Also used : MbengNode(com.qwest.mbeng.MbengNode) Node(org.w3c.dom.Node) DomNode(com.qwest.mbeng.DomNode) MbengNode(com.qwest.mbeng.MbengNode)

Example 20 with MbengNode

use of com.qwest.mbeng.MbengNode in project mdw-designer by CenturyLinkCloud.

the class SwingFormGenerator method getWidgetFromEventSource.

public Component getWidgetFromEventSource(Component obj) {
    if (obj instanceof JTextArea) {
        obj = obj.getParent().getParent();
    } else if (obj instanceof JTable) {
        while (obj != null && !(obj instanceof JTablePlus)) {
            obj = obj.getParent();
        }
    } else if (obj instanceof JTableHeader) {
        JTableHeader header = (JTableHeader) obj;
        obj = header.getTable();
        while (obj != null && !(obj instanceof JTablePlus)) {
            obj = obj.getParent();
        }
    } else if (obj instanceof JScrollPane) {
        // can be text area, list, or table (the last one is not the main widget)
        Component rootobj = obj;
        while (rootobj != null) {
            MbengNode node = widgetmap.get(rootobj);
            if (node != null)
                return rootobj;
            rootobj = rootobj.getParent();
        }
        // should never come here
        return obj;
    } else if (obj instanceof JList) {
        obj = obj.getParent().getParent();
    // TODO handle JPickList
    }
    return obj;
}
Also used : MbengNode(com.qwest.mbeng.MbengNode) JTableHeader(javax.swing.table.JTableHeader)

Aggregations

MbengNode (com.qwest.mbeng.MbengNode)25 MbengException (com.qwest.mbeng.MbengException)10 JTablePlus (com.centurylink.mdw.designer.utils.JTablePlus)3 Component (java.awt.Component)3 MenuButton (com.centurylink.mdw.designer.utils.SwingFormGenerator.MenuButton)2 DomDocument (com.qwest.mbeng.DomDocument)2 FormatDom (com.qwest.mbeng.FormatDom)2 Container (java.awt.Container)2 ArrayList (java.util.ArrayList)2 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 CallURL (com.centurylink.mdw.common.utilities.form.CallURL)1 FormActionParser (com.centurylink.mdw.common.utilities.form.FormActionParser)1 SelectOption (com.centurylink.mdw.designer.utils.SwingFormGenerator.SelectOption)1 FormDataDocument (com.centurylink.mdw.model.FormDataDocument)1 ActivityVO (com.centurylink.mdw.model.value.activity.ActivityVO)1 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)1 DocumentReference (com.centurylink.mdw.model.value.variable.DocumentReference)1 DomNode (com.qwest.mbeng.DomNode)1 FormatXml (com.qwest.mbeng.FormatXml)1 MbengDocumentClass (com.qwest.mbeng.MbengDocumentClass)1