Search in sources :

Example 1 with Workgroup

use of org.jivesoftware.smackx.workgroup.user.Workgroup 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 2 with Workgroup

use of org.jivesoftware.smackx.workgroup.user.Workgroup in project Spark by igniterealtime.

the class WorkgroupManager method showWorkgroup.

private void showWorkgroup(final ContactItem contactItem) throws Exception {
    VCard vcard = SparkManager.getVCardManager().getVCard();
    final Map<String, String> variables = new HashMap<String, String>();
    String firstName = vcard.getFirstName();
    String lastName = vcard.getLastName();
    if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
        variables.put("username", firstName + " " + lastName);
    } else if (ModelUtil.hasLength(firstName)) {
        variables.put("username", firstName);
    } else if (ModelUtil.hasLength(lastName)) {
        variables.put("username", lastName);
    }
    String email = vcard.getEmailHome();
    String emailWork = vcard.getEmailWork();
    if (ModelUtil.hasLength(emailWork)) {
        email = emailWork;
    }
    if (ModelUtil.hasLength(email)) {
        variables.put("email", email);
    }
    String workgroupJID = contactItem.getJID();
    String nameOfWorkgroup = XmppStringUtils.parseLocalpart(workgroupJID);
    final JDialog workgroupDialog = new JDialog(SparkManager.getMainWindow(), "Contact " + nameOfWorkgroup + " Workgroup");
    Workgroup workgroup = new Workgroup(workgroupJID, SparkManager.getConnection());
    final Form workgroupForm = workgroup.getWorkgroupForm();
    String welcomeText = FormText.getWelcomeText(workgroupJID);
    String startButton = FormText.getStartButton(workgroupJID);
    final WorkgroupDataForm formUI = new WorkgroupDataForm(workgroupForm, variables);
    formUI.setBackground(Color.white);
    final JPanel titlePane = new LiveTitlePane("Contact Workgroup", FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_24x24)) {

        private static final long serialVersionUID = -4484940286068835770L;

        public Dimension getPreferredSize() {
            final Dimension size = super.getPreferredSize();
            size.width = 400;
            return size;
        }
    };
    formUI.add(titlePane, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    final JButton submitButton = new JButton("Start Chat!");
    submitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                enterQueue(contactItem.getJID(), formUI.getFilledForm());
                workgroupDialog.dispose();
            }
        }
    });
    formUI.setEnterListener(new WorkgroupDataForm.EnterListener() {

        public void enterPressed() {
            if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                enterQueue(contactItem.getJID(), formUI.getFilledForm());
                workgroupDialog.dispose();
            }
        }
    });
    formUI.add(submitButton, new GridBagConstraints(1, 100, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    workgroupDialog.getContentPane().setLayout(new BorderLayout());
    workgroupDialog.getContentPane().add(formUI, BorderLayout.CENTER);
    workgroupDialog.pack();
    GraphicUtils.centerWindowOnScreen(workgroupDialog);
    workgroupDialog.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) HashMap(java.util.HashMap) Form(org.jivesoftware.smackx.xdata.Form) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) Workgroup(org.jivesoftware.smackx.workgroup.user.Workgroup) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) JDialog(javax.swing.JDialog)

Example 3 with Workgroup

use of org.jivesoftware.smackx.workgroup.user.Workgroup 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)

Example 4 with Workgroup

use of org.jivesoftware.smackx.workgroup.user.Workgroup in project Spark by igniterealtime.

the class WorkgroupManager method getChatSetting.

/**
 * Returns the chat settings for a particular workgroup.
 *
 * @param key           the key in the chat settings.
 * @param workgroupName the name of the workgroup
 * @return the <code>ChatSetting</code> found with the specified key.
 */
public ChatSetting getChatSetting(String key, String workgroupName) {
    ChatSettings settings = null;
    if (chatSettings.containsKey(workgroupName)) {
        settings = (ChatSettings) chatSettings.get(workgroupName);
    } else {
        XMPPConnection connection = SparkManager.getConnection();
        Workgroup workgroup = new Workgroup(workgroupName, connection);
        try {
            settings = workgroup.getChatSettings();
            chatSettings.put(workgroupName, settings);
        } catch (XMPPException | SmackException e) {
            Log.error("Error retrieving chat setting using key=" + key + " and workgroup=" + workgroupName, e);
        }
    }
    if (settings != null) {
        return settings.getChatSetting(key);
    }
    return null;
}
Also used : ChatSettings(org.jivesoftware.smackx.workgroup.settings.ChatSettings) SmackException(org.jivesoftware.smack.SmackException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Workgroup(org.jivesoftware.smackx.workgroup.user.Workgroup) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

Workgroup (org.jivesoftware.smackx.workgroup.user.Workgroup)4 SmackException (org.jivesoftware.smack.SmackException)3 XMPPException (org.jivesoftware.smack.XMPPException)3 Dimension (java.awt.Dimension)2 GridBagConstraints (java.awt.GridBagConstraints)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JButton (javax.swing.JButton)2 JDialog (javax.swing.JDialog)2 JPanel (javax.swing.JPanel)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 SwingWorker (org.jivesoftware.spark.util.SwingWorker)2 BorderLayout (java.awt.BorderLayout)1 GridBagLayout (java.awt.GridBagLayout)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 HashMap (java.util.HashMap)1 JLabel (javax.swing.JLabel)1 Workpane (org.jivesoftware.fastpath.workspace.Workpane)1