Issue #2563 added user server add/remove functionality
now persists user entered servers to localization Former-commit-id: 43fc94e9cc2a7f518971d509478f3b9a65588d19
This commit is contained in:
parent
de58f318cb
commit
487aa58778
10 changed files with 1025 additions and 326 deletions
|
@ -37,6 +37,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
* Jun 12, 2012 mnash Initial creation
|
* Jun 12, 2012 mnash Initial creation
|
||||||
|
* Jan 08, 2014 2563 bclement added format/parse methods to HostConfig
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -125,6 +126,33 @@ public class SiteConfigInformation {
|
||||||
public void setPrettyName(String prettyName) {
|
public void setPrettyName(String prettyName) {
|
||||||
this.prettyName = prettyName;
|
this.prettyName = prettyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format for display to the user
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (prettyName == null) {
|
||||||
|
return "Site Server : " + hostname;
|
||||||
|
} else {
|
||||||
|
return prettyName + " : " + hostname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove description name from hostname
|
||||||
|
*
|
||||||
|
* @param text
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String removeDescription(String text) {
|
||||||
|
int firstColon = text.indexOf(':');
|
||||||
|
if (firstColon >= 0) {
|
||||||
|
text = text.substring(firstColon + 1);
|
||||||
|
}
|
||||||
|
return text.trim();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlAccessorType(XmlAccessType.NONE)
|
@XmlAccessorType(XmlAccessType.NONE)
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.jivesoftware.smackx.muc.MultiUserChat;
|
||||||
import org.jivesoftware.smackx.muc.RoomInfo;
|
import org.jivesoftware.smackx.muc.RoomInfo;
|
||||||
|
|
||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
|
import com.google.common.net.HostAndPort;
|
||||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
import com.raytheon.uf.common.status.UFStatus;
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||||
|
@ -107,6 +108,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueId;
|
||||||
* Dec 19, 2013 2563 bclement added connection listener,
|
* Dec 19, 2013 2563 bclement added connection listener,
|
||||||
* added better error message on failed connection
|
* added better error message on failed connection
|
||||||
* Jan 07, 2013 2563 bclement use getServiceName instead of getHost when creating room id
|
* Jan 07, 2013 2563 bclement use getServiceName instead of getHost when creating room id
|
||||||
|
* Jan 08, 2014 2563 bclement fixed custom port and service name in user id
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -179,16 +181,23 @@ public class CollaborationConnection implements IEventPublisher {
|
||||||
eventBus = new EventBus();
|
eventBus = new EventBus();
|
||||||
sessions = new HashMap<String, ISession>();
|
sessions = new HashMap<String, ISession>();
|
||||||
|
|
||||||
ConnectionConfiguration conConfig = new ConnectionConfiguration(
|
HostAndPort hnp = HostAndPort.fromString(connectionData.getServer());
|
||||||
connectionData.getServer());
|
ConnectionConfiguration conConfig;
|
||||||
|
if (hnp.hasPort()) {
|
||||||
|
conConfig = new ConnectionConfiguration(hnp.getHostText(),
|
||||||
|
hnp.getPort());
|
||||||
|
} else {
|
||||||
|
conConfig = new ConnectionConfiguration(hnp.getHostText());
|
||||||
|
}
|
||||||
|
|
||||||
conConfig.setCompressionEnabled(COMPRESS);
|
conConfig.setCompressionEnabled(COMPRESS);
|
||||||
|
|
||||||
connection = new XMPPConnection(conConfig);
|
connection = new XMPPConnection(conConfig);
|
||||||
|
|
||||||
this.user = new UserId(connectionData.getUserName(),
|
connectInternal(connectionData.getUserName(), password);
|
||||||
connectionData.getServer());
|
|
||||||
|
|
||||||
connectInternal(user.getName(), password);
|
this.user = new UserId(connectionData.getUserName(),
|
||||||
|
connection.getServiceName());
|
||||||
|
|
||||||
setupConnectionListener();
|
setupConnectionListener();
|
||||||
setupAccountManager();
|
setupAccountManager();
|
||||||
|
|
|
@ -88,6 +88,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
* Dec 18, 2013 2562 bclement moved data to packet extension
|
* Dec 18, 2013 2562 bclement moved data to packet extension
|
||||||
* Dec 19, 2013 2563 bclement status listeners now send all events to bus
|
* Dec 19, 2013 2563 bclement status listeners now send all events to bus
|
||||||
* Jan 07, 2013 2563 bclement use getServiceName instead of getHost when creating room id
|
* Jan 07, 2013 2563 bclement use getServiceName instead of getHost when creating room id
|
||||||
|
* Jan 08, 2014 2563 bclement fixed service name in user IDs from chat history
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -654,8 +655,9 @@ public class VenueSession extends BaseSession implements IVenueSession {
|
||||||
message.setBody(moddedBody);
|
message.setBody(moddedBody);
|
||||||
TextMessage msg = new TextMessage(message.getFrom(),
|
TextMessage msg = new TextMessage(message.getFrom(),
|
||||||
message.getBody());
|
message.getBody());
|
||||||
UserId id = new UserId(username, CollaborationConnection
|
UserId account = CollaborationConnection.getConnection()
|
||||||
.getConnection().getConnectionData().getServer());
|
.getUser();
|
||||||
|
UserId id = new UserId(username, account.getHost());
|
||||||
msg.setFrom(id);
|
msg.setFrom(id);
|
||||||
msg.setTimeStamp(time);
|
msg.setTimeStamp(time);
|
||||||
msg.setSubject(site);
|
msg.setSubject(site);
|
||||||
|
|
|
@ -26,7 +26,10 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import javax.xml.bind.DataBindingException;
|
||||||
|
import javax.xml.bind.JAXB;
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
|
@ -37,11 +40,15 @@ import com.raytheon.uf.common.localization.LocalizationContext;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||||
import com.raytheon.uf.common.localization.LocalizationFile;
|
import com.raytheon.uf.common.localization.LocalizationFile;
|
||||||
|
import com.raytheon.uf.common.localization.LocalizationFileOutputStream;
|
||||||
import com.raytheon.uf.common.localization.PathManager;
|
import com.raytheon.uf.common.localization.PathManager;
|
||||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||||
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
import com.raytheon.uf.common.localization.exception.LocalizationException;
|
||||||
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||||
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.SiteConfig;
|
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation.SiteConfig;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation.SiteColor;
|
import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation.SiteColor;
|
||||||
|
|
||||||
|
@ -55,6 +62,8 @@ import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation.SiteColor;
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
* Jun 12, 2012 mnash Initial creation
|
* Jun 12, 2012 mnash Initial creation
|
||||||
|
* Jan 08, 2014 2563 bclement duplicate code elimination
|
||||||
|
* added methods to partially modify user config
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -62,13 +71,137 @@ import com.raytheon.uf.viz.collaboration.ui.SiteColorInformation.SiteColor;
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
public class SiteConfigurationManager {
|
public class SiteConfigurationManager {
|
||||||
|
|
||||||
|
private static final IUFStatusHandler log = UFStatus.getHandler(SiteConfigurationManager.class);
|
||||||
|
|
||||||
private static SiteConfigInformation instance;
|
private static SiteConfigInformation instance;
|
||||||
|
|
||||||
private static SiteConfigInformation userInstance;
|
private static SiteConfigInformation userInstance;
|
||||||
|
|
||||||
|
private static final ReentrantLock userConfigLock = new ReentrantLock();
|
||||||
|
|
||||||
private static SiteColorInformation colorInfo;
|
private static SiteColorInformation colorInfo;
|
||||||
|
|
||||||
|
// level hierarchy for site config
|
||||||
|
private static final LocalizationLevel[] siteLevels;
|
||||||
|
|
||||||
|
static{
|
||||||
|
// load site levels with all levels except for USER
|
||||||
|
PathManager pm = (PathManager) PathManagerFactory.getPathManager();
|
||||||
|
LocalizationLevel[] available = pm.getAvailableLevels();
|
||||||
|
List<LocalizationLevel> levels = new ArrayList<LocalizationLevel>(available.length -1);
|
||||||
|
for (int i = available.length - 1; i >= 0; --i) {
|
||||||
|
if (!available[i].equals(LocalizationLevel.USER)) {
|
||||||
|
levels.add(available[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
siteLevels = levels.toArray(new LocalizationLevel[levels.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get first localization file for SiteConfigInformation found in levels
|
||||||
|
*
|
||||||
|
* @param levels
|
||||||
|
* localization levels to search in order
|
||||||
|
* @return null if none found
|
||||||
|
*/
|
||||||
|
private static LocalizationFile findConfigLocalizationFile(
|
||||||
|
LocalizationLevel[] levels) {
|
||||||
|
LocalizationFile rval = null;
|
||||||
|
for (LocalizationLevel level : levels) {
|
||||||
|
rval = getConfigLocalizationFile(level);
|
||||||
|
if (rval != null && rval.exists()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get LocalizationFile for SiteConfigInformation at specified level.
|
||||||
|
*
|
||||||
|
* @param level
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static LocalizationFile getConfigLocalizationFile(
|
||||||
|
LocalizationLevel level) {
|
||||||
|
PathManager pm = (PathManager) PathManagerFactory.getPathManager();
|
||||||
|
LocalizationContext localContext = pm.getContext(
|
||||||
|
LocalizationType.CAVE_STATIC, level);
|
||||||
|
return pm.getLocalizationFile(localContext, "collaboration"
|
||||||
|
+ File.separator + "config.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read configuration file from file system. Must be externally
|
||||||
|
* synchronized.
|
||||||
|
*
|
||||||
|
* @param levels
|
||||||
|
* localization levels to search in order
|
||||||
|
* @return null if configuration file wasn't found or an error occurred
|
||||||
|
*/
|
||||||
|
private static SiteConfigInformation readConfigInformation(
|
||||||
|
LocalizationLevel[] levels) {
|
||||||
|
LocalizationFile file = findConfigLocalizationFile(levels);
|
||||||
|
SiteConfigInformation rval = null;
|
||||||
|
if (file != null && file.exists()) {
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = file.openInputStream();
|
||||||
|
rval = JAXB.unmarshal(in, SiteConfigInformation.class);
|
||||||
|
} catch (DataBindingException e) {
|
||||||
|
log.error("Unable to parse collaboration configuration file '"
|
||||||
|
+ file.getName() + "' at localization level '"
|
||||||
|
+ file.getContext().getLocalizationLevel() + "'", e);
|
||||||
|
} catch (LocalizationException e) {
|
||||||
|
// unlikely to happen since we checked that the file exists
|
||||||
|
log.error(e.getLocalizedMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write configuration out to specified localization level. Must be
|
||||||
|
* externally synchronized.
|
||||||
|
*
|
||||||
|
* @param level
|
||||||
|
* @param config
|
||||||
|
* @throws JAXBException
|
||||||
|
* @throws LocalizationException
|
||||||
|
*/
|
||||||
|
private static void writeConfigInformation(LocalizationLevel level,
|
||||||
|
SiteConfigInformation config) throws JAXBException,
|
||||||
|
LocalizationException {
|
||||||
|
LocalizationFile file = getConfigLocalizationFile(level);
|
||||||
|
LocalizationFileOutputStream out = null;
|
||||||
|
try {
|
||||||
|
out = file.openOutputStream();
|
||||||
|
JAXBContext context = JAXBContext
|
||||||
|
.newInstance(SiteConfigInformation.class);
|
||||||
|
Marshaller marshaller = context.createMarshaller();
|
||||||
|
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
|
||||||
|
new Boolean(true));
|
||||||
|
marshaller.marshal(userInstance, out);
|
||||||
|
} finally {
|
||||||
|
if (out != null) {
|
||||||
|
try {
|
||||||
|
out.closeAndSave();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go to the config.xml file and grab the user information, for use in
|
* Go to the config.xml file and grab the user information, for use in
|
||||||
* determining what kind of user you are in collaboration
|
* determining what kind of user you are in collaboration
|
||||||
|
@ -77,55 +210,16 @@ public class SiteConfigurationManager {
|
||||||
*/
|
*/
|
||||||
public static synchronized SiteConfigInformation getSiteConfigInformation() {
|
public static synchronized SiteConfigInformation getSiteConfigInformation() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
PathManager pm = (PathManager) PathManagerFactory.getPathManager();
|
SiteConfigInformation info = readConfigInformation(siteLevels);
|
||||||
Map<LocalizationLevel, LocalizationFile> files = pm
|
if (isValid(info)) {
|
||||||
.getTieredLocalizationFile(LocalizationType.CAVE_STATIC,
|
instance = info;
|
||||||
"collaboration" + File.separator + "config.xml");
|
} else {
|
||||||
|
log.handle(Priority.PROBLEM,
|
||||||
LocalizationLevel[] levels = LocalizationLevel.values();
|
"Misconfigured config.xml file at site level. "
|
||||||
for (int i = levels.length - 1; i >= 0 && instance == null; --i) {
|
+ "Does not contain required "
|
||||||
LocalizationLevel level = levels[i];
|
+ SiteConfigInformation.SITE_NAME + " and "
|
||||||
if (level.isSystemLevel() || level == LocalizationLevel.SITE) {
|
+ SiteConfigInformation.ROLE_NAME
|
||||||
LocalizationFile file = files.get(level);
|
+ " attributes.");
|
||||||
if (file != null) {
|
|
||||||
InputStream in = null;
|
|
||||||
try {
|
|
||||||
in = file.openInputStream();
|
|
||||||
JAXBContext context = JAXBContext
|
|
||||||
.newInstance(SiteConfigInformation.class);
|
|
||||||
Unmarshaller unmarshaller = context
|
|
||||||
.createUnmarshaller();
|
|
||||||
SiteConfigInformation info = (SiteConfigInformation) unmarshaller
|
|
||||||
.unmarshal(in);
|
|
||||||
if (isValid(info)) {
|
|
||||||
instance = info;
|
|
||||||
} else {
|
|
||||||
Activator.statusHandler
|
|
||||||
.handle(Priority.PROBLEM,
|
|
||||||
"Misconfigured config.xml file at "
|
|
||||||
+ level
|
|
||||||
+ " level. "
|
|
||||||
+ "Does not contain required "
|
|
||||||
+ SiteConfigInformation.SITE_NAME
|
|
||||||
+ " and "
|
|
||||||
+ SiteConfigInformation.ROLE_NAME
|
|
||||||
+ " attributes.");
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
Activator.statusHandler.handle(Priority.PROBLEM,
|
|
||||||
e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
if (in != null) {
|
|
||||||
try {
|
|
||||||
in.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Activator.statusHandler.handle(
|
|
||||||
Priority.PROBLEM,
|
|
||||||
e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
|
@ -161,61 +255,146 @@ public class SiteConfigurationManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows users to have their own extra configured sites, but does not check
|
* Allows users to have their own extra configured sites, but does not check
|
||||||
* for validity as we don't have to have a role or a site specified, only
|
* for validity as we don't have to have a role or a site specified. Must be
|
||||||
* subscribed sites
|
* externally synchronized.
|
||||||
*/
|
*/
|
||||||
private static synchronized void readUserSiteConfigInformation() {
|
private static void readUserSiteConfigInformation() {
|
||||||
LocalizationFile file = getUserConfigFile();
|
// we always want to read/write the same localization file, only give
|
||||||
if (file != null && file.exists()) {
|
// one level to search
|
||||||
InputStream in = null;
|
userInstance = readConfigInformation(new LocalizationLevel[] { LocalizationLevel.USER });
|
||||||
try {
|
if (userInstance == null) {
|
||||||
in = file.openInputStream();
|
// user config doesn't exist, create a new one
|
||||||
JAXBContext context = JAXBContext
|
userInstance = new SiteConfigInformation();
|
||||||
.newInstance(SiteConfigInformation.class);
|
|
||||||
Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
||||||
SiteConfigInformation info = (SiteConfigInformation) unmarshaller
|
|
||||||
.unmarshal(in);
|
|
||||||
userInstance = info;
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
Activator.statusHandler.handle(Priority.PROBLEM,
|
|
||||||
e.getLocalizedMessage(), e);
|
|
||||||
} catch (LocalizationException e) {
|
|
||||||
Activator.statusHandler.handle(Priority.PROBLEM,
|
|
||||||
e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeUserSiteConfigInformation(
|
|
||||||
SiteConfigInformation information) {
|
|
||||||
userInstance = information;
|
|
||||||
LocalizationFile file = getUserConfigFile();
|
|
||||||
try {
|
|
||||||
JAXBContext context = JAXBContext
|
|
||||||
.newInstance(SiteConfigInformation.class);
|
|
||||||
Marshaller marshaller = context.createMarshaller();
|
|
||||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
|
|
||||||
new Boolean(true));
|
|
||||||
marshaller.marshal(information, file.getFile());
|
|
||||||
file.save();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Activator.statusHandler.handle(Priority.PROBLEM,
|
|
||||||
e.getLocalizedMessage(), e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut method for retrieving the user configuration file
|
* Overwrite user enabled sites list. Persists to localization file.
|
||||||
*
|
*
|
||||||
* @return
|
* @param userEnabledSites
|
||||||
*/
|
*/
|
||||||
private static LocalizationFile getUserConfigFile() {
|
public static void writeUserEnabledSites(String[] userEnabledSites) {
|
||||||
IPathManager pathMgr = PathManagerFactory.getPathManager();
|
userConfigLock.lock();
|
||||||
LocalizationContext lContext = pathMgr.getContext(
|
try {
|
||||||
LocalizationType.CAVE_STATIC, LocalizationLevel.USER);
|
if (userInstance == null) {
|
||||||
LocalizationFile file = pathMgr.getLocalizationFile(lContext,
|
readUserSiteConfigInformation();
|
||||||
"collaboration" + File.separator + "config.xml");
|
}
|
||||||
return file;
|
// update object
|
||||||
|
List<SiteConfig> configs = userInstance.getConfig();
|
||||||
|
SiteConfig config;
|
||||||
|
if (configs == null || configs.isEmpty()) {
|
||||||
|
configs = new ArrayList<SiteConfigInformation.SiteConfig>(1);
|
||||||
|
config = new SiteConfig();
|
||||||
|
configs.add(config);
|
||||||
|
userInstance.setConfig(configs);
|
||||||
|
} else {
|
||||||
|
config = configs.get(0);
|
||||||
|
}
|
||||||
|
config.setSubscribedSites(userEnabledSites);
|
||||||
|
|
||||||
|
// update on file system
|
||||||
|
writeConfigInformation(LocalizationLevel.USER, userInstance);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.handle(Priority.PROBLEM, e.getLocalizedMessage(), e);
|
||||||
|
} finally {
|
||||||
|
userConfigLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add host configuration specific to this user. Persists to localization
|
||||||
|
* file.
|
||||||
|
*
|
||||||
|
* @param config
|
||||||
|
*/
|
||||||
|
public static void addUserHostConfig(HostConfig config){
|
||||||
|
userConfigLock.lock();
|
||||||
|
try{
|
||||||
|
if(userInstance == null){
|
||||||
|
readUserSiteConfigInformation();
|
||||||
|
}
|
||||||
|
List<HostConfig> servers = userInstance.getServer();
|
||||||
|
if (servers == null){
|
||||||
|
servers = new ArrayList<SiteConfigInformation.HostConfig>(1);
|
||||||
|
userInstance.setServer(servers);
|
||||||
|
}
|
||||||
|
if (!hasHost(servers, config)) {
|
||||||
|
servers.add(config);
|
||||||
|
writeConfigInformation(LocalizationLevel.USER, userInstance);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getLocalizedMessage(), e);
|
||||||
|
} finally {
|
||||||
|
userConfigLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param servers
|
||||||
|
* @param config
|
||||||
|
* @return true if the hostname in config matches any in servers
|
||||||
|
*/
|
||||||
|
private static boolean hasHost(List<HostConfig> servers, HostConfig config) {
|
||||||
|
for (HostConfig hc : servers) {
|
||||||
|
if (hc.getHostname().equalsIgnoreCase(config.getHostname())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove any host configuration that has serverAddress from current user's
|
||||||
|
* localization file.
|
||||||
|
*
|
||||||
|
* @param serverAddress
|
||||||
|
*/
|
||||||
|
public static void removeUserHostConfig(String serverAddress) {
|
||||||
|
userConfigLock.lock();
|
||||||
|
try {
|
||||||
|
if (userInstance == null) {
|
||||||
|
readUserSiteConfigInformation();
|
||||||
|
}
|
||||||
|
List<HostConfig> servers = userInstance.getServer();
|
||||||
|
if (servers != null) {
|
||||||
|
List<HostConfig> newServers = new ArrayList<HostConfig>();
|
||||||
|
for (HostConfig hc : servers) {
|
||||||
|
if (!hc.getHostname().equalsIgnoreCase(serverAddress)) {
|
||||||
|
newServers.add(hc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
userInstance.setServer(newServers);
|
||||||
|
writeConfigInformation(LocalizationLevel.USER, userInstance);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getLocalizedMessage(), e);
|
||||||
|
} finally {
|
||||||
|
userConfigLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get host configuration added by this user.
|
||||||
|
*
|
||||||
|
* @return empty list if none are found
|
||||||
|
*/
|
||||||
|
public static List<HostConfig> getUserHostConfig() {
|
||||||
|
List<HostConfig> rval;
|
||||||
|
userConfigLock.lock();
|
||||||
|
try {
|
||||||
|
if (userInstance == null) {
|
||||||
|
readUserSiteConfigInformation();
|
||||||
|
}
|
||||||
|
List<HostConfig> servers = userInstance.getServer();
|
||||||
|
if (servers == null) {
|
||||||
|
rval = new ArrayList<HostConfig>(0);
|
||||||
|
} else {
|
||||||
|
rval = new ArrayList<HostConfig>(servers);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
userConfigLock.unlock();
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -269,7 +448,7 @@ public class SiteConfigurationManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param info
|
* @param info
|
||||||
* @return
|
* @return true if info is not null and has at least one site configuration
|
||||||
*/
|
*/
|
||||||
private static boolean isValid(SiteConfigInformation info) {
|
private static boolean isValid(SiteConfigInformation info) {
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
|
@ -283,6 +462,12 @@ public class SiteConfigurationManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of subscribed sites from site configuration
|
||||||
|
*
|
||||||
|
* @param site
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static List<String> getSubscribeList(String site) {
|
public static List<String> getSubscribeList(String site) {
|
||||||
List<String> subscribed = new ArrayList<String>();
|
List<String> subscribed = new ArrayList<String>();
|
||||||
for (SiteConfig config : instance.getConfig()) {
|
for (SiteConfig config : instance.getConfig()) {
|
||||||
|
@ -295,29 +480,37 @@ public class SiteConfigurationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads and sets the user subscribe list
|
* Reads the user subscribe list
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static List<String> getUserSubscribeList() {
|
public static List<String> getUserSubscribeList() {
|
||||||
if (userInstance == null) {
|
|
||||||
readUserSiteConfigInformation();
|
|
||||||
}
|
|
||||||
List<String> subscribed = new ArrayList<String>();
|
List<String> subscribed = new ArrayList<String>();
|
||||||
if (userInstance != null) {
|
userConfigLock.lock();
|
||||||
for (SiteConfig config : userInstance.getConfig()) {
|
try {
|
||||||
if (config.getSubscribedSites() != null) {
|
if (userInstance == null) {
|
||||||
subscribed = new ArrayList<String>();
|
readUserSiteConfigInformation();
|
||||||
for (String item : config.getSubscribedSites()) {
|
}
|
||||||
subscribed.add(item);
|
if (userInstance != null) {
|
||||||
|
for (SiteConfig config : userInstance.getConfig()) {
|
||||||
|
if (config.getSubscribedSites() != null) {
|
||||||
|
subscribed = new ArrayList<String>();
|
||||||
|
for (String item : config.getSubscribedSites()) {
|
||||||
|
subscribed.add(item);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
userConfigLock.unlock();
|
||||||
}
|
}
|
||||||
return subscribed;
|
return subscribed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list of colors from site information config
|
||||||
|
*/
|
||||||
public static List<SiteColor> getSiteColors() {
|
public static List<SiteColor> getSiteColors() {
|
||||||
SiteColorInformation colorInfo = getSiteColorInformation();
|
SiteColorInformation colorInfo = getSiteColorInformation();
|
||||||
if (colorInfo != null) {
|
if (colorInfo != null) {
|
||||||
|
@ -327,6 +520,9 @@ public class SiteConfigurationManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reset in-memory configuration
|
||||||
|
*/
|
||||||
public static void nullifySiteConfigInstance() {
|
public static void nullifySiteConfigInstance() {
|
||||||
instance = null;
|
instance = null;
|
||||||
userInstance = null;
|
userInstance = null;
|
||||||
|
|
|
@ -21,6 +21,7 @@ package com.raytheon.uf.viz.collaboration.ui.login;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -42,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 com.google.common.collect.Iterators;
|
||||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||||
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.info.SiteConfigInformation;
|
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation;
|
||||||
|
@ -67,6 +69,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
||||||
* Jun 18, 2012 mschenke Initial creation
|
* Jun 18, 2012 mschenke Initial creation
|
||||||
* Dec 19, 2013 2563 bclement added option to connect to server not in list
|
* Dec 19, 2013 2563 bclement added option to connect to server not in list
|
||||||
* 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
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -76,8 +79,6 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
||||||
|
|
||||||
public class LoginDialog extends Dialog {
|
public class LoginDialog extends Dialog {
|
||||||
|
|
||||||
private static final String OTHER_SERVER_OPTION = "Other server...";
|
|
||||||
|
|
||||||
private IPreferenceStore preferences;
|
private IPreferenceStore preferences;
|
||||||
|
|
||||||
private CollaborationConnectionData loginData;
|
private CollaborationConnectionData loginData;
|
||||||
|
@ -86,6 +87,10 @@ public class LoginDialog extends Dialog {
|
||||||
|
|
||||||
private Combo serverText;
|
private Combo serverText;
|
||||||
|
|
||||||
|
private Button addServerButton;
|
||||||
|
|
||||||
|
private Button removeServerButton;
|
||||||
|
|
||||||
private Text passwordText;
|
private Text passwordText;
|
||||||
|
|
||||||
private Combo statusCombo;
|
private Combo statusCombo;
|
||||||
|
@ -148,33 +153,56 @@ 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;
|
||||||
gd.horizontalSpan = 2;
|
|
||||||
serverText.setLayoutData(gd);
|
serverText.setLayoutData(gd);
|
||||||
|
|
||||||
// retrieve the servers
|
// retrieve the servers
|
||||||
SiteConfigInformation information = SiteConfigurationManager
|
SiteConfigInformation information = SiteConfigurationManager
|
||||||
.getSiteConfigInformation();
|
.getSiteConfigInformation();
|
||||||
List<HostConfig> servers = information.getServer();
|
List<HostConfig> siteServers = information.getServer();
|
||||||
if (servers == null) {
|
if (siteServers == null) {
|
||||||
servers = new ArrayList<SiteConfigInformation.HostConfig>(0);
|
siteServers = new ArrayList<SiteConfigInformation.HostConfig>(0);
|
||||||
}
|
}
|
||||||
|
List<HostConfig> userServers = SiteConfigurationManager
|
||||||
|
.getUserHostConfig();
|
||||||
// put configured as true so we don't disable the login button
|
// put configured as true so we don't disable the login button
|
||||||
serverText.setData("configured", true);
|
serverText.setData("configured", true);
|
||||||
String[] names = new String[servers.size() + 1];
|
String[] names = new String[siteServers.size() + userServers.size()];
|
||||||
names[0] = OTHER_SERVER_OPTION;
|
Iterator<HostConfig> iter = Iterators.concat(siteServers.iterator(),
|
||||||
int index = 1;
|
userServers.iterator());
|
||||||
for (int i = 1; i < names.length; i++) {
|
int index = 0;
|
||||||
HostConfig config = servers.get(i - 1);
|
for (int i = 0; iter.hasNext() && i < names.length; i++) {
|
||||||
names[i] = config.getPrettyName() + " : " + config.getHostname();
|
HostConfig config = iter.next();
|
||||||
|
names[i] = config.toString();
|
||||||
if (loginData.getServer().equals(names[i])) {
|
if (loginData.getServer().equals(names[i])) {
|
||||||
index = i;
|
index = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
serverText.setItems(names);
|
serverText.setItems(names);
|
||||||
serverText.select(index);
|
serverText.select(index);
|
||||||
serverText.addListener(SWT.Selection, new ServerInput(serverText, 0));
|
|
||||||
|
// add remove server buttons
|
||||||
|
Composite serverButtons = new Composite(body, SWT.NONE);
|
||||||
|
serverButtons.setLayout(new GridLayout(2, false));
|
||||||
|
serverButtons.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true,
|
||||||
|
false));
|
||||||
|
|
||||||
|
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||||
|
addServerButton = new Button(serverButtons, SWT.PUSH);
|
||||||
|
addServerButton.setText(ServerListListener.addButtonText);
|
||||||
|
addServerButton.setLayoutData(gd);
|
||||||
|
addServerButton.addListener(SWT.Selection, new ServerListListener(serverText));
|
||||||
|
removeServerButton = new Button(serverButtons, SWT.PUSH);
|
||||||
|
removeServerButton.setText(ServerListListener.removeButtonText);
|
||||||
|
removeServerButton.setLayoutData(gd);
|
||||||
|
removeServerButton.addListener(SWT.Selection, new ServerListListener(
|
||||||
|
serverText));
|
||||||
|
|
||||||
|
|
||||||
// Password setting
|
// Password setting
|
||||||
new Label(body, SWT.NONE).setText("Password: ");
|
new Label(body, SWT.NONE).setText("Password: ");
|
||||||
|
@ -290,7 +318,7 @@ public class LoginDialog extends Dialog {
|
||||||
public void widgetSelected(SelectionEvent event) {
|
public void widgetSelected(SelectionEvent event) {
|
||||||
loginData.setUserName(userText.getText().trim());
|
loginData.setUserName(userText.getText().trim());
|
||||||
loginData.setPassword(passwordText.getText().trim());
|
loginData.setPassword(passwordText.getText().trim());
|
||||||
loginData.setServer(ServerInput.removeDescription(serverText
|
loginData.setServer(HostConfig.removeDescription(serverText
|
||||||
.getText()));
|
.getText()));
|
||||||
loginData.setStatus(statusCombo.getText());
|
loginData.setStatus(statusCombo.getText());
|
||||||
loginData.setMessage(messageText.getText().trim());
|
loginData.setMessage(messageText.getText().trim());
|
||||||
|
@ -313,16 +341,7 @@ public class LoginDialog extends Dialog {
|
||||||
if (server.isEmpty()) {
|
if (server.isEmpty()) {
|
||||||
errorMessages.add("Must have a server.");
|
errorMessages.add("Must have a server.");
|
||||||
}
|
}
|
||||||
String error = ServerInput.validate(server);
|
loginData.setServer(server);
|
||||||
if (error != null) {
|
|
||||||
errorMessages.add(error);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
loginData.setServer(ServerInput.getFullName(server));
|
|
||||||
} catch (CollaborationException e) {
|
|
||||||
errorMessages.add(e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loginData.getPassword().isEmpty()) {
|
if (loginData.getPassword().isEmpty()) {
|
||||||
errorMessages.add("Must enter a password.");
|
errorMessages.add("Must enter a password.");
|
||||||
|
|
|
@ -1,176 +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.login;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.eclipse.jface.dialogs.InputDialog;
|
|
||||||
import org.eclipse.jface.window.Window;
|
|
||||||
import org.eclipse.swt.widgets.Combo;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
|
||||||
import org.eclipse.swt.widgets.Event;
|
|
||||||
import org.eclipse.swt.widgets.Listener;
|
|
||||||
|
|
||||||
import com.google.common.net.HostAndPort;
|
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listens for add server option in a Combo box, gets new input from user and
|
|
||||||
* appends to the combo box
|
|
||||||
*
|
|
||||||
* <pre>
|
|
||||||
*
|
|
||||||
* SOFTWARE HISTORY
|
|
||||||
*
|
|
||||||
* Date Ticket# Engineer Description
|
|
||||||
* ------------ ---------- ----------- --------------------------
|
|
||||||
* Dec 18, 2013 2563 bclement Initial creation
|
|
||||||
* Jan 06, 2014 2563 bclement added removeDescription
|
|
||||||
* Jan 07, 2014 2563 bclement updated default xmpp port
|
|
||||||
*
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @author bclement
|
|
||||||
* @version 1.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ServerInput implements Listener {
|
|
||||||
|
|
||||||
private final Combo serverText;
|
|
||||||
|
|
||||||
private final int addItemIndex;
|
|
||||||
|
|
||||||
private static final int DEFAULT_XMPP_PORT = 5222;
|
|
||||||
|
|
||||||
private static final int TIMEOUT = 5000; // 5 seconds
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param serverText
|
|
||||||
*/
|
|
||||||
public ServerInput(Combo serverText, int addItemIndex) {
|
|
||||||
this.serverText = serverText;
|
|
||||||
this.addItemIndex = addItemIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see
|
|
||||||
* org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
|
|
||||||
* Event)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void handleEvent(Event event) {
|
|
||||||
int index = serverText.getSelectionIndex();
|
|
||||||
if (index == addItemIndex) {
|
|
||||||
InputDialog dlg = new InputDialog(Display.getCurrent()
|
|
||||||
.getActiveShell(), "", "Enter server address", "", null);
|
|
||||||
int status = dlg.open();
|
|
||||||
if (status == Window.OK) {
|
|
||||||
String value = dlg.getValue();
|
|
||||||
addToOptions(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append new server to options combo and select it
|
|
||||||
*
|
|
||||||
* @param server
|
|
||||||
*/
|
|
||||||
private void addToOptions(String server) {
|
|
||||||
String[] items = serverText.getItems();
|
|
||||||
items = Arrays.copyOf(items, items.length + 1);
|
|
||||||
items[items.length - 1] = "Custom Server : " + server;
|
|
||||||
serverText.setItems(items);
|
|
||||||
serverText.select(items.length - 1);
|
|
||||||
// this doesn't persist the new server. I can
|
|
||||||
// see that being a good thing or an annoyance.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate server by parsing the string and attempting to ping the server.
|
|
||||||
* Returns an error string if server string could not be parsed or server
|
|
||||||
* could not be contacted.
|
|
||||||
*
|
|
||||||
* @param server
|
|
||||||
* @return null if there were no issues
|
|
||||||
*/
|
|
||||||
public static String validate(String server) {
|
|
||||||
Socket s = null;
|
|
||||||
try {
|
|
||||||
HostAndPort hnp = HostAndPort.fromString(server).withDefaultPort(
|
|
||||||
DEFAULT_XMPP_PORT);
|
|
||||||
s = new Socket();
|
|
||||||
s.setReuseAddress(true);
|
|
||||||
SocketAddress sa = new InetSocketAddress(hnp.getHostText(),
|
|
||||||
hnp.getPort());
|
|
||||||
s.connect(sa, TIMEOUT);
|
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return "Unable to connect to server: " + e.getLocalizedMessage();
|
|
||||||
} finally {
|
|
||||||
if (s != null) {
|
|
||||||
try {
|
|
||||||
s.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// no action
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempt to get canonical host name for server
|
|
||||||
*
|
|
||||||
* @param server
|
|
||||||
* @return
|
|
||||||
* @throws CollaborationException
|
|
||||||
*/
|
|
||||||
public static String getFullName(String server)
|
|
||||||
throws CollaborationException {
|
|
||||||
try {
|
|
||||||
String hostText = HostAndPort.fromString(server).getHostText();
|
|
||||||
return InetAddress.getByName(hostText).getCanonicalHostName();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new CollaborationException("Unable to get full host name", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove server description from server text field
|
|
||||||
*
|
|
||||||
* @param text
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String removeDescription(String text) {
|
|
||||||
int firstColon = text.indexOf(':');
|
|
||||||
if (firstColon >= 0) {
|
|
||||||
text = text.substring(firstColon + 1);
|
|
||||||
}
|
|
||||||
return text.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,301 @@
|
||||||
|
/**
|
||||||
|
* 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.login;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
|
import org.eclipse.jface.dialogs.Dialog;
|
||||||
|
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||||
|
import org.eclipse.jface.preference.BooleanFieldEditor;
|
||||||
|
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
||||||
|
import org.eclipse.jface.preference.StringFieldEditor;
|
||||||
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.layout.GridData;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
|
import com.google.common.net.HostAndPort;
|
||||||
|
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||||
|
import com.raytheon.uf.common.status.UFStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dialog for users to add new servers to options in login dialog
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Jan 7, 2014 2563 bclement Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author bclement
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ServerInputDialog extends Dialog {
|
||||||
|
|
||||||
|
private static final IUFStatusHandler log = UFStatus
|
||||||
|
.getHandler(ServerInputDialog.class);
|
||||||
|
|
||||||
|
private static final int DEFAULT_XMPP_PORT = 5222;
|
||||||
|
|
||||||
|
private static final int TIMEOUT = 5000; // 5 seconds
|
||||||
|
|
||||||
|
private static final String DEFAULT_DESCRIPTION = "Custom Server";
|
||||||
|
|
||||||
|
private FieldEditorPreferencePage page;
|
||||||
|
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
private String serverAddress;
|
||||||
|
|
||||||
|
private boolean persist;
|
||||||
|
|
||||||
|
private StringFieldEditor descriptionEditor;
|
||||||
|
|
||||||
|
private StringFieldEditor serverAddressEditor;
|
||||||
|
|
||||||
|
private BooleanFieldEditor persistEditor;
|
||||||
|
|
||||||
|
private Text errorMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parentShell
|
||||||
|
*/
|
||||||
|
public ServerInputDialog(Shell parentShell) {
|
||||||
|
super(parentShell);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parentShell
|
||||||
|
*/
|
||||||
|
public ServerInputDialog(IShellProvider parentShell) {
|
||||||
|
super(parentShell);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
|
||||||
|
* .Composite)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Control createDialogArea(Composite parent) {
|
||||||
|
Composite composite = (Composite) super.createDialogArea(parent);
|
||||||
|
|
||||||
|
page = new FieldEditorPreferencePage(FieldEditorPreferencePage.GRID) {
|
||||||
|
@Override
|
||||||
|
protected void createFieldEditors() {
|
||||||
|
Composite parent = getFieldEditorParent();
|
||||||
|
descriptionEditor = new StringFieldEditor("",
|
||||||
|
"Server Description:", parent);
|
||||||
|
descriptionEditor.setStringValue(DEFAULT_DESCRIPTION);
|
||||||
|
addField(descriptionEditor);
|
||||||
|
serverAddressEditor = new StringFieldEditor("",
|
||||||
|
"Server Address:", parent);
|
||||||
|
addField(serverAddressEditor);
|
||||||
|
persistEditor = new BooleanFieldEditor("",
|
||||||
|
"Persist to user localization", parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createControl(Composite parent) {
|
||||||
|
noDefaultAndApplyButton();
|
||||||
|
super.createControl(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
page.createControl(composite);
|
||||||
|
Control pageControl = page.getControl();
|
||||||
|
GridData layoutData = new GridData(GridData.GRAB_HORIZONTAL
|
||||||
|
| GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL
|
||||||
|
| GridData.VERTICAL_ALIGN_CENTER);
|
||||||
|
layoutData.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
|
||||||
|
pageControl.setLayoutData(layoutData);
|
||||||
|
|
||||||
|
errorMessage = new Text(composite, SWT.READ_ONLY | SWT.WRAP);
|
||||||
|
errorMessage.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
|
||||||
|
| GridData.HORIZONTAL_ALIGN_FILL));
|
||||||
|
Display display = errorMessage.getDisplay();
|
||||||
|
errorMessage.setBackground(display
|
||||||
|
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
|
||||||
|
errorMessage.setForeground(display.getSystemColor(SWT.COLOR_RED));
|
||||||
|
|
||||||
|
serverAddressEditor.setFocus();
|
||||||
|
return pageControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void buttonPressed(int buttonId) {
|
||||||
|
if (buttonId == IDialogConstants.OK_ID) {
|
||||||
|
this.description = descriptionEditor.getStringValue();
|
||||||
|
if (isBlank(this.description)) {
|
||||||
|
this.description = DEFAULT_DESCRIPTION;
|
||||||
|
}
|
||||||
|
this.serverAddress = serverAddressEditor.getStringValue();
|
||||||
|
String error = null;
|
||||||
|
if (isBlank(this.serverAddress)) {
|
||||||
|
error = "Server address cannot be blank";
|
||||||
|
} else {
|
||||||
|
this.serverAddress = processAddress(this.serverAddress);
|
||||||
|
error = validate(this.serverAddress);
|
||||||
|
}
|
||||||
|
if (error != null) {
|
||||||
|
errorMessage.setText(error);
|
||||||
|
errorMessage.setEnabled(true);
|
||||||
|
errorMessage.setVisible(true);
|
||||||
|
errorMessage.getParent().update();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.persist = persistEditor.getBooleanValue();
|
||||||
|
}
|
||||||
|
super.buttonPressed(buttonId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* First pass at user input processing
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
|
* must not be null or blank
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String processAddress(String input) {
|
||||||
|
HostAndPort address = HostAndPort.fromString(input.trim());
|
||||||
|
String host = getFullName(address);
|
||||||
|
if (address.hasPort()) {
|
||||||
|
return HostAndPort.fromParts(host, address.getPort()).toString();
|
||||||
|
} else {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param input
|
||||||
|
* @return true if input is null, empty or only contains whitespace
|
||||||
|
*/
|
||||||
|
public static boolean isBlank(String input) {
|
||||||
|
// this could be replaced with apache commons stringutils if we bring in
|
||||||
|
// the dependency
|
||||||
|
return input == null || input.trim().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate server by parsing the string and attempting to ping the server.
|
||||||
|
* Returns an error string if server string could not be parsed or server
|
||||||
|
* could not be contacted.
|
||||||
|
*
|
||||||
|
* @param server
|
||||||
|
* @return null if there were no issues
|
||||||
|
*/
|
||||||
|
public static String validate(String server) {
|
||||||
|
Socket s = null;
|
||||||
|
try {
|
||||||
|
HostAndPort hnp = HostAndPort.fromString(server).withDefaultPort(
|
||||||
|
DEFAULT_XMPP_PORT);
|
||||||
|
s = new Socket();
|
||||||
|
s.setReuseAddress(true);
|
||||||
|
SocketAddress sa = new InetSocketAddress(hnp.getHostText(),
|
||||||
|
hnp.getPort());
|
||||||
|
s.connect(sa, TIMEOUT);
|
||||||
|
return null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "Unable to connect to server: " + e.getLocalizedMessage();
|
||||||
|
} finally {
|
||||||
|
if (s != null) {
|
||||||
|
try {
|
||||||
|
s.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// no action
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to get canonical host name for server
|
||||||
|
*
|
||||||
|
* @param server
|
||||||
|
* @return input host text if unable to get full name
|
||||||
|
*/
|
||||||
|
public static String getFullName(HostAndPort address) {
|
||||||
|
String hostText = address.getHostText();
|
||||||
|
try {
|
||||||
|
return InetAddress.getByName(hostText).getCanonicalHostName();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// not severe because we will test if the host exists later
|
||||||
|
log.info(String.format(
|
||||||
|
"Unable to get full name for host '%s' with reason: %s",
|
||||||
|
hostText, e.getLocalizedMessage()));
|
||||||
|
return hostText;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
|
||||||
|
* .Shell)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void configureShell(Shell newShell) {
|
||||||
|
super.configureShell(newShell);
|
||||||
|
newShell.setText("Add Server");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the description
|
||||||
|
*/
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the serverAddress
|
||||||
|
*/
|
||||||
|
public String getServerAddress() {
|
||||||
|
return serverAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if new address should be persisted to localization
|
||||||
|
*/
|
||||||
|
public boolean isPersist() {
|
||||||
|
return persist;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,173 @@
|
||||||
|
/**
|
||||||
|
* 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.login;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jface.window.Window;
|
||||||
|
import org.eclipse.swt.widgets.Button;
|
||||||
|
import org.eclipse.swt.widgets.Combo;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.swt.widgets.Event;
|
||||||
|
import org.eclipse.swt.widgets.Listener;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
|
||||||
|
import com.raytheon.uf.viz.collaboration.comm.identity.info.SiteConfigInformation.HostConfig;
|
||||||
|
import com.raytheon.uf.viz.collaboration.ui.SiteConfigurationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listens for add/remove events for servers in a Combo box, gets input from
|
||||||
|
* user and edits user server list
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Dec 18, 2013 2563 bclement Initial creation
|
||||||
|
* Jan 06, 2014 2563 bclement added removeDescription
|
||||||
|
* Jan 07, 2014 2563 bclement updated default xmpp port
|
||||||
|
* Jan 08, 2014 2563 bclement renamed from ServerInput to ServerListListener
|
||||||
|
* moved input responsibility to ServerInputDialog
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author bclement
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ServerListListener implements Listener {
|
||||||
|
|
||||||
|
private final Combo serverText;
|
||||||
|
|
||||||
|
public static final String addButtonText = "Add";
|
||||||
|
|
||||||
|
public static final String removeButtonText = "Remove";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param serverText
|
||||||
|
*/
|
||||||
|
public ServerListListener(Combo serverText) {
|
||||||
|
this.serverText = serverText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.
|
||||||
|
* Event)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void handleEvent(Event event) {
|
||||||
|
if (!(event.widget instanceof Button)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Button b = (Button) event.widget;
|
||||||
|
if (b.getText().equals(addButtonText)) {
|
||||||
|
add();
|
||||||
|
} else if (b.getText().equalsIgnoreCase(removeButtonText)) {
|
||||||
|
remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get server to add from user and modify user config.
|
||||||
|
*/
|
||||||
|
private void add() {
|
||||||
|
Shell shell = Display.getCurrent().getActiveShell();
|
||||||
|
ServerInputDialog dlg = new ServerInputDialog(shell);
|
||||||
|
int status = dlg.open();
|
||||||
|
if (status == Window.OK) {
|
||||||
|
addToOptions(dlg.getDescription(), dlg.getServerAddress());
|
||||||
|
if (dlg.isPersist()) {
|
||||||
|
HostConfig hc = new HostConfig();
|
||||||
|
hc.setPrettyName(dlg.getDescription());
|
||||||
|
hc.setHostname(dlg.getServerAddress());
|
||||||
|
SiteConfigurationManager.addUserHostConfig(hc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get server to remove from user and modify user config.
|
||||||
|
*/
|
||||||
|
private void remove() {
|
||||||
|
Shell shell = Display.getCurrent().getActiveShell();
|
||||||
|
List<HostConfig> userHosts = SiteConfigurationManager
|
||||||
|
.getUserHostConfig();
|
||||||
|
if (!userHosts.isEmpty()) {
|
||||||
|
String[] options = new String[userHosts.size()];
|
||||||
|
Iterator<HostConfig> iter = userHosts.iterator();
|
||||||
|
for (int i = 0; iter.hasNext() && i < options.length; ++i) {
|
||||||
|
options[i] = iter.next().toString();
|
||||||
|
}
|
||||||
|
ServerRemoveDialog dlg = new ServerRemoveDialog(shell, options);
|
||||||
|
int status = dlg.open();
|
||||||
|
if (status == Window.OK) {
|
||||||
|
String selection = dlg.getSelection();
|
||||||
|
removeFromOptions(selection);
|
||||||
|
SiteConfigurationManager.removeUserHostConfig(HostConfig
|
||||||
|
.removeDescription(selection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append new server to options combo and select it
|
||||||
|
*
|
||||||
|
* @param server
|
||||||
|
*/
|
||||||
|
private void addToOptions(String description, String server) {
|
||||||
|
String[] items = serverText.getItems();
|
||||||
|
items = Arrays.copyOf(items, items.length + 1);
|
||||||
|
items[items.length - 1] = description + " : " + server;
|
||||||
|
serverText.setItems(items);
|
||||||
|
serverText.select(items.length - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove server from options combo
|
||||||
|
*
|
||||||
|
* @param displayText
|
||||||
|
*/
|
||||||
|
private void removeFromOptions(String displayText) {
|
||||||
|
String[] items = serverText.getItems();
|
||||||
|
String[] newItems = new String[items.length - 1];
|
||||||
|
for (int i = 0, j = 0; i < items.length; ++i) {
|
||||||
|
String old = items[i];
|
||||||
|
if (old.equals(displayText)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
newItems[j] = items[i];
|
||||||
|
j += 1;
|
||||||
|
}
|
||||||
|
serverText.setItems(newItems);
|
||||||
|
int oldSelection = serverText.getSelectionIndex();
|
||||||
|
if (oldSelection >= newItems.length) {
|
||||||
|
serverText.select(newItems.length - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,144 @@
|
||||||
|
/**
|
||||||
|
* 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.login;
|
||||||
|
|
||||||
|
import org.eclipse.jface.dialogs.Dialog;
|
||||||
|
import org.eclipse.jface.window.IShellProvider;
|
||||||
|
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.GridLayout;
|
||||||
|
import org.eclipse.swt.widgets.Combo;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dialog for users to remove user servers to options in login dialog
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Jan 8, 2014 2563 bclement Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author bclement
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ServerRemoveDialog extends Dialog {
|
||||||
|
|
||||||
|
private String selection = null;
|
||||||
|
|
||||||
|
private final String[] options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parentShell
|
||||||
|
*/
|
||||||
|
public ServerRemoveDialog(Shell parentShell, String[] options) {
|
||||||
|
super(parentShell);
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param parentShell
|
||||||
|
*/
|
||||||
|
public ServerRemoveDialog(IShellProvider parentShell, String[] options) {
|
||||||
|
super(parentShell);
|
||||||
|
this.options = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
|
||||||
|
* .Composite)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Control createDialogArea(Composite parent) {
|
||||||
|
Composite composite = (Composite) super.createDialogArea(parent);
|
||||||
|
Composite innerComposite = new Composite(composite, SWT.NONE);
|
||||||
|
innerComposite.setLayoutData(new GridData());
|
||||||
|
GridLayout gl = new GridLayout();
|
||||||
|
gl.numColumns = 2;
|
||||||
|
innerComposite.setLayout(gl);
|
||||||
|
|
||||||
|
Label label = new Label(innerComposite, SWT.NONE);
|
||||||
|
label.setText("Server to Remove:");
|
||||||
|
label.setLayoutData(new GridData());
|
||||||
|
|
||||||
|
final Combo combo = new Combo(innerComposite, SWT.READ_ONLY);
|
||||||
|
for (int i = 0; i < options.length; i++) {
|
||||||
|
combo.add(options[i]);
|
||||||
|
}
|
||||||
|
selection = combo.getItem(0);
|
||||||
|
GridData gd = new GridData();
|
||||||
|
gd.widthHint = convertWidthInCharsToPixels(getMaxStringLength());
|
||||||
|
gd.minimumWidth = 200;
|
||||||
|
combo.setLayoutData(gd);
|
||||||
|
combo.addSelectionListener(new SelectionAdapter() {
|
||||||
|
@Override
|
||||||
|
public void widgetSelected(SelectionEvent e) {
|
||||||
|
selection = combo.getItem(combo.getSelectionIndex());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
applyDialogFont(composite);
|
||||||
|
return composite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return longest string length in options or 0 if options is empty
|
||||||
|
*/
|
||||||
|
private int getMaxStringLength() {
|
||||||
|
int max = 0;
|
||||||
|
for (int i = 0; i < options.length; i++) {
|
||||||
|
max = Math.max(max, options[i].length());
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets
|
||||||
|
* .Shell)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void configureShell(Shell newShell) {
|
||||||
|
super.configureShell(newShell);
|
||||||
|
newShell.setText("Remove Server");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the selection
|
||||||
|
*/
|
||||||
|
public String getSelection() {
|
||||||
|
return selection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -39,7 +39,6 @@ import org.jivesoftware.smack.packet.Presence;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
|
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
|
||||||
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.SiteConfig;
|
|
||||||
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.uf.viz.collaboration.comm.provider.user.UserId;
|
||||||
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
import com.raytheon.uf.viz.collaboration.ui.Activator;
|
||||||
|
@ -60,6 +59,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
|
||||||
* Jun 7, 2012 mnash Initial creation
|
* Jun 7, 2012 mnash Initial creation
|
||||||
* Dec 6, 2013 2561 bclement removed ECF
|
* Dec 6, 2013 2561 bclement removed ECF
|
||||||
* Dec 19, 2013 2563 bclement moved participant filter logic to one method
|
* Dec 19, 2013 2563 bclement moved participant filter logic to one method
|
||||||
|
* Jan 08, 2014 2563 bclement changes to match SiteConfigurationManager user sites config
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -379,6 +379,14 @@ public class SessionFeedView extends SessionView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see com.raytheon.uf.viz.collaboration.ui.session.SessionView#
|
||||||
|
* participantPresenceUpdated
|
||||||
|
* (com.raytheon.uf.viz.collaboration.comm.provider.user.UserId,
|
||||||
|
* org.jivesoftware.smack.packet.Presence)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void participantPresenceUpdated(UserId participant,
|
protected void participantPresenceUpdated(UserId participant,
|
||||||
Presence presence) {
|
Presence presence) {
|
||||||
|
@ -399,13 +407,8 @@ public class SessionFeedView extends SessionView {
|
||||||
SiteConfigurationManager.writeSiteColorInformation(information);
|
SiteConfigurationManager.writeSiteColorInformation(information);
|
||||||
|
|
||||||
// write out the user enabled sites information to a file
|
// write out the user enabled sites information to a file
|
||||||
SiteConfigInformation userInformation = new SiteConfigInformation();
|
String[] sites = userEnabledSites.toArray(new String[userEnabledSites
|
||||||
List<SiteConfig> sites = new ArrayList<SiteConfig>();
|
.size()]);
|
||||||
SiteConfig config = new SiteConfig();
|
SiteConfigurationManager.writeUserEnabledSites(sites);
|
||||||
config.setSubscribedSites(userEnabledSites.toArray(new String[0]));
|
|
||||||
sites.add(config);
|
|
||||||
userInformation.setConfig(sites);
|
|
||||||
SiteConfigurationManager
|
|
||||||
.writeUserSiteConfigInformation(userInformation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue