Fixes the inability to remove a ChatRoom from the "My chat rooms..." dialog when its ProtocolProviderService is not online and the ChatRoom hasn't been created at all. Otherwise, it pops up an error message which says that I have to connect in order to remove the ChatRoom while the ChatRoom in the dialog is just a configuration value which I should be able to remove at all times.

Also removes duplication in the modified files and reduces the shallow runtime size of ChatRoomRightButtonMenu.
cusax-fix
Lyubomir Marinov 17 years ago
parent 96f879d3dc
commit 3932e0f779

@ -20,6 +20,7 @@
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*;
// Java 1.6 has javax.swing.SwingWorker so we have to disambiguate.
@ -855,13 +856,16 @@ public void joinChatRoom(AdHocChatRoomWrapper chatRoomWrapper)
*/
public void removeChatRoom(ChatRoomWrapper chatRoomWrapper)
{
this.leaveChatRoom(chatRoomWrapper);
ChatRoom chatRoom = chatRoomWrapper.getChatRoom();
if (chatRoom != null)
leaveChatRoom(chatRoomWrapper);
this.closeChatRoom(chatRoomWrapper);
chatRoomList.removeChatRoom(chatRoomWrapper);
this.fireChatRoomListChangedEvent(
fireChatRoomListChangedEvent(
chatRoomWrapper,
ChatRoomListChangeEvent.CHAT_ROOM_REMOVED);
}
@ -1026,12 +1030,15 @@ public void leaveChatRoom(ChatRoomWrapper chatRoomWrapper)
if (chatRoom == null)
{
ResourceManagementService resources = GuiActivator.getResources();
new ErrorDialog(
GuiActivator.getUIService().getMainFrame(),
GuiActivator.getResources().getI18NString("service.gui.WARNING"),
GuiActivator.getResources().getI18NString(
"service.gui.CHAT_ROOM_LEAVE_NOT_CONNECTED"))
.showDialog();
GuiActivator.getUIService().getMainFrame(),
resources.getI18NString("service.gui.WARNING"),
resources
.getI18NString(
"service.gui.CHAT_ROOM_LEAVE_NOT_CONNECTED"))
.showDialog();
return;
}

@ -162,31 +162,22 @@ public void mousePressed(MouseEvent e)
if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0)
{
JPopupMenu rightButtonMenu;
if(o instanceof ChatRoomProviderWrapper)
{
ChatRoomServerRightButtonMenu rightButtonMenu
rightButtonMenu
= new ChatRoomServerRightButtonMenu(
(ChatRoomProviderWrapper) o);
rightButtonMenu.setInvoker(this);
rightButtonMenu.setLocation(selectedCellPoint.x,
selectedCellPoint.y + 20);
rightButtonMenu.setVisible(true);
}
(ChatRoomProviderWrapper) o);
else if (o instanceof ChatRoomWrapper)
{
ChatRoomRightButtonMenu rightButtonMenu
rightButtonMenu
= new ChatRoomRightButtonMenu((ChatRoomWrapper) o);
else
return;
rightButtonMenu.setInvoker(this);
rightButtonMenu.setLocation(selectedCellPoint.x,
selectedCellPoint.y + 20);
rightButtonMenu.setVisible(true);
}
rightButtonMenu.setInvoker(this);
rightButtonMenu
.setLocation(selectedCellPoint.x, selectedCellPoint.y + 20);
rightButtonMenu.setVisible(true);
}
}

