Merge "Issue #2785 - Change connection order of events Fixed classpath Change-Id: I15296306ee105a54379a370da7d53c7e46dc34bb" into development
Former-commit-id:323e6beb3e
[formerly44f93acd4d
] [formerly847481950c
] [formerlyea3a8e29c3
[formerly847481950c
[formerly 2f4d6ca7b78e40d11a3dbfd66969681ddd2135fd]]] Former-commit-id:ea3a8e29c3
Former-commit-id: 2d66ea60e65694f8edb4f2b29eaafcecb6c33f34 [formerlye99ad67ada
] Former-commit-id:7a9f211997
This commit is contained in:
commit
d252a00965
10 changed files with 594 additions and 561 deletions
|
@ -19,6 +19,7 @@
|
||||||
**/
|
**/
|
||||||
package com.raytheon.uf.viz.collaboration.comm.identity.roster;
|
package com.raytheon.uf.viz.collaboration.comm.identity.roster;
|
||||||
|
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.session.ISubscriptionRequestCompleteAction;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +35,8 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
* Jan 27, 2014 2700 bclement handle subscribe request returns a boolean
|
* Jan 27, 2014 2700 bclement handle subscribe request returns a boolean
|
||||||
* all methods take user id instead of qualified id
|
* all methods take user id instead of qualified id
|
||||||
* Feb 13, 2014 2755 bclement handleSubscribeRequest now returns SubscriptionResponse
|
* Feb 13, 2014 2755 bclement handleSubscribeRequest now returns SubscriptionResponse
|
||||||
|
* Apr 07, 2014 2785 mpduff Remove return type from and add parameter to handleSubscribeRequest
|
||||||
|
* Removed unused methods
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -47,22 +50,8 @@ public interface ISubscriptionResponder {
|
||||||
* Triggered when a contact requests a presence subscription
|
* Triggered when a contact requests a presence subscription
|
||||||
*
|
*
|
||||||
* @param fromID
|
* @param fromID
|
||||||
* @return true if the subscribe request is accepted.
|
* @param action
|
||||||
*/
|
*/
|
||||||
public SubscriptionResponse handleSubscribeRequest(UserId fromID);
|
public void handleSubscribeRequest(UserId fromID,
|
||||||
|
ISubscriptionRequestCompleteAction action);
|
||||||
/**
|
|
||||||
* Triggered when a contact subscribes to user
|
|
||||||
*
|
|
||||||
* @param fromID
|
|
||||||
*/
|
|
||||||
public void handleSubscribed(UserId fromID);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggered when a contact unsubscribes to user
|
|
||||||
*
|
|
||||||
* @param fromID
|
|
||||||
*/
|
|
||||||
public void handleUnsubscribed(UserId fromID);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,31 +22,19 @@ package com.raytheon.uf.viz.collaboration.comm.provider.session;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.jivesoftware.smack.PacketListener;
|
|
||||||
import org.jivesoftware.smack.Roster.SubscriptionMode;
|
import org.jivesoftware.smack.Roster.SubscriptionMode;
|
||||||
import org.jivesoftware.smack.RosterEntry;
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.Packet;
|
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
import org.jivesoftware.smack.packet.Presence.Type;
|
|
||||||
|
|
||||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
|
||||||
import com.raytheon.uf.common.status.UFStatus;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
|
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager;
|
import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
|
import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
|
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.event.IRosterChangeEvent;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.event.RosterChangeType;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
|
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.roster.SubscriptionResponse;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
|
import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.event.RosterChangeEvent;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.event.UserPresenceChangedEvent;
|
import com.raytheon.uf.viz.collaboration.comm.provider.event.UserPresenceChangedEvent;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,6 +59,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
* Jan 31, 2014 2700 bclement fixed subscribe back after accepting subscription
|
* Jan 31, 2014 2700 bclement fixed subscribe back after accepting subscription
|
||||||
* Feb 12, 2014 2797 bclement added protective copy to sendPresence
|
* Feb 12, 2014 2797 bclement added protective copy to sendPresence
|
||||||
* Feb 13, 2014 2755 bclement added user input for which group to add contact to
|
* Feb 13, 2014 2755 bclement added user input for which group to add contact to
|
||||||
|
* Apr 07, 2014 2785 mpduff Moved PacketListener implementation to its own class
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -80,139 +69,28 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
|
|
||||||
public class AccountManager implements IAccountManager {
|
public class AccountManager implements IAccountManager {
|
||||||
|
|
||||||
private final IUFStatusHandler log = UFStatus.getHandler(this.getClass());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listens for subscription events including subscription requests. If the
|
|
||||||
* subscription responder is null, the default action is to accept
|
|
||||||
* subscription requests.
|
|
||||||
*/
|
|
||||||
private PacketListener subscriptionEventListener = new PacketListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processPacket(Packet packet) {
|
|
||||||
if ( packet instanceof Presence){
|
|
||||||
Presence pres = (Presence) packet;
|
|
||||||
Type type = pres.getType();
|
|
||||||
if (type == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
UserId fromId = IDConverter.convertFrom(pres.getFrom());
|
|
||||||
switch (type) {
|
|
||||||
case subscribe:
|
|
||||||
SubscriptionResponse response;
|
|
||||||
if (responder != null) {
|
|
||||||
response = responder.handleSubscribeRequest(fromId);
|
|
||||||
} else {
|
|
||||||
response = new SubscriptionResponse(true);
|
|
||||||
}
|
|
||||||
handleSubRequest(fromId, response);
|
|
||||||
break;
|
|
||||||
case subscribed:
|
|
||||||
if (responder != null) {
|
|
||||||
responder.handleSubscribed(fromId);
|
|
||||||
}
|
|
||||||
handleSubscribed(fromId);
|
|
||||||
break;
|
|
||||||
case unsubscribed:
|
|
||||||
if (responder != null) {
|
|
||||||
responder.handleUnsubscribed(fromId);
|
|
||||||
}
|
|
||||||
handleUnsubscribed(fromId);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// do nothing
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* notify UI that someone subscribed to user
|
|
||||||
*
|
|
||||||
* @param fromID
|
|
||||||
*/
|
|
||||||
private void handleSubscribed(UserId fromID) {
|
|
||||||
ContactsManager cm = sessionManager.getContactsManager();
|
|
||||||
RosterEntry entry = cm.getRosterEntry((UserId) fromID);
|
|
||||||
IRosterChangeEvent event = new RosterChangeEvent(
|
|
||||||
RosterChangeType.ADD, entry);
|
|
||||||
sessionManager.postEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* notify UI that someone unsubscribed to user
|
|
||||||
*
|
|
||||||
* @param fromID
|
|
||||||
*/
|
|
||||||
private void handleUnsubscribed(UserId fromID) {
|
|
||||||
ContactsManager cm = sessionManager.getContactsManager();
|
|
||||||
RosterEntry entry = cm.getRosterEntry((UserId) fromID);
|
|
||||||
if (entry == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
IRosterChangeEvent event = new RosterChangeEvent(
|
|
||||||
RosterChangeType.DELETE, entry);
|
|
||||||
sessionManager.postEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* process subscription request
|
|
||||||
*
|
|
||||||
* @param fromId
|
|
||||||
*/
|
|
||||||
private void handleSubRequest(UserId fromId,
|
|
||||||
SubscriptionResponse response) {
|
|
||||||
Presence.Type subscribedType;
|
|
||||||
ContactsManager cm = sessionManager.getContactsManager();
|
|
||||||
boolean addToRoster = false;
|
|
||||||
if (response.isAccepted()) {
|
|
||||||
subscribedType = Presence.Type.subscribed;
|
|
||||||
RosterEntry entry = cm.getRosterEntry(fromId);
|
|
||||||
if (entry == null) {
|
|
||||||
addToRoster = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
subscribedType = Presence.Type.unsubscribed;
|
|
||||||
}
|
|
||||||
|
|
||||||
Presence presence = new Presence(subscribedType);
|
|
||||||
try {
|
|
||||||
sendPresence(fromId, presence);
|
|
||||||
if (addToRoster) {
|
|
||||||
if (response.addToGroup()) {
|
|
||||||
cm.addToGroup(response.getGroup(), fromId);
|
|
||||||
} else {
|
|
||||||
cm.addToRoster(fromId);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (CollaborationException e) {
|
|
||||||
AccountManager.this.log.error("Unable to send presence", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
private ISubscriptionResponder responder;
|
private ISubscriptionResponder responder;
|
||||||
|
|
||||||
private CollaborationConnection sessionManager = null;
|
private CollaborationConnection sessionManager = null;
|
||||||
|
|
||||||
private org.jivesoftware.smack.AccountManager smackManager;
|
private final org.jivesoftware.smack.AccountManager smackManager;
|
||||||
|
|
||||||
|
private final SubscriptionPacketListener subscriptionEventListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param adapter
|
* @param adapter
|
||||||
*/
|
*/
|
||||||
AccountManager(
|
AccountManager(CollaborationConnection manager) {
|
||||||
CollaborationConnection manager) {
|
|
||||||
sessionManager = manager;
|
sessionManager = manager;
|
||||||
|
subscriptionEventListener = new SubscriptionPacketListener(
|
||||||
|
sessionManager);
|
||||||
XMPPConnection xmppConnection = manager.getXmppConnection();
|
XMPPConnection xmppConnection = manager.getXmppConnection();
|
||||||
smackManager = new org.jivesoftware.smack.AccountManager(
|
smackManager = new org.jivesoftware.smack.AccountManager(xmppConnection);
|
||||||
xmppConnection);
|
|
||||||
xmppConnection.getRoster().setSubscriptionMode(SubscriptionMode.manual);
|
xmppConnection.getRoster().setSubscriptionMode(SubscriptionMode.manual);
|
||||||
sessionManager.getXmppConnection().addPacketListener(subscriptionEventListener,
|
sessionManager.getXmppConnection()
|
||||||
new PacketTypeFilter(Presence.class));
|
.addPacketListener(subscriptionEventListener,
|
||||||
|
new PacketTypeFilter(Presence.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -232,6 +110,7 @@ public class AccountManager implements IAccountManager {
|
||||||
@Override
|
@Override
|
||||||
public void setSubscriptionRequestResponder(ISubscriptionResponder responder) {
|
public void setSubscriptionRequestResponder(ISubscriptionResponder responder) {
|
||||||
this.responder = responder;
|
this.responder = responder;
|
||||||
|
subscriptionEventListener.setResponder(responder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,6 +120,7 @@ public class AccountManager implements IAccountManager {
|
||||||
@Override
|
@Override
|
||||||
public void removeSubscriptionRequestResponder() {
|
public void removeSubscriptionRequestResponder() {
|
||||||
responder = null;
|
responder = null;
|
||||||
|
subscriptionEventListener.setResponder(responder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -340,11 +220,11 @@ public class AccountManager implements IAccountManager {
|
||||||
* @param userPresence
|
* @param userPresence
|
||||||
* @throws CollaborationException
|
* @throws CollaborationException
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void sendPresence(UserId toId, Presence userPresence)
|
public void sendPresence(UserId toId, Presence userPresence)
|
||||||
throws CollaborationException {
|
throws CollaborationException {
|
||||||
userPresence.setFrom(sessionManager.getUser().getFQName());
|
userPresence.setFrom(sessionManager.getUser().getFQName());
|
||||||
userPresence.setTo(toId.getNormalizedId());
|
userPresence.setTo(toId.getNormalizedId());
|
||||||
sessionManager.getXmppConnection().sendPacket(userPresence);
|
sessionManager.getXmppConnection().sendPacket(userPresence);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,6 @@ import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
import org.jivesoftware.smack.filter.PacketTypeFilter;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
import org.jivesoftware.smack.packet.Presence.Mode;
|
|
||||||
import org.jivesoftware.smack.packet.Presence.Type;
|
|
||||||
import org.jivesoftware.smack.packet.StreamError;
|
import org.jivesoftware.smack.packet.StreamError;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
import org.jivesoftware.smack.provider.ProviderManager;
|
import org.jivesoftware.smack.provider.ProviderManager;
|
||||||
|
@ -119,6 +117,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
|
||||||
* Feb 28, 2014 2756 bclement added authManager
|
* Feb 28, 2014 2756 bclement added authManager
|
||||||
* Mar 07, 2014 2848 bclement removed join*Venue methods, now only creates venue objects
|
* Mar 07, 2014 2848 bclement removed join*Venue methods, now only creates venue objects
|
||||||
* changed session map to a concurrent hash map
|
* changed session map to a concurrent hash map
|
||||||
|
* Apr 07, 2014 2785 mpduff Changed the order of startup, sets up listeners before actually connecting.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -144,9 +143,9 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
|
|
||||||
private static Map<CollaborationConnectionData, CollaborationConnection> instanceMap = new HashMap<CollaborationConnectionData, CollaborationConnection>();
|
private static Map<CollaborationConnectionData, CollaborationConnection> instanceMap = new HashMap<CollaborationConnectionData, CollaborationConnection>();
|
||||||
|
|
||||||
private final Map<String, ISession> sessions;
|
private Map<String, ISession> sessions;
|
||||||
|
|
||||||
private final UserId user;
|
private UserId user;
|
||||||
|
|
||||||
private Presence userPresence;
|
private Presence userPresence;
|
||||||
|
|
||||||
|
@ -154,17 +153,17 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
|
|
||||||
private IAccountManager accountManager = null;
|
private IAccountManager accountManager = null;
|
||||||
|
|
||||||
private final EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
|
||||||
private final ContactsManager contactsMgr;
|
private ContactsManager contactsMgr;
|
||||||
|
|
||||||
private final CollaborationConnectionData connectionData;
|
private final CollaborationConnectionData connectionData;
|
||||||
|
|
||||||
private XMPPConnection connection;
|
private XMPPConnection connection;
|
||||||
|
|
||||||
private final ClientAuthManager authManager;
|
private ClientAuthManager authManager;
|
||||||
|
|
||||||
public static boolean COMPRESS = true;
|
private static boolean COMPRESS = true;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
|
@ -181,15 +180,13 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
private CollaborationConnection(CollaborationConnectionData connectionData)
|
private CollaborationConnection(CollaborationConnectionData connectionData)
|
||||||
throws CollaborationException {
|
throws CollaborationException {
|
||||||
this.connectionData = connectionData;
|
this.connectionData = connectionData;
|
||||||
String password = connectionData.getPassword();
|
init();
|
||||||
Mode mode = connectionData.getStatus();
|
}
|
||||||
if (mode == null) {
|
|
||||||
mode = Mode.available;
|
|
||||||
}
|
|
||||||
Presence initialPresence = new Presence(Type.available,
|
|
||||||
connectionData.getMessage(), 0, mode);
|
|
||||||
Tools.setProperties(initialPresence, connectionData.getAttributes());
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize this object.
|
||||||
|
*/
|
||||||
|
private void init() throws CollaborationException {
|
||||||
eventBus = new EventBus();
|
eventBus = new EventBus();
|
||||||
sessions = new ConcurrentHashMap<String, ISession>();
|
sessions = new ConcurrentHashMap<String, ISession>();
|
||||||
|
|
||||||
|
@ -205,29 +202,17 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
conConfig.setCompressionEnabled(COMPRESS);
|
conConfig.setCompressionEnabled(COMPRESS);
|
||||||
|
|
||||||
connection = new XMPPConnection(conConfig);
|
connection = new XMPPConnection(conConfig);
|
||||||
|
accountManager = new AccountManager(this);
|
||||||
connectInternal(connectionData.getUserName(), password);
|
|
||||||
|
|
||||||
this.user = new UserId(connectionData.getUserName(),
|
this.user = new UserId(connectionData.getUserName(),
|
||||||
connection.getServiceName());
|
connection.getServiceName());
|
||||||
|
|
||||||
setupConnectionListener();
|
setupConnectionListener();
|
||||||
setupAccountManager();
|
|
||||||
setupInternalConnectionListeners();
|
setupInternalConnectionListeners();
|
||||||
setupInternalVenueInvitationListener();
|
setupInternalVenueInvitationListener();
|
||||||
setupP2PComm();
|
setupP2PComm();
|
||||||
getPeerToPeerSession();
|
getPeerToPeerSession();
|
||||||
|
|
||||||
authManager = new ClientAuthManager(connection);
|
|
||||||
|
|
||||||
userPresence = initialPresence;
|
|
||||||
if (accountManager != null && initialPresence != null) {
|
|
||||||
accountManager.sendPresence(initialPresence);
|
|
||||||
}
|
|
||||||
|
|
||||||
contactsMgr = new ContactsManager(this, connection);
|
|
||||||
this.registerEventHandler(contactsMgr);
|
|
||||||
|
|
||||||
instanceMap.put(connectionData, this);
|
instanceMap.put(connectionData, this);
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
@ -278,7 +263,6 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
* @see com.raytheon.uf.viz.collaboration.comm.identity.roster.IRoster#getUser()
|
|
||||||
*/
|
*/
|
||||||
public UserId getUser() {
|
public UserId getUser() {
|
||||||
return user;
|
return user;
|
||||||
|
@ -294,32 +278,18 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @param presence
|
||||||
*/
|
*/
|
||||||
public void setPresence(Presence presence) {
|
public void setPresence(Presence presence) {
|
||||||
userPresence = presence;
|
userPresence = presence;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void setupAccountManager() {
|
|
||||||
if (accountManager == null) {
|
|
||||||
if (isConnected()) {
|
|
||||||
accountManager = new AccountManager(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the account manager for this connection.
|
* Get the account manager for this connection.
|
||||||
*
|
*
|
||||||
* @return The account manager for this connection.
|
* @return The account manager for this connection.
|
||||||
*/
|
*/
|
||||||
public IAccountManager getAccountManager() {
|
public IAccountManager getAccountManager() {
|
||||||
if (accountManager == null) {
|
|
||||||
setupAccountManager();
|
|
||||||
}
|
|
||||||
return accountManager;
|
return accountManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,6 +344,7 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
* Get the PeerToPeerChat session instance.
|
* Get the PeerToPeerChat session instance.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
|
* @throws CollaborationException
|
||||||
*/
|
*/
|
||||||
public ISession getPeerToPeerSession() throws CollaborationException {
|
public ISession getPeerToPeerSession() throws CollaborationException {
|
||||||
if (chatInstance == null) {
|
if (chatInstance == null) {
|
||||||
|
@ -427,7 +398,6 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
* @throws CollaborationException
|
|
||||||
*/
|
*/
|
||||||
public SharedDisplaySession createCollaborationVenue(CreateSessionData data) {
|
public SharedDisplaySession createCollaborationVenue(CreateSessionData data) {
|
||||||
SharedDisplaySession session = new SharedDisplaySession(eventBus, this,
|
SharedDisplaySession session = new SharedDisplaySession(eventBus, this,
|
||||||
|
@ -445,7 +415,6 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
* @param venueName
|
* @param venueName
|
||||||
* @param handle
|
* @param handle
|
||||||
* @return
|
* @return
|
||||||
* @throws CollaborationException
|
|
||||||
*/
|
*/
|
||||||
public VenueSession createTextOnlyVenue(String venueName, String handle) {
|
public VenueSession createTextOnlyVenue(String venueName, String handle) {
|
||||||
return createTextOnlyVenue(new CreateSessionData(venueName, handle));
|
return createTextOnlyVenue(new CreateSessionData(venueName, handle));
|
||||||
|
@ -557,11 +526,9 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupP2PComm() {
|
private void setupP2PComm() {
|
||||||
if (isConnected()) {
|
PeerToPeerCommHelper helper = new PeerToPeerCommHelper(this);
|
||||||
PeerToPeerCommHelper helper = new PeerToPeerCommHelper(this);
|
connection.addPacketListener(helper,
|
||||||
connection.addPacketListener(helper, new PacketTypeFilter(
|
new PacketTypeFilter(Message.class));
|
||||||
Message.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupConnectionListener() {
|
private void setupConnectionListener() {
|
||||||
|
@ -750,14 +717,15 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
* @return
|
* @return
|
||||||
* @throws CollaborationException
|
* @throws CollaborationException
|
||||||
*/
|
*/
|
||||||
public static CollaborationConnection connect(
|
public static CollaborationConnection createConnection(
|
||||||
CollaborationConnectionData userData) throws CollaborationException {
|
CollaborationConnectionData userData) throws CollaborationException {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
throw new CollaborationException("Already connected");
|
throw new CollaborationException("Already connected");
|
||||||
} else {
|
|
||||||
instance = new CollaborationConnection(userData);
|
|
||||||
return getConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance = new CollaborationConnection(userData);
|
||||||
|
|
||||||
|
return getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -795,4 +763,19 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
return authManager;
|
return authManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to the XMPP server. This needs to be called after the
|
||||||
|
* CollaborationConnection has been created and initialized.
|
||||||
|
*
|
||||||
|
* @throws CollaborationException
|
||||||
|
*/
|
||||||
|
public void connect() throws CollaborationException {
|
||||||
|
contactsMgr = new ContactsManager(this, this.getXmppConnection());
|
||||||
|
registerEventHandler(instance.getContactsManager());
|
||||||
|
|
||||||
|
connectInternal(connectionData.getUserName(),
|
||||||
|
connectionData.getPassword());
|
||||||
|
|
||||||
|
authManager = new ClientAuthManager(getXmppConnection());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
* This software was developed and / or modified by Raytheon Company,
|
||||||
|
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||||
|
*
|
||||||
|
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||||
|
* This software product contains export-restricted data whose
|
||||||
|
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||||
|
* to non-U.S. persons whether in the United States or abroad requires
|
||||||
|
* an export license or other authorization.
|
||||||
|
*
|
||||||
|
* Contractor Name: Raytheon Company
|
||||||
|
* Contractor Address: 6825 Pine Street, Suite 340
|
||||||
|
* Mail Stop B8
|
||||||
|
* Omaha, NE 68106
|
||||||
|
* 402.291.0100
|
||||||
|
*
|
||||||
|
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
|
* further licensing information.
|
||||||
|
**/
|
||||||
|
package com.raytheon.uf.viz.collaboration.comm.provider.session;
|
||||||
|
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.roster.SubscriptionResponse;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for post request actions.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Apr 04, 2014 2785 mpduff Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author mpduff
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface ISubscriptionRequestCompleteAction {
|
||||||
|
/**
|
||||||
|
* Called after subscription request is complete.
|
||||||
|
*
|
||||||
|
* @param userId
|
||||||
|
* The originating userId
|
||||||
|
* @param response
|
||||||
|
* The response
|
||||||
|
*/
|
||||||
|
public void executeSubscriptionRequestComplete(UserId userId,
|
||||||
|
SubscriptionResponse response);
|
||||||
|
}
|
|
@ -0,0 +1,193 @@
|
||||||
|
/**
|
||||||
|
* This software was developed and / or modified by Raytheon Company,
|
||||||
|
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||||
|
*
|
||||||
|
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||||
|
* This software product contains export-restricted data whose
|
||||||
|
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||||
|
* to non-U.S. persons whether in the United States or abroad requires
|
||||||
|
* an export license or other authorization.
|
||||||
|
*
|
||||||
|
* Contractor Name: Raytheon Company
|
||||||
|
* Contractor Address: 6825 Pine Street, Suite 340
|
||||||
|
* Mail Stop B8
|
||||||
|
* Omaha, NE 68106
|
||||||
|
* 402.291.0100
|
||||||
|
*
|
||||||
|
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
|
* further licensing information.
|
||||||
|
**/
|
||||||
|
package com.raytheon.uf.viz.collaboration.comm.provider.session;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.PacketListener;
|
||||||
|
import org.jivesoftware.smack.RosterEntry;
|
||||||
|
import org.jivesoftware.smack.packet.Packet;
|
||||||
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
|
import org.jivesoftware.smack.packet.Presence.Type;
|
||||||
|
|
||||||
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.event.IRosterChangeEvent;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.event.RosterChangeType;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.roster.SubscriptionResponse;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.event.RosterChangeEvent;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.ContactsManager;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.IDConverter;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens for subscription events including subscription requests. If the
|
||||||
|
* subscription responder is null, the default action is to accept subscription
|
||||||
|
* requests.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Apr 04, 2014 2785 mpduff Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author mpduff
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SubscriptionPacketListener implements PacketListener,
|
||||||
|
ISubscriptionRequestCompleteAction {
|
||||||
|
|
||||||
|
private static final IUFStatusHandler log = UFStatus
|
||||||
|
.getHandler(SubscriptionPacketListener.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The responder for this listener.
|
||||||
|
*/
|
||||||
|
private ISubscriptionResponder responder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The CollaborationConnection for his listener.
|
||||||
|
*/
|
||||||
|
private CollaborationConnection sessionManager = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param sessionManager
|
||||||
|
* The CollaborationConnection to use
|
||||||
|
*/
|
||||||
|
public SubscriptionPacketListener(CollaborationConnection sessionManager) {
|
||||||
|
this.sessionManager = sessionManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void processPacket(Packet packet) {
|
||||||
|
if (packet instanceof Presence) {
|
||||||
|
Presence pres = (Presence) packet;
|
||||||
|
Type type = pres.getType();
|
||||||
|
if (type == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UserId fromId = IDConverter.convertFrom(pres.getFrom());
|
||||||
|
switch (type) {
|
||||||
|
case subscribe:
|
||||||
|
responder.handleSubscribeRequest(fromId, this);
|
||||||
|
break;
|
||||||
|
case subscribed:
|
||||||
|
handleSubscribed(fromId);
|
||||||
|
break;
|
||||||
|
case unsubscribed:
|
||||||
|
handleUnsubscribed(fromId);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notify UI that someone subscribed to user
|
||||||
|
*
|
||||||
|
* @param fromID
|
||||||
|
*/
|
||||||
|
private void handleSubscribed(UserId fromID) {
|
||||||
|
ContactsManager cm = sessionManager.getContactsManager();
|
||||||
|
RosterEntry entry = cm.getRosterEntry(fromID);
|
||||||
|
IRosterChangeEvent event = new RosterChangeEvent(RosterChangeType.ADD,
|
||||||
|
entry);
|
||||||
|
sessionManager.postEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notify UI that someone unsubscribed to user
|
||||||
|
*
|
||||||
|
* @param fromID
|
||||||
|
*/
|
||||||
|
private void handleUnsubscribed(UserId fromID) {
|
||||||
|
ContactsManager cm = sessionManager.getContactsManager();
|
||||||
|
RosterEntry entry = cm.getRosterEntry(fromID);
|
||||||
|
if (entry == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IRosterChangeEvent event = new RosterChangeEvent(
|
||||||
|
RosterChangeType.DELETE, entry);
|
||||||
|
sessionManager.postEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process subscription request
|
||||||
|
*
|
||||||
|
* @param fromId
|
||||||
|
*/
|
||||||
|
private void handleSubResponse(UserId fromId, SubscriptionResponse response) {
|
||||||
|
Presence.Type subscribedType;
|
||||||
|
ContactsManager cm = sessionManager.getContactsManager();
|
||||||
|
boolean addToRoster = false;
|
||||||
|
if (response.isAccepted()) {
|
||||||
|
subscribedType = Presence.Type.subscribed;
|
||||||
|
RosterEntry entry = cm.getRosterEntry(fromId);
|
||||||
|
if (entry == null) {
|
||||||
|
addToRoster = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
subscribedType = Presence.Type.unsubscribed;
|
||||||
|
}
|
||||||
|
|
||||||
|
Presence presence = new Presence(subscribedType);
|
||||||
|
try {
|
||||||
|
sendPresence(fromId, presence);
|
||||||
|
if (addToRoster) {
|
||||||
|
if (response.addToGroup()) {
|
||||||
|
cm.addToGroup(response.getGroup(), fromId);
|
||||||
|
} else {
|
||||||
|
cm.addToRoster(fromId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (CollaborationException e) {
|
||||||
|
log.error("Unable to send presence", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPresence(UserId toId, Presence userPresence) {
|
||||||
|
userPresence.setFrom(sessionManager.getUser().getFQName());
|
||||||
|
userPresence.setTo(toId.getNormalizedId());
|
||||||
|
sessionManager.getXmppConnection().sendPacket(userPresence);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeSubscriptionRequestComplete(UserId userId,
|
||||||
|
SubscriptionResponse response) {
|
||||||
|
handleSubResponse(userId, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponder(ISubscriptionResponder responder) {
|
||||||
|
this.responder = responder;
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,8 +44,8 @@ import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConn
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction;
|
import com.raytheon.uf.viz.collaboration.ui.actions.PeerToPeerChatAction;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.jobs.AwayTimeOut;
|
import com.raytheon.uf.viz.collaboration.ui.jobs.AwayTimeOut;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.prefs.AutoSubscribePropertyListener;
|
|
||||||
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
||||||
|
import com.raytheon.uf.viz.collaboration.ui.prefs.SubscriptionResponderImpl;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
|
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
|
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.session.SessionView;
|
import com.raytheon.uf.viz.collaboration.ui.session.SessionView;
|
||||||
|
@ -69,6 +69,7 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
|
||||||
* Jan 30, 2014 2698 bclement moved xmpp join logic to dialog so we can reprompt user on failure
|
* Jan 30, 2014 2698 bclement moved xmpp join logic to dialog so we can reprompt user on failure
|
||||||
* Feb 13, 2014 2751 bclement messages return IUser instead of IQualifiedID
|
* Feb 13, 2014 2751 bclement messages return IUser instead of IQualifiedID
|
||||||
* Mar 06, 2014 2848 bclement moved SharedDisplaySessionMgr.joinSession call to InviteDialog
|
* Mar 06, 2014 2848 bclement moved SharedDisplaySessionMgr.joinSession call to InviteDialog
|
||||||
|
* Apr 08, 2014 2785 mpduff removed preference listener
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -88,11 +89,6 @@ public class ConnectionSubscriber {
|
||||||
private final AwayTimeOut awayTimeOut = new AwayTimeOut();
|
private final AwayTimeOut awayTimeOut = new AwayTimeOut();
|
||||||
|
|
||||||
private ConnectionSubscriber() {
|
private ConnectionSubscriber() {
|
||||||
Activator
|
|
||||||
.getDefault()
|
|
||||||
.getPreferenceStore()
|
|
||||||
.addPropertyChangeListener(
|
|
||||||
AutoSubscribePropertyListener.getInstance());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,9 +120,8 @@ public class ConnectionSubscriber {
|
||||||
|
|
||||||
private void setup(final CollaborationConnection connection) {
|
private void setup(final CollaborationConnection connection) {
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
AutoSubscribePropertyListener autoSub = AutoSubscribePropertyListener
|
connection.getAccountManager().setSubscriptionRequestResponder(
|
||||||
.getInstance();
|
new SubscriptionResponderImpl(connection));
|
||||||
autoSub.initialize(connection);
|
|
||||||
// Register handlers and events for the new sessionManager.
|
// Register handlers and events for the new sessionManager.
|
||||||
connection.registerEventHandler(this);
|
connection.registerEventHandler(this);
|
||||||
try {
|
try {
|
||||||
|
@ -170,9 +165,6 @@ public class ConnectionSubscriber {
|
||||||
"Error unregistering peer to peer handler", e);
|
"Error unregistering peer to peer handler", e);
|
||||||
}
|
}
|
||||||
connection.unregisterEventHandler(this);
|
connection.unregisterEventHandler(this);
|
||||||
AutoSubscribePropertyListener autoSub = AutoSubscribePropertyListener
|
|
||||||
.getInstance();
|
|
||||||
autoSub.close();
|
|
||||||
}
|
}
|
||||||
PlatformUI.getWorkbench().removeWorkbenchListener(wbListener);
|
PlatformUI.getWorkbench().removeWorkbenchListener(wbListener);
|
||||||
}
|
}
|
||||||
|
@ -193,7 +185,8 @@ public class ConnectionSubscriber {
|
||||||
IVenueSession session = inviteBox.getSession();
|
IVenueSession session = inviteBox.getSession();
|
||||||
if (inviteBox.isSharedDisplay()) {
|
if (inviteBox.isSharedDisplay()) {
|
||||||
CaveWorkbenchPageManager.getActiveInstance().showView(
|
CaveWorkbenchPageManager.getActiveInstance().showView(
|
||||||
CollaborationSessionView.ID, session.getSessionId(),
|
CollaborationSessionView.ID,
|
||||||
|
session.getSessionId(),
|
||||||
IWorkbenchPage.VIEW_ACTIVATE);
|
IWorkbenchPage.VIEW_ACTIVATE);
|
||||||
} else {
|
} else {
|
||||||
CaveWorkbenchPageManager.getActiveInstance().showView(
|
CaveWorkbenchPageManager.getActiveInstance().showView(
|
||||||
|
|
|
@ -19,28 +19,30 @@
|
||||||
**/
|
**/
|
||||||
package com.raytheon.uf.viz.collaboration.ui;
|
package com.raytheon.uf.viz.collaboration.ui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.jface.dialogs.Dialog;
|
|
||||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
|
||||||
import org.eclipse.jface.window.IShellProvider;
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
|
import org.eclipse.swt.events.SelectionEvent;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
|
import org.eclipse.swt.widgets.Button;
|
||||||
import org.eclipse.swt.widgets.Combo;
|
import org.eclipse.swt.widgets.Combo;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Control;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.jivesoftware.smack.RosterGroup;
|
import org.jivesoftware.smack.RosterGroup;
|
||||||
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
|
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialog to respond to a chat subscription request
|
* Dialog to respond to a chat subscription request. Returns the name of the
|
||||||
|
* group if accepted, null for denial of request.
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
*
|
*
|
||||||
|
@ -51,94 +53,90 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
* Jan 27, 2014 2700 bclement Initial creation
|
* Jan 27, 2014 2700 bclement Initial creation
|
||||||
* Jan 31, 2014 2700 bclement don't prompt for group if user is already in one
|
* Jan 31, 2014 2700 bclement don't prompt for group if user is already in one
|
||||||
* Feb 13, 2014 2755 bclement roster addition now done in account manager, user input passed back
|
* Feb 13, 2014 2755 bclement roster addition now done in account manager, user input passed back
|
||||||
|
* Apr 07, 2014 2785 mpduff Changed to implement CaveSWTDialog
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author bclement
|
* @author bclement
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public class SubRequestDialog extends Dialog {
|
public class SubRequestDialog extends CaveSWTDialog {
|
||||||
|
private final String NEW_GROUP = "New Group...";
|
||||||
private final String title;
|
|
||||||
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
private final UserId userid;
|
private final String userid;
|
||||||
|
|
||||||
private Combo groupCombo;
|
private Combo groupCbo;
|
||||||
|
|
||||||
private String group;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
* @param parentShell
|
* @param parentShell
|
||||||
|
* @param userid
|
||||||
*/
|
*/
|
||||||
public SubRequestDialog(Shell parentShell, String title, String message,
|
public SubRequestDialog(Shell parentShell, String userid) {
|
||||||
UserId userid) {
|
super(parentShell, SWT.DIALOG_TRIM);
|
||||||
super(parentShell);
|
|
||||||
this.title = title;
|
|
||||||
this.message = message;
|
|
||||||
this.userid = userid;
|
this.userid = userid;
|
||||||
|
setText("Contact Request");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param parentShell
|
|
||||||
*/
|
|
||||||
public SubRequestDialog(IShellProvider parentShell, String title,
|
|
||||||
String message, UserId userid) {
|
|
||||||
super(parentShell);
|
|
||||||
this.title = title;
|
|
||||||
this.message = message;
|
|
||||||
this.userid = userid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected void buttonPressed(int buttonId) {
|
protected void initializeComponents(Shell shell) {
|
||||||
if (buttonId == IDialogConstants.OK_ID) {
|
GridLayout gl = new GridLayout(1, false);
|
||||||
int count = groupCombo.getItemCount();
|
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||||
int index = groupCombo.getSelectionIndex();
|
Composite mainComp = new Composite(shell, SWT.NONE);
|
||||||
if ( index == count - 1){
|
mainComp.setLayout(gl);
|
||||||
// new group
|
mainComp.setLayoutData(gd);
|
||||||
CreateGroupDialog dialog = new CreateGroupDialog(Display
|
|
||||||
.getCurrent().getActiveShell());
|
|
||||||
dialog.open();
|
|
||||||
group = dialog.getNewGroup();
|
|
||||||
} else if ( index >= 0){
|
|
||||||
group = groupCombo.getItem(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.buttonPressed(buttonId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
|
||||||
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
Label msgLbl = new Label(mainComp, SWT.NONE);
|
||||||
*/
|
msgLbl.setText(userid + " wants to add you to their contacts list.");
|
||||||
@Override
|
msgLbl.setLayoutData(gd);
|
||||||
protected Control createDialogArea(Composite parent) {
|
|
||||||
Composite container = (Composite) super.createDialogArea(parent);
|
|
||||||
|
|
||||||
new Label(container, SWT.NONE).setText(message);
|
gl = new GridLayout(2, false);
|
||||||
|
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
|
||||||
|
Composite groupComp = new Composite(mainComp, SWT.NONE);
|
||||||
|
groupComp.setLayout(gl);
|
||||||
|
groupComp.setLayoutData(gd);
|
||||||
|
|
||||||
Composite groupComposite = new Composite(container, SWT.NONE);
|
gd = new GridData(SWT.RIGHT, SWT.DEFAULT, true, false);
|
||||||
groupComposite.setLayout(new GridLayout(2, false));
|
Label groupLbl = new Label(groupComp, SWT.NONE);
|
||||||
groupComposite.setLayoutData(new GridData(SWT.LEFT, SWT.DEFAULT,
|
groupLbl.setText("Group: ");
|
||||||
true, false));
|
groupLbl.setLayoutData(gd);
|
||||||
new Label(groupComposite, SWT.NONE).setText("Group: ");
|
groupCbo = new Combo(groupComp, SWT.DROP_DOWN | SWT.READ_ONLY);
|
||||||
groupCombo = new Combo(groupComposite, SWT.BORDER | SWT.READ_ONLY
|
groupCbo.setItems(getGroupNames());
|
||||||
| SWT.DROP_DOWN);
|
groupCbo.select(0);
|
||||||
groupCombo.setItems(getGroupNames());
|
groupCbo.setLayout(gl);
|
||||||
CollaborationConnection conn = CollaborationConnection.getConnection();
|
groupCbo.setLayoutData(gd);
|
||||||
Collection<RosterGroup> groups = conn.getContactsManager().getGroups(
|
|
||||||
userid);
|
|
||||||
if (!groups.isEmpty()) {
|
|
||||||
// we already have this user in a group in our roster, no need to
|
|
||||||
// prompt
|
|
||||||
groupComposite.setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return container;
|
gl = new GridLayout(2, false);
|
||||||
|
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
|
||||||
|
Composite btnComp = new Composite(mainComp, SWT.NONE);
|
||||||
|
btnComp.setLayout(gl);
|
||||||
|
btnComp.setLayoutData(gd);
|
||||||
|
|
||||||
|
int btnWidth = 75;
|
||||||
|
|
||||||
|
gd = new GridData(btnWidth, SWT.DEFAULT);
|
||||||
|
Button allowBtn = new Button(btnComp, SWT.PUSH);
|
||||||
|
allowBtn.setText("Allow");
|
||||||
|
allowBtn.setLayoutData(gd);
|
||||||
|
allowBtn.addSelectionListener(new SelectionAdapter() {
|
||||||
|
@Override
|
||||||
|
public void widgetSelected(SelectionEvent event) {
|
||||||
|
action(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
gd = new GridData(btnWidth, SWT.DEFAULT);
|
||||||
|
Button denyBtn = new Button(btnComp, SWT.PUSH);
|
||||||
|
denyBtn.setText("Deny");
|
||||||
|
denyBtn.setLayoutData(gd);
|
||||||
|
denyBtn.addSelectionListener(new SelectionAdapter() {
|
||||||
|
@Override
|
||||||
|
public void widgetSelected(SelectionEvent event) {
|
||||||
|
action(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,43 +150,39 @@ public class SubRequestDialog extends Dialog {
|
||||||
}
|
}
|
||||||
Collection<RosterGroup> groups = connection.getContactsManager()
|
Collection<RosterGroup> groups = connection.getContactsManager()
|
||||||
.getGroups();
|
.getGroups();
|
||||||
String[] rval = new String[groups.size() + 1];
|
List<String> groupList = new ArrayList<String>(groups.size());
|
||||||
Iterator<RosterGroup> iter = groups.iterator();
|
for (String group : groupList) {
|
||||||
int i = 0;
|
groupList.add(group);
|
||||||
for (; iter.hasNext(); ++i) {
|
|
||||||
rval[i] = iter.next().getName();
|
|
||||||
}
|
}
|
||||||
rval[i] = "New Group...";
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
Collections.sort(groupList);
|
||||||
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
|
groupList.add(0, NEW_GROUP);
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void configureShell(Shell newShell) {
|
|
||||||
super.configureShell(newShell);
|
|
||||||
newShell.setText(title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
return groupList.toArray(new String[groupList.size()]);
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
|
|
||||||
* .swt.widgets.Composite)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void createButtonsForButtonBar(Composite parent) {
|
|
||||||
createButton(parent, IDialogConstants.OK_ID, "Allow", true);
|
|
||||||
createButton(parent, IDialogConstants.CANCEL_ID, "Deny", false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the group
|
* Action handler.
|
||||||
|
*
|
||||||
|
* @param approved
|
||||||
|
* true if request approved, false if denied
|
||||||
*/
|
*/
|
||||||
public String getGroup() {
|
private void action(boolean approved) {
|
||||||
return group;
|
if (approved) {
|
||||||
}
|
if (groupCbo.getSelectionIndex() == 0) {
|
||||||
|
// new group
|
||||||
|
CreateGroupDialog dialog = new CreateGroupDialog(Display
|
||||||
|
.getCurrent().getActiveShell());
|
||||||
|
dialog.open();
|
||||||
|
String group = dialog.getNewGroup();
|
||||||
|
setReturnValue(group);
|
||||||
|
} else {
|
||||||
|
setReturnValue(groupCbo.getItem(groupCbo.getSelectionIndex()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setReturnValue(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,7 @@ import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
import org.jivesoftware.smack.packet.Presence;
|
import org.jivesoftware.smack.packet.Presence;
|
||||||
import org.jivesoftware.smack.packet.Presence.Mode;
|
import org.jivesoftware.smack.packet.Presence.Mode;
|
||||||
|
import org.jivesoftware.smack.packet.Presence.Type;
|
||||||
|
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||||
|
@ -50,6 +51,7 @@ import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation;
|
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation.HostConfig;
|
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation.HostConfig;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation.SiteConfig;
|
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation.SiteConfig;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.Tools;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
|
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnectionData;
|
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnectionData;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
||||||
|
@ -72,6 +74,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
||||||
* Jan 06, 2014 2563 bclement moved server text parsing to ServerInput class
|
* Jan 06, 2014 2563 bclement moved server text parsing to ServerInput class
|
||||||
* Jan 08, 2014 2563 bclement added Add/Remove buttons for server list
|
* Jan 08, 2014 2563 bclement added Add/Remove buttons for server list
|
||||||
* Jan 15, 2014 2630 bclement connection data stores status as Mode object
|
* Jan 15, 2014 2630 bclement connection data stores status as Mode object
|
||||||
|
* Apr 07, 2014 2785 mpduff Implemented change to CollaborationConnection
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -81,9 +84,9 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
||||||
|
|
||||||
public class LoginDialog extends Dialog {
|
public class LoginDialog extends Dialog {
|
||||||
|
|
||||||
private IPreferenceStore preferences;
|
private final IPreferenceStore preferences;
|
||||||
|
|
||||||
private CollaborationConnectionData loginData;
|
private final CollaborationConnectionData loginData;
|
||||||
|
|
||||||
private Text userText;
|
private Text userText;
|
||||||
|
|
||||||
|
@ -156,9 +159,7 @@ public class LoginDialog extends Dialog {
|
||||||
// Server setting
|
// Server setting
|
||||||
new Label(body, SWT.NONE).setText("Server: ");
|
new Label(body, SWT.NONE).setText("Server: ");
|
||||||
|
|
||||||
|
serverText = new Combo(body, SWT.BORDER | SWT.READ_ONLY | SWT.DROP_DOWN);
|
||||||
serverText = new Combo(body, SWT.BORDER | SWT.READ_ONLY
|
|
||||||
| SWT.DROP_DOWN);
|
|
||||||
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||||
gd.minimumWidth = 200;
|
gd.minimumWidth = 200;
|
||||||
serverText.setLayoutData(gd);
|
serverText.setLayoutData(gd);
|
||||||
|
@ -198,14 +199,14 @@ public class LoginDialog extends Dialog {
|
||||||
addServerButton = new Button(serverButtons, SWT.PUSH);
|
addServerButton = new Button(serverButtons, SWT.PUSH);
|
||||||
addServerButton.setText(ServerListListener.addButtonText);
|
addServerButton.setText(ServerListListener.addButtonText);
|
||||||
addServerButton.setLayoutData(gd);
|
addServerButton.setLayoutData(gd);
|
||||||
addServerButton.addListener(SWT.Selection, new ServerListListener(serverText));
|
addServerButton.addListener(SWT.Selection, new ServerListListener(
|
||||||
|
serverText));
|
||||||
removeServerButton = new Button(serverButtons, SWT.PUSH);
|
removeServerButton = new Button(serverButtons, SWT.PUSH);
|
||||||
removeServerButton.setText(ServerListListener.removeButtonText);
|
removeServerButton.setText(ServerListListener.removeButtonText);
|
||||||
removeServerButton.setLayoutData(gd);
|
removeServerButton.setLayoutData(gd);
|
||||||
removeServerButton.addListener(SWT.Selection, new ServerListListener(
|
removeServerButton.addListener(SWT.Selection, new ServerListListener(
|
||||||
serverText));
|
serverText));
|
||||||
|
|
||||||
|
|
||||||
// Password setting
|
// Password setting
|
||||||
new Label(body, SWT.NONE).setText("Password: ");
|
new Label(body, SWT.NONE).setText("Password: ");
|
||||||
passwordText = new Text(body, SWT.PASSWORD | SWT.BORDER);
|
passwordText = new Text(body, SWT.PASSWORD | SWT.BORDER);
|
||||||
|
@ -365,11 +366,33 @@ public class LoginDialog extends Dialog {
|
||||||
messageBox.open();
|
messageBox.open();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
CollaborationConnection connection = CollaborationConnection
|
// Create the connection
|
||||||
.connect(loginData);
|
CollaborationConnection collabConnection = CollaborationConnection
|
||||||
ConnectionSubscriber.subscribe(connection);
|
.createConnection(loginData);
|
||||||
|
|
||||||
|
// Subscribe to the collaboration connection
|
||||||
|
ConnectionSubscriber.subscribe(collabConnection);
|
||||||
|
|
||||||
|
// Connect to the XMPP server
|
||||||
|
collabConnection.connect();
|
||||||
|
|
||||||
storeLoginData();
|
storeLoginData();
|
||||||
shell.dispose();
|
shell.dispose();
|
||||||
|
|
||||||
|
// send initial presence
|
||||||
|
Mode mode = loginData.getStatus();
|
||||||
|
if (mode == null) {
|
||||||
|
mode = Mode.available;
|
||||||
|
}
|
||||||
|
|
||||||
|
Presence initialPresence = new Presence(Type.available,
|
||||||
|
loginData.getMessage(), 0, mode);
|
||||||
|
Tools.setProperties(initialPresence,
|
||||||
|
loginData.getAttributes());
|
||||||
|
|
||||||
|
collabConnection.getAccountManager().sendPresence(
|
||||||
|
initialPresence);
|
||||||
|
|
||||||
} catch (CollaborationException e) {
|
} catch (CollaborationException e) {
|
||||||
Activator.statusHandler.handle(Priority.PROBLEM,
|
Activator.statusHandler.handle(Priority.PROBLEM,
|
||||||
"Error connecting to collaboration server: "
|
"Error connecting to collaboration server: "
|
||||||
|
|
|
@ -1,225 +0,0 @@
|
||||||
/**
|
|
||||||
* This software was developed and / or modified by Raytheon Company,
|
|
||||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
|
||||||
*
|
|
||||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
|
||||||
* This software product contains export-restricted data whose
|
|
||||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
|
||||||
* to non-U.S. persons whether in the United States or abroad requires
|
|
||||||
* an export license or other authorization.
|
|
||||||
*
|
|
||||||
* Contractor Name: Raytheon Company
|
|
||||||
* Contractor Address: 6825 Pine Street, Suite 340
|
|
||||||
* Mail Stop B8
|
|
||||||
* Omaha, NE 68106
|
|
||||||
* 402.291.0100
|
|
||||||
*
|
|
||||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
|
||||||
* further licensing information.
|
|
||||||
**/
|
|
||||||
package com.raytheon.uf.viz.collaboration.ui.prefs;
|
|
||||||
|
|
||||||
import org.eclipse.jface.preference.IPersistentPreferenceStore;
|
|
||||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
|
||||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
|
||||||
import org.eclipse.jface.window.Window;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Shell;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
|
||||||
|
|
||||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
|
||||||
import com.raytheon.uf.common.status.UFStatus;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.IAccountManager;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.roster.SubscriptionResponse;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserSearch;
|
|
||||||
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
|
||||||
import com.raytheon.uf.viz.collaboration.ui.SubRequestDialog;
|
|
||||||
import com.raytheon.uf.viz.core.VizApp;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listens to collaboration preferences and alters the subscription request
|
|
||||||
* handler as appropriate.
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
*
|
|
||||||
* SOFTWARE HISTORY
|
|
||||||
*
|
|
||||||
* Date Ticket# Engineer Description
|
|
||||||
* ------------ ---------- ----------- --------------------------
|
|
||||||
* Jan 24, 2014 2700 bclement Initial creation
|
|
||||||
* Feb 3, 2014 2699 bclement fixed assumption that username search was exact
|
|
||||||
* Feb 13, 2014 2755 bclement added user input for which group to add contact to
|
|
||||||
* Mar 12, 2014 2632 mpduff Property change to handle String and Boolean
|
|
||||||
*
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @author bclement
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
public class AutoSubscribePropertyListener implements IPropertyChangeListener {
|
|
||||||
|
|
||||||
private static final IUFStatusHandler log = UFStatus
|
|
||||||
.getHandler(AutoSubscribePropertyListener.class);
|
|
||||||
|
|
||||||
private static AutoSubscribePropertyListener instance;
|
|
||||||
|
|
||||||
private static final Object INSTANCE_MUTEX = new Object();
|
|
||||||
|
|
||||||
public static AutoSubscribePropertyListener getInstance() {
|
|
||||||
synchronized (INSTANCE_MUTEX) {
|
|
||||||
if (instance == null) {
|
|
||||||
instance = new AutoSubscribePropertyListener();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CollaborationConnection connection;
|
|
||||||
|
|
||||||
private IAccountManager accountManager;
|
|
||||||
|
|
||||||
private AutoSubscribePropertyListener() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize auto subscribe state after login
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
*/
|
|
||||||
public synchronized void initialize(CollaborationConnection connection) {
|
|
||||||
this.connection = connection;
|
|
||||||
this.accountManager = connection.getAccountManager();
|
|
||||||
updateManager(isAutoInPrefs());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clean up auto subscribe state after logout
|
|
||||||
*/
|
|
||||||
public synchronized void close() {
|
|
||||||
this.accountManager = null;
|
|
||||||
this.connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
|
|
||||||
* .jface.util.PropertyChangeEvent)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void propertyChange(PropertyChangeEvent event) {
|
|
||||||
if (event.getProperty().equals(
|
|
||||||
CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE)
|
|
||||||
&& accountManager != null) {
|
|
||||||
|
|
||||||
// The HierarchicalPreferenceStore store sometimes returns a string
|
|
||||||
Object valueObject = event.getNewValue();
|
|
||||||
|
|
||||||
if (valueObject instanceof Boolean) {
|
|
||||||
updateManager((Boolean) valueObject);
|
|
||||||
} else {
|
|
||||||
updateManager(Boolean.valueOf(valueObject.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if preferences have auto accept enabled
|
|
||||||
*/
|
|
||||||
private boolean isAutoInPrefs() {
|
|
||||||
IPersistentPreferenceStore prefs = Activator.getDefault()
|
|
||||||
.getPreferenceStore();
|
|
||||||
return prefs.getBoolean(CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update auto subscribe state in account manager
|
|
||||||
*
|
|
||||||
* @param auto
|
|
||||||
*/
|
|
||||||
private void updateManager(boolean auto) {
|
|
||||||
// manager auto accepts by default if responder is not set
|
|
||||||
boolean accountManagerAutoAccepts = !accountManager
|
|
||||||
.isSubscriptionRequestResponderSet();
|
|
||||||
// update if the settings don't match
|
|
||||||
if (auto != accountManagerAutoAccepts) {
|
|
||||||
if (auto) {
|
|
||||||
accountManager.removeSubscriptionRequestResponder();
|
|
||||||
} else {
|
|
||||||
accountManager.setSubscriptionRequestResponder(newResponder());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create responder to handle subscription requests
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private ISubscriptionResponder newResponder() {
|
|
||||||
return new ISubscriptionResponder() {
|
|
||||||
|
|
||||||
private final UserSearch search = connection.createSearch();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleUnsubscribed(UserId fromID) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleSubscribed(UserId fromID) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SubscriptionResponse handleSubscribeRequest(
|
|
||||||
final UserId fromID) {
|
|
||||||
String displayName = getDisplayName(fromID);
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append(fromID.getFQName());
|
|
||||||
if (displayName != null) {
|
|
||||||
builder.append(" (").append(displayName).append(")");
|
|
||||||
}
|
|
||||||
builder.append(" wants to add you to his or her contacts list.");
|
|
||||||
final String msg = builder.toString();
|
|
||||||
final SubscriptionResponse rval = new SubscriptionResponse();
|
|
||||||
VizApp.runSync(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Shell shell = new Shell(Display.getCurrent());
|
|
||||||
SubRequestDialog dlg = new SubRequestDialog(shell,
|
|
||||||
"Authorize Collaboration Contact", msg, fromID);
|
|
||||||
int index = dlg.open();
|
|
||||||
|
|
||||||
rval.setAccepted(index == Window.OK);
|
|
||||||
rval.setGroup(dlg.getGroup());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get display name for user from server
|
|
||||||
*
|
|
||||||
* @param fromID
|
|
||||||
* @return null if none found
|
|
||||||
*/
|
|
||||||
private String getDisplayName(UserId fromID) {
|
|
||||||
String rval = null;
|
|
||||||
try {
|
|
||||||
UserId user = search.byExactUsername(fromID.getName());
|
|
||||||
return user != null ? user.getAlias() : null;
|
|
||||||
} catch (XMPPException e) {
|
|
||||||
log.error("Unable to get display name for user: " + fromID,
|
|
||||||
e);
|
|
||||||
}
|
|
||||||
return rval;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,150 @@
|
||||||
|
/**
|
||||||
|
* This software was developed and / or modified by Raytheon Company,
|
||||||
|
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||||
|
*
|
||||||
|
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||||
|
* This software product contains export-restricted data whose
|
||||||
|
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||||
|
* to non-U.S. persons whether in the United States or abroad requires
|
||||||
|
* an export license or other authorization.
|
||||||
|
*
|
||||||
|
* Contractor Name: Raytheon Company
|
||||||
|
* Contractor Address: 6825 Pine Street, Suite 340
|
||||||
|
* Mail Stop B8
|
||||||
|
* Omaha, NE 68106
|
||||||
|
* 402.291.0100
|
||||||
|
*
|
||||||
|
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
|
* further licensing information.
|
||||||
|
**/
|
||||||
|
package com.raytheon.uf.viz.collaboration.ui.prefs;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.eclipse.jface.preference.IPersistentPreferenceStore;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.jivesoftware.smack.RosterGroup;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
|
||||||
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.roster.ISubscriptionResponder;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.roster.SubscriptionResponse;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.session.CollaborationConnection;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.session.ISubscriptionRequestCompleteAction;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.provider.user.UserSearch;
|
||||||
|
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
||||||
|
import com.raytheon.uf.viz.collaboration.ui.SubRequestDialog;
|
||||||
|
import com.raytheon.uf.viz.core.VizApp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subscription responder impelementation.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Apr 03, 2014 2785 mpduff Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author mpduff
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SubscriptionResponderImpl implements ISubscriptionResponder {
|
||||||
|
/**
|
||||||
|
* Log instance
|
||||||
|
*/
|
||||||
|
private final IUFStatusHandler log = UFStatus.getHandler(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map tracking user contact requests
|
||||||
|
*/
|
||||||
|
private final Set<String> subRequest = Collections
|
||||||
|
.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search instance
|
||||||
|
*/
|
||||||
|
private final UserSearch search;
|
||||||
|
|
||||||
|
public SubscriptionResponderImpl(CollaborationConnection connection) {
|
||||||
|
this.search = connection.createSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleSubscribeRequest(final UserId fromID,
|
||||||
|
final ISubscriptionRequestCompleteAction action) {
|
||||||
|
final SubscriptionResponse rval = new SubscriptionResponse();
|
||||||
|
IPersistentPreferenceStore prefs = Activator.getDefault()
|
||||||
|
.getPreferenceStore();
|
||||||
|
if (prefs.getBoolean(CollabPrefConstants.AUTO_ACCEPT_SUBSCRIBE)) {
|
||||||
|
rval.setAccepted(true);
|
||||||
|
action.executeSubscriptionRequestComplete(fromID, rval);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CollaborationConnection conn = CollaborationConnection.getConnection();
|
||||||
|
Collection<RosterGroup> groups = conn.getContactsManager().getGroups(
|
||||||
|
fromID);
|
||||||
|
if (!groups.isEmpty()) {
|
||||||
|
// we already have this user in a group in our roster
|
||||||
|
rval.setAccepted(true);
|
||||||
|
action.executeSubscriptionRequestComplete(fromID, rval);
|
||||||
|
} else {
|
||||||
|
Boolean dlgExists = subRequest.contains(fromID.getFQName());
|
||||||
|
|
||||||
|
if (!dlgExists) {
|
||||||
|
subRequest.add(fromID.getFQName());
|
||||||
|
VizApp.runAsync(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
String displayName = getDisplayName(fromID);
|
||||||
|
Shell shell = new Shell(Display.getCurrent());
|
||||||
|
|
||||||
|
SubRequestDialog dlg = new SubRequestDialog(shell,
|
||||||
|
displayName);
|
||||||
|
Object returnVal = dlg.open();
|
||||||
|
if (returnVal == null) {
|
||||||
|
// Denied
|
||||||
|
rval.setAccepted(false);
|
||||||
|
rval.setGroup(null);
|
||||||
|
} else {
|
||||||
|
if (returnVal instanceof String) {
|
||||||
|
rval.setAccepted(true);
|
||||||
|
rval.setGroup((String) returnVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subRequest.remove(fromID.getFQName());
|
||||||
|
action.executeSubscriptionRequestComplete(fromID, rval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get display name for user from server
|
||||||
|
*
|
||||||
|
* @param fromID
|
||||||
|
* @return null if none found
|
||||||
|
*/
|
||||||
|
private String getDisplayName(UserId fromID) {
|
||||||
|
String rval = null;
|
||||||
|
try {
|
||||||
|
UserId user = search.byExactUsername(fromID.getName());
|
||||||
|
return user != null ? user.getAlias() : null;
|
||||||
|
} catch (XMPPException e) {
|
||||||
|
log.error("Unable to get display name for user: " + fromID, e);
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue