use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ScratchPadPlugin method retrieveNotes.
/**
* Retrieve private notes from server.
*/
private void retrieveNotes() {
// Retrieve private notes from server.
final SwingWorker notesWorker = new SwingWorker() {
public Object construct() {
return PrivateNotes.getPrivateNotes();
}
public void finished() {
final PrivateNotes privateNotes = (PrivateNotes) get();
showPrivateNotes(privateNotes);
}
};
notesWorker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class NotificationsPreference method load.
public void load() {
SwingWorker thread = new SwingWorker() {
LocalPreferences localPreferences;
public Object construct() {
localPreferences = SettingsManager.getLocalPreferences();
return localPreferences;
}
public void finished() {
boolean toaster = localPreferences.getShowToasterPopup();
boolean asteriskToaster = localPreferences.getDisableAsteriskToasterPopup();
boolean windowFocus = localPreferences.getWindowTakesFocus();
boolean offlineNotification = localPreferences.isOfflineNotificationsOn();
boolean onlineNotification = localPreferences.isOnlineNotificationsOn();
boolean betaChecking = localPreferences.isBetaCheckingEnabled();
int DisplayTime = localPreferences.getNotificationsDisplayTime();
boolean typingNotification = localPreferences.isTypingNotificationShown();
boolean systemTrayNotification = localPreferences.isSystemTrayNotificationEnabled();
panel.setShowToaster(toaster);
panel.setDisableAsteriskToaster(asteriskToaster);
panel.setShowWindowPopup(windowFocus);
panel.setOfflineNotification(offlineNotification);
panel.setOnlineNotification(onlineNotification);
panel.setCheckForBeta(betaChecking);
panel.setNotificationsDisplayTime(DisplayTime / 1000);
panel.setTypingNotification(typingNotification);
panel.setSystemTrayNotification(systemTrayNotification);
// when windowFocus is selected the systemtraynotification doesn't work --> disable it
if (windowFocus) {
panel.setSystemTrayNotification(false);
panel.setSystemTrayNotificationEnabled(false);
} else
panel.setSystemTrayNotificationEnabled(true);
if (systemTrayNotification) {
panel.setShowWindowPopup(false);
panel.setShowWindowPopupEnabled(false);
} else
panel.setShowWindowPopupEnabled(true);
}
};
thread.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class WorkgroupManager method enterQueue.
private void enterQueue(String workgroupJID, Form form) {
String workgroupName = XmppStringUtils.parseLocalpart(workgroupJID).toUpperCase();
final JDialog workgroupDialog = new JDialog(SparkManager.getMainWindow(), workgroupName + " Workgroup");
final Workgroup workgroup = new Workgroup(workgroupJID, SparkManager.getConnection());
try {
workgroup.joinQueue(form);
} catch (XMPPException | SmackException e) {
Log.error(e);
}
final JPanel titlePane = new LiveTitlePane("Waiting in Queue", FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_24x24)) {
private static final long serialVersionUID = -7370226759188539384L;
public Dimension getPreferredSize() {
final Dimension size = super.getPreferredSize();
size.width = 400;
return size;
}
};
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridBagLayout());
mainPanel.add(titlePane, new GridBagConstraints(0, 0, 4, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
final JLabel queuePostionLabel = new JLabel();
final JLabel queueWaitTime = new JLabel();
queuePostionLabel.setText("Waiting for position information.");
queueWaitTime.setText("Gathering wait time.");
mainPanel.add(queuePostionLabel, new GridBagConstraints(0, 1, 4, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
mainPanel.add(queueWaitTime, new GridBagConstraints(0, 2, 4, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
final JButton leaveQueueButton = new JButton("Leave Queue");
mainPanel.add(queueWaitTime, new GridBagConstraints(0, 3, 4, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
leaveQueueButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (workgroup.isInQueue()) {
try {
invites.add(workgroup.getWorkgroupJID());
workgroup.departQueue();
} catch (XMPPException | SmackException e1) {
Log.error(e1);
}
}
}
});
mainPanel.add(leaveQueueButton, new GridBagConstraints(3, 4, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
mainPanel.setBackground(Color.white);
workgroupDialog.getContentPane().add(mainPanel);
workgroupDialog.pack();
GraphicUtils.centerWindowOnScreen(workgroupDialog);
workgroupDialog.setVisible(true);
workgroupDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (workgroup.isInQueue()) {
try {
workgroup.departQueue();
} catch (XMPPException | SmackException e1) {
Log.error(e1);
}
}
}
});
SwingWorker worker = new SwingWorker() {
public Object construct() {
while (true) {
if (workgroup.isInQueue()) {
queuePostionLabel.setText("Current Position in Queue: " + workgroup.getQueuePosition());
queueWaitTime.setText("It is estimated your wait time to now be " + FormUtils.getTimeFromLong(workgroup.getQueueRemainingTime()));
} else {
return true;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.error(e);
}
}
}
public void finished() {
workgroupDialog.setVisible(false);
if (invites.contains(workgroup.getWorkgroupJID())) {
invites.remove(workgroup.getWorkgroupJID());
} else {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), "Unable to contact a member of the workgroup. Please try back later.", "No Answer", JOptionPane.INFORMATION_MESSAGE);
}
}
};
worker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class CurrentActivity method addCurrentChats.
public void addCurrentChats() {
SwingWorker agentWorker = new SwingWorker() {
AgentRoster agentRoster;
Collection agentSet;
public Object construct() {
try {
agentRoster = FastpathPlugin.getAgentSession().getAgentRoster();
} catch (SmackException.NotConnectedException e) {
Log.error("Unable to get agent roster.", e);
}
agentSet = agentRoster.getAgents();
return agentSet;
}
public void finished() {
agentRoster.addListener(new AgentRosterListener() {
public void agentAdded(String jid) {
}
public void agentRemoved(String jid) {
}
public void presenceChanged(Presence presence) {
String agentJID = XmppStringUtils.parseBareJid(presence.getFrom());
agentJID = UserManager.unescapeJID(agentJID);
AgentStatus agentStatus = (AgentStatus) presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
String status = presence.getStatus();
if (status == null) {
status = "Available";
}
if (agentStatus != null) {
List list = agentStatus.getCurrentChats();
// Add new ones.
Iterator iter = list.iterator();
while (iter.hasNext()) {
AgentStatus.ChatInfo chatInfo = (AgentStatus.ChatInfo) iter.next();
Date startDate = chatInfo.getDate();
String username = chatInfo.getUserID();
String nickname = chatInfo.getUsername();
if (!ModelUtil.hasLength(nickname)) {
nickname = FpRes.getString("message.not.specified");
}
String question = chatInfo.getQuestion();
if (!ModelUtil.hasLength(question)) {
question = "No question asked";
}
String email = chatInfo.getEmail();
if (!ModelUtil.hasLength(email)) {
email = FpRes.getString("message.not.specified");
}
addAgentChat(agentJID, nickname, email, question, startDate, chatInfo.getSessionID());
}
}
}
});
}
};
agentWorker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class OnlineAgents method init.
public void init() {
if (agentRoster != null) {
return;
}
SwingWorker agentWorker = new SwingWorker() {
Collection<String> agentSet;
public Object construct() {
// Initialize Agent Roster
try {
agentRoster = FastpathPlugin.getAgentSession().getAgentRoster();
agentSet = agentRoster.getAgents();
return agentSet;
} catch (SmackException.NotConnectedException e) {
Log.error("Unable to load agent roster.", e);
return null;
}
}
public void finished() {
final List<String> agentList = new ArrayList<>(agentSet);
Collections.sort(agentList);
for (String agent : agentList) {
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(agent);
if (nickname == null) {
nickname = agent;
}
ContactItem item = new ContactItem(nickname, nickname, agent) {
private static final long serialVersionUID = -8888899031363239813L;
public String getToolTipText() {
Presence agentPresence = agentRoster.getPresence(agent);
return buildTooltip(agentPresence);
}
};
Presence agentPresence = agentRoster.getPresence(agent);
item.setPresence(agentPresence);
}
agentRoster.addListener(new OnlineAgentListener());
}
};
agentWorker.start();
}
Aggregations