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();
}
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));
}
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();
}
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();
}
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();
}
Aggregations