use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.
the class SharedModelFactory method createSharedDataSource.
public IMasterModel createSharedDataSource(ISharedObjectContainer container, final ID id, Object data, String updaterID) throws SharedObjectCreateException {
final ISharedObjectManager mgr = container.getSharedObjectManager();
final Object[] result = new Object[1];
final Object monitor = new Object();
IContainerListener listener = new IContainerListener() {
public void handleEvent(IContainerEvent event) {
if (event instanceof ISharedObjectActivatedEvent) {
ISharedObjectActivatedEvent e = (ISharedObjectActivatedEvent) event;
if (e.getActivatedID().equals(id)) {
result[0] = mgr.getSharedObject(id);
synchronized (monitor) {
monitor.notify();
}
}
}
}
};
try {
container.addListener(listener);
/* SharedObjectDescription desc = createLocalAgentDescription(id, container.getID(), data, updaterID);
synchronized (monitor) {
mgr.createSharedObject(desc);
if (result[0] == null)
monitor.wait(getCreationTimeout());
}
*/
synchronized (monitor) {
addSharedObject(mgr, id, data, updaterID);
if (result[0] == null)
monitor.wait(getCreationTimeout());
}
} catch (InterruptedException e) {
throw new SharedObjectCreateException(e);
} finally {
container.removeListener(listener);
}
return (IMasterModel) result[0];
}
use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.
the class SSLClientContainerConnectTest method testRemoveListener.
public void testRemoveListener() throws Exception {
final IContainer client = getClients()[0];
final IContainerListener l = createListener();
client.addListener(l);
client.removeListener(l);
client.connect(createServerID(), null);
assertTrue(clientConnectingEvents.size() == 0);
}
use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.
the class ChatRoomManagerUI method setupNewView.
private void setupNewView() throws Exception {
IChatRoomInfo roomInfo = manager.getChatRoomInfo(null);
Assert.isNotNull(roomInfo, Messages.ChatRoomManagerUI_EXCEPTION_NO_ROOT_CHAT_ROOM_MANAGER);
final IChatRoomContainer managerChatRoom = roomInfo.createChatRoomContainer();
chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID), ChatRoomManagerView.getHostnameFromID(targetID), managerChatRoom, this, createChatRoomViewCloseListener());
chatroomview.setMessageRenderer(getDefaultMessageRenderer());
// Add listener for container, so that if the container is spontaneously
// disconnected,
// then we will be able to have the UI respond by making itself inactive
container.addListener(new IContainerListener() {
public void handleEvent(final IContainerEvent evt) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (evt instanceof IContainerDisconnectedEvent || evt instanceof IContainerEjectedEvent) {
final ID departedContainerID = ((evt instanceof IContainerDisconnectedEvent) ? ((IContainerDisconnectedEvent) evt).getTargetID() : ((IContainerEjectedEvent) evt).getTargetID());
ID connectedID = targetID;
if (connectedID == null || connectedID.equals(departedContainerID)) {
chatroomview.disconnected();
isContainerConnected = false;
}
} else if (evt instanceof IContainerConnectedEvent) {
isContainerConnected = true;
chatroomview.setEnabled(true);
String[] roomsForTarget = getRoomsForTarget();
for (int i = 0; i < roomsForTarget.length; i++) {
IChatRoomInfo info = manager.getChatRoomInfo(roomsForTarget[i]);
chatroomview.joinRoom(info, getPasswordForChatRoomConnect(info));
}
}
}
});
}
});
// Add listeners so that the new chat room gets
// asynch notifications of various relevant chat room events
managerChatRoom.addMessageListener(new IIMMessageListener() {
public void handleMessageEvent(IIMMessageEvent messageEvent) {
if (messageEvent instanceof IChatRoomMessageEvent) {
IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent).getChatRoomMessage();
chatroomview.handleMessage(m.getFromID(), m.getMessage());
} else if (messageEvent instanceof IChatMessageEvent) {
final IChatMessage chatMessage = ((IChatMessageEvent) messageEvent).getChatMessage();
chatroomview.handleChatMessage(chatMessage);
}
}
});
}
use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.
the class ChatRoomManagerView method doJoinRoom.
protected void doJoinRoom(final IChatRoomInfo roomInfo, final String password) {
final ID targetRoomID = roomInfo.getRoomID();
final String targetRoomName = targetRoomID.getName();
// first, check to see if we already have it open. If so just activate
ChatRoom room = (ChatRoom) chatRooms.get(targetRoomName);
if (room != null && room.isConnected()) {
room.setSelected();
return;
}
// Then we create a new chatRoomContainer from the roomInfo
try {
final IChatRoomContainer chatRoomContainer = roomInfo.createChatRoomContainer();
// Setup new user interface (new tab)
final ChatRoom chatroom = new ChatRoom(chatRoomContainer, new ChatRoomTab(rootTabFolder, targetRoomName));
// setup message listener
chatRoomContainer.addMessageListener(new IIMMessageListener() {
public void handleMessageEvent(IIMMessageEvent messageEvent) {
if (messageEvent instanceof IChatRoomMessageEvent) {
IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent).getChatRoomMessage();
chatroom.handleMessage(m.getFromID(), m.getMessage());
}
}
});
// setup participant listener
chatRoomContainer.addChatRoomParticipantListener(new IChatRoomParticipantListener() {
public void handlePresenceUpdated(ID fromID, IPresence presence) {
chatroom.handlePresence(fromID, presence);
}
public void handleArrived(IUser participant) {
// do nothing
}
public void handleUpdated(IUser updatedParticipant) {
// do nothing
}
public void handleDeparted(IUser participant) {
// do nothing
}
});
chatRoomContainer.addListener(new IContainerListener() {
public void handleEvent(IContainerEvent evt) {
if (evt instanceof IContainerDisconnectedEvent || evt instanceof IContainerEjectedEvent) {
chatroom.disconnected();
}
}
});
// Now connect/join
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
chatRoomContainer.connect(targetRoomID, ConnectContextFactory.createPasswordConnectContext(password));
chatRooms.put(targetRoomName, chatroom);
} catch (Exception e) {
// $NON-NLS-1$
MessageDialog.openError(// $NON-NLS-1$
getSite().getShell(), // $NON-NLS-1$
"Connect Error", // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
"Could not connect to {0}.\n\nError is {1}.", targetRoomName, e.getLocalizedMessage()));
}
}
});
} catch (Exception e) {
// $NON-NLS-1$
MessageDialog.openError(// $NON-NLS-1$
getSite().getShell(), // $NON-NLS-1$
"Container Create Error", // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
"Could not create chatRoomContainer for {0}.\n\nError is {1}.", targetRoomName, e.getLocalizedMessage()));
}
}
use of org.eclipse.ecf.core.IContainerListener in project ecf by eclipse.
the class MSNConnectWizard method performFinish.
public boolean performFinish() {
final String connectID = page.getEmail();
final String password = page.getPassword();
// Save combo text even if we don't successfully login
page.saveComboText();
connectContext = ConnectContextFactory.createPasswordConnectContext(password);
try {
targetID = container.getConnectNamespace().createInstance(new Object[] { connectID });
} catch (final IDCreateException e) {
new IDCreateErrorDialog(null, connectID, e).open();
return false;
}
page.saveComboItems();
final IPresenceContainerAdapter adapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
container.addListener(new IContainerListener() {
public void handleEvent(IContainerEvent event) {
if (event instanceof IContainerConnectedEvent) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
openView();
}
});
}
}
});
final IChatManager icm = adapter.getChatManager();
icms = icm.getChatMessageSender();
itms = icm.getTypingMessageSender();
icm.addMessageListener(new IIMMessageListener() {
public void handleMessageEvent(IIMMessageEvent e) {
if (e instanceof IChatMessageEvent) {
displayMessage((IChatMessageEvent) e);
} else if (e instanceof ITypingMessageEvent) {
displayTypingNotification((ITypingMessageEvent) e);
}
}
});
new AsynchContainerConnectAction(container, targetID, connectContext, null, new Runnable() {
public void run() {
cachePassword(connectID, password);
}
}).run();
return true;
}
Aggregations