@ -14,6 +14,8 @@
import net.java.sip.communicator.impl.gui.main.chat.conference.*;
import net.java.sip.communicator.impl.gui.main.chatroomslist.joinforms.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.resources.*;
/**
* The <tt>ChatRoomsListRightButtonMenu</tt> is the menu, opened when user clicks
@ -21,28 +23,13 @@
* contains the create chat room item.
*
* @author Yana Stamcheva
* @author Lubomir Marinov
*/
public class ChatRoomRightButtonMenu
extends JPopupMenu
implements ActionListener
{
private JMenuItem leaveChatRoomItem = new JMenuItem(
GuiActivator.getResources().getI18NString("service.gui.LEAVE"),
new ImageIcon(ImageLoader.getImage(ImageLoader.LEAVE_ICON)));
private JMenuItem joinChatRoomItem = new JMenuItem(
GuiActivator.getResources().getI18NString("service.gui.JOIN"),
new ImageIcon(ImageLoader.getImage(ImageLoader.JOIN_ICON)));
private JMenuItem joinAsChatRoomItem = new JMenuItem(
GuiActivator.getResources().getI18NString("service.gui.JOIN_AS"),
new ImageIcon(ImageLoader.getImage(ImageLoader.JOIN_AS_ICON)));
private JMenuItem removeChatRoomItem = new JMenuItem(
GuiActivator.getResources().getI18NString("service.gui.REMOVE"),
new ImageIcon(ImageLoader.getImage(ImageLoader.DELETE_16x16_ICON)));
private ChatRoomWrapper chatRoomWrapper = null;
private final ChatRoomWrapper chatRoomWrapper;
/**
* Creates an instance of <tt>ChatRoomsListRightButtonMenu</tt>.
@ -51,55 +38,39 @@ public class ChatRoomRightButtonMenu
*/
public ChatRoomRightButtonMenu(ChatRoomWrapper chatRoomWrapper)
{
super();
this.chatRoomWrapper = chatRoomWrapper;
this.setLocation(getLocation());
this.init();
}
/**
* Initializes the menu, by adding all containing menu items.
*/
private void init()
{
this.add(joinChatRoomItem);
this.add(joinAsChatRoomItem);
this.add(leaveChatRoomItem);
this.add(removeChatRoomItem);
this.joinChatRoomItem.setName("joinChatRoom");
this.joinAsChatRoomItem.setName("joinAsChatRoom");
this.leaveChatRoomItem.setName("leaveChatRoom");
this.removeChatRoomItem.setName("removeChatRoom");
this.joinChatRoomItem.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.JOIN"));
this.joinAsChatRoomItem.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.JOIN_AS"));
this.leaveChatRoomItem.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.LEAVE"));
this.removeChatRoomItem.setMnemonic(
GuiActivator.getResources().getI18nMnemonic("service.gui.REMOVE"));
this.joinChatRoomItem.addActionListener(this);
this.joinAsChatRoomItem.addActionListener(this);
this.leaveChatRoomItem.addActionListener(this);
this.removeChatRoomItem.addActionListener(this);
if (chatRoomWrapper.getChatRoom() != null
&& chatRoomWrapper.getChatRoom().isJoined())
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())
{
this.joinAsChatRoomItem.setEnabled(false);
this.joinChatRoomItem.setEnabled(false);
joinAsChatRoomItem.setEnabled(false);
joinChatRoomItem.setEnabled(false);
}
else
this.leaveChatRoomItem.setEnabled(false);
leaveChatRoomItem.setEnabled(false);
}
/**
@ -117,7 +88,6 @@ public void actionPerformed(ActionEvent e)
if (itemName.equals("removeChatRoom"))
{
conferenceManager.removeChatRoom(chatRoomWrapper);
}
else if (itemName.equals("leaveChatRoom"))
{
@ -135,4 +105,37 @@ else if(itemName.equals("joinAsChatRoom"))
authWindow.setVisible(true);
}
}
/**
* Creates a new <tt>JMenuItem</tt> and adds it to this <tt>JPopupMenu</tt>.
*
* @param textKey the key of the internationalized string in the resources
* of the application which represents the text of the new
* <tt>JMenuItem</tt>
* @param iconID the <tt>ImageID</tt> of the image in the resources of the
* application which represents the icon of the new <tt>JMenuItem</tt>
* @param name the name of the new <tt>JMenuItem</tt>
* @return a new <tt>JMenuItem</tt> instance which has been added to this
* <tt>JPopupMenu</tt>
*/
private JMenuItem createMenuItem(
String textKey,
ImageID iconID,
String name)
{
ResourceManagementService resources = GuiActivator.getResources();
JMenuItem menuItem
= new JMenuItem(
resources.getI18NString(textKey),
new ImageIcon(ImageLoader.getImage(iconID)));
menuItem.setMnemonic(resources.getI18nMnemonic(textKey));
menuItem.setName(name);
menuItem.addActionListener(this);
add(menuItem);
return menuItem;
}
}

Loading…
Cancel
Save