Reduces the use of ChatRoomList in GUI bundle.

cusax-fix 4902
hristoterezov 12 years ago
parent d67b903d83
commit 74f26b4424

@ -1048,25 +1048,6 @@ public OperationSetAdHocMultiUserChat getAdHocMultiUserChatOpSet(
: null;
}
/**
* Returns the multi user chat operation set for the given protocol provider.
*
* @param protocolProvider The protocol provider for which the multi user
* chat operation set is about.
* @return OperationSetMultiUserChat The telephony operation
* set for the given protocol provider.
*/
public OperationSetMultiUserChat getMultiUserChatOpSet(
ProtocolProviderService protocolProvider)
{
OperationSet opSet
= protocolProvider.getOperationSet(OperationSetMultiUserChat.class);
return (opSet instanceof OperationSetMultiUserChat)
? (OperationSetMultiUserChat) opSet
: null;
}
/**
* Returns <tt>true</tt> if there's any currently selected menu related to
* this <tt>ContactListContainer</tt>, <tt>false</tt> - otherwise.

@ -756,27 +756,9 @@ private ChatPanel getMultiChatInternal(ChatRoom chatRoom,
{
synchronized (chatSyncRoot)
{
ChatRoomList chatRoomList
= GuiActivator
.getMUCService().getChatRoomList();
// Search in the chat room's list for a chat room that correspond
// to the given one.
ChatRoomWrapper chatRoomWrapper
= chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);
if ((chatRoomWrapper == null) && create)
{
ChatRoomProviderWrapper parentProvider
= chatRoomList.findServerWrapperFromProvider(
chatRoom.getParentProvider());
chatRoomWrapper
= GuiActivator.getMUCService().createChatRoomWrapper(
parentProvider, chatRoom);
chatRoomList.addChatRoom(chatRoomWrapper);
}
= GuiActivator.getMUCService().getChatRoomWrapperByChatRoom(
chatRoom, create);
ChatPanel chatPanel = null;

@ -65,11 +65,6 @@ public class ConferenceChatManager
private final Hashtable<ChatRoomWrapper, HistoryWindow> chatRoomHistory =
new Hashtable<ChatRoomWrapper, HistoryWindow>();
/**
* The list of persistent chat rooms.
*/
private final ChatRoomList chatRoomList;
/**
* The list of ad-hoc chat rooms.
*/
@ -86,15 +81,13 @@ public class ConferenceChatManager
*/
public ConferenceChatManager()
{
chatRoomList = GuiActivator.getMUCService().getChatRoomList();
chatRoomList.addChatRoomProviderWrapperListener(this);
GuiActivator.getMUCService().addChatRoomProviderWrapperListener(this);
// Loads the chat rooms list in a separate thread.
new Thread()
{
@Override
public void run()
{
chatRoomList.loadList();
adHocChatRoomList.loadList();
}
}.start();
@ -223,7 +216,7 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt)
if(sourceChatRoom.isSystem())
{
ChatRoomProviderWrapper serverWrapper
= chatRoomList.findServerWrapperFromProvider(
= GuiActivator.getMUCService().findServerWrapperFromProvider(
sourceChatRoom.getParentProvider());
chatPanel = chatWindowManager.getMultiChat(
@ -478,7 +471,8 @@ public void run()
ChatRoom sourceChatRoom = evt.getChatRoom();
ChatRoomWrapper chatRoomWrapper
= chatRoomList.findChatRoomWrapperFromChatRoom(sourceChatRoom);
= GuiActivator.getMUCService().findChatRoomWrapperFromChatRoom(
sourceChatRoom);
String eventType = evt.getEventType();
@ -512,8 +506,9 @@ public void run()
if (sourceChatRoom.isSystem())
{
ChatRoomProviderWrapper serverWrapper
= chatRoomList.findServerWrapperFromProvider(
sourceChatRoom.getParentProvider());
= GuiActivator.getMUCService()
.findServerWrapperFromProvider(
sourceChatRoom.getParentProvider());
serverWrapper.setSystemRoom(sourceChatRoom);
}
@ -708,7 +703,7 @@ public void removeChatRoom(ChatRoomWrapper chatRoomWrapper)
this.closeChatRoom(chatRoomWrapper);
chatRoomList.removeChatRoom(chatRoomWrapper);
GuiActivator.getMUCService().removeChatRoom(chatRoomWrapper);
}
@ -945,15 +940,12 @@ public void serviceChanged(ServiceEvent event)
ProtocolProviderService protocolProvider
= (ProtocolProviderService) service;
Object multiUserChatOpSet
= protocolProvider
.getOperationSet(OperationSetMultiUserChat.class);
Object multiUserChatAdHocOpSet
= protocolProvider
.getOperationSet(OperationSetAdHocMultiUserChat.class);
if (multiUserChatOpSet == null && multiUserChatAdHocOpSet != null)
if (multiUserChatAdHocOpSet != null)
{
if (event.getType() == ServiceEvent.REGISTERED)
{
@ -964,17 +956,6 @@ else if (event.getType() == ServiceEvent.UNREGISTERING)
adHocChatRoomList.removeChatProvider(protocolProvider);
}
}
else if (multiUserChatAdHocOpSet == null && multiUserChatOpSet != null)
{
if (event.getType() == ServiceEvent.REGISTERED)
{
chatRoomList.addChatProvider(protocolProvider);
}
else if (event.getType() == ServiceEvent.UNREGISTERING)
{
chatRoomList.removeChatProvider(protocolProvider);
}
}
}
/**

@ -99,8 +99,7 @@ public JoinChatRoomWindow(ChatRoomProviderWrapper chatRoomProvider)
super();
Iterator<ChatRoomProviderWrapper> providers =
GuiActivator.getMUCService().getChatRoomList()
.getChatRoomProviders();
GuiActivator.getMUCService().getChatRoomProviders();
while(providers.hasNext())
{

@ -47,8 +47,7 @@ public JoinChatRoomWizard(MainFrame mainFrame)
.getI18NString("service.gui.JOIN"));
Iterator<ChatRoomProviderWrapper> chatRoomProviders
= GuiActivator.getMUCService().getChatRoomList()
.getChatRoomProviders();
= GuiActivator.getMUCService().getChatRoomProviders();
page1 = new JoinChatRoomWizardPage1(this,
newChatRoom,

@ -10,9 +10,9 @@
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.impl.gui.main.authorization.*;
import net.java.sip.communicator.service.muc.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.account.*;
import net.java.sip.communicator.util.account.LoginManager;
/**
* The <tt>LoginRendererSwingImpl</tt> provides a Swing base implementation of
@ -85,7 +85,7 @@ public void protocolProviderConnected(
= AccountStatusUtils.getProtocolPresenceOpSet(protocolProvider);
OperationSetMultiUserChat multiUserChat =
mainFrame.getMultiUserChatOpSet(protocolProvider);
MUCService.getMultiUserChatOpSet(protocolProvider);
if (presence != null)
{
@ -95,8 +95,7 @@ public void protocolProviderConnected(
if(multiUserChat != null)
{
GuiActivator.getMUCService().getChatRoomList()
.synchronizeOpSetWithLocalContactList(
GuiActivator.getMUCService().synchronizeOpSetWithLocalContactList(
protocolProvider, multiUserChat);
}
}

@ -23,7 +23,7 @@
* @author Hristo Terezov
*/
public class ChatRoomListImpl
implements RegistrationStateChangeListener, ChatRoomList
implements RegistrationStateChangeListener, ChatRoomList, ServiceListener
{
/**
* The logger.
@ -48,6 +48,16 @@ public class ChatRoomListImpl
private final Vector<ChatRoomListChangeListener> listChangeListeners
= new Vector<ChatRoomListChangeListener>();
/**
* Constructs and initializes new <tt>ChatRoomListImpl</tt> objects. Adds
* the created object as service lister to the bundle context.
*/
public ChatRoomListImpl()
{
loadList();
MUCActivator.bundleContext.addServiceListener(this);
}
/**
* Initializes the list of chat rooms.
*/
@ -139,7 +149,7 @@ public void fireChatRoomListChangedEvent( ChatRoomWrapper chatRoomWrapper,
* @param pps the <tt>ProtocolProviderService</tt> corresponding to the chat
* server
*/
private ChatRoomProviderWrapper
ChatRoomProviderWrapper
addRegisteredChatProvider(ProtocolProviderService pps)
{
ChatRoomProviderWrapper chatRoomProvider
@ -443,35 +453,6 @@ public ChatRoomProviderWrapper findServerWrapperFromProvider(
return null;
}
/**
* Goes through the locally stored chat rooms list and for each
* {@link ChatRoomWrapper} tries to find the corresponding server stored
* {@link ChatRoom} in the specified operation set. Joins automatically all
* found chat rooms.
*
* @param protocolProvider the protocol provider for the account to
* synchronize
* @param opSet the multi user chat operation set, which give us access to
* chat room server
*/
public void synchronizeOpSetWithLocalContactList(
ProtocolProviderService protocolProvider,
final OperationSetMultiUserChat opSet)
{
ChatRoomProviderWrapper chatRoomProvider
= findServerWrapperFromProvider(protocolProvider);
if(chatRoomProvider == null)
{
chatRoomProvider = addRegisteredChatProvider(protocolProvider);
}
if (chatRoomProvider != null)
{
chatRoomProvider.synchronizeProvider();
}
}
/**
* Returns an iterator to the list of chat room providers.
*
@ -563,4 +544,40 @@ else if(evt.getNewState() == RegistrationState.UNREGISTERED
}
}
}
@Override
public void serviceChanged(ServiceEvent event)
{
// if the event is caused by a bundle being stopped, we don't want to
// know
if (event.getServiceReference().getBundle().getState()
== Bundle.STOPPING)
return;
Object service = MUCActivator.bundleContext.getService(event
.getServiceReference());
// we don't care if the source service is not a protocol provider
if (!(service instanceof ProtocolProviderService))
return;
ProtocolProviderService protocolProvider
= (ProtocolProviderService) service;
Object multiUserChatOpSet
= protocolProvider
.getOperationSet(OperationSetMultiUserChat.class);
if (multiUserChatOpSet != null)
{
if (event.getType() == ServiceEvent.REGISTERED)
{
addChatProvider(protocolProvider);
}
else if (event.getType() == ServiceEvent.UNREGISTERING)
{
removeChatProvider(protocolProvider);
}
}
}
}

@ -71,17 +71,6 @@ public class MUCActivator
private static CredentialsStorageService credentialsService;
public MUCActivator()
{
try
{
mucService = new MUCServiceImpl();
}
catch(Exception e)
{
}
}
/**
* Starts this bundle.
*
@ -95,6 +84,7 @@ public void start(BundleContext context) throws Exception
ContactSourceService.class.getName(),
chatRoomContactSource,
null);
mucService = new MUCServiceImpl();
bundleContext.registerService(
MUCService.class.getName(),
mucService,

@ -12,7 +12,7 @@
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactsource.SourceContact;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.muc.*;
import net.java.sip.communicator.service.protocol.*;
@ -56,21 +56,6 @@ public void acceptInvitation(ChatRoomInvitation invitation)
joinChatRoom(chatRoom, nickName, password);
}
/**
* Creates a <tt>ChatRoomWrapper</tt> instance.
*
* @param parentProvider the protocol provider to which the corresponding
* chat room belongs.
* @param chatRoom the chat room to which this wrapper corresponds.
* @return the <tt>ChatRoomWrapper</tt> instance.
*/
@Override
public ChatRoomWrapper createChatRoomWrapper(
ChatRoomProviderWrapper parentProvider, ChatRoom chatRoom)
{
return new ChatRoomWrapperImpl(parentProvider, chatRoom);
}
/**
* Returns the <tt>ChatRoomList</tt> instance.
*
@ -852,4 +837,123 @@ public ChatRoomWrapper findChatRoomWrapperFromSourceContact(
return chatRoomList.findChatRoomWrapperFromChatRoomID(
chatRoomContact.getChatRoomID(), chatRoomContact.getProvider());
}
/**
* Searches for chat room wrapper in chat room list by chat room.
*
* @param chatRoom the chat room.
* @param create if <tt>true</tt> and the chat room wrapper is not found new
* chatRoomWrapper is created.
* @return found chat room wrapper or the created chat room wrapper.
*/
@Override
public ChatRoomWrapper getChatRoomWrapperByChatRoom(ChatRoom chatRoom,
boolean create)
{
ChatRoomWrapper chatRoomWrapper
= chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);
if ((chatRoomWrapper == null) && create)
{
ChatRoomProviderWrapper parentProvider
= chatRoomList.findServerWrapperFromProvider(
chatRoom.getParentProvider());
chatRoomWrapper
= new ChatRoomWrapperImpl(
parentProvider, chatRoom);
chatRoomList.addChatRoom(chatRoomWrapper);
}
return chatRoomWrapper;
}
/**
* Goes through the locally stored chat rooms list and for each
* {@link ChatRoomWrapper} tries to find the corresponding server stored
* {@link ChatRoom} in the specified operation set. Joins automatically all
* found chat rooms.
*
* @param protocolProvider the protocol provider for the account to
* synchronize
* @param opSet the multi user chat operation set, which give us access to
* chat room server
*/
public void synchronizeOpSetWithLocalContactList(
ProtocolProviderService protocolProvider,
final OperationSetMultiUserChat opSet)
{
ChatRoomProviderWrapper chatRoomProvider
= findServerWrapperFromProvider(protocolProvider);
if(chatRoomProvider == null)
{
chatRoomProvider = chatRoomList.addRegisteredChatProvider(protocolProvider);
}
if (chatRoomProvider != null)
{
chatRoomProvider.synchronizeProvider();
}
}
/**
* Returns an iterator to the list of chat room providers.
*
* @return an iterator to the list of chat room providers.
*/
public Iterator<ChatRoomProviderWrapper> getChatRoomProviders()
{
return chatRoomList.getChatRoomProviders();
}
/**
* Removes the given <tt>ChatRoom</tt> from the list of all chat rooms.
*
* @param chatRoomWrapper the <tt>ChatRoomWrapper</tt> to remove
*/
public void removeChatRoom(ChatRoomWrapper chatRoomWrapper)
{
chatRoomList.removeChatRoom(chatRoomWrapper);
}
/**
* Adds a ChatRoomProviderWrapperListener to the listener list.
*
* @param listener the ChatRoomProviderWrapperListener to be added
*/
public void addChatRoomProviderWrapperListener(
ChatRoomList.ChatRoomProviderWrapperListener listener)
{
chatRoomList.addChatRoomProviderWrapperListener(listener);
}
/**
* Returns the <tt>ChatRoomProviderWrapper</tt> that correspond to the
* given <tt>ProtocolProviderService</tt>. If the list doesn't contain a
* corresponding wrapper - returns null.
*
* @param protocolProvider the protocol provider that we're looking for
* @return the <tt>ChatRoomProvider</tt> object corresponding to
* the given <tt>ProtocolProviderService</tt>
*/
public ChatRoomProviderWrapper findServerWrapperFromProvider(
ProtocolProviderService protocolProvider)
{
return chatRoomList.findServerWrapperFromProvider(protocolProvider);
}
/**
* Returns the <tt>ChatRoomWrapper</tt> that correspond to the given
* <tt>ChatRoom</tt>. If the list of chat rooms doesn't contain a
* corresponding wrapper - returns null.
*
* @param chatRoom the <tt>ChatRoom</tt> that we're looking for
* @return the <tt>ChatRoomWrapper</tt> object corresponding to the given
* <tt>ChatRoom</tt>
*/
public ChatRoomWrapper findChatRoomWrapperFromChatRoom(ChatRoom chatRoom)
{
return chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom);
}
}

@ -94,21 +94,6 @@ public ChatRoomWrapper findChatRoomWrapperFromChatRoomID(String chatRoomID,
public ChatRoomProviderWrapper findServerWrapperFromProvider(
ProtocolProviderService protocolProvider);
/**
* Goes through the locally stored chat rooms list and for each
* {@link ChatRoomWrapper} tries to find the corresponding server stored
* {@link ChatRoom} in the specified operation set. Joins automatically all
* found chat rooms.
*
* @param protocolProvider the protocol provider for the account to
* synchronize
* @param opSet the multi user chat operation set, which give us access to
* chat room server
*/
public void synchronizeOpSetWithLocalContactList(
ProtocolProviderService protocolProvider,
final OperationSetMultiUserChat opSet);
/**
* Returns an iterator to the list of chat room providers.
*

@ -19,18 +19,6 @@
*/
public abstract class MUCService
{
/**
* Creates a <tt>ChatRoomWrapper</tt> by specifying the corresponding chat
* room.
*
* @param parentProvider the protocol provider to which the corresponding
* chat room belongs
* @param chatRoom the chat room to which this wrapper corresponds.
*/
public abstract ChatRoomWrapper createChatRoomWrapper(
ChatRoomProviderWrapper parentProvider,
ChatRoom chatRoom);
/**
* Returns the <tt>ChatRoomList</tt> instance.
*
@ -219,4 +207,96 @@ public static boolean isPrivate(ChatRoom chatRoom)
public abstract ChatRoomWrapper findChatRoomWrapperFromSourceContact(
SourceContact contact);
/**
* Searches for chat room wrapper in chat room list by chat room.
*
* @param chatRoom the chat room.
* @param create if <tt>true</tt> and the chat room wrapper is not found new
* chatRoomWrapper is created.
* @return found chat room wrapper or the created chat room wrapper.
*/
public abstract ChatRoomWrapper getChatRoomWrapperByChatRoom(
ChatRoom chatRoom, boolean create);
/**
* Returns the multi user chat operation set for the given protocol provider.
*
* @param protocolProvider The protocol provider for which the multi user
* chat operation set is about.
* @return OperationSetMultiUserChat The telephony operation
* set for the given protocol provider.
*/
public static OperationSetMultiUserChat getMultiUserChatOpSet(
ProtocolProviderService protocolProvider)
{
OperationSet opSet
= protocolProvider.getOperationSet(OperationSetMultiUserChat.class);
return (opSet instanceof OperationSetMultiUserChat)
? (OperationSetMultiUserChat) opSet
: null;
}
/**
* Goes through the locally stored chat rooms list and for each
* {@link ChatRoomWrapper} tries to find the corresponding server stored
* {@link ChatRoom} in the specified operation set. Joins automatically all
* found chat rooms.
*
* @param protocolProvider the protocol provider for the account to
* synchronize
* @param opSet the multi user chat operation set, which give us access to
* chat room server
*/
public abstract void synchronizeOpSetWithLocalContactList(
ProtocolProviderService protocolProvider,
final OperationSetMultiUserChat opSet);
/**
* Returns an iterator to the list of chat room providers.
*
* @return an iterator to the list of chat room providers.
*/
public abstract Iterator<ChatRoomProviderWrapper> getChatRoomProviders();
/**
* Removes the given <tt>ChatRoom</tt> from the list of all chat rooms.
*
* @param chatRoomWrapper the <tt>ChatRoomWrapper</tt> to remove
*/
public abstract void removeChatRoom(ChatRoomWrapper chatRoomWrapper);
/**
* Adds a ChatRoomProviderWrapperListener to the listener list.
*
* @param listener the ChatRoomProviderWrapperListener to be added
*/
public abstract void addChatRoomProviderWrapperListener(
ChatRoomList.ChatRoomProviderWrapperListener listener);
/**
* Returns the <tt>ChatRoomProviderWrapper</tt> that correspond to the
* given <tt>ProtocolProviderService</tt>. If the list doesn't contain a
* corresponding wrapper - returns null.
*
* @param protocolProvider the protocol provider that we're looking for
* @return the <tt>ChatRoomProvider</tt> object corresponding to
* the given <tt>ProtocolProviderService</tt>
*/
public abstract ChatRoomProviderWrapper findServerWrapperFromProvider(
ProtocolProviderService protocolProvider);
/**
* Returns the <tt>ChatRoomWrapper</tt> that correspond to the given
* <tt>ChatRoom</tt>. If the list of chat rooms doesn't contain a
* corresponding wrapper - returns null.
*
* @param chatRoom the <tt>ChatRoom</tt> that we're looking for
* @return the <tt>ChatRoomWrapper</tt> object corresponding to the given
* <tt>ChatRoom</tt>
*/
public abstract ChatRoomWrapper findChatRoomWrapperFromChatRoom(
ChatRoom chatRoom);
}

Loading…
Cancel
Save