org.jivesoftware.smackx.xdata.Form Java Examples

The following examples show how to use org.jivesoftware.smackx.xdata.Form. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnswerFormDialog.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Sends the Answer Form
    * @param answer <u>must be an answer-form</u>
    * @param chat
    */
   private void sendAnswerForm(Form answer, MultiUserChat chat) {

ChatRoom room = SparkManager.getChatManager().getChatRoom(chat.getRoom().toString()); 

for (String key : _map.keySet()) {
    String value = getValueFromComponent(key);
    answer.setAnswer(key, value);
}
try {
    chat.sendRegistrationForm(answer);
    
    
    String reg = Res.getString("message.groupchat.registered.member", chat.getRoom());
   room.getTranscriptWindow().insertNotificationMessage(reg,ChatManager.NOTIFICATION_COLOR);
} catch (XMPPException | SmackException | InterruptedException e) {
    room.getTranscriptWindow().insertNotificationMessage(e.getMessage(),ChatManager.ERROR_COLOR);
}

   }
 
Example #2
Source File: ChatManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new public Conference Room.
 *
 * @param roomName    the name of the room.
 * @param serviceName the service name to use (ex.conference.jivesoftware.com)
 * @return the new ChatRoom created. If an error occured, null will be returned.
 */
public ChatRoom createConferenceRoom(Localpart roomName, DomainBareJid serviceName) {
    EntityBareJid roomAddress = JidCreate.entityBareFrom(roomName, serviceName);
    final MultiUserChat chatRoom = MultiUserChatManager.getInstanceFor( SparkManager.getConnection()).getMultiUserChat( roomAddress);

    final GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(chatRoom);

    try {
        LocalPreferences pref = SettingsManager.getLocalPreferences();
        Resourcepart nickname = pref.getNickname();
        chatRoom.create(nickname);

        // Send an empty room configuration form which indicates that we want
        // an instant room
        chatRoom.sendConfigurationForm(new Form( DataForm.Type.submit ));
    }
    catch (XMPPException | SmackException | InterruptedException e1) {
        Log.error("Unable to send conference room chat configuration form.", e1);
        return null;
    }

    getChatContainer().addChatRoom(room);
    return room;
}
 
Example #3
Source File: PrivateKeyReceiver.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
private void sendRequestAsync(String registrationToken) {
    // connect
    try {
        mConn.connect();
    } catch (XMPPException | SmackException | IOException | InterruptedException ex) {
        LOGGER.log(Level.WARNING, "can't connect to "+mConn.getServer(), ex);
        mHandler.handle(new Callback<>(ex));
        return;
    }

    Registration iq = new Registration();
    iq.setType(IQ.Type.set);
    iq.setTo(mConn.getXMPPServiceDomain());
    Form form = new Form(DataForm.Type.submit);

    // form type field
    FormField type = new FormField(FormField.FORM_TYPE);
    type.setType(FormField.Type.hidden);
    type.addValue(FORM_TYPE_VALUE);
    form.addField(type);

    // token field
    FormField fieldKey = new FormField(FORM_TOKEN_VAR);
    fieldKey.setLabel("Registration token");
    fieldKey.setType(FormField.Type.text_single);
    fieldKey.addValue(registrationToken);
    form.addField(fieldKey);

    iq.addExtension(form.getDataFormToSend());

    mConn.sendIqRequestAsync(iq)
         .onSuccess(this)
         .onError(exception -> mHandler.handle(new Callback<>(exception)));
}
 
Example #4
Source File: DataFormUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DataFormUI
 *
 * @param form the <code>DataForm</code> to build a UI with.
 */
