Search in sources :

Example 1 with AgentSession

use of org.jivesoftware.smackx.workgroup.agent.AgentSession in project Spark by igniterealtime.

the class ChatSearch method search.

public void search(String query) {
    final List<ChatSearchResult> results = new ArrayList<ChatSearchResult>();
    AgentSession agentSession = FastpathPlugin.getAgentSession();
    try {
        Form form = agentSession.getTranscriptSearchForm();
        Form filledForm = form.createAnswerForm();
        filledForm.setAnswer("queryString", query);
        // Define Workgroups
        final List<String> workgroups = new ArrayList<String>();
        workgroups.add(FastpathPlugin.getWorkgroup().getWorkgroupJID());
        filledForm.setAnswer("workgroups", workgroups);
        ReportedData reportedData = null;
        try {
            reportedData = agentSession.searchTranscripts(filledForm);
            for (final ReportedData.Row row : reportedData.getRows()) {
                ChatSearchResult result = new ChatSearchResult(row, query);
                results.add(result);
            }
        } catch (XMPPException | SmackException e) {
            Log.error(e);
        }
        Collections.sort(results, dateComporator);
        DefaultListModel model = new DefaultListModel();
        final JList list = new JList(model);
        list.setCellRenderer(new HistoryItemRenderer());
        Iterator<ChatSearchResult> iter = results.iterator();
        while (iter.hasNext()) {
            ChatSearchResult result = iter.next();
            String person = result.getUsername();
            String question = result.getQuestion();
            String sessionID = result.getSessionID();
            Date date = result.getStartDate();
            final SearchItem item = new SearchItem(person, date, question);
            item.setSessionID(sessionID);
            model.addElement(item);
        }
        list.addMouseListener(new MouseAdapter() {

            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    SearchItem item = (SearchItem) list.getSelectedValue();
                    Transcript transcript = null;
                    try {
                        transcript = FastpathPlugin.getAgentSession().getTranscript(item.getSessionID());
                    } catch (XMPPException | SmackException ee) {
                        Log.error("Error showing transcripts.", ee);
                    }
                    if (transcript == null) {
                        return;
                    }
                    ChatViewer chatViewer = new ChatViewer(transcript);
                    final JFrame frame = new JFrame(FpRes.getString("title.chat.transcript"));
                    frame.setIconImage(SparkManager.getMainWindow().getIconImage());
                    frame.getContentPane().setLayout(new BorderLayout());
                    frame.getContentPane().add(chatViewer, BorderLayout.CENTER);
                    frame.pack();
                    frame.setSize(600, 400);
                    frame.setLocationRelativeTo(SparkManager.getMainWindow());
                    frame.setVisible(true);
                }
            }
        });
        JScrollPane scrollPane = new JScrollPane(list);
        scrollPane.getViewport().setBackground(Color.white);
        JFrame frame = new JFrame(FpRes.getString("title.search.results"));
        frame.setIconImage(SparkManager.getMainWindow().getIconImage());
        frame.getContentPane().setLayout(new BorderLayout());
        frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
        final BackgroundPane titlePane = new BackgroundPane() {

            private static final long serialVersionUID = -5603280927139789177L;

            public Dimension getPreferredSize() {
                final Dimension size = super.getPreferredSize();
                size.width = 0;
                return size;
            }
        };
        titlePane.setLayout(new GridBagLayout());
        titlePane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY));
        JLabel userImage = new JLabel(FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_24x24));
        userImage.setHorizontalAlignment(JLabel.LEFT);
        userImage.setText(FpRes.getString("title.chat.transcripts.search"));
        titlePane.add(userImage, new GridBagConstraints(0, 0, 4, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
        userImage.setFont(new Font("Dialog", Font.BOLD, 12));
        JLabel itemsFound = new JLabel(Integer.toString(results.size()));
        titlePane.add(new JLabel(FpRes.getString("title.number.of.conversations.found")), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        titlePane.add(itemsFound, new GridBagConstraints(1, 1, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
        JLabel searchTerm = new JLabel(FpRes.getString("query") + ": " + query);
        titlePane.add(searchTerm, new GridBagConstraints(0, 2, 4, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 5, 5), 0, 0));
        frame.getContentPane().add(titlePane, BorderLayout.NORTH);
        frame.pack();
        frame.setSize(400, 400);
        GraphicUtils.centerWindowOnScreen(frame);
        frame.setVisible(true);
    } catch (XMPPException | SmackException e) {
        Log.error(e);
    }
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) Form(org.jivesoftware.smackx.xdata.Form) ArrayList(java.util.ArrayList) ChatViewer(org.jivesoftware.fastpath.workspace.panes.ChatViewer) DefaultListModel(javax.swing.DefaultListModel) BackgroundPane(org.jivesoftware.fastpath.workspace.panes.BackgroundPane) Font(java.awt.Font) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) AgentSession(org.jivesoftware.smackx.workgroup.agent.AgentSession) JScrollPane(javax.swing.JScrollPane) Transcript(org.jivesoftware.smackx.workgroup.packet.Transcript) MouseEvent(java.awt.event.MouseEvent) SmackException(org.jivesoftware.smack.SmackException) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Date(java.util.Date) HistoryItemRenderer(org.jivesoftware.fastpath.workspace.panes.HistoryItemRenderer) XMPPException(org.jivesoftware.smack.XMPPException) JList(javax.swing.JList) ReportedData(org.jivesoftware.smackx.search.ReportedData)

Example 2 with AgentSession

use of org.jivesoftware.smackx.workgroup.agent.AgentSession 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 3 with AgentSession

use of org.jivesoftware.smackx.workgroup.agent.AgentSession in project Spark by igniterealtime.

the class Notes method saveNotes.

private void saveNotes() {
    String note = textPane.getText();
    // Check for empty note.
    if (!ModelUtil.hasLength(note)) {
        return;
    }
    // Save note.
    AgentSession agentSession = FastpathPlugin.getAgentSession();
    try {
        agentSession.setNote(sessionID, note);
        saveButton.setEnabled(false);
        statusLabel.setText(" " + FpRes.getString("message.notes.updated"));
        SwingWorker worker = new SwingWorker() {

            public Object construct() {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e1) {
                    Log.error(e1);
                }
                return true;
            }

            public void finished() {
                statusLabel.setText("");
            }
        };
        worker.start();
    } catch (XMPPException | SmackException e1) {
        showError(FpRes.getString("message.unable.to.update.notes"));
        Log.error("Could not commit note.", e1);
    }
}
Also used : AgentSession(org.jivesoftware.smackx.workgroup.agent.AgentSession) SmackException(org.jivesoftware.smack.SmackException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException)

