Fix issues with chatroom dialog:

Proper handling disabled accounts and stored chatrooms.
Proper searching for chatroom wrapper if the same chat room exists for different providers.
Close window when leaving chat room(pressing leave button).
Fix default state of ok button in the dialog, and further changes of this state.
cusax-fix
Damian Minkov 16 years ago
parent 4a445998e8
commit b741c059fb

@ -1125,6 +1125,8 @@ public void leaveChatRoom(ChatRoomWrapper chatRoomWrapper)
chatRoomWrapper.getParentProvider().getProtocolProvider(),
chatRoomWrapper.getChatRoomID(),
Constants.OFFLINE_STATUS);
this.closeChatRoom(existChatRoomWrapper);
}
/**

@ -161,31 +161,37 @@ private void removeChatProvider(ChatRoomProviderWrapper chatRoomProvider)
ConfigurationService configService
= GuiActivator.getConfigurationService();
String prefix = "net.java.sip.communicator.impl.gui.accounts";
String providerAccountUID
= chatRoomProvider
.getProtocolProvider().getAccountID().getAccountUniqueID();
AccountID accountID =
chatRoomProvider.getProtocolProvider().getAccountID();
for (String accountRootPropName
: configService.getPropertyNamesByPrefix(prefix, true))
// if provider is just disabled don't remove its stored rooms
if(!GuiActivator.getAccountManager().getStoredAccounts()
.contains(accountID))
{
String accountUID
= configService.getString(accountRootPropName);
String providerAccountUID = accountID.getAccountUniqueID();
if(accountUID.equals(providerAccountUID))
for (String accountRootPropName
: configService.getPropertyNamesByPrefix(prefix, true))
{
List<String> chatRooms
= configService.getPropertyNamesByPrefix(
accountRootPropName + ".chatRooms",
true);
String accountUID
= configService.getString(accountRootPropName);
for (String chatRoomPropName : chatRooms)
if(accountUID.equals(providerAccountUID))
{
configService.setProperty(
chatRoomPropName + ".chatRoomName",
null);
}
List<String> chatRooms
= configService.getPropertyNamesByPrefix(
accountRootPropName + ".chatRooms",
true);
configService.setProperty(accountRootPropName, null);
for (String chatRoomPropName : chatRooms)
{
configService.setProperty(
chatRoomPropName + ".chatRoomName",
null);
}
configService.setProperty(accountRootPropName, null);
}
}
}
@ -253,6 +259,11 @@ public ChatRoomWrapper findChatRoomWrapperFromChatRoom(ChatRoom chatRoom)
{
for (ChatRoomProviderWrapper provider : providersList)
{
// check only for the right PP
if(!chatRoom.getParentProvider()
.equals(provider.getProtocolProvider()))
continue;
ChatRoomWrapper systemRoomWrapper = provider.getSystemRoomWrapper();
ChatRoom systemRoom = systemRoomWrapper.getChatRoom();

@ -209,6 +209,11 @@ public void itemStateChanged(ItemEvent e)
public void keyTyped(KeyEvent e)
{
chatRoomsTableUI.clearSelection();
if(editor.getText().trim().length() > 0)
okButton.setEnabled(true);
else
okButton.setEnabled(false);
}
public void keyPressed(KeyEvent e)
@ -217,7 +222,7 @@ public void keyPressed(KeyEvent e)
public void keyReleased(KeyEvent e)
{}
});
// when we select a room from the available ones we clear anyting
// when we select a room from the available ones we clear anything
// typed for the room name and set the room we selected
chatRoomsTableUI.addSelectionListener(new ListSelectionListener() {
@ -231,6 +236,7 @@ public void valueChanged(ListSelectionEvent e)
{
editor.setText(room.getChatRoomName());
providersCombo.setSelectedItem(room.getParentProvider());
okButton.setEnabled(true);
}
}
}
@ -404,7 +410,7 @@ public void run()
if(rooms == null)
{
roomsCombo.setEnabled(true);
okButton.setEnabled(true);
//okButton.setEnabled(true);
return;
}
@ -417,7 +423,7 @@ public void run()
roomsCombo.setSelectedIndex(-1);
roomsCombo.setEnabled(true);
okButton.setEnabled(true);
//okButton.setEnabled(true);
}
}.start();
}

@ -26,7 +26,8 @@
public class ChatRoomTableModel
extends AbstractTableModel
implements ChatRoomListChangeListener,
ProviderPresenceStatusListener
ProviderPresenceStatusListener,
ChatRoomList.ChatRoomProviderWrapperListener
{
/**
* The <tt>ChatRoomsList</tt> is the list containing all chat rooms.
@ -65,23 +66,64 @@ public ChatRoomTableModel(JTable parentTable)
chatRoomList = GuiActivator.getUIService()
.getConferenceChatManager().getChatRoomList();
chatRoomList.addChatRoomProviderWrapperListener(this);
Iterator<ChatRoomProviderWrapper> iter =
chatRoomList.getChatRoomProviders();
while (iter.hasNext())
{
ChatRoomProviderWrapper provider = iter.next();
for (int i = 0; i < provider.countChatRooms(); i++)
if(!provider.getProtocolProvider().getAccountID().isEnabled())
{
ChatRoomWrapper room = provider.getChatRoom(i);
rooms.add(room);
continue;
}
OperationSetPresence presence
= provider.getProtocolProvider()
handleProviderAdded(provider);
}
}
/**
* Performs all actions on chat room provider added. Add listeners and
* add its saved rooms to the list of rooms.
*
* @param chatProviderWrapper the provider.
*/
private void handleProviderAdded(
ChatRoomProviderWrapper chatProviderWrapper)
{
for (int i = 0; i < chatProviderWrapper.countChatRooms(); i++)
{
addChatRoom(chatProviderWrapper.getChatRoom(i), false);
}
OperationSetPresence presence =
chatProviderWrapper.getProtocolProvider()
.getOperationSet(OperationSetPresence.class);
if(presence != null)
presence.addProviderPresenceStatusListener(this);
}
/**
* Performs all actions on chat room provider removed. Remove listeners and
* remove its saved rooms of the list of rooms.
*
* @param chatProviderWrapper the provider.
*/
private void handleProviderRemoved(
ChatRoomProviderWrapper chatProviderWrapper)
{
OperationSetPresence presence =
chatProviderWrapper.getProtocolProvider()
.getOperationSet(OperationSetPresence.class);
if(presence != null)
presence.addProviderPresenceStatusListener(this);
if(presence != null)
presence.removeProviderPresenceStatusListener(this);
for (int i = 0; i < chatProviderWrapper.countChatRooms(); i++)
{
ChatRoomWrapper room = chatProviderWrapper.getChatRoom(i);
removeChatRoom(room);
}
}
@ -221,32 +263,11 @@ public void contentChanged(ChatRoomListChangeEvent evt)
if (evt.getEventID() == ChatRoomListChangeEvent.CHAT_ROOM_ADDED)
{
rooms.add(chatRoomWrapper);
int index = rooms.indexOf(chatRoomWrapper);
if (index != -1)
{
fireTableRowsInserted(index, index);
parentTable.setRowSelectionInterval(index, index);
}
addChatRoom(chatRoomWrapper, true);
}
else if (evt.getEventID() == ChatRoomListChangeEvent.CHAT_ROOM_REMOVED)
{
int ix = rooms.indexOf(chatRoomWrapper);
rooms.remove(chatRoomWrapper);
OperationSetPresence presence
= chatRoomWrapper.getParentProvider().getProtocolProvider()
.getOperationSet(OperationSetPresence.class);
if(presence != null)
presence.removeProviderPresenceStatusListener(this);
if (ix != -1)
{
fireTableRowsDeleted(ix, ix);
}
removeChatRoom(chatRoomWrapper);
}
else if (evt.getEventID() == ChatRoomListChangeEvent.CHAT_ROOM_CHANGED)
{
@ -259,6 +280,41 @@ else if (evt.getEventID() == ChatRoomListChangeEvent.CHAT_ROOM_CHANGED)
}
}
/**
* Remove chat room from the ui.
* @param chatRoomWrapper the room wrapper.
*/
private void removeChatRoom(ChatRoomWrapper chatRoomWrapper)
{
int ix = rooms.indexOf(chatRoomWrapper);
rooms.remove(chatRoomWrapper);
if (ix != -1)
{
fireTableRowsDeleted(ix, ix);
}
}
/**
* Adds a chat room to the ui, updates the ui and if pointed selects
* that chat room.
* @param chatRoomWrapper the room to add.
* @param select whether we should select the room.
*/
private void addChatRoom(ChatRoomWrapper chatRoomWrapper, boolean select)
{
rooms.add(chatRoomWrapper);
int index = rooms.indexOf(chatRoomWrapper);
if (index != -1)
{
fireTableRowsInserted(index, index);
if(select)
parentTable.setRowSelectionInterval(index, index);
}
}
/**
* Listens for provider status change to change protocol icon.
* @param evt the event
@ -289,4 +345,26 @@ public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt)
*/
public void providerStatusMessageChanged(PropertyChangeEvent evt)
{}
/**
* When a provider wrapper is added this method is called to inform
* listeners.
*
* @param provider which was added.
*/
public void chatRoomProviderWrapperAdded(ChatRoomProviderWrapper provider)
{
handleProviderAdded(provider);
}
/**
* When a provider wrapper is removed this method is called to inform
* listeners.
*
* @param provider which was removed.
*/
public void chatRoomProviderWrapperRemoved(ChatRoomProviderWrapper provider)
{
handleProviderRemoved(provider);
}
}

Loading…
Cancel
Save