use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class OnlineAgents method activateChat.
/**
* Activate a chat room with the selected user.
*/
private void activateChat(final String userJID, final String nickname) {
if (!ModelUtil.hasLength(userJID)) {
return;
}
SwingWorker worker = new SwingWorker() {
final ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom;
public Object construct() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Log.error("Error in activate chat.", e);
}
ChatContainer chatRooms = chatManager.getChatContainer();
try {
chatRoom = chatRooms.getChatRoom(userJID);
} catch (ChatRoomNotFoundException e) {
Log.warning("Room not found for jid: " + userJID, e);
}
return chatRoom;
}
public void finished() {
if (chatRoom == null) {
chatRoom = new ChatRoomImpl(userJID, nickname, nickname);
chatManager.getChatContainer().addChatRoom(chatRoom);
}
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
};
worker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class FastpathPlugin method initialize.
public void initialize() {
new WorkgroupInitializer().initialize();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
container = new FastpathContainer();
workgroupLabel = new JLabel(FpRes.getString("workgroup"));
comboBox = new JComboBox();
joinButton = new JButton(FpRes.getString("join"), null);
logoutButton = new RolloverButton(FpRes.getString("logout"), null);
// Initialize tab handler for Fastpath chats.
fastpathTabHandler = new FastpathTabHandler();
mainPanel = new BackgroundPane();
}
});
try {
DiscoverItems items = SparkManager.getSessionManager().getDiscoveredItems();
for (DiscoverItems.Item item : items.getItems()) {
String entityID = item.getEntityID() != null ? item.getEntityID() : "";
if (entityID.startsWith("workgroup")) {
// Log into workgroup
final String workgroupService = "workgroup." + SparkManager.getSessionManager().getServerAddress();
final String jid = SparkManager.getSessionManager().getJID();
SwingWorker worker = new SwingWorker() {
public Object construct() {
try {
return Agent.getWorkgroups(workgroupService, jid, SparkManager.getConnection());
} catch (XMPPException | SmackException e1) {
return Collections.emptyList();
}
}
public void finished() {
Collection<String> agents = (Collection<String>) get();
if (agents.size() == 0) {
return;
}
showSelection(agents);
}
};
worker.start();
}
}
} catch (Exception e) {
Log.error(e);
}
SparkManager.getConnection().addConnectionListener(this);
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class FastpathPlugin method joinWorkgroup.
private void joinWorkgroup() {
wasConnected = false;
joinButton.setEnabled(false);
SwingWorker worker = new SwingWorker() {
public Object construct() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Log.error(e);
}
return null;
}
public void finished() {
XMPPConnection con = SparkManager.getConnection();
String workgroupName = org.jivesoftware.spark.util.StringUtils.makeFirstWordCaptial((String) comboBox.getSelectedItem());
workgroupLabel.setText(FpRes.getString("message.workgroup.logged.into", workgroupName));
logoutButton.setVisible(true);
joinButton.setVisible(false);
comboBox.setVisible(false);
String workgroup = comboBox.getSelectedItem() + "@" + getComponentAddress();
if (agentSession != null && agentSession.isOnline()) {
try {
agentSession.setOnline(false);
agentSession.setOnline(true);
} catch (XMPPException | SmackException e) {
Log.error(e);
leaveWorkgroup();
joinButton.setEnabled(true);
return;
}
} else {
agentSession = new AgentSession(workgroup, con);
try {
agentSession.setOnline(true);
} catch (XMPPException | SmackException e1) {
Log.error(e1);
leaveWorkgroup();
joinButton.setEnabled(true);
return;
}
}
// Send actual presence to workgroup.
final Presence actualPresence = SparkManager.getWorkspace().getStatusBar().getPresence();
Presence toWorkgroupPresence = new Presence(actualPresence.getType(), actualPresence.getStatus(), actualPresence.getPriority(), actualPresence.getMode());
toWorkgroupPresence.setTo(workgroup);
try {
con.sendStanza(toWorkgroupPresence);
wgroup = new Workgroup(workgroup, con);
} catch (Exception e) {
e.printStackTrace();
joinButton.setEnabled(true);
return;
}
// Initialize Workspace
litWorkspace = new Workpane();
litWorkspace.listenForOffers();
joinButton.setEnabled(true);
// Register tab handler
SparkManager.getChatManager().addSparkTabHandler(fastpathTabHandler);
}
};
worker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ContactList method switchAllUserOffline.
/**
* Switches all users to Offline and Creates a Reconnection Group
*/
private synchronized void switchAllUserOffline(final boolean onError) {
SwingWorker worker = new SwingWorker() {
@Override
public Object construct() {
mainPanel.add(_reconnectpanelsmall, 0);
_reconnectpanelsmall.setClosedOnError(onError);
final Collection<RosterEntry> roster = Roster.getInstanceFor(SparkManager.getConnection()).getEntries();
for (RosterEntry r : roster) {
Presence p = new Presence(Presence.Type.unavailable);
moveToOfflineGroup(p, r.getUser());
}
return true;
}
};
worker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ContactGroupTransferHandler method addContactItem.
private void addContactItem(final ContactGroup contactGroup, final ContactItem item) {
ContactItem newContact = UIComponentRegistry.createContactItem(Res.getString("group.empty"), null, null);
newContact.setPresence(item.getPresence());
newContact.setIcon(item.getIcon());
newContact.getNicknameLabel().setFont(item.getNicknameLabel().getFont());
if (!PresenceManager.isOnline(item.getJID())) {
contactGroup.addOfflineContactItem(item.getAlias(), item.getNickname(), item.getJID(), null);
} else {
contactGroup.addContactItem(newContact);
}
contactGroup.clearSelection();
// Updating group title
contactGroup.fireContactGroupUpdated();
final ContactGroup oldGroup = getContactGroup(item.getGroupName());
SwingWorker worker = new SwingWorker() {
public Object construct() {
Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
RosterEntry entry = roster.getEntry(item.getJID());
RosterGroup groupFound = null;
for (RosterGroup group : roster.getGroups()) {
if (group.getName().equals(contactGroup.getGroupName())) {
try {
groupFound = group;
group.addEntry(entry);
} catch (XMPPException | SmackException e1) {
Log.error(e1);
return false;
}
}
}
// This is a new group
if (groupFound == null) {
groupFound = roster.createGroup(contactGroup.getGroupName());
try {
groupFound.addEntry(entry);
} catch (XMPPException | SmackException e) {
Log.error(e);
}
}
return true;
}
public void finished() {
if ((Boolean) get()) {
// Now try and remove the group from the old one.
removeContactItem(oldGroup, item);
}
}
};
worker.start();
}
Aggregations