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());
}
}
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;
}
}
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;
}
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);
}
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;
}
Aggregations