Search in sources :

Example 1 with MbengNode

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

the class DesignerDataAccess method updateVariableInstanceThruServer.

public void updateVariableInstanceThruServer(VariableInstanceInfo var, String value, boolean isDocument) throws RemoteException, DataAccessException {
    if (this.dbSchemaVersion < 5000 && isDocument) {
        // temporary work-around by updating database directly
        // need to enhance 4.5 code to handle document variables
        DocumentReference docref = new DocumentReference(var.getStringValue());
        rtinfo.updateDocumentContent(docref.getDocumentId(), value);
    } else {
        DomDocument domdoc = new DomDocument();
        FormatDom fmter = new FormatDom();
        domdoc.getRootNode().setName("_mdw_update_variable");
        MbengNode node = domdoc.newNode("var_value", value, "", ' ');
        domdoc.getRootNode().appendChild(node);
        if (var.getInstanceId() == null) {
            node = domdoc.newNode("var_name", var.getName(), "", ' ');
            domdoc.getRootNode().appendChild(node);
            node = domdoc.newNode("proc_inst_id", var.getStringValue(), "", ' ');
            domdoc.getRootNode().appendChild(node);
            String res = this.engineCall(fmter.format(domdoc));
            if (res.startsWith("OK:")) {
                String[] vs = res.split(":");
                var.setInstanceId(new Long(vs[1]));
                if (vs.length == 3) {
                    DocumentReference docref = new DocumentReference(new Long(vs[2]), null);
                    var.setStringValue(docref.toString());
                }
            } else
                throw new DataAccessException(res);
        } else {
            node = domdoc.newNode("var_inst_id", var.getInstanceId().toString(), "", ' ');
            domdoc.getRootNode().appendChild(node);
            String res = this.engineCall(fmter.format(domdoc));
            if (!"OK".equals(res))
                throw new DataAccessException(res);
        }
    }
    auditLog(Action.Create, Entity.VariableInstance, var.getInstanceId(), var.getName());
}
Also used : FormatDom(com.qwest.mbeng.FormatDom) MbengNode(com.qwest.mbeng.MbengNode) DocumentReference(com.centurylink.mdw.model.value.variable.DocumentReference) DataAccessException(com.centurylink.mdw.common.exception.DataAccessException) DomDocument(com.qwest.mbeng.DomDocument)

Example 2 with MbengNode

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

the class Graph method addNode.

private Node addNode(GraphCommon owner, ActivityImplementorVO nmi, int x, int y, boolean recordchange) {
    String name = "New " + nmi.getLabel();
    if (nmi.isManualTask()) {
        if (owner instanceof SubGraph)
            name = processVO.getProcessName() + " Fallout";
        else
            name = "New Task for " + processVO.getProcessName();
    }
    Long pActId = genNodeId();
    String pDesc = null;
    String pActImplClass = nmi.getImplementorClassName();
    ArrayList<AttributeVO> pAttribs = new ArrayList<AttributeVO>();
    if (nmi.isManualTask()) {
        pAttribs.add(new AttributeVO(TaskActivity.ATTRIBUTE_TASK_NAME, name));
        pAttribs.add(new AttributeVO(TaskActivity.ATTRIBUTE_TASK_CATEGORY, "COM"));
        pAttribs.add(new AttributeVO(TaskActivity.ATTRIBUTE_TASK_VARIABLES, TaskVO.getVariablesAsString(processVO.getVariables(), null)));
    }
    ActivityVO nodet = new ActivityVO(pActId, name, pDesc, pActImplClass, pAttribs);
    owner.getProcessVO().getActivities().add(nodet);
    Node node = new Node(nodet, owner, metainfo);
    String iconname = node.getIconName();
    javax.swing.Icon icon = getIconFactory().getIcon(iconname);
    if (nodestyle.equals(Node.NODE_STYLE_ICON)) {
        node.w = icon.getIconWidth();
        node.h = icon.getIconHeight();
    } else {
        if (icon instanceof ImageIcon) {
            node.w = 100;
            node.h = 60;
        } else {
            node.w = 60;
            node.h = 40;
        }
    }
    node.x = x;
    node.y = y;
    owner.nodes.add(node);
    String xmldesc = nmi.getAttributeDescription();
    if (xmldesc != null && xmldesc.length() > 0) {
        FormatDom fmter = new FormatDom();
        DomDocument doc = new DomDocument();
        try {
            fmter.load(doc, xmldesc);
            MbengNode widget;
            String default_value, attr_name;
            for (widget = doc.getRootNode().getFirstChild(); widget != null; widget = widget.getNextSibling()) {
                default_value = widget.getAttribute("DEFAULT");
                if (default_value == null)
                    continue;
                if (widget.getAttribute("UNITS_ATTR") != null)
                    continue;
                attr_name = widget.getAttribute("NAME");
                if (attr_name == null)
                    continue;
                if (default_value.equals("$DefaultNotices")) {
                    node.setAttribute(attr_name, TaskVO.getDefaultNotices());
                } else
                    node.setAttribute(attr_name, default_value);
            }
        } catch (MbengException e) {
        }
    }
    if (recordchange)
        node.getChanges().setChangeType(Changes.NEW);
    setDirtyLevel(DIRTY);
    return node;
}
Also used : ImageIcon(javax.swing.ImageIcon) MbengException(com.qwest.mbeng.MbengException) AttributeVO(com.centurylink.mdw.model.value.attribute.AttributeVO) ActivityVO(com.centurylink.mdw.model.value.activity.ActivityVO) MbengNode(com.qwest.mbeng.MbengNode) FormatDom(com.qwest.mbeng.FormatDom) ArrayList(java.util.ArrayList) MbengNode(com.qwest.mbeng.MbengNode) DomDocument(com.qwest.mbeng.DomDocument)

