org.jivesoftware.smackx.bookmarks.BookmarkedConference Java Examples

The following examples show how to use org.jivesoftware.smackx.bookmarks.BookmarkedConference. 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: ConferenceUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Invites users to an existing room.
 *
 * @param serviceName the service name to use.
 * @param roomName    the name of the room.
 * @param jids        a collection of the users to invite.
 */
public static void inviteUsersToRoom(DomainBareJid serviceName, EntityBareJid roomName, Collection<Jid> jids, boolean randomName) {
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    boolean useTextField = pref.isUseAdHocRoom();
    Collection<BookmarkedConference> rooms = null;
    if (!useTextField) {
        try {
            rooms = retrieveBookmarkedConferences();
        } catch (Exception ex) {
            Log.error(ex);
        }
        useTextField = !randomName || (rooms == null || rooms.size() == 0);
    }
    InvitationDialog inviteDialog = new InvitationDialog(useTextField);
    inviteDialog.inviteUsersToRoom(serviceName, rooms, roomName.toString(), jids);
}
 
Example #2
Source File: ConferenceServices.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
  * Load all bookmarked data.
  */
 public void loadConferenceBookmarks() {
 	final TimerTask bookmarkLoader = new TimerTask(){

@Override
public void run() {
	Collection<BookmarkedConference> bc = null;

             try {
                 while (bc == null) {
                     BookmarkManager manager = BookmarkManager.getBookmarkManager(SparkManager.getConnection());
                     bc = manager.getBookmarkedConferences();
                 }
             } catch (XMPPException | SmackException | InterruptedException error) {
                 Log.error(error);
             }
             bookmarksUI.loadUI();
             addBookmarksUI();
}
 		
 	};
 	TaskEngine.getInstance().schedule(bookmarkLoader, 500);
 }
 
Example #3
Source File: InvitationDialog.java    From Spark with Apache License 2.0 6 votes vote down vote up
private void fillRoomsUI(Collection<BookmarkedConference> rooms, String adHocRoomName) {
    if (textRoomsField != null) {
        textRoomsField.setText(adHocRoomName);
    }
    if (comboRoomsField != null) {
        // comboRoomsField.setSelectedIndex(-1);
        ConferenceItem bookmarkedConf = null;
        final EntityBareJid bookmarkedConfJid = SettingsManager.getLocalPreferences().getDefaultBookmarkedConf();

        for (BookmarkedConference room : rooms) {
            final ConferenceItem ci = new ConferenceItem(room);
            if (bookmarkedConfJid != null && bookmarkedConfJid.equals(ci.getBookmarkedConf().getJid())) {
                bookmarkedConf = ci;
            }
            comboRoomsField.addItem(ci);
        }
        if (bookmarkedConf != null) {
            comboRoomsField.setSelectedItem(bookmarkedConf);
        }
    }
}
 
Example #4
Source File: GetBookmarks.java    From jmeter-bzm-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception {
    BookmarkManager manager = BookmarkManager.getBookmarkManager(sampler.getXMPPConnection());
    Collection<BookmarkedConference> confs = manager.getBookmarkedConferences();
    StringBuilder text = new StringBuilder();
    for (BookmarkedConference room : confs) {
        text.append(room.getJid());
        text.append("\r\n");
    }
    res.setResponseData(text.toString().getBytes());
    return res;
}
 
Example #5
Source File: ConferenceRoomBrowser.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * Returns true if the room specified is bookmarked.
    *
    * @param roomJID
    *            the jid of the room to check.
    * @return true if the room is bookmarked.
    */
   private boolean isBookmarked(EntityBareJid roomJID) {
for (Object o : conferences.getBookmarks()) {
    BookmarkedConference bk = (BookmarkedConference) o;
    EntityBareJid jid = bk.getJid();
    if (jid != null && roomJID.equals(jid)) {
	return true;
    }
}

return false;

   }
 
Example #6
Source File: BookmarksUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the current bookmarks used with this account.
 *
 * @param bookmarks the current bookmarks used with this account.
 */
public void setBookmarks(Collection<BookmarkedConference> bookmarks) {

    for (BookmarkedConference bookmark : bookmarks) {
        DomainBareJid serviceName = bookmark.getJid().asDomainBareJid();
        EntityBareJid roomJID = bookmark.getJid();
        Localpart roomName = roomJID.getLocalpart();

        if (bookmark.isAutoJoin()) {
            ConferenceUtils.joinConferenceOnSeperateThread(roomName, bookmark.getJid(), bookmark.getPassword());
            ConferenceUtils.addUnclosableChatRoom(roomJID);
            autoJoinRooms.add(bookmark.getJid());
        }

        // Get Service Node
        TreePath path = tree.findByName(tree, new String[]{rootNode.getUserObject().toString(), serviceName.toString()});
        JiveTreeNode serviceNode;
        if (path == null) {
            serviceNode = addServiceToList(serviceName);
            path = tree.findByName(tree, new String[]{rootNode.getUserObject().toString(), serviceName.toString()});
        }
        else {
            serviceNode = (JiveTreeNode)path.getLastPathComponent();
        }

        addBookmark(serviceNode, roomName.toString(), roomJID.toString());

        tree.expandPath(path);
    }
}
 
Example #7
Source File: BookmarksUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a list of bookmarks.
 * @return a Collection of bookmarks.
 */
public Collection<BookmarkedConference> getBookmarks() {
    try {
        return manager.getBookmarkedConferences();
    }
    catch (XMPPException | SmackException | InterruptedException e) {
        Log.error(e);
    }
    return Collections.emptyList();
}
 
