Search in sources :

Example 6 with Form

use of org.jivesoftware.smackx.xdata.form.Form in project Smack by igniterealtime.

the class MultiUserChat method getRegistrationForm.

/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <code>null</code> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <code>null</code> if no registration is possible.
 * @throws XMPPErrorException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public Form getRegistrationForm() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.get);
    reg.setTo(room);
    IQ result = connection.sendIqRequestAndWaitForResponse(reg);
    DataForm dataForm = DataForm.from(result);
    return new Form(dataForm);
}
Also used : Form(org.jivesoftware.smackx.xdata.form.Form) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) FillableForm(org.jivesoftware.smackx.xdata.form.FillableForm) Registration(org.jivesoftware.smackx.iqregister.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm)

Example 7 with Form

use of org.jivesoftware.smackx.xdata.form.Form in project Spark by igniterealtime.

the class ChatQueue method offerRecieved.

public void offerRecieved(Offer offer) {
    this.offer = offer;
    // Retrieve workgroup form
    Form form;
    try {
        form = FastpathPlugin.getWorkgroup().getWorkgroupForm();
    } catch (XMPPException | SmackException | InterruptedException e) {
        Log.error("Unable to retrieve Workgroup form.", e);
        return;
    }
    final RequestUtils utils = new RequestUtils(offer.getMetaData());
    nameLabel.setText(FpRes.getString("message.incoming.chat.request", utils.getUsername()));
    nameLabel.setIcon(FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_16x16));
    Color linkColor = new Color(69, 92, 137);
    int count = 1;
    for (final FormField field : form.getDataForm().getFields()) {
        String variable = field.getFieldName();
        String label = field.getLabel();
        if (label != null) {
            final JLabel nameLabel = new JLabel(label);
            nameLabel.setFont(new Font("Dialog", Font.BOLD, 11));
            String value = utils.getValue(variable);
            if (value == null) {
                value = "";
            }
            final WrappedLabel valueLabel = new WrappedLabel();
            valueLabel.setBackground(Color.white);
            valueLabel.setText(value);
            add(nameLabel, new GridBagConstraints(0, count, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
            add(valueLabel, new GridBagConstraints(1, count, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
            count++;
        }
    }
    add(progressBar, new GridBagConstraints(0, count, 3, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(15, 5, 5, 5), 0, 0));
    count++;
    viewLabel = new LinkLabel(FpRes.getString("message.view.more.information"), null, linkColor, Color.red);
    add(viewLabel, new GridBagConstraints(0, count, 1, 1, 0.0, 1.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonPanel.setOpaque(false);
    buttonPanel.add(acceptButton);
    buttonPanel.add(declineButton);
    add(buttonPanel, new GridBagConstraints(1, count, 2, 1, 1.0, 1.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
    viewLabel.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            showInformation();
        }
    });
    final Date endTime = offer.getExpiresDate();
    Date now = new Date();
    long mill = endTime.getTime() - now.getTime();
    int seconds = (int) (mill / 1000);
    progressBar.setMaximum(seconds);
    progressBar.setValue(seconds);
    SwingWorker worker = new SwingWorker() {

        public Object construct() {
            while (true) {
                Date now = new Date();
                if (now.getTime() >= endTime.getTime()) {
                    break;
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    Log.error(e);
                }
                progressBar.setValue(progressBar.getValue() - 1);
                progressBar.setStringPainted(true);
                int seconds = (int) (endTime.getTime() - now.getTime()) / 1000;
                if (seconds <= 60) {
                    String timeString = seconds + " " + FpRes.getString("seconds");
                    progressBar.setString(timeString);
                } else {
                    long difference = endTime.getTime() - now.getTime();
                    String timeString = ModelUtil.getTimeFromLong(difference);
                    progressBar.setString(timeString);
                }
            }
            return progressBar;
        }
    };
    worker.start();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) MouseEvent(java.awt.event.MouseEvent) Form(org.jivesoftware.smackx.xdata.form.Form) SmackException(org.jivesoftware.smack.SmackException) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) RequestUtils(org.jivesoftware.fastpath.workspace.util.RequestUtils) Font(java.awt.Font) Date(java.util.Date) LinkLabel(org.jivesoftware.spark.component.LinkLabel) SwingWorker(org.jivesoftware.spark.util.SwingWorker) WrappedLabel(org.jivesoftware.spark.component.WrappedLabel) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.xdata.FormField)

Aggregations

Form (org.jivesoftware.smackx.xdata.form.Form)7 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)5 GridBagConstraints (java.awt.GridBagConstraints)3 Insets (java.awt.Insets)3 SmackException (org.jivesoftware.smack.SmackException)3 XMPPException (org.jivesoftware.smack.XMPPException)3 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)3 BorderLayout (java.awt.BorderLayout)2 Dimension (java.awt.Dimension)2 Font (java.awt.Font)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 Date (java.util.Date)2 JPanel (javax.swing.JPanel)2 IQ (org.jivesoftware.smack.packet.IQ)2 Color (java.awt.Color)1 FlowLayout (java.awt.FlowLayout)1 GridBagLayout (java.awt.GridBagLayout)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1