Search in sources :

Example 16 with SwingWorker

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

the class SearchForm method performSearch.

/**
 * Starts a search based on the Answered form.
 */
public void performSearch() {
    searchResults.clearTable();
    SwingWorker worker = new SwingWorker() {

        ReportedData data;

        public Object construct() {
            try {
                Form answerForm = questionForm.getFilledForm();
                data = searchManager.getSearchResults(answerForm, serviceName);
            } catch (XMPPException | SmackException e) {
                Log.error("Unable to load search service.", e);
            }
            return data;
        }

        public void finished() {
            if (data != null) {
                searchResults.showUsersFound(data);
                searchResults.invalidate();
                searchResults.validate();
                searchResults.repaint();
            } else {
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(searchResults, Res.getString("message.no.results.found"), Res.getString("title.notification"), JOptionPane.ERROR_MESSAGE);
            }
        }
    };
    worker.start();
}
Also used : Form(org.jivesoftware.smackx.xdata.Form) SmackException(org.jivesoftware.smack.SmackException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException) ReportedData(org.jivesoftware.smackx.search.ReportedData)

Example 17 with SwingWorker

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

the class UserSearchForm method addSearchServices.

private void addSearchServices() {
    // Populate with Search Services
    servicesBox = new JComboBox();
    for (String searchService : searchServices) {
        String service = searchService;
        servicesBox.addItem(service);
    }
    // Load the property file and add the search services that are read
    final Properties props = new Properties();
    String nextprop;
    boolean numbprop_bool;
    int numbprop;
    if (pluginsettings.exists()) {
        // Log.warning("Search-service Properties-file does exist= " + pluginsettings.getPath());
        try {
            numbprop = 0;
            props.load(new FileInputStream(pluginsettings));
            String testsearch;
            numbprop_bool = true;
            while (numbprop_bool) {
                nextprop = "search" + numbprop;
                testsearch = props.getProperty(nextprop);
                if (null != testsearch) {
                    Log.warning("Search-Info: SearchService-" + numbprop + " from properties-file is " + nextprop + " : " + testsearch);
                    servicesBox.addItem(testsearch);
                    numbprop++;
                } else
                    numbprop_bool = false;
            }
        } catch (IOException ioe) {
            System.err.println(ioe);
        }
    } else {
    // Log.error("Search-Searvice-Error: Properties-file does not exist= " + pluginsettings.getPath());
    }
    if (servicesBox.getItemCount() > 0) {
        servicesBox.setSelectedIndex(0);
    }
    titlePanel = new TitlePanel("", "", SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
    add(titlePanel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    // Add Search Service ComboBox
    final JLabel serviceLabel = new JLabel("");
    ResourceUtils.resLabel(serviceLabel, servicesBox, Res.getString("label.search.service") + ":");
    add(serviceLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    add(servicesBox, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 150, 0));
    final JButton addService = new JButton();
    ResourceUtils.resButton(addService, Res.getString("button.add.service"));
    add(addService, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    addService.addActionListener(actionEvent -> {
        final String serviceName = JOptionPane.showInputDialog(getRootPane(), Res.getString("message.name.of.search.service.question"), Res.getString("title.add.search.service"), JOptionPane.QUESTION_MESSAGE);
        if (ModelUtil.hasLength(serviceName)) {
            SwingWorker findServiceThread = new SwingWorker() {

                Form newForm;

                public Object construct() {
                    try {
                        newForm = searchManager.getSearchForm(serviceName);
                    } catch (XMPPException | SmackException e) {
                    // Nothing to do
                    }
                    return newForm;
                }

                public void finished() {
                    if (newForm == null) {
                        UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                        JOptionPane.showMessageDialog(getGUI(), Res.getString("message.search.service.not.available"), Res.getString("title.notification"), JOptionPane.ERROR_MESSAGE);
                    } else {
                        servicesBox.addItem(serviceName);
                        servicesBox.setSelectedItem(serviceName);
                        int numbprop1 = 0;
                        boolean numbprop_bool1 = true;
                        String nextprop1, testsearch;
                        while (numbprop_bool1) {
                            nextprop1 = "search" + numbprop1;
                            testsearch = props.getProperty(nextprop1);
                            if (testsearch != null)
                                numbprop1++;
                            else {
                                Log.warning("Search-Service: " + nextprop1 + " : " + serviceName + " added");
                                props.setProperty(nextprop1, serviceName);
                                numbprop_bool1 = false;
                            }
                        }
                        try {
                            props.store(new FileOutputStream(pluginsettings), null);
                        } catch (IOException e) {
                            System.err.println(e);
                        }
                    }
                }
            };
            findServiceThread.start();
        }
    });
    servicesBox.addActionListener(actionEvent -> {
        SwingWorker worker = new SwingWorker() {

            public Object construct() {
                try {
                    Thread.sleep(50);
                } catch (Exception e) {
                    Log.error("Problem sleeping thread.", e);
                }
                return "ok";
            }

            public void finished() {
                showService(getSearchService());
            }
        };
        worker.start();
    });
    add(cardPanel, new GridBagConstraints(0, 3, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JComboBox(javax.swing.JComboBox) Form(org.jivesoftware.smackx.xdata.Form) SmackException(org.jivesoftware.smack.SmackException) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream) TitlePanel(org.jivesoftware.spark.component.TitlePanel) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) XMPPException(org.jivesoftware.smack.XMPPException) FileOutputStream(java.io.FileOutputStream) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException)

Example 18 with SwingWorker

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

the class UserSearchService method search.

public void search(final String query) {
    SwingWorker worker = new SwingWorker() {

        public Object construct() {
            // On initialization, find search service.
            if (searchServices == null) {
                loadSearchServices();
            }
            return true;
        }

        public void finished() {
            processQuery(query);
        }
    };
    worker.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker)

Example 19 with SwingWorker

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

the class ChatPreference method load.

public void load() {
    SwingWorker thread = new SwingWorker() {

        LocalPreferences localPreferences;

        public Object construct() {
            localPreferences = SettingsManager.getLocalPreferences();
            return localPreferences;
        }

        public void finished() {
            boolean showTime = localPreferences.isTimeDisplayedInChat();
            boolean notificationsOn = localPreferences.isChatRoomNotificationsOn();
            boolean chatHistoryHidden = !localPreferences.isChatHistoryEnabled();
            boolean prevChatHistoryHidden = !localPreferences.isPrevChatHistoryEnabled();
            boolean tabsOnTop = localPreferences.isTabTopPosition();
            boolean buzzAllowed = localPreferences.isBuzzEnabled();
            boolean isChatHistoryAscending = localPreferences.getChatHistoryAscending();
            panel.setShowTime(showTime);
            panel.setGroupChatNotificationsOn(notificationsOn);
            panel.setChatHistoryHidden(chatHistoryHidden);
            panel.setPrevChatHistoryHidden(prevChatHistoryHidden);
            panel.setChatTimeoutTime(localPreferences.getChatLengthDefaultTimeout());
            panel.setTabsOnTop(tabsOnTop);
            panel.setBuzzEnabled(buzzAllowed);
            panel.setSortChatHistoryAscending(isChatHistoryAscending);
        }
    };
    thread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 20 with SwingWorker

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

the class GroupChatPreference method load.

public void load() {
    SwingWorker thread = new SwingWorker() {

        LocalPreferences localPreferences;

        public Object construct() {
            localPreferences = SettingsManager.getLocalPreferences();
            return localPreferences;
        }

        public void finished() {
            boolean highlightMyName = localPreferences.isMucHighNameEnabled();
            boolean highlightMyText = localPreferences.isMucHighTextEnabled();
            boolean highlightPopName = localPreferences.isMucHighToastEnabled();
            boolean showjoinleavemessage = localPreferences.isShowJoinLeaveMessagesEnabled();
            boolean showroleicons = localPreferences.isShowingRoleIcons();
            boolean autoAcceptMucInvite = localPreferences.isAutoAcceptMucInvite();
            boolean randomColors = localPreferences.isMucRandomColors();
            boolean inviteToBookmark = !localPreferences.isUseAdHocRoom();
            panel.setMucHighNameEnabled(highlightMyName);
            panel.setMucHighTextEnabled(highlightMyText);
            panel.setMuchHighToastEnabled(highlightPopName);
            panel.setShowJoinLeaveMessagesEnabled(showjoinleavemessage);
            panel.setShowRoleIconInsteadStatusIcon(showroleicons);
            panel.setAutoAcceptMuc(autoAcceptMucInvite);
            panel.setRandomColors(randomColors);
            panel.setInviteToBookmark(inviteToBookmark);
        }
    };
    thread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

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