use of org.jivesoftware.spark.component.CheckNode in project Spark by igniterealtime.
the class BroadcastDialog method hideOfflineUsers.
private void hideOfflineUsers() {
int i;
if (OfflineUsers.isSelected()) {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
i = 0;
for (CheckNode node : nodes) {
if (contactList.getContactItemByDisplayName(node.toString()).getPresence().getType() == Presence.Type.unavailable) {
if (node.getParent() != null) {
TreeNode parent = node.getParent();
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(node);
checkTree.getTree().setSelectionPath(new TreePath(path));
NodesGroups.add(new ArrayList<>());
NodesGroups.get(i).add(parent);
NodesGroups.get(i).add(node);
i++;
}
}
}
for (int x = 0; x < groupNodes.size(); x++) {
if (groupNodes.get(x).toString().equals(Res.getString("group.offline"))) {
OfflineGroup = x;
TreeNode parent = groupNodes.get(x).getParent();
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(groupNodes.get(x));
checkTree.getTree().setSelectionPath(new TreePath(path));
}
}
} else {
i = 0;
DefaultMutableTreeNode child = groupNodes.get(OfflineGroup);
((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, rosterNode, rosterNode.getChildCount());
TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(rosterNode);
checkTree.getTree().expandPath(new TreePath(path));
checkTree.expandTree();
for (CheckNode node : nodes) {
if (node.getParent() == null) {
child = (CheckNode) NodesGroups.get(i).get(1);
((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, ((CheckNode) NodesGroups.get(i).get(0)), ((CheckNode) NodesGroups.get(i).get(0)).getChildCount());
path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(node);
checkTree.getTree().expandPath(new TreePath(path));
checkTree.expandTree();
i++;
}
}
}
}
use of org.jivesoftware.spark.component.CheckNode in project Spark by igniterealtime.
the class BroadcastDialog method sendBroadcasts.
/**
* Sends a broadcast message to all users selected.
* @param dlg
*/
private boolean sendBroadcasts(JDialog dlg) throws SmackException.NotConnectedException {
final Set<String> jids = new HashSet<>();
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
for (CheckNode node : nodes) {
if (node.isSelected()) {
String jid = (String) node.getAssociatedObject();
jids.add(jid);
}
}
if (jids.size() == 0) {
JOptionPane.showMessageDialog(dlg, Res.getString("message.broadcast.no.user.selected"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
return false;
}
String text = messageBox.getText();
if (!ModelUtil.hasLength(text)) {
JOptionPane.showMessageDialog(dlg, Res.getString("message.broadcast.no.text"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
return false;
}
String recipients = "";
for (String jid : jids) {
final Message message = new Message();
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
recipients = recipients + nickname + ", ";
message.setTo(jid);
message.setBody(text);
if (normalMessageButton.isSelected()) {
message.setType(Message.Type.normal);
} else {
message.setType(Message.Type.headline);
}
SparkManager.getConnection().sendStanza(message);
}
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd" + " - " + "HH:mm");
Date date = new Date();
String out = dateFormat.format(date) + " (" + recipients + "): " + text + "\n";
try {
addDataToFile(out);
} catch (IOException ex) {
Log.error("Couldn't add data to file" + ex.getStackTrace());
}
return true;
}
Aggregations