Esempio n. 1
0
  /**
   * Leaves the given chat room.
   *
   * @param chatRoomWrapper the chat room to leave.
   * @return <tt>ChatRoomWrapper</tt> instance associated with the chat room.
   */
  public ChatRoomWrapper leaveChatRoom(ChatRoomWrapper chatRoomWrapper) {
    ChatRoom chatRoom = chatRoomWrapper.getChatRoom();

    if (chatRoom == null) {
      ResourceManagementService resources = MUCActivator.getResources();

      MUCActivator.getAlertUIService()
          .showAlertDialog(
              resources.getI18NString("service.gui.WARNING"),
              resources.getI18NString("service.gui.CHAT_ROOM_LEAVE_NOT_CONNECTED"));

      return null;
    }

    if (chatRoom.isJoined()) chatRoom.leave();

    ChatRoomWrapper existChatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);

    if (existChatRoomWrapper == null) return null;

    // We save the choice of the user, before the chat room is really
    // joined, because even the join fails we want the next time when
    // we login to join this chat room automatically.
    ConfigurationUtils.updateChatRoomStatus(
        chatRoomWrapper.getParentProvider().getProtocolProvider(),
        chatRoomWrapper.getChatRoomID(),
        GlobalStatusEnum.OFFLINE_STATUS);

    return existChatRoomWrapper;
  }
    /**
     * Checks if the menu item should be enabled or disabled.
     *
     * @param contact the contact associated with the menu item.
     * @return <tt>true</tt> if the item should be enabled and <tt>false</tt> if not.
     */
    public boolean check(SourceContact contact) {
      ChatRoomWrapper chatRoomWrapper =
          MUCActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact);
      ChatRoom chatRoom = null;
      if (chatRoomWrapper != null) {
        chatRoom = chatRoomWrapper.getChatRoom();
      }

      if ((chatRoom != null) && chatRoom.isJoined()) return false;
      return true;
    }
  /**
   * Creates an instance of <tt>ChatRoomsListRightButtonMenu</tt>.
   *
   * @param chatRoomWrapper the chat room wrapper, corresponding to the selected chat room
   */
  public ChatRoomRightButtonMenu(ChatRoomWrapper chatRoomWrapper) {
    this.chatRoomWrapper = chatRoomWrapper;

    this.setLocation(getLocation());

    createMenuItem("service.gui.OPEN", ImageLoader.CHAT_ROOM_16x16_ICON, "openChatRoom");
    JMenuItem joinChatRoomItem =
        createMenuItem("service.gui.JOIN", ImageLoader.JOIN_ICON, "joinChatRoom");
    JMenuItem joinAsChatRoomItem =
        createMenuItem("service.gui.JOIN_AS", ImageLoader.JOIN_AS_ICON, "joinAsChatRoom");
    JMenuItem leaveChatRoomItem =
        createMenuItem("service.gui.LEAVE", ImageLoader.LEAVE_ICON, "leaveChatRoom");
    createMenuItem("service.gui.REMOVE", ImageLoader.DELETE_16x16_ICON, "removeChatRoom");
    JMenuItem nickNameChatRoomItem =
        createMenuItem("service.gui.CHANGE_NICK", ImageLoader.LEAVE_ICON, "nickNameChatRoom");

    ChatRoom chatRoom = chatRoomWrapper.getChatRoom();

    if ((chatRoom != null) && chatRoom.isJoined()) {
      joinAsChatRoomItem.setEnabled(false);
      joinChatRoomItem.setEnabled(false);
    } else leaveChatRoomItem.setEnabled(false);
  }