Exemplo n.º 1
0
 private static Kenai.Status getKenaiStatus() {
   Kenai.Status s = Kenai.Status.OFFLINE;
   for (Kenai k : KenaiManager.getDefault().getKenais()) {
     if (k.getStatus() == Kenai.Status.ONLINE) return Kenai.Status.ONLINE;
     else if (k.getStatus() == Kenai.Status.LOGGED_IN) {
       s = Kenai.Status.LOGGED_IN;
     }
   }
   return s;
 }
Exemplo n.º 2
0
    @Override
    public void mouseClicked(MouseEvent event) {
      Kenai.Status s = getKenaiStatus();
      if (event.getClickCount() == 2) {
        if (s == Kenai.Status.ONLINE) {
          ChatTopComponent.openAction(ChatTopComponent.findInstance(), "", "", false)
              .actionPerformed(new ActionEvent(event, event.getID(), "")); // NOI18N
        }
      } else {
        if (s != Kenai.Status.OFFLINE) {
          JPopupMenu menu = new JPopupMenu();
          final JMenuItem contactListMenu =
              new JMenuItem(NbBundle.getMessage(PresenceIndicator.class, "CTL_WhoIsOnlineAction"));
          menu.add(contactListMenu);
          contactListMenu.setEnabled(s == Kenai.Status.ONLINE);
          final JCheckBoxMenuItem onlineCheckBox =
              new JCheckBoxMenuItem(
                  NbBundle.getMessage(PresenceIndicator.class, "CTL_OnlineCheckboxMenuItem"),
                  s == Kenai.Status.ONLINE); // NOI18N
          menu.add(onlineCheckBox);

          for (final Kenai k : KenaiManager.getDefault().getKenais()) {
            if (k.getStatus() == Kenai.Status.OFFLINE) continue;
            JMenu m = new JMenu(k.getName());
            final JCheckBoxMenuItem onlineCheckBoxForKenai =
                new JCheckBoxMenuItem(
                    NbBundle.getMessage(PresenceIndicator.class, "CTL_OnlineCheckboxMenuItem"),
                    k.getStatus() == Kenai.Status.ONLINE); // NOI18N
            m.add(onlineCheckBoxForKenai);
            final JMenuItem logoutItem =
                new JMenuItem(
                    NbBundle.getMessage(PresenceIndicator.class, "CTL_LogoutMenuItem")); // NOI18N
            m.add(logoutItem);
            menu.add(m);

            onlineCheckBoxForKenai.setEnabled(Utilities.isChatSupported(k));
            onlineCheckBoxForKenai.addActionListener(
                new ActionListener() {

                  @Override
                  public void actionPerformed(ActionEvent e) {
                    try {
                      PasswordAuthentication passwordAuthentication = k.getPasswordAuthentication();
                      if (passwordAuthentication != null) {
                        k.login(
                            passwordAuthentication.getUserName(),
                            passwordAuthentication.getPassword(),
                            onlineCheckBoxForKenai.isSelected());
                      }
                    } catch (KenaiException ex) {
                      Exceptions.printStackTrace(ex);
                    }
                  }
                });

            logoutItem.addActionListener(
                new ActionListener() {

                  public void actionPerformed(ActionEvent e) {
                    RequestProcessor.getDefault()
                        .post(
                            new Runnable() {

                              @Override
                              public void run() {
                                k.logout();
                              }
                            });
                  }
                });
          }
          final JMenuItem logoutItem =
              new JMenuItem(
                  NbBundle.getMessage(PresenceIndicator.class, "CTL_LogoutMenuItem")); // NOI18N
          menu.add(logoutItem);
          onlineCheckBox.addActionListener(
              new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                  RequestProcessor.getDefault()
                      .post(
                          new Runnable() {

                            public void run() {
                              try {
                                for (Kenai kenai : KenaiManager.getDefault().getKenais()) {
                                  PasswordAuthentication passwordAuthentication =
                                      kenai.getPasswordAuthentication();
                                  if (passwordAuthentication != null
                                      && Utilities.isChatSupported(kenai)) {
                                    kenai.login(
                                        passwordAuthentication.getUserName(),
                                        passwordAuthentication.getPassword(),
                                        onlineCheckBox.isSelected());
                                  }
                                }
                              } catch (KenaiException ex) {
                                Exceptions.printStackTrace(ex);
                              }
                            }
                          });
                }
              });
          logoutItem.addActionListener(
              new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                  Actions.forID("Team", "org.netbeans.modules.team.ui.LogoutAction")
                      .actionPerformed(e);
                }
              });

          contactListMenu.addActionListener(new WhoIsOnlineAction());
          menu.show(label, event.getPoint().x, event.getPoint().y);
        }
      }
    }