Search in sources :

Example 6 with HostedRoom

use of org.jivesoftware.smackx.muc.HostedRoom in project Spark by igniterealtime.

the class ConferenceRoomBrowser method invoke.

/**
 * Displays the ConferenceRoomBrowser.
 */
public void invoke() {
    startLoadingImg();
    TimerTask invokeThread = new TimerTask() {

        Collection<HostedRoom> rooms;

        @Override
        public void run() {
            try {
                rooms = getRoomList(serviceName);
                if (rooms == null) {
                    UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                    JOptionPane.showMessageDialog(conferences, Res.getString("message.conference.info.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                    if (dlg != null) {
                        dlg.dispose();
                    }
                } else {
                    try {
                        for (HostedRoom room : rooms) {
                            String roomName = room.getName();
                            String roomJID = room.getJid();
                            int numberOfOccupants = -1;
                            // service.
                            if (!partialDiscovery) {
                                RoomInfo roomInfo = null;
                                try {
                                    roomInfo = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getRoomInfo(roomJID);
                                } catch (Exception e) {
                                // Nothing to do
                                }
                                if (roomInfo != null) {
                                    numberOfOccupants = roomInfo.getOccupantsCount();
                                }
                                if (roomInfo == null || numberOfOccupants == -1) {
                                    partialDiscovery = true;
                                }
                            }
                            addRoomToTable(roomJID, roomName, numberOfOccupants);
                        }
                    } catch (Exception e) {
                        Log.error("Error setting up GroupChatTable", e);
                    }
                }
            } catch (Exception e) {
                Log.error("Unable to retrieve list of rooms.", e);
            }
            stopLoadingImg();
        }
    };
    final JOptionPane pane;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("title.create.or.bookmark.room"), Res.getString("message.add.favorite.room"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
    // Construct main panel w/ layout.
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    // The user should only be able to close this dialog.
    Object[] options = { Res.getString("close") };
    pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(pane, BorderLayout.CENTER);
    final JOptionPane p = new JOptionPane();
    dlg = p.createDialog(SparkManager.getMainWindow(), Res.getString("title.browse.room.service", serviceName));
    dlg.setModal(false);
    dlg.addComponentListener(this);
    dlg.setResizable(true);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(SparkManager.getMainWindow());
    PropertyChangeListener changeListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent e) {
            String value = (String) pane.getValue();
            if (Res.getString("close").equals(value)) {
                pane.removePropertyChangeListener(this);
                dlg.dispose();
            } else if (Res.getString("close").equals(value)) {
                pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            }
        }
    };
    pane.addPropertyChangeListener(changeListener);
    dlg.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                dlg.dispose();
            }
        }
    });
    // will need that, when the window is smaller then the buttons width...
    setButtonsWidth();
    showHiddenButtons.setVisible(false);
    dlg.pack();
    final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getConferenceRoomBrowserBounds();
    if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
        /*
             * looking up which bundle is used to set the size of the Window (not
             * using Localpreferences getLanguage() because sometimes language is
             * not saved in the properties file and so the method only returns an
             * empty String)
             */
        if (Res.getBundle().getLocale().toString().equals("de")) {
            dlg.setSize(700, 400);
        } else {
            dlg.setSize(500, 400);
        }
    } else {
        dlg.setBounds(bounds);
    }
    dlg.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setConferenceRoomBrowserBounds(dlg.getBounds());
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setConferenceRoomBrowserBounds(dlg.getBounds());
        }
    });
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    TaskEngine.getInstance().submit(invokeThread);
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) HostedRoom(org.jivesoftware.smackx.muc.HostedRoom) JOptionPane(javax.swing.JOptionPane) SmackException(org.jivesoftware.smack.SmackException) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) XMPPException(org.jivesoftware.smack.XMPPException) TitlePanel(org.jivesoftware.spark.component.TitlePanel) TimerTask(java.util.TimerTask) Collection(java.util.Collection)

Example 7 with HostedRoom

use of org.jivesoftware.smackx.muc.HostedRoom in project xabber-android by redsolution.

the class HostedConferencesAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // A ViewHolder keeps references to children views to avoid unnecessary calls
    // to findViewById() on each row.
    ViewHolder holder;
    // by ListView is null.
    if (convertView == null) {
        convertView = inflater.inflate(android.R.layout.simple_list_item_2, null);
        // Creates a ViewHolder and store references to the two children views
        // we want to bind data to.
        holder = new ViewHolder();
        holder.name = (TextView) convertView.findViewById(android.R.id.text1);
        holder.jid = (TextView) convertView.findViewById(android.R.id.text2);
        // Bind the data efficiently with the holder.
        convertView.setTag(holder);
    } else {
        // Get the ViewHolder back to get fast access to the TextView
        // and the ImageView.
        holder = (ViewHolder) convertView.getTag();
    }
    // If weren't re-ordering this you could rely on what you set last time
    HostedRoom hostedRoom = filteredData.get(position);
    holder.name.setText(hostedRoom.getName());
    holder.jid.setText(hostedRoom.getJid());
    return convertView;
}
Also used : HostedRoom(org.jivesoftware.smackx.muc.HostedRoom)

Aggregations

HostedRoom (org.jivesoftware.smackx.muc.HostedRoom)7 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 XMPPException (org.jivesoftware.smack.XMPPException)3 TimerTask (java.util.TimerTask)2 SmackException (org.jivesoftware.smack.SmackException)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)2 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Iterator (java.util.Iterator)1 JOptionPane (javax.swing.JOptionPane)1 JPanel (javax.swing.JPanel)1 ID (org.eclipse.ecf.core.identity.ID)1 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)1 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)1 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)1 RoomInfo (org.jivesoftware.smackx.muc.RoomInfo)1 TitlePanel (org.jivesoftware.spark.component.TitlePanel)1