Search in sources :

Example 1 with Workpane

use of org.jivesoftware.fastpath.workspace.Workpane 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();
}
Also used : AgentSession(org.jivesoftware.smackx.workgroup.agent.AgentSession) Workpane(org.jivesoftware.fastpath.workspace.Workpane) SmackException(org.jivesoftware.smack.SmackException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Presence(org.jivesoftware.smack.packet.Presence) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPException(org.jivesoftware.smack.XMPPException) Workgroup(org.jivesoftware.smackx.workgroup.user.Workgroup) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

Workpane (org.jivesoftware.fastpath.workspace.Workpane)1 SmackException (org.jivesoftware.smack.SmackException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Presence (org.jivesoftware.smack.packet.Presence)1 AgentSession (org.jivesoftware.smackx.workgroup.agent.AgentSession)1 Workgroup (org.jivesoftware.smackx.workgroup.user.Workgroup)1 SwingWorker (org.jivesoftware.spark.util.SwingWorker)1