Issue #2632 - Fixed notifier preference OK, Apply, Cancel actions

Change-Id: I9af93c4935c5d9dc6777be0e0435bb71be5f613b

Former-commit-id: 5476afd095 [formerly d2eed9891a] [formerly d803986440] [formerly 5476afd095 [formerly d2eed9891a] [formerly d803986440] [formerly 98b5fd762e [formerly d803986440 [formerly a50bd58e95a929fe569f5df68dd4d4a8b6625807]]]]
Former-commit-id: 98b5fd762e
Former-commit-id: cd626d0555 [formerly f92754f752] [formerly 7b61ae882d35a9231f7bff856832af42ae2f309a [formerly b1d74f855e]]
Former-commit-id: 7aadfd7a15d93ff37cbf9b952a4c1868beb41dee [formerly 531e66cbb6]
Former-commit-id: 5e0e640336
This commit is contained in:
Mike Duff 2014-03-27 16:31:30 -05:00
parent 81409b58ad
commit db4d8b76f0
5 changed files with 129 additions and 42 deletions

View file

@ -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.
*
* </pre>
*
@ -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());
}
}

View file

@ -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.
*
* </pre>
*
@ -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();

View file

@ -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()
*
* </pre>
*
@ -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();
}
}

View file

@ -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
*
* </pre>
*
@ -90,7 +91,7 @@ public class ContactNotifierPreferencePage extends PreferencePage implements
.getNotifierTasks();
/** Data map backing the notifier list */
private final Map<String, NotifierTask> dataMap = new HashMap<String, NotifierTask>();
private Map<String, NotifierTask> dataMap = new HashMap<String, NotifierTask>();
/**
* {@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<String, NotifierTask>) 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<String, NotifierTask>) 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<String, NotifierTask> 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();
}
}

View file

@ -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.
*
* </pre>
*
@ -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);
}
}
}