Search in sources :

Example 1 with CheckNode

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++;
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ContactList(org.jivesoftware.spark.ui.ContactList) CheckNode(org.jivesoftware.spark.component.CheckNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 2 with CheckNode

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;
}
Also used : Message(org.jivesoftware.smack.packet.Message) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CheckNode(org.jivesoftware.spark.component.CheckNode) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

CheckNode (org.jivesoftware.spark.component.CheckNode)2 IOException (java.io.IOException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 TreeNode (javax.swing.tree.TreeNode)1 TreePath (javax.swing.tree.TreePath)1 Message (org.jivesoftware.smack.packet.Message)1 ContactList (org.jivesoftware.spark.ui.ContactList)1