001 /** =====================================================================
002 *
003 * File Name : $Id: ModifyFaultSubscriptionListDialog.java,v 1.3 2008/01/15 11:08:15 cb Exp $
004 *
005 * Description
006 * -----------
007 *
008 * =====================================================================
009 *
010 * @author : Craige Bevil
011 * Control Software Group
012 * Isaac Newton Group of Telescopes
013 *
014 * =====================================================================
015 *
016 * Modification Log
017 *
018 * Vers Date Author Reason
019 * ---- ---- ------ ------
020 * 1 5 Oct 2007 C.Bevil First Release
021 *
022 * Commissioning Notes
023 * -------------------
024 *
025 * None
026 *
027 * =====================================================================
028 *
029 * @version : $Id: ModifyFaultSubscriptionListDialog.java,v 1.3 2008/01/15 11:08:15 cb Exp $
030 *
031 * @author : $Author: cb $
032 *
033 * Header : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/client/ModifyFaultSubscriptionListDialog.java,v 1.3 2008/01/15 11:08:15 cb Exp $
034 *
035 * Log : $Log: ModifyFaultSubscriptionListDialog.java,v $
036 * Log : Revision 1.3 2008/01/15 11:08:15 cb
037 * Log : Ran through PMD and sorted out the javadoc so that we could export the
038 * Log : javadoc to the javadoc repository.
039 * Log :
040 * Log : Revision 1.2 2007/12/12 15:26:12 cb
041 * Log : Added new javascript library which allows fancy message boxes to be
042 * Log : displayed.
043 * Log :
044 * Log : Revision 1.1 2007/10/08 09:33:35 cb
045 * Log : First version
046 * Log :
047 * Log : Revision 1.2 2007/08/17 14:22:28 cb
048 * Log : Optimised after PMD, display in centre of screen
049 * Log :
050 * Log : Revision 1.1 2007/07/24 08:25:23 cb
051 * Log : First version
052 * Log :
053 *
054 * =====================================================================*/
055
056 package GWTApplication.client;
057
058 import com.google.gwt.user.client.*;
059 import com.google.gwt.user.client.rpc.*;
060 import com.google.gwt.user.client.ui.*;
061 import com.google.gwt.user.client.ui.DockPanel.*;
062
063 import com.gwtext.client.core.EventObject;
064 import com.gwtext.client.util.Format;
065 import com.gwtext.client.widgets.MessageBox;
066 import com.gwtext.client.widgets.MessageBoxConfig;
067
068 import com.google.gwt.user.client.ui.FlexTable.*;
069 import java.util.*;
070
071 /**
072 * This class will allow the user to review the list of faults which
073 * he has subscribed to recieve emails for so he can opt out of
074 * recieving emails for faults that he has previosuly subscribed to.
075 * @author Craige Bevil
076 * @version $Id: ModifyFaultSubscriptionListDialog.java,v 1.3 2008/01/15 11:08:15 cb Exp $
077 */
078
079 public class ModifyFaultSubscriptionListDialog extends FaultDBForm implements ClickListener {
080
081 /**
082 * Unsubscribe all
083 */
084
085 private Button UnsubscribeAllButton;
086
087 /**
088 * This is the submit button widget
089 */
090
091 private Button SubmitButton;
092
093 /**
094 * This is the cancel button widget
095 */
096
097 private Button CancelButton;
098
099 /**
100 * This is the grid that contains all of the faults.
101 */
102
103 private Grid SubscribedFaultsTable;
104
105 /**
106 * This is the main dialog box which will be displayed
107 */
108
109 private DialogBox ChangeFaultsSubscribedToDialog;
110
111 /**
112 * This is a hashmap of all of the checkboxes which are included
113 * in the list of faults which have been subscribed to.
114 */
115
116 private HashMap SubmitCheckBoxList = new HashMap();
117
118 /**
119 * Constructor
120 * @param svc Used to communicate with the remote servlet
121 * container.
122 * @param authenticationDetails Authentication details of the
123 * current user.
124 */
125
126 ModifyFaultSubscriptionListDialog (final FaultServiceAsync svc,final AuthenticationDetails authenticationDetails) {
127
128 final ArrayList subscribedFaults = new ArrayList();
129
130 final DockPanel panel = new DockPanel();
131 final ScrollPanel faultsPanel = new ScrollPanel();
132
133 this.svc = svc;
134 this.UserAuthentication = authenticationDetails;
135
136 // Now create the submit and cancel button
137
138 SubmitButton = new Button(internationalizationConstants.update(),this);
139 CancelButton = new Button(internationalizationConstants.cancel(),this);
140 UnsubscribeAllButton = new Button(internationalizationConstants.unsubscribeAll(),this);
141
142 // Get the list of faults which the user is subscribed to
143
144 svc.getSubscribedFaults (authenticationDetails,internationalizationConstants.locale(),new AsyncCallback() {
145
146 public void onSuccess (final Object result) {
147
148 ChangeFaultsSubscribedToDialog = new DialogBox(false);
149
150 // If the number of faults which the user has
151 // subscribed to is zero then we do not display
152 // the dialog and return
153
154 ArrayList temp = (ArrayList)result;
155
156 for (int i=0; i < temp.size() ;i++) {
157 subscribedFaults.add((Fault)temp.get(i));
158 }
159
160 if (subscribedFaults.size() == 0) {
161 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.userNotSubscribedToAnyFaults());
162 return;
163 }
164
165 // Now we need to create the table which contains the faults
166 // that the user has subscribed to with all of the details
167
168 SubscribedFaultsTable = new Grid(subscribedFaults.size() + 1,3);
169
170 for (int i=0; i < subscribedFaults.size(); i++) {
171
172 CheckBox userSubscribed = new CheckBox();
173
174 Fault currentFault = (Fault)subscribedFaults.get(i);
175
176 SubscribedFaultsTable.setWidget(i,0,userSubscribed);
177 SubscribedFaultsTable.setHTML(i,1,Integer.toString(currentFault.id));
178 SubscribedFaultsTable.setHTML(i,2,currentFault.title);
179
180 // Store the checkbox against the defect number
181
182 SubmitCheckBoxList.put(new Integer(currentFault.id),userSubscribed);
183
184 userSubscribed.setChecked(true);
185 }
186
187 // Add the table to the scroll panel
188
189 faultsPanel.add(SubscribedFaultsTable);
190 faultsPanel.setWidth("100%");
191 faultsPanel.setHeight("10cm");
192
193
194 // Now create the dialog from which the user will modify the
195 // list of fault which he is subscribed to
196
197 panel.add(faultsPanel,DockPanel.NORTH);
198 panel.add(SubmitButton,DockPanel.WEST);
199 panel.add(UnsubscribeAllButton,DockPanel.WEST);
200
201 panel.add(CancelButton,DockPanel.WEST);
202 panel.setSpacing(10);
203
204 // Now add the main panel to the dialog box
205
206 ChangeFaultsSubscribedToDialog.setWidget(panel);
207
208 ChangeFaultsSubscribedToDialog.setText(internationalizationConstants.changeFaultsSusbscribedTo());
209
210 showChangeFaultsSubscribedToDialog();
211 }
212
213 public void onFailure (Throwable ex) {
214 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToGetListOfSubscribedFaults());
215 return;
216 }
217 });
218
219 }
220
221 /**
222 * This is the click handler which is called when the user calls
223 * presses one of the buttons on the dialog. It results in the
224 * process of changing the password being initiated.
225 * @param sender This is the widget which raised the event.
226 */
227
228 public void onClick (final Widget sender) {
229
230 if (sender.equals(SubmitButton)) {
231
232 // Now go through all of the fault the user has subscribed
233 // to and then request the servlet to udpate the list
234
235 Iterator iterator = SubmitCheckBoxList.keySet().iterator();
236
237 HashMap defectSubscriptionState = new HashMap();
238
239 while (iterator.hasNext()) {
240
241 final Integer defectNo = (Integer)iterator.next();
242
243 final CheckBox temp = (CheckBox)SubmitCheckBoxList.get(defectNo);
244
245 defectSubscriptionState.put(defectNo,new Boolean(temp.isChecked()));
246 }
247
248 // Now we need to update the list of faults subscribed to
249 // by this user by sending off the data to the servlet
250
251 svc.updateFaultSubscriptionList (UserAuthentication,defectSubscriptionState,new AsyncCallback() {
252
253 public void onSuccess (final Object result) {
254 ChangeFaultsSubscribedToDialog.hide();
255 }
256
257 public void onFailure (Throwable ex) {
258 MessageBox.alert(internationalizationConstants.information(),internationalizationConstants.unableToUpdateTheSubscriptionList());
259 return;
260 }
261 });
262
263 } else if (sender.equals(UnsubscribeAllButton)) {
264
265 // Now go through all of the faults which we are currently
266 // subscribed to an uncheck them
267
268 Iterator iterator = SubmitCheckBoxList.keySet().iterator();
269
270 while (iterator.hasNext()) {
271
272 final Integer defectNo = (Integer)iterator.next();
273 final CheckBox temp = (CheckBox)SubmitCheckBoxList.get(defectNo);
274
275 temp.setChecked(false);
276 }
277
278 } else if (sender.equals(CancelButton)) {
279 ChangeFaultsSubscribedToDialog.hide();
280 }
281 }
282
283 /**
284 * Displays the dialog which will allow the user to change his
285 * password.
286 */
287
288 public void showChangeFaultsSubscribedToDialog () {
289 ChangeFaultsSubscribedToDialog.show();
290 ChangeFaultsSubscribedToDialog.center();
291 }
292 }
293