Package org.jivesoftware.smackx

Examples of org.jivesoftware.smackx.Form


     * @param type
     *            the type of form, either "configure" or "registerFor"
     * @return false if the required fields have not been filled out
     */
    private boolean submitConfigurationForm(JBDataForm form, final String type) {
        final Form answer = form.getAnswerForm();
        if (answer == null)
            return false;

        Thread thread = new Thread(new Runnable() {
            public void run() {
View Full Code Here


        /**
         * Called by the enclosing thread
         */
        public void run() {
            try {
                Form temp;

                // get the form
                if (type.equals("configure")) {
                    temp = chat.getConfigurationForm();
                } else {
                    temp = chat.getRegistrationForm();
                }

                if (temp == null) {
                    serverErrorMessage(resources
                            .getString("couldNotCollectForm"));
                    return;
                }

                final Form form = temp;
                final JBDataForm f = new JBDataForm(BuddyList.getInstance().getTabFrame(), form);
                f.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        // if the cancel button is pressed, close the form
                        if (e.getActionCommand().equals("cancel")) {
View Full Code Here

        setSize(new Dimension(630, 450));
        setLocationRelativeTo(parent);
    }

    public Form getAnswerForm() {
        Form a = null;
        try {
            a = form.createAnswerForm();
        } catch (Exception ex) {
            Standard.warningMessage(this, resources.getString("dataForm"),
                    resources.getString("unknownError"));
            dispose();
            return null;
        }

        for (int i = 0; i < this.fields.size(); i++) {
            Field field = (Field) this.fields.get(i);
            if (field.getVariable() == null || field.getVariable().equals(""))
                continue;

            if (!ensureAnswer(field.getFormField(), field.getAnswer()))
                return null;
            Object answer = field.getAnswer();

            //com.valhalla.Logger.debug( i + " " + field.getVariable() + " " +
            // answer + " " + field.getFormField().getType() );

            if (answer instanceof Boolean) {
                a.setAnswer(field.getVariable(), ((Boolean) answer)
                        .booleanValue());
            } else if (answer instanceof java.util.List) {
                a.setAnswer(field.getVariable(), (java.util.List) answer);
            } else {
                a.setAnswer(field.getVariable(), (String) answer);
            }
        }

        return a;
    }
View Full Code Here

            addParticipationsListener();
          } catch (XMPPException e) {
            try {
              if (e.getXMPPError().getCode() == 404) {
                muc.create(nickname);
                Form form = muc.getConfigurationForm();
                Form answer = form.createAnswerForm();
 
                FormField fieldRoomName = new FormField("muc#roomconfig_roomname");
                fieldRoomName.addValue(roomName);
                answer.addField(fieldRoomName);
 
                FormField fieldMaxUsers = new FormField("muc#roomconfig_maxusers");
                fieldMaxUsers.addValue("0");// 0 means unlimited
                answer.addField(fieldMaxUsers);
 
                muc.sendConfigurationForm(answer);
                addMessageListener();
                addParticipationsListener();
              } else {
View Full Code Here

  }
 
  private void test( final SearchIQ result )
  {
    System.out.println( "RESULT ::::: " + result.getChildElementXML() );
    final Form form = Form.getFormFrom(result);
    if( form != null){
    shell.getDisplay().asyncExec(new Runnable() { public void run() {
    //SearchForm sForm = new SearchForm( shell, form, account, searchservice, result  );
      new SearchForm( shell, form, account, result.getFrom(), result  );
//    sForm.open();
View Full Code Here

        } catch (XMPPException e) {
          e.printStackTrace();
          ErrorDialog.openError(sShell,"Error while retrieving registration information","Could not retrieve registration information from " + reg.getFrom() + ": " + e.getLocalizedMessage(),new Status(IStatus.ERROR,GOIMPlugin.ID,IStatus.OK,"Error while retrieving registration information.",e));
          return;
        }
        Form form = Form.getFormFrom(result);
        new FormAnswerDialog(sShell, (Registration)result, form).open();
      }
    });
    searchItem.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        String addressid = (String) selectedItem.getData("address");
        new SearchUI(account,addressid);
      }
    });
    multiUserChatCreateRoom.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event event) {
        String addressid = (String) selectedItem.getData("address");
        if (addressid == null)
          return;
        InputDialog dialog = new InputDialog(sShell,
            "Creating MUC Room",
            "Enter the name for the New Room (will be known as yourinput@" + addressid + ")",
            null,null);
        int r = dialog.open();
        if(r != InputDialog.OK) return;
        String room = dialog.getValue();
        String froom = room + "@" + addressid;
        MultiUserChat muc = new MultiUserChat(account.xmpp.getConnection(),froom);
        try {
          muc.create(account.getUsername());
          account.chatWindowExtensionManager.openMUCWindow(froom,muc);
          Form form = muc.getConfigurationForm();
          FormAnswerDialog d = new FormAnswerDialog(sShell, null, form);
          r = d.open();
          if(r != FormAnswerDialog.OK) {
            // Creating instant room
            muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
          } else {
            muc.sendConfigurationForm(d.getResultForm());
          }
          MessageDialog.openInformation(sShell,"Successfully created Room.","Successfully created and joined room: " + froom);
        } catch (XMPPException e) {
View Full Code Here

          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 {
View Full Code Here

    if (searchIQ != null)
      iq.setTo(searchIQ.getFrom());
   

    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) {
        reply.setAnswer(field.getVariable(), ((Text) obj)
            .getText());
      } else if (obj instanceof Button) {
        reply.setAnswer(field.getVariable(), ((Button) obj)
            .getSelection());
      }
    }
    replyValue = reply;
    if (searchIQ != null)
      iq.addExtension(reply.getDataFormToSend());

    if (searchIQ == null) {
//      close();
      return;
    }
View Full Code Here

    }

    protected void configureRoom() {
        try {
            // Get the the room's configuration form
            Form form = muc.getConfigurationForm();

            // Create a new form to submit based on the original form
            Form submitForm = form.createAnswerForm();

            // Add default answers to the form to submit
            for (Iterator<FormField> fields = form.getFields(); fields
                .hasNext();) {
                FormField field = fields.next();
                if (!FormField.TYPE_HIDDEN.equals(field.getType())
                    && (field.getVariable() != null)) {
                    // Sets the default value as the answer
                    submitForm.setDefaultAnswer(field.getVariable());
                }
            }

            // set configuration, see XMPP Specs
            submitForm.setAnswer("muc#roomconfig_moderatedroom", false);
            submitForm.setAnswer("muc#roomconfig_publicroom", false);
            submitForm.setAnswer("muc#roomconfig_passwordprotectedroom", true);
            submitForm.setAnswer("muc#roomconfig_roomsecret",
                preferences.getPassword());
            submitForm.setAnswer("muc#roomconfig_allowinvites", true);
            submitForm.setAnswer("muc#roomconfig_persistentroom", false);

            // Send the completed form (with default values) to the
            // server to configure the room
            muc.sendConfigurationForm(submitForm);
        } catch (XMPPException e) {
View Full Code Here

                        public boolean hasPermission(String jid) {
                            return true;
                        }

                        public void execute() throws XMPPException {
                            Form result = new Form(Form.TYPE_RESULT);
                            FormField resultField = new FormField("test2");
                            resultField.setLabel("test node");
                            resultField.addValue("it worked");
                            result.addField(resultField);
                            setForm(result);
                        }

                        public void next(Form response) throws XMPPException {
                            //
View Full Code Here

TOP

Related Classes of org.jivesoftware.smackx.Form

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.