diff --git a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/user/SharedGroup.java b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/user/SharedGroup.java index 3638ecc09e..657851b8df 100644 --- a/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/user/SharedGroup.java +++ b/cave/com.raytheon.uf.viz.collaboration.comm/src/com/raytheon/uf/viz/collaboration/comm/provider/user/SharedGroup.java @@ -36,6 +36,7 @@ import org.jivesoftware.smack.RosterGroup; * ------------ ---------- ----------- -------------------------- * Jan 23, 2014 2701 bclement Initial creation * Feb 17, 2014 2800 bclement added equals/hashcode + * Mar 27, 2014 2632 mpduff Changed to call a convenience method. * * * @@ -101,7 +102,7 @@ public class SharedGroup { return false; } SharedGroup other = (SharedGroup) obj; - return this.delegate.getName().equals(other.getName()); + return this.getName().equals(other.getName()); } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/InviteDialog.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/InviteDialog.java index e036e8a086..4502bd49f3 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/InviteDialog.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/InviteDialog.java @@ -66,6 +66,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialogBase; * Feb 11, 2014 2699 bclement require non-blank handle * Feb 13, 2014 2751 bclement better types for roomid and inviter * Mar 06, 2014 2848 bclement moved join logic to separate method + * Mar 27, 2014 2632 mpduff Set the OK button as the default button. * * * @@ -77,15 +78,15 @@ public class InviteDialog extends CaveSWTDialogBase { /** Main composite. */ private Composite mainComp; - private String inviter; + private final String inviter; - private String subject; + private final String subject; - private String room; + private final String room; - private String inviteText; + private final String inviteText; - private String message; + private final String message; private Font font; @@ -93,9 +94,9 @@ public class InviteDialog extends CaveSWTDialogBase { private VenueSession session; - private boolean sharedDisplay; + private final boolean sharedDisplay; - private IVenueInvitationEvent event; + private final IVenueInvitationEvent event; private Text errorMessage; @@ -292,6 +293,8 @@ public class InviteDialog extends CaveSWTDialogBase { close(); } }); + + this.getShell().setDefaultButton(okBtn); } /** @@ -302,7 +305,7 @@ public class InviteDialog extends CaveSWTDialogBase { * @throws CollaborationException */ public void join(IVenueInvitationEvent invitation, String handle) - throws CollaborationException { + throws CollaborationException { String venueName = invitation.getRoomId().getName(); CollaborationConnection connection = CollaborationConnection .getConnection(); diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/notifier/NotifierTask.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/notifier/NotifierTask.java index 59c7ca0896..edb5f2b2e5 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/notifier/NotifierTask.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/notifier/NotifierTask.java @@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElements; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; +import com.raytheon.uf.common.util.StringUtil; /** * Notifier Task. Holds a list of {@link Notifier} actions. @@ -38,7 +39,8 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Feb 20, 2014 2632 mpduff Initial creation + * Feb 20, 2014 2632 mpduff Initial creation. + * Mar 27, 2014 2632 mpduff Implemented toString() * * * @@ -234,4 +236,22 @@ public class NotifierTask { } return true; } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + String nl = StringUtil.NEWLINE; + StringBuilder sb = new StringBuilder(); + sb.append("User: " + this.userName).append(nl); + sb.append("Sound: " + this.soundFilePath).append(nl); + for (Notifier notifier : this.notifierList) { + sb.append(notifier.getDescription()).append(" "); + } + + return sb.toString(); + } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/ContactNotifierPreferencePage.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/ContactNotifierPreferencePage.java index d942d441c0..7a615073a8 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/ContactNotifierPreferencePage.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/prefs/ContactNotifierPreferencePage.java @@ -64,6 +64,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Feb 20, 2014 2632 mpduff Initial creation + * Mar 27, 2014 2632 mpduff Corrected the OK, Apply, Cancel actions * * * @@ -90,7 +91,7 @@ public class ContactNotifierPreferencePage extends PreferencePage implements .getNotifierTasks(); /** Data map backing the notifier list */ - private final Map dataMap = new HashMap(); + private Map dataMap = new HashMap(); /** * {@inheritDoc} @@ -160,7 +161,7 @@ public class ContactNotifierPreferencePage extends PreferencePage implements } }); - populate(); + populate(true); return null; } @@ -168,8 +169,13 @@ public class ContactNotifierPreferencePage extends PreferencePage implements /** * Populate the list. */ - private void populate() { - taskList = NotifierTools.getNotifierTasks(); + private void populate(boolean reload) { + if (reload) { + taskList = NotifierTools.getNotifierTasks(); + } else { + taskList.clear(); + taskList.addAll(dataMap.values()); + } for (NotifierTask task : taskList) { dataMap.put(task.getUserName(), task); } @@ -184,11 +190,25 @@ public class ContactNotifierPreferencePage extends PreferencePage implements * Edit the notifier task. */ private void editNotifierTask() { + if (notifierList.getSelectionIndex() == -1) { + MessageBox messageDialog = new MessageBox(this.getShell(), SWT.OK); + messageDialog.setText("Select User"); + messageDialog.setMessage("Please select a user to edit."); + messageDialog.open(); + return; + } String user = notifierList.getItem(notifierList.getSelectionIndex()); NotifierTask task = dataMap.get(user); if (task != null) { + ICloseCallback callback = new ICloseCallback() { + @Override + public void dialogClosed(Object returnValue) { + updatePrefs((Map) returnValue); + } + }; + AddNotifierDlg dlg = new AddNotifierDlg(getShell(), - new String[] { task.getUserName() }); + new String[] { task.getUserName() }, callback); dlg.open(); } } @@ -197,8 +217,15 @@ public class ContactNotifierPreferencePage extends PreferencePage implements * Delete the notifier task. */ private void deleteNotifierTask() { + if (notifierList.getSelectionIndex() == -1) { + MessageBox messageDialog = new MessageBox(this.getShell(), SWT.OK); + messageDialog.setText("Select User"); + messageDialog.setMessage("Please select a user to delete."); + messageDialog.open(); + return; + } String user = notifierList.getItem(notifierList.getSelectionIndex()); - NotifierTask task = dataMap.get(user); + NotifierTask task = dataMap.remove(user); if (task != null) { taskList.remove(task); notifierList.remove(notifierList.getSelectionIndex()); @@ -206,19 +233,6 @@ public class ContactNotifierPreferencePage extends PreferencePage implements setButtonState(); } - /** - * Set the state of the buttons. - */ - private void setButtonState() { - if (notifierList.getSelectionCount() > 0) { - deleteBtn.setEnabled(true); - editBtn.setEnabled(true); - } else { - deleteBtn.setEnabled(false); - editBtn.setEnabled(false); - } - } - /** * Create a new notifier task. */ @@ -229,7 +243,8 @@ public class ContactNotifierPreferencePage extends PreferencePage implements ICloseCallback callback = new ICloseCallback() { @Override public void dialogClosed(Object returnValue) { - populate(); + updatePrefs((Map) returnValue); + setButtonState(); } }; AddNotifierDlg dlg = new AddNotifierDlg(getShell(), contacts, @@ -244,6 +259,19 @@ public class ContactNotifierPreferencePage extends PreferencePage implements } } + /** + * Set the state of the buttons. + */ + private void setButtonState() { + if (notifierList.getSelectionCount() > 0) { + deleteBtn.setEnabled(true); + editBtn.setEnabled(true); + } else { + deleteBtn.setEnabled(false); + editBtn.setEnabled(false); + } + } + /** * Get the contacts. * @@ -275,9 +303,35 @@ public class ContactNotifierPreferencePage extends PreferencePage implements return users.toArray(new String[users.size()]); } + /** + * Update with the new settings. + */ + private void updatePrefs(Map dataMap) { + this.dataMap = dataMap; + populate(false); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.PreferencePage#performOk() + */ @Override public boolean performOk() { - NotifierTools.saveNotifiers(taskList); + performApply(); return true; } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.preference.PreferencePage#performApply() + */ + @Override + protected void performApply() { + taskList.clear(); + taskList.addAll(dataMap.values()); + NotifierTools.saveNotifiers(taskList); + setButtonState(); + } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AddNotifierDlg.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AddNotifierDlg.java index 2e3535efe4..6c84c05321 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AddNotifierDlg.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AddNotifierDlg.java @@ -20,6 +20,7 @@ package com.raytheon.uf.viz.collaboration.ui.session; import java.io.File; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -66,6 +67,7 @@ import com.raytheon.viz.ui.dialogs.ICloseCallback; * ------------ ---------- ----------- -------------------------- * Feb 20, 2014 2632 mpduff Initial creation * Mar 05, 2014 2632 mpduff Changed task set to map of user->task. + * Mar 27, 2014 2632 mpduff Sorted users in combo box, changed how Add action works. * * * @@ -395,6 +397,7 @@ public class AddNotifierDlg extends CaveSWTDialog { usernames[i] = userIds[i]; } + Arrays.sort(usernames); return usernames; } @@ -414,17 +417,23 @@ public class AddNotifierDlg extends CaveSWTDialog { task.setRecurring(recurringRdo.getSelection()); this.taskMap.put(task.getUserName(), task); - if (NotifierTools.saveNotifiers(Lists.newArrayList(taskMap.values()))) { - MessageBox messageDialog = new MessageBox(this.getShell(), SWT.OK); - messageDialog.setText("Notifier Saved"); - messageDialog - .setMessage("The contact notifier was successfully saved."); - messageDialog.open(); + updatePreferences(); + + MessageBox messageDialog = new MessageBox(this.getShell(), SWT.OK); + messageDialog.setText("Notifier Saved"); + messageDialog + .setMessage("The contact notifier was successfully saved."); + messageDialog.open(); + } + + /** + * Update the preferences. + */ + private void updatePreferences() { + if (this.callback == null) { + NotifierTools.saveNotifiers(Lists.newArrayList(taskMap.values())); } else { - MessageBox messageDialog = new MessageBox(this.getShell(), SWT.OK); - messageDialog.setText("Save Failed"); - messageDialog.setMessage("The contact notifier failed to save."); - messageDialog.open(); + callback.dialogClosed(taskMap); } } @@ -436,7 +445,7 @@ public class AddNotifierDlg extends CaveSWTDialog { @Override protected void disposed() { if (this.callback != null) { - callback.dialogClosed(returnValue); + callback.dialogClosed(taskMap); } } }