MCPcopy Create free account
hub / github.com/BombusMod/BombusMod / FormField

Method FormField

src/main/java/ServiceDiscovery/FormField.java:65–186  ·  view source on GitHub ↗

Creates a new instance of FormField

(JabberDataBlock field)

Source from the content-addressed store, hash-verified

63
64 /** Creates a new instance of FormField */
65 public FormField(JabberDataBlock field) {
66 name = field.getTagName();
67 label = name;
68 body = field.getText();
69 if (name.equals("field")) {
70 // x:data
71 type = field.getTypeAttribute();
72 name = field.getAttribute("var");
73 label = field.getAttribute("label");
74 if (label == null) {
75 label = name;
76 }
77 body = field.getChildBlockText("value");
78 if (type == null) {
79 media = extractMedia(field);
80 formItem = new TextInput(label, body, null);
81 return;
82 }
83
84 required = field.getChildBlock("required") != null;
85 if (required) {
86 label = label + " *";
87 }
88
89 hidden = type.equals("hidden");
90
91 if (type.equals("fixed")) {
92 formItem = new MultiLine(label, body);
93 } else if (type.equals("boolean")) {
94 boolean set = false;
95 if (body.equals("1")) {
96 set = true;
97 }
98 if (body.equals("true")) {
99 set = true;
100 }
101 numericBoolean = body.length() == 1;
102 CheckBox ch = new CheckBox(label, set);
103 formItem = ch;
104 } else if (type.equals("list-single")) {
105 DropChoiceBox ch = new DropChoiceBox(label);
106
107 optionsList = null;
108 optionsList = new Vector();
109 for (Enumeration e = field.getChildBlocks().elements(); e.hasMoreElements();) {
110 JabberDataBlock option = (JabberDataBlock) e.nextElement();
111 if (option.getTagName().equals("option")) {
112 String value = option.getChildBlockText("value");
113 String label = option.getAttribute("label");
114 if (label == null) {
115 label = value;
116 }
117 optionsList.addElement(value);
118 ch.items.addElement(label);
119 if (body.equals(value)) {
120 int index = ch.items.size() - 1;
121 ((DropChoiceBox) ch).setSelectedIndex(index);
122 }

Callers

nothing calls this directly

Calls 15

getTagNameMethod · 0.95
getAttributeMethod · 0.95
getChildBlockTextMethod · 0.95
extractMediaMethod · 0.95
getTypeAttributeMethod · 0.80
getChildBlockMethod · 0.80
elementsMethod · 0.80
getChildBlocksMethod · 0.80
addElementMethod · 0.80
setSelectedIndexMethod · 0.80
getChildBlockByTextMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected