/** * Destroys the given <tt>ChatRoom</tt> from the list of all chat rooms. * * @param chatRoomWrapper the <tt>ChatRoomWrapper</tt> to be destroyed. * @param reason the reason for destroying. * @param alternateAddress the alternate address. */ public void destroyChatRoom( ChatRoomWrapper chatRoomWrapper, String reason, String alternateAddress) { if (chatRoomWrapper.getChatRoom().destroy(reason, alternateAddress)) { MUCActivator.getUIService().closeChatRoomWindow(chatRoomWrapper); chatRoomList.removeChatRoom(chatRoomWrapper); } else { // if we leave a chat room which is not persistent // the room can be destroyed on the server, and error is returned // when we try to destroy it not-authorized(401) if (!chatRoomWrapper.getChatRoom().isPersistent() && !chatRoomWrapper.getChatRoom().isJoined()) { chatRoomList.removeChatRoom(chatRoomWrapper); } } }
/** * Joins the given chat room with the given password and manages all the exceptions that could * occur during the join process. * * @param chatRoomWrapper the chat room to join. * @param nickName the nickname we choose for the given chat room. * @param password the password. * @param rememberPassword if true the password should be saved. * @param isFirstAttempt is this the first attempt to join room, used to check whether to show * some error messages * @param subject the subject which will be set to the room after the user join successful. */ private void joinChatRoom( ChatRoomWrapper chatRoomWrapper, String nickName, byte[] password, boolean rememberPassword, boolean isFirstAttempt, String subject) { ChatRoom chatRoom = chatRoomWrapper.getChatRoom(); if (chatRoom == null) { MUCActivator.getAlertUIService() .showAlertDialog( MUCActivator.getResources().getI18NString("service.gui.WARNING"), MUCActivator.getResources() .getI18NString( "service.gui.CHAT_ROOM_NOT_CONNECTED", new String[] {chatRoomWrapper.getChatRoomName()})); return; } new JoinChatRoomTask( (ChatRoomWrapperImpl) chatRoomWrapper, nickName, password, rememberPassword, isFirstAttempt, subject) .start(); }
/** * 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; }
/** * Handles the <tt>ActionEvent</tt>. Determines which menu item was selected and makes the * appropriate operations. * * @param e the event. */ public void actionPerformed(ActionEvent e) { JMenuItem menuItem = (JMenuItem) e.getSource(); String itemName = menuItem.getName(); ConferenceChatManager conferenceManager = GuiActivator.getUIService().getConferenceChatManager(); if (itemName.equals("removeChatRoom")) { conferenceManager.removeChatRoom(chatRoomWrapper); } else if (itemName.equals("leaveChatRoom")) { conferenceManager.leaveChatRoom(chatRoomWrapper); } else if (itemName.equals("joinChatRoom")) { conferenceManager.joinChatRoom(chatRoomWrapper); } else if (itemName.equals("openChatRoom")) { if (chatRoomWrapper.getChatRoom() != null) { if (!chatRoomWrapper.getChatRoom().isJoined()) { conferenceManager.joinChatRoom(chatRoomWrapper); } } else { // this is not a server persistent room we must create it // and join chatRoomWrapper = GuiActivator.getUIService() .getConferenceChatManager() .createChatRoom( chatRoomWrapper.getChatRoomName(), chatRoomWrapper.getParentProvider().getProtocolProvider(), new ArrayList<String>(), "", true, true); } ChatWindowManager chatWindowManager = GuiActivator.getUIService().getChatWindowManager(); ChatPanel chatPanel = chatWindowManager.getMultiChat(chatRoomWrapper, true); chatWindowManager.openChat(chatPanel, true); } else if (itemName.equals("joinAsChatRoom")) { ChatRoomAuthenticationWindow authWindow = new ChatRoomAuthenticationWindow(chatRoomWrapper); authWindow.setVisible(true); } }
/** * 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; }
/** * Opens a chat window for the chat room. * * @param room the chat room. */ public void openChatRoom(ChatRoomWrapper room) { if (room.getChatRoom() == null) { room = createChatRoom( room.getChatRoomName(), room.getParentProvider().getProtocolProvider(), new ArrayList<String>(), "", false, false, true); // leave the chatroom because getChatRoom().isJoined() returns true // otherwise if (room.getChatRoom().isJoined()) room.getChatRoom().leave(); } if (!room.getChatRoom().isJoined()) { String savedNick = ConfigurationUtils.getChatRoomProperty( room.getParentProvider().getProtocolProvider(), room.getChatRoomID(), "userNickName"); String subject = null; if (savedNick == null) { String[] joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( room.getParentProvider().getProtocolProvider(), room.getChatRoomID(), getDefaultNickname(room.getParentProvider().getProtocolProvider())); savedNick = joinOptions[0]; subject = joinOptions[1]; } if (savedNick != null) { joinChatRoom(room, savedNick, null, subject); } else return; } MUCActivator.getUIService().openChatRoomWindow(room); }
/** * Indicates that a change has occurred in the chat room data list. * * @param evt the event that describes the change. */ @Override public void contentChanged(final ChatRoomListChangeEvent evt) { ChatRoomWrapper chatRoom = evt.getSourceChatRoom(); switch (evt.getEventID()) { case ChatRoomListChangeEvent.CHAT_ROOM_ADDED: addChatRoom(chatRoom.getChatRoom(), false, chatRoom.isAutojoin()); break; case ChatRoomListChangeEvent.CHAT_ROOM_REMOVED: LinkedList<ChatRoomSourceContact> tmpContactResults; synchronized (contactResults) { tmpContactResults = new LinkedList<ChatRoomSourceContact>(contactResults); for (ChatRoomSourceContact contact : tmpContactResults) { if (contactEqualsChatRoom(contact, chatRoom)) { contactResults.remove(contact); fireContactRemoved(contact); break; } } } break; case ChatRoomListChangeEvent.CHAT_ROOM_CHANGED: synchronized (contactResults) { for (ChatRoomSourceContact contact : contactResults) { if (contactEqualsChatRoom(contact, chatRoom.getChatRoom())) { if (chatRoom.isAutojoin() != contact.isAutoJoin()) { contact.setAutoJoin(chatRoom.isAutojoin()); fireContactChanged(contact); } break; } } } break; default: break; } }
/** * Joins the given chat room with the given password and manages all the exceptions that could * occur during the join process. * * @param chatRoomWrapper the chat room to join. * @param nickName the nickname we choose for the given chat room. * @param password the password. */ public void joinChatRoom(ChatRoomWrapper chatRoomWrapper, String nickName, byte[] password) { ChatRoom chatRoom = chatRoomWrapper.getChatRoom(); if (chatRoom == null) { MUCActivator.getAlertUIService() .showAlertDialog( MUCActivator.getResources().getI18NString("service.gui.WARNING"), MUCActivator.getResources() .getI18NString( "service.gui.CHAT_ROOM_NOT_CONNECTED", new String[] {chatRoomWrapper.getChatRoomName()})); return; } new JoinChatRoomTask((ChatRoomWrapperImpl) chatRoomWrapper, nickName, password).start(); }
/** * 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"); ChatRoom chatRoom = chatRoomWrapper.getChatRoom(); if ((chatRoom != null) && chatRoom.isJoined()) { joinAsChatRoomItem.setEnabled(false); joinChatRoomItem.setEnabled(false); } else leaveChatRoomItem.setEnabled(false); }
/** * Handles the <tt>ActionEvent</tt>. Determines which menu item was selected and makes the * appropriate operations. * * @param e the event. */ public void actionPerformed(ActionEvent e) { JMenuItem menuItem = (JMenuItem) e.getSource(); String itemName = menuItem.getName(); ConferenceChatManager conferenceManager = GuiActivator.getUIService().getConferenceChatManager(); if (itemName.equals("removeChatRoom")) { conferenceManager.removeChatRoom(chatRoomWrapper); } else if (itemName.equals("leaveChatRoom")) { conferenceManager.leaveChatRoom(chatRoomWrapper); } else if (itemName.equals("joinChatRoom")) { String nickName = null; nickName = ConfigurationManager.getChatRoomProperty( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), "userNickName"); if (nickName == null) nickName = getNickname(); if (nickName != null) conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null); else conferenceManager.joinChatRoom(chatRoomWrapper); } else if (itemName.equals("openChatRoom")) { if (chatRoomWrapper.getChatRoom() != null) { if (!chatRoomWrapper.getChatRoom().isJoined()) { String nickName = null; nickName = ConfigurationManager.getChatRoomProperty( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), "userNickName"); if (nickName == null) nickName = getNickname(); if (nickName != null) conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null); else conferenceManager.joinChatRoom(chatRoomWrapper); } } else { // this is not a server persistent room we must create it // and join chatRoomWrapper = GuiActivator.getUIService() .getConferenceChatManager() .createChatRoom( chatRoomWrapper.getChatRoomName(), chatRoomWrapper.getParentProvider().getProtocolProvider(), new ArrayList<String>(), "", false, true); String nickName = null; nickName = ConfigurationManager.getChatRoomProperty( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), "userNickName"); if (nickName == null) nickName = getNickname(); if (nickName != null) conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null); else conferenceManager.joinChatRoom(chatRoomWrapper); } ChatWindowManager chatWindowManager = GuiActivator.getUIService().getChatWindowManager(); ChatPanel chatPanel = chatWindowManager.getMultiChat(chatRoomWrapper, true); chatWindowManager.openChat(chatPanel, true); } else if (itemName.equals("joinAsChatRoom")) { ChatRoomAuthenticationWindow authWindow = new ChatRoomAuthenticationWindow(chatRoomWrapper); authWindow.setVisible(true); } else if (itemName.equals("nickNameChatRoom")) { String nickName = null; nickName = ConfigurationManager.getChatRoomProperty( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), "userNickName"); ChatOperationReasonDialog reasonDialog = new ChatOperationReasonDialog( GuiActivator.getResources().getI18NString("service.gui.CHANGE_NICKNAME"), GuiActivator.getResources().getI18NString("service.gui.CHANGE_NICKNAME_LABEL")); reasonDialog.setReasonFieldText( nickName == null ? chatRoomWrapper.getParentProvider().getProtocolProvider().getAccountID().getUserID() : nickName); int result = reasonDialog.showDialog(); if (result == MessageDialog.OK_RETURN_CODE) { nickName = reasonDialog.getReason().trim(); } ConfigurationManager.updateChatRoomProperty( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), "userNickName", nickName); } }