Example 3 with MbengNode

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

the class FormDesignCanvas method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    Component src = (Component) e.getSource();
    MbengNode node = generator.getNode(src);
    if (cmd.equals(FormConstants.ACTION_MENU)) {
        MenuButton button = (MenuButton) src;
        JPopupMenu menu = button.getMenu();
        menu.show(src, src.getWidth() - 10, src.getHeight() - 10);
    } else {
        showWidgetDialog(node);
    }
}
Also used : MbengNode(com.qwest.mbeng.MbengNode) MenuButton(com.centurylink.mdw.designer.utils.SwingFormGenerator.MenuButton)

Example 4 with MbengNode

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

the class FormPanel method setData.

/**
 * this is invoked when coming from script list page or package tree
 */
public void setData(String formname, String data) throws Exception {
    try {
        formdoc = loadForm(formname);
        datadoc = new FormDataDocument();
        if (data != null && data.length() > 0)
            datadoc.load(data);
        canvas = new FormDesignCanvas(frame, this, dao);
        canvas.setFormXml(formdoc, datadoc);
        JScrollPane canvasScrollpane = new JScrollPane(canvas);
        MbengNode rootnode = canvas.getFormXml().getRootNode();
        String av = rootnode.getAttribute(FormConstants.FORMATTR_VW);
        int w = (av == null) ? 800 : Integer.parseInt(av);
        av = rootnode.getAttribute(FormConstants.FORMATTR_VH);
        int h = (av == null) ? 600 : Integer.parseInt(av);
        this.add(canvasScrollpane, BorderLayout.CENTER);
        Container content_pane;
        if (frame instanceof JDialog) {
            content_pane = ((JDialog) frame).getContentPane();
        } else {
            content_pane = ((JFrame) frame).getContentPane();
        }
        content_pane.add(this);
        frame.setSize(w + 10, h + 30);
    } catch (Exception e) {
        e.printStackTrace();
        show_error("failed to set data for canvas: " + e.getMessage());
        throw e;
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) Container(java.awt.Container) MbengNode(com.qwest.mbeng.MbengNode) FormDataDocument(com.centurylink.mdw.model.FormDataDocument) JDialog(javax.swing.JDialog) MbengException(com.qwest.mbeng.MbengException)

Example 5 with MbengNode

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

the class FormPanel method performJavaScriptAction.

private void performJavaScriptAction(ActionEvent event, Component src, String cmd, MbengNode node) {
    String action = node.getAttribute(FormConstants.FORMATTR_ACTION);
    if (cmd.equals(SwingFormGenerator.ACTION_DROPDOWN)) {
        Object selected = ((JComboBox) src).getSelectedItem();
        if (selected != null && selected instanceof SelectOption) {
            this.setDataValue(node, ((SelectOption) selected).getValue());
        }
    } else if (cmd.equals(SwingFormGenerator.ACTION_RADIOBUTTON)) {
        this.setDataValue(node, ((JRadioButton) src).getName());
    } else if (cmd.equals(SwingFormGenerator.ACTION_CHECKBOX)) {
        String av = ((JCheckBox) src).getName();
        String[] choices = av.split(",");
        this.setDataValue(node, ((JCheckBox) src).isSelected() ? choices[1] : choices[0]);
    }
    try {
        FormActionParser command = new FormActionParser(action);
        String functionName = command.getFunctionName();
        if (functionName.equals("dialog_open")) {
            try {
                String formname = command.getArgument(0);
                show_dialog(formname, true);
            } catch (Exception e) {
                e.printStackTrace();
                show_error("Failed to load script " + e.getMessage());
            }
        } else if (functionName.equals("dialog_ok")) {
            frame.setVisible(false);
        } else if (functionName.equals("dialog_cancel")) {
            exit_copy = false;
            frame.setVisible(false);
        } else if (functionName.equals("hyperlink")) {
            this.launchBrowser(command.getArgument(0));
        } else if (functionName.equals("validate")) {
        } else if (functionName.equals("repaint")) {
        } else if (functionName.equals("task_action")) {
        } else if (functionName.equals("perform_action")) {
            performGenericAction(command.getArgument(0));
        } else if (functionName.equals("ajax_action")) {
            performGenericAction(command.getArgument(0));
        } else if (functionName.equals("ajax_action_async")) {
            performGenericAction(command.getArgument(0));
        } else if (functionName.equals("show_page")) {
            boolean inNewWindow = "true".equalsIgnoreCase(command.getArgument(1));
            String formname = command.getArgument(0);
            if (inNewWindow) {
                try {
                    show_dialog(formname, false);
                } catch (Exception e) {
                    e.printStackTrace();
                    show_error("Failed to load script " + e.getMessage());
                }
            } else {
                try {
                    this.resetData(formname, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    show_error("Failed to load script " + e.getMessage());
                }
            }
        } else if (functionName.equals("start_process")) {
            action = FormConstants.ACTION_START_PROCESS + "?" + FormDataDocument.META_PROCESS_NAME + "=" + command.getArgument(0);
            if (command.getArgumentCount() >= 2 && command.getArgument(1).length() > 0)
                action += "&" + FormDataDocument.META_MASTER_REQUEST_ID + "=" + command.getArgument(1);
            performGenericAction(action);
        } else if (functionName.equals("table_row_view")) {
            String tableId = command.getArgument(0);
            // String dialogId = command.getArgument(1); TODO implement custom dialog
            MbengNode tableNode = canvas.getGenerator().getNodeById(tableId);
            if (tableNode == null)
                throw new Exception("Table node does not exist - id=" + 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 if (functionName.equals("table_row_new")) {
            String tableId = command.getArgument(0);
            // String dialogId = command.getArgument(1); TODO implement custom dialog
            MbengNode tableNode = canvas.getGenerator().getNodeById(tableId);
            if (tableNode == null)
                throw new Exception("Table node does not exist - id=" + tableId);
            JTablePlus table = (JTablePlus) canvas.getGenerator().getWidget(tableNode);
            TableRowDialog dialog = new TableRowDialog(tableNode, table, -1);
            dialog.setVisible(true);
        } else if (functionName.equals("table_row_delete")) {
            String tableId = command.getArgument(0);
            // String dialogId = command.getArgument(1); TODO implement custom dialog
            MbengNode tableNode = canvas.getGenerator().getNodeById(tableId);
            if (tableNode == null)
                throw new Exception("Table node does not exist - id=" + tableId);
            JTablePlus table = (JTablePlus) canvas.getGenerator().getWidget(tableNode);
            String datapath = tableNode.getAttribute(FormConstants.FORMATTR_DATA);
            String paginator = tableNode.getAttribute(FormConstants.FORMATTR_ACTION);
            String av = tableNode.getAttribute(FormConstants.FORMATTR_TABLE_STYLE);
            boolean isPaginated = FormConstants.FORMATTRVALUE_TABLESTYLE_PAGINATED.equals(av);
            boolean useMetaData = true;
            if (useMetaData) {
                action = paginator + "?action=deleterow&table=" + datapath + "&meta=" + datapath + "_META&topage=" + (isPaginated ? "S" : "R");
            } else {
                int row = table.getSelectedRow();
                if (row < 0)
                    throw new Exception("You need to select a row");
                action = paginator + "?action=deleterow&table=" + datapath + "&meta=" + datapath + "_META&row=" + row + "&topage=" + (isPaginated ? "S" : "R");
            }
            performGenericAction(action);
        } else if (functionName.equals("switch_server")) {
            String server_name = datadoc.getValue(command.getArgument(0));
            server_name = server_name.replace(" port ", ":");
            String serverUrl = dao.getCurrentServer().getServerUrl();
            int k1 = serverUrl.indexOf("://");
            int k2 = serverUrl.indexOf("/", k1 + 4);
            String newServerUrl = k2 > 0 ? (serverUrl.substring(0, k1 + 3) + server_name + serverUrl.substring(k2)) : (serverUrl.substring(0, k1 + 3) + server_name);
            dao.getCurrentServer().setServerUrl(newServerUrl);
            performGenericAction(command.getArgument(1));
        } else
            throw new Exception("Unknown action function " + functionName);
    } catch (Exception e) {
        if (!(action == null || action.length() == 0) || !(cmd.equals(SwingFormGenerator.ACTION_DROPDOWN) || cmd.equals(SwingFormGenerator.ACTION_RADIOBUTTON)))
            show_error(e.getMessage());
    }
}
Also used : FormActionParser(com.centurylink.mdw.common.utilities.form.FormActionParser) JRadioButton(javax.swing.JRadioButton) JComboBox(javax.swing.JComboBox) MbengNode(com.qwest.mbeng.MbengNode) MbengException(com.qwest.mbeng.MbengException) JCheckBox(javax.swing.JCheckBox) SelectOption(com.centurylink.mdw.designer.utils.SwingFormGenerator.SelectOption) JTablePlus(com.centurylink.mdw.designer.utils.JTablePlus)

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