Issue #2630 fixed status parsing bug

status from preference store wasn't being parsed correctly
changed connection data to store as Mode object instead of string
added parse method to collaboration utils


Former-commit-id: 0176ba7963a5ff5bbd37b2e0867cbf97f4a3ef66
This commit is contained in:
Brian Clements 2014-01-15 10:24:09 -06:00
parent 2251876406
commit 79446d983b
4 changed files with 51 additions and 16 deletions

View file

@ -109,6 +109,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueId;
* added better error message on failed connection
* 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
* Jan 15, 2014 2630 bclement connection data stores status as Mode object
*
* </pre>
*
@ -167,12 +168,9 @@ public class CollaborationConnection implements IEventPublisher {
throws CollaborationException {
this.connectionData = connectionData;
String password = connectionData.getPassword();
String status = connectionData.getStatus();
Mode mode;
if (status == null || status.trim().isEmpty()) {
Mode mode = connectionData.getStatus();
if (mode == null) {
mode = Mode.available;
} else {
mode = Mode.valueOf(status.toLowerCase());
}
Presence initialPresence = new Presence(Type.available,
connectionData.getMessage(), 0, mode);

View file

@ -22,8 +22,11 @@ package com.raytheon.uf.viz.collaboration.comm.provider.session;
import java.util.HashMap;
import java.util.Map;
import org.jivesoftware.smack.packet.Presence.Mode;
/**
* Collaboration connection data object used for creating a {@link CollaborationConnection}
* Collaboration connection data object used for creating a
* {@link CollaborationConnection}
*
* <pre>
*
@ -32,6 +35,7 @@ import java.util.Map;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jun 18, 2012 mschenke Initial creation
* Jan 15, 2014 2630 bclement connection data stores status as Mode object
*
* </pre>
*
@ -47,7 +51,7 @@ public class CollaborationConnectionData {
private String password;
private String status;
private Mode status;
private String message;
@ -105,7 +109,7 @@ public class CollaborationConnectionData {
/**
* @return the status
*/
public String getStatus() {
public Mode getStatus() {
return status;
}
@ -113,7 +117,7 @@ public class CollaborationConnectionData {
* @param status
* the status to set
*/
public void setStatus(String status) {
public void setStatus(Mode status) {
this.status = status;
}

View file

@ -21,7 +21,10 @@ package com.raytheon.uf.viz.collaboration.ui;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXB;
@ -55,6 +58,7 @@ import com.raytheon.uf.viz.core.icon.IconUtil;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Feb 24, 2012 mnash Initial creation
* Jan 15, 2014 2630 bclement added mode map
*
* </pre>
*
@ -70,6 +74,17 @@ public class CollaborationUtils {
public static final Presence.Mode[] statusModes = { Mode.available,
Mode.dnd, Mode.away };
private static final Map<String, Mode> modeMap;
static {
Mode[] modes = Mode.values();
HashMap<String, Mode> map = new HashMap<String, Mode>(modes.length);
for (Mode m : modes) {
map.put(formatMode(m), m);
}
modeMap = Collections.unmodifiableMap(map);
}
/**
* Get an image associated with the node.
*
@ -101,6 +116,12 @@ public class CollaborationUtils {
return new UserId[0];
}
/**
* Format mode into user readable string
*
* @param mode
* @return
*/
public static String formatMode(Mode mode) {
if (mode == null) {
mode = Mode.available;
@ -121,6 +142,15 @@ public class CollaborationUtils {
}
}
/**
* @param status
* user entered mode string
* @return null if status string isn't bound to a Mode
*/
public static Mode parseMode(String status) {
return modeMap.get(status);
}
public static List<AlertWord> getAlertWords() {
LocalizationFile file = null;
IPathManager pm = PathManagerFactory.getPathManager();

View file

@ -42,6 +42,7 @@ import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Mode;
import com.google.common.collect.Iterators;
import com.raytheon.uf.common.status.UFStatus.Priority;
@ -70,6 +71,7 @@ import com.raytheon.uf.viz.collaboration.ui.prefs.CollabPrefConstants;
* 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 08, 2014 2563 bclement added Add/Remove buttons for server list
* Jan 15, 2014 2630 bclement connection data stores status as Mode object
*
* </pre>
*
@ -220,9 +222,9 @@ public class LoginDialog extends Dialog {
for (Presence.Mode mode : CollaborationUtils.statusModes) {
statusCombo.add(CollaborationUtils.formatMode(mode));
}
String status = loginData.getStatus();
if (status != null && status.isEmpty() == false) {
statusCombo.setText(status);
Mode status = loginData.getStatus();
if (status != null) {
statusCombo.setText(CollaborationUtils.formatMode(status));
} else {
statusCombo.select(0);
}
@ -320,7 +322,8 @@ public class LoginDialog extends Dialog {
loginData.setPassword(passwordText.getText().trim());
loginData.setServer(HostConfig.removeDescription(serverText
.getText()));
loginData.setStatus(statusCombo.getText());
loginData.setStatus(CollaborationUtils.parseMode(statusCombo
.getText()));
loginData.setMessage(messageText.getText().trim());
Map<String, String> attributes = new HashMap<String, String>();
for (String attribKey : attributeCombos.keySet()) {
@ -396,7 +399,7 @@ public class LoginDialog extends Dialog {
preferences.setValue(CollabPrefConstants.P_MESSAGE,
loginData.getMessage());
preferences.setValue(CollabPrefConstants.P_STATUS,
loginData.getStatus());
CollaborationUtils.formatMode(loginData.getStatus()));
}
private void readLoginData() {
@ -404,8 +407,8 @@ public class LoginDialog extends Dialog {
.getString(CollabPrefConstants.P_USERNAME));
loginData
.setServer(preferences.getString(CollabPrefConstants.P_SERVER));
loginData
.setStatus(preferences.getString(CollabPrefConstants.P_STATUS));
loginData.setStatus(CollaborationUtils.parseMode(preferences
.getString(CollabPrefConstants.P_STATUS)));
loginData.setMessage(preferences
.getString(CollabPrefConstants.P_MESSAGE));
}