public DataFormUI(Form form) {
    this.setLayout(new GridBagLayout());
    this.searchForm = form;

    buildUI(form);

    this.add(new JLabel(), new GridBagConstraints(0, row, 3, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
}
 
Example #5
Source File: SearchForm.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
  * Starts a search based on the Answered form.
  */
 public void performSearch() {
     searchResults.clearTable();

     SwingWorker worker = new SwingWorker() {
         ReportedData data;

         @Override
public Object construct() {
             try {
                 Form answerForm = questionForm.getFilledForm();
                 data = searchManager.getSearchResults(answerForm, serviceName);
             }
             catch (XMPPException | SmackException | InterruptedException e) {
                 Log.error("Unable to load search service.", e);
             }

             return data;
         }

         @Override
public void finished() {
             if (data != null && !data.getRows().isEmpty() ) {
                 searchResults.showUsersFound(data);
                 searchResults.invalidate();
                 searchResults.validate();
                 searchResults.repaint();
             }
             else {
             	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                 JOptionPane.showMessageDialog(searchResults, Res.getString("message.no.results.found"), Res.getString("title.notification"), JOptionPane.ERROR_MESSAGE);
             }
         }
     };

     worker.start();


 }
 
Example #6
Source File: WorkgroupDataForm.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new DataFormUI
 *
 * @param form the <code>DataForm</code> to build a UI with.
 */
public WorkgroupDataForm(Form form, Map presetVariables) {
    this.presetVariables  = presetVariables;
    this.setLayout(new GridBagLayout());
    this.searchForm = form;

    buildUI(form);

    this.add(new JLabel(), new GridBagConstraints(0, row, 3, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
}
 
Example #7
Source File: WorkgroupManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
private static boolean validateForm(JDialog parent, Form workgroupForm, Form form) {
    for ( final FormField field : form.getFields()) {
        if (field.isRequired() && field.getValues().isEmpty()) {
            String variable = field.getVariable();
            String elementName = workgroupForm.getField(variable).getLabel();
            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
            JOptionPane.showMessageDialog(parent, variable + " is required to complete the form.", "Incomplete Form", JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }

    return true;
}
 
Example #8
Source File: RoomInformation.java    From Spark with Apache License 2.0 5 votes vote down vote up
public void showFormInformation(Form form, final RequestUtils utils) {
    setLayout(new GridBagLayout());
    setBackground(Color.white);

    int count = 1;
    for ( final FormField field : form.getFields() ) {
        String variable = field.getVariable();
        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(2, 5, 2, 5), 0, 0));
            add(valueLabel, new GridBagConstraints(1, count, 3, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, 5, 2, 5), 0, 0));
            count++;
        }
    }

    final Color linkColor = new Color(69, 92, 137);

    LinkLabel viewLabel = new LinkLabel(FpRes.getString("message.view.more.information"), null, linkColor, Color.red);
    viewLabel.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            RoomInformation roomInformation = new RoomInformation();
            roomInformation.showAllInformation(utils.getMap());
            roomInformation.showRoomInformation();
        }
    });

    add(viewLabel, new GridBagConstraints(0, count, 3, 1, 0.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0));

}
 
Example #9
Source File: MucRoomInfo.java    From xyTalk-pc with GNU Affero General Public License v3.0 4 votes vote down vote up
public Form getForm() {
    return form;
}
 
Example #10
Source File: ConferenceRoomBrowser.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
    * Create a new room based on room table selection.
    */
   private void createRoom() {
RoomCreationDialog mucRoomDialog = new RoomCreationDialog();
final MultiUserChat groupChat = mucRoomDialog.createGroupChat(
	SparkManager.getMainWindow(), serviceName);
LocalPreferences pref = SettingsManager.getLocalPreferences();

if (null != groupChat) {

    // Join Room
    try {
	GroupChatRoom room = UIComponentRegistry.createGroupChatRoom(groupChat);

	Resourcepart nickname = pref.getNickname();
	groupChat.create(nickname);
	chatManager.getChatContainer().addChatRoom(room);
	chatManager.getChatContainer().activateChatRoom(room);

	// Send Form
	Form form = groupChat.getConfigurationForm().createAnswerForm();
	if (mucRoomDialog.isPasswordProtected()) {
	    String password = mucRoomDialog.getPassword();
	    room.setPassword(password);
	    form.setAnswer("muc#roomconfig_passwordprotectedroom", true);
	    form.setAnswer("muc#roomconfig_roomsecret", password);
	}
	form.setAnswer("muc#roomconfig_roomname",
		mucRoomDialog.getRoomName());
	form.setAnswer("muc#roomconfig_roomdesc",
		mucRoomDialog.getRoomTopic());

	if (mucRoomDialog.isPermanent()) {
	    form.setAnswer("muc#roomconfig_persistentroom", true);
	}

	List<String> owners = new ArrayList<>();
	owners.add(SparkManager.getSessionManager().getBareUserAddress().toString());
	form.setAnswer("muc#roomconfig_roomowners", owners);

	// new DataFormDialog(groupChat, form);
	groupChat.sendConfigurationForm(form);
       addRoomToTable(groupChat.getRoom(), groupChat.getRoom().getLocalpart(), 1);
    } catch (XMPPException | SmackException | InterruptedException e1) {
	Log.error("Error creating new room.", e1);
	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
	JOptionPane
		.showMessageDialog(this,
			Res.getString("message.room.creation.error"),
			Res.getString("title.error"),
			JOptionPane.ERROR_MESSAGE);
    }
}
   }
 
