use of org.jivesoftware.smackx.bookmarks.BookmarkedURL in project Spark by igniterealtime.
the class BookmarkPlugin method initialize.
@Override
public void initialize() {
final SwingWorker bookmarkThreadWorker = new SwingWorker() {
@Override
public Object construct() {
return this;
}
/**
* Installing menu into spark menu and adding events to bookmarks
*/
@Override
public void finished() {
try {
initialize();
} catch (Exception e) {
Log.error(e);
}
}
/**
*/
public void initialize() {
final JMenu bookmarkMenu = new JMenu(Res.getString("menuitem.bookmarks"));
createMenu(bookmarkMenu);
if (bookmarkMenu.getMenuComponentCount() > 0) {
SparkManager.getMainWindow().getMenu().add(bookmarkMenu, 3);
}
BookmarksUI bookmarksUi = ConferenceServices.getBookmarkedConferences();
bookmarksUi.addBookmarksListener(new BookmarksListener() {
@Override
public void bookmarkAdded(String roomJID) {
rescan(bookmarkMenu);
}
@Override
public void bookmarkRemoved(String roomJID) {
rescan(bookmarkMenu);
}
});
}
/**
* Rescaning our bookmarks and remaking menu items
*
* @param bookmarkMenu menu Jmenu
*/
public void rescan(JMenu bookmarkMenu) {
// removing old menus
bookmarkMenu.removeAll();
try {
// making new
setBookmarks(bookmarkMenu);
int onPanel = SparkManager.getMainWindow().getMenu().getComponentIndex(bookmarkMenu);
if (onPanel < 0) {
if (bookmarkMenu.getMenuComponentCount() > 0) {
int menuCount = SparkManager.getMainWindow().getMenu().getMenuCount();
SparkManager.getMainWindow().getMenu().add(bookmarkMenu, menuCount - 2);
}
}
if (onPanel >= 0) {
if (bookmarkMenu.getMenuComponentCount() <= 0) {
SparkManager.getMainWindow().getMenu().remove(bookmarkMenu);
}
}
SparkManager.getMainWindow().getMenu().invalidate();
SparkManager.getMainWindow().getMenu().validate();
SparkManager.getMainWindow().getMenu().repaint();
} catch (XMPPException | SmackException ex) {
Log.error(ex);
}
}
/**
* Updating statusbar and generating menu items
*
* @param bookmarkMenu menu Jmenu
*/
public void createMenu(JMenu bookmarkMenu) {
try {
setBookmarks(bookmarkMenu);
} catch (XMPPException | SmackException ex) {
Log.error(ex);
}
}
/**
* loading menu items and setting bookmarks listeners
*
* @param bookmarkMenu menu Jmenu
*/
public void setBookmarks(JMenu bookmarkMenu) throws XMPPException, SmackException {
BookmarkManager manager = BookmarkManager.getBookmarkManager(SparkManager.getConnection());
if (manager != null) {
Collection<BookmarkedConference> bookmarkedConferences = manager.getBookmarkedConferences();
final Collection<BookmarkedURL> bookmarkedLinks = manager.getBookmarkedURLs();
for (Object bookmarkedLink : bookmarkedLinks) {
final BookmarkedURL link = (BookmarkedURL) bookmarkedLink;
Action urlAction = new AbstractAction() {
private static final long serialVersionUID = 4246574779205966917L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
try {
BrowserLauncher.openURL(link.getURL());
} catch (Exception e) {
Log.error(e);
}
}
};
urlAction.putValue(Action.NAME, link.getName());
urlAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.LINK_16x16));
bookmarkMenu.add(urlAction);
}
for (Object bookmarkedConference : bookmarkedConferences) {
final BookmarkedConference conferences = (BookmarkedConference) bookmarkedConference;
Action conferenceAction = new AbstractAction() {
private static final long serialVersionUID = 5964584172262968704L;
@Override
public void actionPerformed(ActionEvent actionEvent) {
final TimerTask task = new SwingTimerTask() {
@Override
public void doRun() {
ConferenceUtils.joinConferenceOnSeperateThread(conferences.getName(), conferences.getJid(), conferences.getPassword());
}
};
TaskEngine.getInstance().schedule(task, 10);
}
};
conferenceAction.putValue(Action.NAME, conferences.getName());
conferenceAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.CONFERENCE_IMAGE_16x16));
bookmarkMenu.add(conferenceAction);
}
}
}
};
bookmarkThreadWorker.start();
}
use of org.jivesoftware.smackx.bookmarks.BookmarkedURL in project xabber-android by redsolution.
the class BookmarksManager method getUrlFromBookmarks.
public List<BookmarkedURL> getUrlFromBookmarks(AccountJid accountJid) {
AccountItem accountItem = AccountManager.getInstance().getAccount(accountJid);
List<BookmarkedURL> urls = Collections.emptyList();
if (accountItem != null) {
BookmarkManager bookmarkManager = BookmarkManager.getBookmarkManager(accountItem.getConnection());
try {
urls = bookmarkManager.getBookmarkedURLs();
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
LogManager.exception(this, e);
}
}
return urls;
}
use of org.jivesoftware.smackx.bookmarks.BookmarkedURL in project xabber-android by redsolution.
the class BookmarksActivity method getBookmarks.
private List<BookmarkVO> getBookmarks(boolean cleanCache) {
final List<BookmarkVO> bookmarksList = new ArrayList<>();
if (cleanCache)
BookmarksManager.getInstance().cleanCache(accountItem.getAccount());
// urls
List<BookmarkedURL> bookmarkedURLs = BookmarksManager.getInstance().getUrlFromBookmarks(accountItem.getAccount());
for (int i = 0; i < bookmarkedURLs.size(); i++) {
BookmarkedURL url = bookmarkedURLs.get(i);
bookmarksList.add(new BookmarkVO(url.getName(), url.getURL()));
}
List<BookmarkedConference> bookmarkedConferences;
try {
bookmarkedConferences = BookmarksManager.getInstance().getConferencesFromBookmarks(accountItem.getAccount());
} catch (SmackException.NoResponseException | InterruptedException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
LogManager.exception(this, e);
bookmarkedConferences = Collections.emptyList();
}
for (int i = 0; i < bookmarkedConferences.size(); i++) {
BookmarkedConference conference = bookmarkedConferences.get(i);
bookmarksList.add(new BookmarkVO(conference.getName() != null ? conference.getName() : "", conference.getJid() != null ? conference.getJid().toString() : "", conference.getNickname() != null ? conference.getNickname().toString() : "", conference.getPassword() != null ? conference.getPassword() : ""));
}
return bookmarksList;
}
Aggregations