@SuppressWarnings("unchecked")
@Override
protected void okPressed() {
setReturnCode(OK);
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
HashMap attributes = new HashMap();
if(reg != null)
registration.setTo(reg.getFrom());
if(form == null) {
// Text username = (Text)dialogArea.getData("username");
// Text password = (Text)dialogArea.getData("password");
// registration.setUsername(username.getText());
// registration.setPassword(password.getText());
Map<String,String> atts = reg.getAttributes();
for(String key : atts.keySet()) {
Text input = (Text)dialogArea.getData(key);
if(input != null)
attributes.put(key,input.getText());
}
} else {
Form reply = form.createAnswerForm();
Iterator i = reply.getFields();
while(i.hasNext()) {
FormField field = (FormField)i.next();
if(field.getType().equals(FormField.TYPE_HIDDEN)) continue;
Object obj = (Control)dialogArea.getData(field.getVariable());
if(obj instanceof Text) {
String val;
reply.setAnswer(val = field.getVariable(),((Text)obj).getText());
// if(field.getVariable().equals("username"))
// registration.setUsername(val);
// else if(field.getVariable().equals("password"))
// registration.setPassword(val);
if(reg != null && reg.getAttributes().containsKey(field.getVariable()))
attributes.put(field.getVariable(),val);
} else if(obj instanceof Button) {
reply.setAnswer(field.getVariable(),((Button)obj).getSelection());
}
}
replyValue = reply;
if(reg != null)
registration.addExtension(reply.getDataFormToSend());
}
if(reg == null) { close(); return; }
registration.setAttributes(attributes);
@SuppressWarnings("unused") IQ result;
try {
result = account.xmpp.sendIQPacketAndWaitForReply(registration);
} catch (XMPPException e) {
e.printStackTrace();