Example #11
Source File: RosterDialog.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
    * Creates a Popupdialog above the Search Button displaying matching
    * Contacts
    * 
    * @param byname
    *            , the Searchname, atleast 5 Chars long
    * @param event
    *            , the MouseEvent which triggered it
    * @throws XMPPException
    * @throws InterruptedException 
    */
   public void searchForContact(String byname, MouseEvent event)
           throws XMPPException, SmackException.NotConnectedException, SmackException.NoResponseException, InterruptedException
   {

   	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
   	
if (byname.contains("@")) {
    byname = byname.substring(0, byname.indexOf("@"));
}

if (byname.length() <= 1) {
    JOptionPane.showMessageDialog(jidField,
	    Res.getString("message.search.input.short"),
	    Res.getString("title.notification"),
	    JOptionPane.ERROR_MESSAGE);

} else {

    JPopupMenu popup = new JPopupMenu();
    JMenuItem header = new JMenuItem(
	    Res.getString("group.search.results") + ":");
    header.setBackground(UIManager.getColor("List.selectionBackground"));
    header.setForeground(Color.red);
    popup.add(header);

    for (DomainBareJid search : _usersearchservice) {

	ReportedData data;
	UserSearchManager usersearchManager = new UserSearchManager(
		SparkManager.getConnection());

	Form f = usersearchManager.getSearchForm(search);

	Form answer = f.createAnswerForm();
	answer.setAnswer("Name", true);
	answer.setAnswer("Email", true);
	answer.setAnswer("Username", true);
	answer.setAnswer("search", byname);

	data = usersearchManager.getSearchResults(answer, search);

	ArrayList<String> columnnames = new ArrayList<>();
	for ( ReportedData.Column column : data.getColumns() ) {
	    String label = column.getLabel();
	    columnnames.add(label);
	}

	for (ReportedData.Row row : data.getRows() ) {
	    if (!row.getValues(columnnames.get(0)).isEmpty()) {
		String s = row.getValues(columnnames.get(0))
			.get(0).toString();
		final JMenuItem item = new JMenuItem(s);
		popup.add(item);
		item.addActionListener( e -> {
           jidField.setText(item.getText());
           nicknameField.setText(XmppStringUtils
               .parseLocalpart(item.getText()));
           } );
	    }

	}
    }

    if (popup.getComponentCount() > 2) {
	popup.setVisible(true);
	popup.show(_searchForName, event.getX(), event.getY());
    } else if (popup.getComponentCount() == 2) {
	jidField.setText(((JMenuItem) popup.getComponent(1)).getText());
	nicknameField.setText(XmppStringUtils.parseLocalpart(((JMenuItem) popup
		.getComponent(1)).getText()));
    } else {
	JOptionPane.showMessageDialog(jidField,
		Res.getString("message.no.results.found"),
		Res.getString("title.notification"),
		JOptionPane.ERROR_MESSAGE);
    }
}
   }
 
Example #12
Source File: SearchForm.java    From Spark with Apache License 2.0 4 votes vote down vote up
public Form getSearchForm() {
    return searchForm;
}
 
