Permalink
Browse files

hook up joining rooms and placeholder for parting

  • Loading branch information...
1 parent 86ef749 commit b23d3eab975b2641559f0d09491465e77debc054 @codingismy11to7 committed Jan 9, 2012
@@ -0,0 +1,33 @@
+package com.progoth.synchrochat.client.events;
+
+import com.google.web.bindery.event.shared.Event;
+import com.progoth.synchrochat.shared.model.ChatRoom;
+
+public class RoomJoinedEvent extends Event<RoomJoinedEvent.Handler>
+{
+ public static interface Handler
+ {
+ void onRoomJoined(ChatRoom aRoom);
+ }
+
+ public static final Type<Handler> TYPE = new Type<RoomJoinedEvent.Handler>();
+
+ private final ChatRoom m_room;
+
+ public RoomJoinedEvent(final ChatRoom aRoom)
+ {
+ m_room = aRoom;
+ }
+
+ @Override
+ protected void dispatch(final Handler aHandler)
+ {
+ aHandler.onRoomJoined(m_room);
+ }
+
+ @Override
+ public Type<Handler> getAssociatedType()
+ {
+ return TYPE;
+ }
+}
@@ -9,6 +9,7 @@
import com.progoth.synchrochat.client.events.RoomJoinRequestEvent;
import com.progoth.synchrochat.client.events.SynchroBus;
import com.progoth.synchrochat.client.gui.controllers.LoginController;
+import com.progoth.synchrochat.client.gui.controllers.RoomController;
import com.progoth.synchrochat.client.gui.views.MainView;
import com.progoth.synchrochat.shared.model.ChatRoom;
import com.sencha.gxt.widget.core.client.container.Viewport;
@@ -27,7 +28,7 @@ public void newRoomRequested(final String aRoomName, String aPassword)
@Override
public void onModuleLoad()
{
- LoginController.login();
+ LoginController.get().login();
final Viewport viewport = new Viewport();
viewport.add(new MainView());
@@ -36,12 +37,14 @@ public void onModuleLoad()
SynchroBus.get().addHandler(NewRoomInputEvent.TYPE, this);
SynchroBus.get().addHandler(RoomJoinRequestEvent.TYPE, this);
+ RoomController.get().getRoomList();
+
Window.addWindowClosingHandler(new ClosingHandler()
{
@Override
public void onWindowClosing(final ClosingEvent aEvent)
{
- LoginController.logout(false, false);
+ LoginController.get().logout(false, false);
}
});
}
@@ -15,9 +15,21 @@
public class LoginController
{
- private static String sm_logoutUrl = null;
+ private static final LoginController sm_instance = new LoginController();
- private static void doLogout(final boolean aRedirect)
+ public static LoginController get()
+ {
+ return sm_instance;
+ }
+
+ private String sm_logoutUrl = null;
+
+ private LoginController()
+ {
+ // singleton
+ }
+
+ private void doLogout(final boolean aRedirect)
{
SynchroRpc.get().logout(new ReallyDontCareCallback<Void>()
{
@@ -32,7 +44,7 @@ public void onSuccess(final Void aResult)
});
}
- public static void login()
+ public void login()
{
if (sm_logoutUrl != null)
{
@@ -59,7 +71,7 @@ public void onSuccess(final LoginResponse aResult)
});
}
- public static void logout(final boolean aConfirm, final boolean aRedirect)
+ public void logout(final boolean aConfirm, final boolean aRedirect)
{
if (sm_logoutUrl == null)
{
@@ -0,0 +1,78 @@
+package com.progoth.synchrochat.client.gui.controllers;
+
+import java.util.SortedMap;
+import java.util.SortedSet;
+import java.util.TreeMap;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.progoth.synchrochat.client.events.NewRoomInputEvent;
+import com.progoth.synchrochat.client.events.RoomJoinRequestEvent;
+import com.progoth.synchrochat.client.events.RoomJoinedEvent;
+import com.progoth.synchrochat.client.events.RoomListReceivedEvent;
+import com.progoth.synchrochat.client.events.SynchroBus;
+import com.progoth.synchrochat.client.rpc.SimpleAsyncCallback;
+import com.progoth.synchrochat.client.rpc.SynchroRpc;
+import com.progoth.synchrochat.shared.model.ChatRoom;
+import com.sencha.gxt.widget.core.client.info.Info;
+
+public class RoomController implements NewRoomInputEvent.Handler, RoomJoinRequestEvent.Handler
+{
+ private static final RoomController sm_instance = new RoomController();
+
+ public static RoomController get()
+ {
+ return sm_instance;
+ }
+
+ private final SortedMap<String, ChatRoom> m_currentRooms = new TreeMap<String, ChatRoom>();
+
+ private final AsyncCallback<SortedSet<ChatRoom>> m_roomsRcvdHandler = new SimpleAsyncCallback<SortedSet<ChatRoom>>()
+ {
+ @Override
+ public void onSuccess(final SortedSet<ChatRoom> aResult)
+ {
+ m_currentRooms.clear();
+ for (final ChatRoom cr : aResult)
+ {
+ m_currentRooms.put(cr.getName(), cr);
+ }
+ SynchroBus.get().fireEvent(new RoomListReceivedEvent(aResult));
+ }
+ };
+
+ private RoomController()
+ {
+ SynchroBus.get().addHandler(NewRoomInputEvent.TYPE, this);
+ SynchroBus.get().addHandler(RoomJoinRequestEvent.TYPE, this);
+ }
+
+ public void getRoomList()
+ {
+ SynchroRpc.get().getRoomList(m_roomsRcvdHandler);
+ }
+
+ public void leaveRoom(final ChatRoom aRoom)
+ {
+ Info.display("leave room", "implement me " + aRoom.getName());
+ }
+
+ @Override
+ public void newRoomRequested(final String aRoomName, final String aPassword)
+ {
+ SynchroRpc.get().subscribe(aRoomName, new SimpleAsyncCallback<SortedSet<ChatRoom>>()
+ {
+ @Override
+ public void onSuccess(final SortedSet<ChatRoom> aResult)
+ {
+ m_roomsRcvdHandler.onSuccess(aResult);
+ SynchroBus.get().fireEvent(new RoomJoinedEvent(m_currentRooms.get(aRoomName)));
+ }
+ });
+ }
+
+ @Override
+ public void roomJoinRequest(final ChatRoom aRoom)
+ {
+ newRoomRequested(aRoom.getName(), null);
+ }
+}
@@ -86,7 +86,7 @@ private void createTop(final BorderLayoutContainer aContainer)
@Override
public void onSelection(final SelectionEvent<MenuItem> aEvent)
{
- LoginController.logout(true, true);
+ LoginController.get().logout(true, true);
}
});
logoutMenuItem.setIcon(SynchroImages.get().disconnect());
@@ -1,5 +1,7 @@
package com.progoth.synchrochat.client.gui.widgets;
+import com.google.gwt.event.logical.shared.ResizeEvent;
+import com.google.gwt.event.logical.shared.ResizeHandler;
import com.progoth.synchrochat.client.gui.resources.SynchroImages;
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
import com.sencha.gxt.core.client.util.Margins;
@@ -32,23 +34,33 @@ private void createBottom()
bld.setSplit(true);
bld.setMinSize(65);
- TextButton send = new TextButton("Send", new SelectHandler()
+ final TextButton send = new TextButton("Send", new SelectHandler()
{
@Override
- public void onSelect(SelectEvent aEvent)
+ public void onSelect(final SelectEvent aEvent)
{
input.setValue(null);
}
});
send.setIcon(SynchroImages.get().font_go());
- send.setIconAlign(IconAlign.BOTTOM);
+ send.setIconAlign(IconAlign.TOP);
- HBoxLayoutContainer horiz = new HBoxLayoutContainer(HBoxLayoutAlign.TOP);
- BoxLayoutData flex = new BoxLayoutData(new Margins());
+ final HBoxLayoutContainer horiz = new HBoxLayoutContainer(HBoxLayoutAlign.TOP);
+ final BoxLayoutData flex = new BoxLayoutData(new Margins());
flex.setFlex(1);
horiz.add(input, flex);
horiz.add(send, new BoxLayoutData(new Margins(0, 5, 0, 5)));
+ horiz.addResizeHandler(new ResizeHandler()
+ {
+ @Override
+ public void onResize(ResizeEvent aEvent)
+ {
+ horiz.forceLayout();
+ send.redraw();
+ }
+ });
+
setSouthWidget(horiz, bld);
}
@@ -1,15 +1,27 @@
package com.progoth.synchrochat.client.gui.widgets;
+import java.util.Map.Entry;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import com.google.gwt.user.client.ui.Widget;
import com.progoth.synchrochat.client.events.LoginResponseReceivedEvent;
+import com.progoth.synchrochat.client.events.RoomJoinedEvent;
import com.progoth.synchrochat.client.events.SynchroBus;
+import com.progoth.synchrochat.client.gui.controllers.RoomController;
import com.progoth.synchrochat.client.gui.resources.SynchroImages;
+import com.progoth.synchrochat.shared.model.ChatRoom;
import com.progoth.synchrochat.shared.model.LoginResponse;
import com.sencha.gxt.widget.core.client.TabItemConfig;
import com.sencha.gxt.widget.core.client.TabPanel;
+import com.sencha.gxt.widget.core.client.event.CloseEvent;
+import com.sencha.gxt.widget.core.client.event.CloseEvent.CloseHandler;
import com.sencha.gxt.widget.core.client.form.TextArea;
-public class MainTabPanel extends TabPanel
+public class MainTabPanel extends TabPanel implements RoomJoinedEvent.Handler
{
+ private final SortedMap<ChatRoom, ChatPanel> m_rooms = new TreeMap<ChatRoom, ChatPanel>();
+
public MainTabPanel()
{
setCloseContextMenu(true);
@@ -32,8 +44,43 @@ public void loginReceived(final LoginResponse aResponse)
ovConf.setIcon(SynchroImages.get().information());
add(overview, ovConf);
- final TabItemConfig tmp = new TabItemConfig("blah", true);
- tmp.setIcon(SynchroImages.get().comments());
- add(new ChatPanel(), tmp);
+ addCloseHandler(new CloseHandler<Widget>()
+ {
+ @Override
+ public void onClose(final CloseEvent<Widget> aEvent)
+ {
+ ChatRoom room = null;
+ for (final Entry<ChatRoom, ChatPanel> entry : m_rooms.entrySet())
+ {
+ if (entry.getValue() == aEvent.getItem())
+ {
+ room = entry.getKey();
+ break;
+ }
+ }
+ RoomController.get().leaveRoom(room);
+ m_rooms.remove(room);
+ }
+ });
+
+ SynchroBus.get().addHandler(RoomJoinedEvent.TYPE, this);
+ }
+
+ @Override
+ public void onRoomJoined(final ChatRoom aRoom)
+ {
+ if (m_rooms.containsKey(aRoom))
+ {
+ setWidget(m_rooms.get(aRoom));
+ }
+ else
+ {
+ final TabItemConfig tmp = new TabItemConfig(aRoom.getName(), true);
+ tmp.setIcon(SynchroImages.get().comments());
+ final ChatPanel panel = new ChatPanel();
+ m_rooms.put(aRoom, panel);
+ add(panel, tmp);
+ setWidget(panel);
+ }
}
}
@@ -10,6 +10,7 @@
import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
import com.progoth.synchrochat.client.events.NewRoomInputEvent;
import com.progoth.synchrochat.client.events.RoomJoinRequestEvent;
+import com.progoth.synchrochat.client.events.RoomListReceivedEvent;
import com.progoth.synchrochat.client.events.SynchroBus;
import com.progoth.synchrochat.client.gui.resources.SynchroImages;
import com.progoth.synchrochat.shared.model.ChatRoom;
@@ -56,23 +57,21 @@ public RoomListPanel()
createCenter(container);
add(container);
+
+ SynchroBus.get().addHandler(RoomListReceivedEvent.TYPE, new RoomListReceivedEvent.Handler()
+ {
+ @Override
+ public void onRoomListReceived(RoomListReceivedEvent aEvt)
+ {
+ m_rooms.clear();
+ m_rooms.addAll(aEvt.getRoomList());
+ }
+ });
}
private void createCenter(final BorderLayoutContainer aContainer)
{
m_rooms = new ListStore<ChatRoom>(sm_props.key());
- ChatRoom room = new ChatRoom();
- room.setName("a room");
- room.setUserCount(500);
- m_rooms.add(room);
- room = new ChatRoom();
- room.setName("blah");
- room.setUserCount(0);
- m_rooms.add(room);
- room = new ChatRoom();
- room.setName("blah2");
- room.setUserCount(10);
- m_rooms.add(room);
final List<ColumnConfig<ChatRoom, ?>> colConfigs = new LinkedList<ColumnConfig<ChatRoom, ?>>();
ColumnConfig<ChatRoom, ?> col;

0 comments on commit b23d3ea

Please sign in to comment.