Search in sources :

Example 21 with SwingWorker

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();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker)

Example 22 with SwingWorker

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();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 23 with SwingWorker

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();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) SmackException(org.jivesoftware.smack.SmackException) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Workgroup(org.jivesoftware.smackx.workgroup.user.Workgroup) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException) JDialog(javax.swing.JDialog)

Example 24 with SwingWorker

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();
}
Also used : AgentRoster(org.jivesoftware.smackx.workgroup.agent.AgentRoster) AgentRosterListener(org.jivesoftware.smackx.workgroup.agent.AgentRosterListener) SmackException(org.jivesoftware.smack.SmackException) Date(java.util.Date) AgentStatus(org.jivesoftware.smackx.workgroup.packet.AgentStatus) Iterator(java.util.Iterator) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Presence(org.jivesoftware.smack.packet.Presence) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List)

Example 25 with SwingWorker

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();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Presence(org.jivesoftware.smack.packet.Presence)

Aggregations

SwingWorker (org.jivesoftware.spark.util.SwingWorker)65 SmackException (org.jivesoftware.smack.SmackException)22 XMPPException (org.jivesoftware.smack.XMPPException)15 Presence (org.jivesoftware.smack.packet.Presence)11 MouseAdapter (java.awt.event.MouseAdapter)8 MouseEvent (java.awt.event.MouseEvent)8 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)8 ActionEvent (java.awt.event.ActionEvent)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 GridBagConstraints (java.awt.GridBagConstraints)6 Insets (java.awt.Insets)6 Collection (java.util.Collection)6 JLabel (javax.swing.JLabel)6 JPanel (javax.swing.JPanel)5 ContactItem (org.jivesoftware.spark.ui.ContactItem)5 Action (javax.swing.Action)4 Cursor (java.awt.Cursor)3 ActionListener (java.awt.event.ActionListener)3 File (java.io.File)3