Example #13
Source File: WorkgroupManager.java    From Spark with Apache License 2.0 4 votes vote down vote up
private void showWorkgroup(final ContactItem contactItem) throws Exception {
     VCard vcard = SparkManager.getVCardManager().getVCard();

     final Map<String, String> variables = new HashMap<String, String>();
     String firstName = vcard.getFirstName();
     String lastName = vcard.getLastName();

     if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
         variables.put("username", firstName + " " + lastName);
     }
     else if (ModelUtil.hasLength(firstName)) {
         variables.put("username", firstName);
     }
     else if (ModelUtil.hasLength(lastName)) {
         variables.put("username", lastName);
     }

     String email = vcard.getEmailHome();
     String emailWork = vcard.getEmailWork();

     if (ModelUtil.hasLength(emailWork)) {
         email = emailWork;
     }

     if (ModelUtil.hasLength(email)) {
         variables.put("email", email);
     }


     EntityBareJid workgroupJID = contactItem.getJid().asEntityBareJidOrThrow();
     Localpart nameOfWorkgroup = workgroupJID.getLocalpart();
     final JDialog workgroupDialog = new JDialog(SparkManager.getMainWindow(), "Contact " + nameOfWorkgroup + " Workgroup");
     Workgroup workgroup = new Workgroup(workgroupJID, SparkManager.getConnection());

     final Form workgroupForm = workgroup.getWorkgroupForm();
     String welcomeText = FormText.getWelcomeText(workgroupJID.toString());
     String startButton = FormText.getStartButton(workgroupJID.toString());

     final WorkgroupDataForm formUI = new WorkgroupDataForm(workgroupForm, variables);
     formUI.setBackground(Color.white);

     final JPanel titlePane = new LiveTitlePane("Contact Workgroup", FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_24x24)) {
private static final long serialVersionUID = -4484940286068835770L;

public Dimension getPreferredSize() {
             final Dimension size = super.getPreferredSize();
             size.width = 400;
             return size;
         }
     };


     formUI.add(titlePane, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

     final JButton submitButton = new JButton("Start Chat!");
     submitButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
             if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                 enterQueue(contactItem.getJid().asEntityBareJidOrThrow(), formUI.getFilledForm());
                 workgroupDialog.dispose();
             }
         }
     });


     formUI.setEnterListener(new WorkgroupDataForm.EnterListener() {
         public void enterPressed() {
             if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                 enterQueue(contactItem.getJid().asEntityBareJidOrThrow(), formUI.getFilledForm());
                 workgroupDialog.dispose();
             }
         }
     });


     formUI.add(submitButton, new GridBagConstraints(1, 100, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));


     workgroupDialog.getContentPane().setLayout(new BorderLayout());
     workgroupDialog.getContentPane().add(formUI, BorderLayout.CENTER);

     workgroupDialog.pack();
     GraphicUtils.centerWindowOnScreen(workgroupDialog);
     workgroupDialog.setVisible(true);
 }
 
Example #14
Source File: UserInvitationPane.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Removes oneself as an owner of the room.
 *
 * @param muc the <code>MultiUserChat</code> of the chat room.
 */
private void removeOwner(MultiUserChat muc) {
    if (muc.isJoined()) {
        // Try and remove myself as an owner if I am one.
        Collection<Affiliate> owners = null;
        try {
            owners = muc.getOwners();
        }
        catch (XMPPException | SmackException | InterruptedException e1) {
            return;
        }

        if (owners == null) {
            return;
        }

        Iterator<Affiliate> iter = owners.iterator();

        List<Jid> list = new ArrayList<>();
        while (iter.hasNext()) {
            Affiliate affilitate = iter.next();
            Jid jid = affilitate.getJid();
            if (!jid.equals(SparkManager.getSessionManager().getBareUserAddress())) {
                list.add(jid);
            }
        }
        if (list.size() > 0) {
            try {
                Form form = muc.getConfigurationForm().createAnswerForm();
                List<String> jidStrings = JidUtil.toStringList(list);
                form.setAnswer("muc#roomconfig_roomowners", jidStrings);

                // new DataFormDialog(groupChat, form);
                muc.sendConfigurationForm(form);
            }
            catch (XMPPException | SmackException | InterruptedException e) {
                Log.error(e);
            }
        }
    }
}
 
Example #15
Source File: InvitationPane.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Removes oneself as an owner of the room.
 *
 * @param muc the <code>MultiUserChat</code> of the chat room.
 */
private void removeOwner(MultiUserChat muc) {
    if (muc.isJoined()) {
        // Try and remove myself as an owner if I am one.
        Collection owners = null;
        try {
            owners = muc.getOwners();
        }
        catch (XMPPException | SmackException | InterruptedException e1) {
            return;
        }

        if (owners == null) {
            return;
        }

        Iterator iter = owners.iterator();

        List<Jid> list = new ArrayList<>();
        while (iter.hasNext()) {
            Affiliate affilitate = (Affiliate)iter.next();
            Jid jid = affilitate.getJid();
            if (!jid.equals(SparkManager.getSessionManager().getBareUserAddress())) {
                list.add(jid);
            }
        }
        if (list.size() > 0) {
            try {
                Form form = muc.getConfigurationForm().createAnswerForm();
                List<String> jidStrings = new ArrayList<>(list.size());
                JidUtil.toStrings(list, jidStrings);
                form.setAnswer("muc#roomconfig_roomowners", jidStrings);

                // new DataFormDialog(groupChat, form);
                muc.sendConfigurationForm(form);
            }
            catch (XMPPException | SmackException | InterruptedException e) {
                Log.error(e);
            }
        }
    }
}