Search in sources :

Example 1 with JTablePlus

use of com.centurylink.mdw.designer.utils.JTablePlus in project mdw-designer by CenturyLinkCloud.

the class FormWidgetDialog method updateWidgetLabel.

private void updateWidgetLabel(MbengNode node) {
    String labelNew = node.getAttribute(FormConstants.FORMATTR_LABEL);
    if (labelNew != null && !labelNew.equals(labelOld)) {
        if (node.getName().equals(FormConstants.WIDGET_PANEL)) {
            JPanel panel = (JPanel) generator.getWidget(node);
            ((TitledBorder) panel.getBorder()).setTitle(labelNew);
        } else if (node.getName().equals(FormConstants.WIDGET_BUTTON)) {
            JButton button = (JButton) generator.getWidget(node);
            button.setText(labelNew);
        } else if (node.getName().equals(FormConstants.WIDGET_MENU)) {
            Component menu = generator.getWidget(node);
            if (menu instanceof JPopupMenu)
                ((JPopupMenu) menu).setName(labelNew);
            else if (menu instanceof MenuButton)
                ((MenuButton) menu).setText(labelNew);
            else
                ((JMenu) menu).setText(labelNew);
        } else if (node.getName().equals(FormConstants.WIDGET_MENUITEM)) {
            JMenuItem menuitem = (JMenuItem) generator.getWidget(node);
            menuitem.setText(labelNew);
        } else if (node.getName().equals(FormConstants.WIDGET_TAB)) {
            JPanel panel = (JPanel) generator.getWidget(node);
            JTabbedPane tabbedPane = (JTabbedPane) panel.getParent();
            for (int i = 0; i < tabbedPane.getTabCount(); i++) {
                Component comp = tabbedPane.getComponent(i);
                if (comp == panel) {
                    tabbedPane.setTitleAt(i, labelNew);
                    break;
                }
            }
        } else if (node.getName().equals(FormConstants.WIDGET_COLUMN)) {
            JTablePlus tablePlus = (JTablePlus) generator.getWidget(node.getParent());
            int c = Integer.parseInt(node.getAttribute("INDEX"));
            tablePlus.setColumnLabel(c, labelNew);
        } else {
            JLabel label = generator.getLabel(node);
            if (label != null) {
                label.setText(generator.formatText(labelNew));
            }
        }
    }
}
Also used : JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) MenuButton(com.centurylink.mdw.designer.utils.SwingFormGenerator.MenuButton) JLabel(javax.swing.JLabel) TitledBorder(javax.swing.border.TitledBorder) JPopupMenu(javax.swing.JPopupMenu) JTablePlus(com.centurylink.mdw.designer.utils.JTablePlus) JComponent(javax.swing.JComponent) Component(java.awt.Component) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 2 with JTablePlus

use of com.centurylink.mdw.designer.utils.JTablePlus 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)

Example 3 with JTablePlus

use of com.centurylink.mdw.designer.utils.JTablePlus in project mdw-designer by CenturyLinkCloud.

the class FormPanel method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    Component src = (Component) e.getSource();
    if (cmd.equals(FormConstants.ACTION_MENU)) {
        MenuButton button = (MenuButton) src;
        JPopupMenu menu = button.getMenu();
        menu.show(src, src.getWidth() - 10, src.getHeight() - 10);
    } else if (cmd.equals(SwingFormGenerator.ACTION_TABBING)) {
        JTabbedPane tabbedPane = (JTabbedPane) src;
        MbengNode node = canvas.getGenerator().getNode(tabbedPane);
        String id = node.getAttribute(FormConstants.FORMATTR_ID);
        String datapath = node.getAttribute(FormConstants.FORMATTR_DATA);
        if (datapath == null || datapath.length() == 0)
            datapath = "__mdwtabindex__" + id;
        String paginator = node.getAttribute(FormConstants.FORMATTR_ACTION);
        if (paginator == null)
            paginator = "com.centurylink.mdw.listener.formaction.TabChanger";
        int index = e.getID();
        String action = paginator + "?action=tabbing&tabs=" + id + "&tab=" + index + "&data=" + datapath;
        performGenericAction(action);
    } else if (cmd.equals(JTablePlus.ACTION_ENGINE_CALL)) {
        String action = ((JTablePlus) src).getEngineCallAction();
        performGenericAction(action);
    } else {
        MbengNode node = canvas.getGenerator().getNode(src);
        performJavaScriptAction(e, src, cmd, node);
    }
}
Also used : JTabbedPane(javax.swing.JTabbedPane) MbengNode(com.qwest.mbeng.MbengNode) MenuButton(com.centurylink.mdw.designer.utils.SwingFormGenerator.MenuButton) JTablePlus(com.centurylink.mdw.designer.utils.JTablePlus) Component(java.awt.Component) JPopupMenu(javax.swing.JPopupMenu)

Example 4 with JTablePlus

use of com.centurylink.mdw.designer.utils.JTablePlus 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)

Aggregations

JTablePlus (com.centurylink.mdw.designer.utils.JTablePlus)4 MbengNode (com.qwest.mbeng.MbengNode)3 MenuButton (com.centurylink.mdw.designer.utils.SwingFormGenerator.MenuButton)2 MbengException (com.qwest.mbeng.MbengException)2 Component (java.awt.Component)2 JPopupMenu (javax.swing.JPopupMenu)2 JTabbedPane (javax.swing.JTabbedPane)2 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 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 JRadioButton (javax.swing.JRadioButton)1 TitledBorder (javax.swing.border.TitledBorder)1