/** * 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(); }
/** * Handles adding a chat room provider. * * @param provider the provider. * @param addQueryResult indicates whether we should add the chat room to the query results or * fire an event without adding it to the results. */ private void providerAdded(ChatRoomProviderWrapper provider, boolean addQueryResult) { for (int i = 0; i < provider.countChatRooms(); i++) { ChatRoomWrapper chatRoom = provider.getChatRoom(i); addChatRoom( provider.getProtocolProvider(), chatRoom.getChatRoomName(), chatRoom.getChatRoomID(), addQueryResult, chatRoom.isAutojoin()); } }
/** * 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(); }
/** * 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); } }
/** * 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); }
/** * 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); } }