Example #8
Source File: ConferenceServices.java    From Spark with Apache License 2.0 5 votes vote down vote up
protected BookmarkedConference getDefaultBookmark() {
    BookmarkedConference bookmarkedConference = null;
    try {
        Collection<BookmarkedConference> bookmarkedConfs = ConferenceUtils.retrieveBookmarkedConferences();
        EntityBareJid implicitBookmarkedJID = SettingsManager.getLocalPreferences().getDefaultBookmarkedConf();
        if (bookmarkedConfs != null && !bookmarkedConfs.isEmpty()) {

            // check if the "default" bookmarked conference is still in the bookmarks list:
            if (implicitBookmarkedJID != null) {
                for (BookmarkedConference bc : bookmarkedConfs) {
                    if (implicitBookmarkedJID.equals(bc.getJid())) {
                        bookmarkedConference = bc;
                        break;
                    }
                }
            }
            // if no match was found, or no "default" bookmark could be retrieved-use the
            // first bookmark:
            if (bookmarkedConference == null) {
                bookmarkedConference = bookmarkedConfs.iterator().next();
            }
        }
        return bookmarkedConference;
    } catch (XMPPException | SmackException | InterruptedException ex) {
        Log.warning("No default bookmark");
        // no bookmark can be retrieved;
    }
    return null;

}
 
Example #9
Source File: InvitationDialog.java    From Spark with Apache License 2.0 5 votes vote down vote up
private BookmarkedConference getSelectedBookmarkedConference() {
    BookmarkedConference bookmarkedConf = null;
    if (comboRoomsField != null) {
        Object bookmarkedConfItem = comboRoomsField.getSelectedItem();
        if (bookmarkedConfItem instanceof ConferenceItem) {
            bookmarkedConf = ((ConferenceItem) bookmarkedConfItem).getBookmarkedConf();
        }
    }
    return bookmarkedConf;
}
 
Example #10
Source File: BookmarkItem.java    From Spark with Apache License 2.0 5 votes vote down vote up
public void addConferenceRoom(final BookmarkedConference bookmark) {
     imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.CONFERENCE_IMAGE_16x16));
     nameLabel.setText(bookmark.getName());
     descriptionLabel.setText(bookmark.getJid().toString());
     action = new AbstractAction() {
private static final long serialVersionUID = 4324785627112595384L;

         @Override
public void actionPerformed(ActionEvent e) {
             SwingWorker worker = new SwingWorker() {
                 @Override
                 public Object construct() {
                     try {
                         Thread.sleep(10);
                     }
                     catch (InterruptedException e1) {
                         Log.error(e1);
                     }
                     return "ok";
                 }

                 @Override
                 public void finished() {
                     ConferenceUtils.joinConferenceOnSeperateThread(bookmark.getName(), bookmark.getJid(), bookmark.getPassword());
                 }
             };
             worker.start();
         }
     };
 }
 
Example #11
Source File: BookmarkUI.java    From Spark with Apache License 2.0 5 votes vote down vote up
public void addConference(BookmarkedConference conference) {
    BookmarkItem item = new BookmarkItem();
    item.addConferenceRoom(conference);

    model.addElement(item);
    if (conference.isAutoJoin()) {
        item.invokeAction();
    }
}
 
Example #12
Source File: ConferenceUtils.java    From Spark with Apache License 2.0 4 votes vote down vote up
public static Collection<BookmarkedConference> retrieveBookmarkedConferences() throws XMPPException, SmackException, InterruptedException
{
    BookmarkManager manager = BookmarkManager.getBookmarkManager(SparkManager.getConnection());
    return manager.getBookmarkedConferences();
}
 
Example #13
Source File: ConferenceServices.java    From Spark with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
          Localpart userName = SparkManager.getSessionManager().getJID().getLocalpart();
          final String roomName = userName + "_" + StringUtils.randomString(3);


          final List<EntityBareJid> jids = new ArrayList<>();
          jids.add(((ChatRoomImpl)chatRoom).getParticipantJID());

          final DomainBareJid serviceName = getDefaultServiceName();
          if (serviceName != null) {
              SwingWorker worker = new SwingWorker() {
                  @Override
			public Object construct() {
                      try {
                          Thread.sleep(25);
                      }
                      catch (InterruptedException e1) {
                          Log.error(e1);
                      }
                      return "ok";
                  }

                  @Override
			public void finished() {
                      try {
                          BookmarkedConference selectedBookmarkedConf = _localPreferences.isUseAdHocRoom() ? null : getDefaultBookmark();
                          if (selectedBookmarkedConf == null) {
                              ConferenceUtils.createPrivateConference(serviceName,
                                      Res.getString("message.please.join.in.conference"), roomName, jids);
                          } else {
                              ConferenceUtils.joinConferenceOnSeperateThread(selectedBookmarkedConf.getName(),
                                      selectedBookmarkedConf.getJid(), selectedBookmarkedConf.getPassword(),
                                      Res.getString("message.please.join.in.conference"), jids);
                          }
                      }
                      catch (SmackException | InterruptedException ex) {
                      	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                          JOptionPane.showMessageDialog(chatRoom, "An error occurred.", Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                      }
                  }
              };
              worker.start();
          }
      }
 
Example #14
Source File: ConferenceItem.java    From Spark with Apache License 2.0 4 votes vote down vote up
public ConferenceItem(BookmarkedConference bookmarkedConf) {
    this.bookmarkedConf = bookmarkedConf;
}
 
Example #15
Source File: ConferenceItem.java    From Spark with Apache License 2.0 4 votes vote down vote up
public BookmarkedConference getBookmarkedConf() {
    return bookmarkedConf;
}