Java Code Examples for org.jivesoftware.smackx.xdata.Form#setAnswer()

The following examples show how to use org.jivesoftware.smackx.xdata.Form#setAnswer() . 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: 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 3
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 4
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 5
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);
            }
        }
    }
}