use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ConferenceRoomBrowser method clearTable.
private void clearTable() {
SwingWorker clearTable = new SwingWorker() {
@Override
public Object construct() {
return null;
}
@Override
public void finished() {
roomsTable.clearTable();
}
};
clearTable.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ConferenceRoomBrowser method stopLoadingImg.
private void stopLoadingImg() {
SwingWorker stopLoading = new SwingWorker() {
@Override
public Object construct() {
return null;
}
public void finished() {
refreshButton.setIcon(SparkRes.getImageIcon(SparkRes.REFRESH_IMAGE));
refreshButton.validate();
refreshButton.repaint();
refreshItem.setIcon(SparkRes.getImageIcon(SparkRes.REFRESH_IMAGE));
refreshItem.validate();
refreshItem.repaint();
}
};
stopLoading.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class AccountCreationWizard method createAccount.
/**
* Creates the new account using the supplied information.
*/
private void createAccount() {
boolean errors = false;
String errorMessage = "";
if (!ModelUtil.hasLength(getUsername())) {
errors = true;
usernameField.requestFocus();
errorMessage = Res.getString("message.username.error");
} else if (!ModelUtil.hasLength(getPassword())) {
errors = true;
errorMessage = Res.getString("message.password.error");
} else if (!ModelUtil.hasLength(getConfirmPassword())) {
errors = true;
errorMessage = Res.getString("message.confirmation.password.error");
} else if (!ModelUtil.hasLength(getServer())) {
errors = true;
errorMessage = Res.getString("message.account.error");
} else if (!isPasswordValid()) {
errors = true;
errorMessage = Res.getString("message.confirmation.password.error");
}
if (errors) {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(this, errorMessage, Res.getString("title.create.problem"), JOptionPane.ERROR_MESSAGE);
return;
}
final Component ui = this;
progressBar.setIndeterminate(true);
progressBar.setStringPainted(true);
progressBar.setString(Res.getString("message.registering", getServer()));
progressBar.setVisible(true);
final SwingWorker worker = new SwingWorker() {
XMPPError.Condition condition = null;
public Object construct() {
try {
createAccountButton.setEnabled(false);
connection = getConnection();
} catch (SmackException | IOException | XMPPException e) {
return e;
}
try {
final AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.createAccount(getUsername(), getPassword());
} catch (XMPPException | SmackException e) {
if (e instanceof XMPPException.XMPPErrorException) {
condition = ((XMPPException.XMPPErrorException) e).getXMPPError().getCondition();
}
if (condition == null) {
condition = XMPPError.Condition.internal_server_error;
}
}
return "ok";
}
public void finished() {
progressBar.setVisible(false);
if (connection == null) {
if (ui.isShowing()) {
createAccountButton.setEnabled(true);
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(ui, Res.getString("message.connection.failed", getServer()), Res.getString("title.create.problem"), JOptionPane.ERROR_MESSAGE);
createAccountButton.setEnabled(true);
}
return;
}
if (condition == null) {
accountCreationSuccessful();
} else {
accountCreationFailed(condition);
}
}
};
worker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class VCardManager method viewFullProfile.
/**
* Displays the full profile for a particular JID.
*
* @param jid the jid of the user to display.
* @param parent the parent component to use for displaying dialog.
*/
public void viewFullProfile(final String jid, final JComponent parent) {
final SwingWorker vcardThread = new SwingWorker() {
VCard vcard = new VCard();
public Object construct() {
vcard = getVCard(jid);
return vcard;
}
public void finished() {
if (vcard.getError() != null || vcard == null) {
// Show vcard not found
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(parent, Res.getString("message.unable.to.load.profile", jid), Res.getString("title.profile.not.found"), JOptionPane.ERROR_MESSAGE);
} else {
editor.viewFullProfile(vcard, parent);
}
}
};
vcardThread.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class VCardManager method initializeUI.
/**
* Adds VCard capabilities to menus and other components in Spark.
*/
private void initializeUI() {
// See if we should disable the "Edit my profile" option under "File"
if (Default.getBoolean("DISABLE_EDIT_PROFILE") || !Enterprise.containsFeature(Enterprise.VCARD_FEATURE))
return;
// Add Actions Menu
final JMenu contactsMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.contacts"));
final JMenu communicatorMenu = SparkManager.getMainWindow().getJMenuBar().getMenu(0);
JMenuItem editProfileMenu = new JMenuItem(SparkRes.getImageIcon(SparkRes.SMALL_BUSINESS_MAN_VIEW));
ResourceUtils.resButton(editProfileMenu, Res.getString("menuitem.edit.my.profile"));
int size = contactsMenu.getMenuComponentCount();
communicatorMenu.insert(editProfileMenu, 1);
editProfileMenu.addActionListener(e -> {
SwingWorker vcardLoaderWorker = new SwingWorker() {
public Object construct() {
try {
personalVCard.load(SparkManager.getConnection());
} catch (XMPPException | SmackException e) {
Log.error("Error loading vcard information.", e);
}
return true;
}
public void finished() {
editor.editProfile(personalVCard, SparkManager.getWorkspace());
personalVCardAvatar = null;
personalVCardHash = null;
}
};
vcardLoaderWorker.start();
});
JMenuItem viewProfileMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.FIND_TEXT_IMAGE));
ResourceUtils.resButton(viewProfileMenu, Res.getString("menuitem.lookup.profile"));
contactsMenu.insert(viewProfileMenu, size > 0 ? size - 1 : 0);
viewProfileMenu.addActionListener(e -> {
String jidToView = JOptionPane.showInputDialog(SparkManager.getMainWindow(), Res.getString("message.enter.jabber.id") + ":", Res.getString("title.lookup.profile"), JOptionPane.QUESTION_MESSAGE);
if (ModelUtil.hasLength(jidToView) && jidToView.contains("@") && ModelUtil.hasLength(XmppStringUtils.parseDomain(jidToView))) {
viewProfile(jidToView, SparkManager.getWorkspace());
} else if (ModelUtil.hasLength(jidToView)) {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.invalid.jabber.id"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
}
});
}
Aggregations