Search in sources :

Example 71 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class BookmarksUI method addRegisteredServices.

private void addRegisteredServices() {
    SwingWorker worker = new SwingWorker() {

        @Override
        public Object construct() {
            try {
                if (SparkManager.getConnection().isConnected()) {
                    mucServices = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMucServiceDomains();
                }
            } catch (XMPPException | SmackException | InterruptedException e) {
                Log.error("Unable to load MUC Service Names.", e);
            }
            return mucServices;
        }

        @Override
        public void finished() {
            if (mucServices == null) {
                return;
            }
            for (DomainBareJid service : mucServices) {
                if (!hasService(service)) {
                    addServiceToList(service);
                }
            }
        }
    };
    worker.start();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 72 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class ContactList method clientReconnected.

public void clientReconnected() {
    switch(localPreferences.getReconnectPanelType()) {
        case 0:
            workspace.changeCardLayout(Workspace.WORKSPACE_PANE);
            break;
        case 1:
            mainPanel.remove(_reconnectpanelsmall);
            break;
        case 2:
            SwingWorker sw = new SwingWorker() {

                @Override
                public Object construct() {
                    _reconnectpanelicon.remove();
                    _reconnectpanelicon.getPanel().revalidate();
                    return 42;
                }
            };
            sw.start();
            break;
    }
    offlineGroup.fireContactGroupUpdated();
    try {
        updateContactList(null);
    } catch (Exception e) {
        Log.error(e);
    }
    final Presence myPresence = SparkManager.getWorkspace().getStatusBar().getPresence();
    SparkManager.getSessionManager().changePresence(myPresence);
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) Presence(org.jivesoftware.smack.packet.Presence) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) IOException(java.io.IOException)

Example 73 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class ContactGroup method displayWindow.

/**
 * Displays the <code>ContactInfoWindow</code>.
 *
 * @param e the mouseEvent that triggered this event.
 */
private void displayWindow(MouseEvent e) {
    if (preferences.areVCardsVisible()) {
        final ContactGroup parent = this;
        final SwingWorker worker = new SwingWorker() {

            @Override
            public Object construct() {
                UIComponentRegistry.getContactInfoWindow().display(parent, e);
                return null;
            }
        };
        worker.start();
    }
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker)

Example 74 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class UserHistory method loadHistory.

public void loadHistory() {
    SwingWorker transcriptThread = new SwingWorker() {

        final List<TranscriptSummary> transcriptList = new ArrayList<>();

        public Object construct() {
            try {
                Transcripts transcripts = FastpathPlugin.getAgentSession().getTranscripts(userID);
                transcriptList.addAll(transcripts.getSummaries());
            } catch (XMPPException | SmackException | InterruptedException e) {
                Log.error("Error getting transcripts.", e);
            }
            transcriptList.sort(timeComparator);
            return transcriptList;
        }

        public void finished() {
            init(transcriptList);
        }
    };
    transcriptThread.start();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) XMPPException(org.jivesoftware.smack.XMPPException) Transcripts(org.jivesoftware.smackx.workgroup.packet.Transcripts)

Example 75 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class AgentConversations method stateChanged.

public void stateChanged(ChangeEvent e) {
    if (FastpathPlugin.getUI().getMainPanel().getSelectedComponent() == this && list == null) {
        init();
        SwingWorker agentWorker = new SwingWorker() {

            AgentRoster agentRoster;

            Collection<EntityBareJid> agentSet;

            public Object construct() {
                try {
                    agentRoster = FastpathPlugin.getAgentSession().getAgentRoster();
                } catch (SmackException.NotConnectedException | InterruptedException e1) {
                    Log.warning("Unable to get agent roster.", e1);
                }
                agentSet = agentRoster.getAgents();
                return agentSet;
            }

            public void finished() {
                agentRoster.addListener(new AgentRosterListener() {

                    @Override
                    public void agentAdded(EntityBareJid jid) {
                    }

                    @Override
                    public void agentRemoved(EntityBareJid jid) {
                    }

                    @Override
                    public void presenceChanged(Presence presence) {
                        EntityBareJid agentJID = presence.getFrom().asEntityBareJidOrThrow();
                        AgentStatus agentStatus = presence.getExtension("agent-status", "http://jabber.org/protocol/workgroup");
                        if (agentStatus != null) {
                            List<AgentStatus.ChatInfo> list = agentStatus.getCurrentChats();
                            removeOldChats(agentJID, list);
                            // Add new ones.
                            for (Object o : list) {
                                AgentStatus.ChatInfo chatInfo = (AgentStatus.ChatInfo) o;
                                Date startDate = chatInfo.getDate();
                                String username = chatInfo.getUserID();
                                String nickname = chatInfo.getUsername();
                                if (!ModelUtil.hasLength(nickname)) {
                                    nickname = "Not specified";
                                }
                                String question = chatInfo.getQuestion();
                                if (!ModelUtil.hasLength(question)) {
                                    question = "No question asked";
                                }
                                String email = chatInfo.getEmail();
                                if (!ModelUtil.hasLength(email)) {
                                    email = "Not specified";
                                }
                                addAgentChat(agentJID, nickname, email, question, startDate, chatInfo.getSessionID());
                            }
                        }
                        calculateNumberOfChats(agentRoster);
                    }
                });
            }
        };
        agentWorker.start();
    }
}
Also used : AgentRoster(org.jivesoftware.smackx.workgroup.agent.AgentRoster) AgentRosterListener(org.jivesoftware.smackx.workgroup.agent.AgentRosterListener) Date(java.util.Date) AgentStatus(org.jivesoftware.smackx.workgroup.packet.AgentStatus) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Presence(org.jivesoftware.smack.packet.Presence) List(java.util.List) ArrayList(java.util.ArrayList) JList(javax.swing.JList) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Aggregations

SwingWorker (org.jivesoftware.spark.util.SwingWorker)78 SmackException (org.jivesoftware.smack.SmackException)21 XMPPException (org.jivesoftware.smack.XMPPException)17 Presence (org.jivesoftware.smack.packet.Presence)12 MouseAdapter (java.awt.event.MouseAdapter)11 MouseEvent (java.awt.event.MouseEvent)11 GridBagConstraints (java.awt.GridBagConstraints)10 Insets (java.awt.Insets)10 JLabel (javax.swing.JLabel)10 ActionEvent (java.awt.event.ActionEvent)9 JPanel (javax.swing.JPanel)9 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 EntityBareJid (org.jxmpp.jid.EntityBareJid)8 Collection (java.util.Collection)7 Action (javax.swing.Action)7 GridBagLayout (java.awt.GridBagLayout)6 AbstractAction (javax.swing.AbstractAction)6 JDialog (javax.swing.JDialog)6