Example 4 with AgentSession

use of org.jivesoftware.smackx.workgroup.agent.AgentSession in project Spark by igniterealtime.

the class ChatHistory method showDialog.

public void showDialog() {
    AgentSession agentSession = FastpathPlugin.getAgentSession();
    String workgroupName = XmppStringUtils.parseLocalpart(agentSession.getWorkgroupJID());
    if (mainFrame == null) {
        mainFrame = new JFrame(FpRes.getString("title.personal.chats"));
    }
    if (mainFrame.isVisible()) {
        return;
    }
    mainFrame.setIconImage(SparkManager.getMainWindow().getIconImage());
    mainFrame.getContentPane().setLayout(new BorderLayout());
    final JScrollPane scrollPane = new JScrollPane(this);
    scrollPane.getVerticalScrollBar().setBlockIncrement(50);
    scrollPane.getVerticalScrollBar().setUnitIncrement(20);
    mainFrame.getContentPane().add(scrollPane);
    mainFrame.pack();
    mainFrame.setSize(400, 400);
    mainFrame.setLocationRelativeTo(SparkManager.getMainWindow());
    mainFrame.setVisible(true);
}
Also used : AgentSession(org.jivesoftware.smackx.workgroup.agent.AgentSession) JScrollPane(javax.swing.JScrollPane) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame)

Aggregations

AgentSession (org.jivesoftware.smackx.workgroup.agent.AgentSession)4 SmackException (org.jivesoftware.smack.SmackException)3 XMPPException (org.jivesoftware.smack.XMPPException)3 BorderLayout (java.awt.BorderLayout)2 JFrame (javax.swing.JFrame)2 JScrollPane (javax.swing.JScrollPane)2 SwingWorker (org.jivesoftware.spark.util.SwingWorker)2 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DefaultListModel (javax.swing.DefaultListModel)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 Workpane (org.jivesoftware.fastpath.workspace.Workpane)1