001 /** =====================================================================
002 *
003 * File Name : $Id: LinkFaultDialog.java,v 1.5 2007/12/17 10:34:56 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 C.Bevil First Release
021 *
022 * Commissioning Notes
023 * -------------------
024 *
025 * None
026 *
027 * =====================================================================
028 *
029 * @version : $Id: LinkFaultDialog.java,v 1.5 2007/12/17 10:34:56 cb Exp $
030 *
031 * @author : $Author: cb $
032 *
033 * Header : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/client/LinkFaultDialog.java,v 1.5 2007/12/17 10:34:56 cb Exp $
034 *
035 * Log : $Log: LinkFaultDialog.java,v $
036 * Log : Revision 1.5 2007/12/17 10:34:56 cb
037 * Log : Removed a problem wherby the use of the fancy js library could lock
038 * Log : the screen. Ensure that the link field has the focus when the dialog
039 * Log : is displayed.
040 * Log :
041 * Log : Revision 1.4 2007/12/12 15:26:14 cb
042 * Log : Added new javascript library which allows fancy message boxes to be
043 * Log : displayed.
044 * Log :
045 * Log : Revision 1.3 2007/09/04 13:26:01 cb
046 * Log : Removed the dialog which says that the link has been made because it
047 * Log : was interferring with the thread which performs the update of the
048 * Log : faults (I think).
049 * Log :
050 * Log : Revision 1.2 2007/08/17 14:26:42 cb
051 * Log : Updated for lastest prototype incorporating a lot of Nikos comments
052 * Log :
053 * Log : Revision 1.1 2007/07/24 08:27:09 cb
054 * Log : First version
055 * Log :
056 *
057 * =====================================================================*/
058
059 package GWTApplication.client;
060
061 import com.google.gwt.user.client.*;
062 import com.google.gwt.user.client.rpc.*;
063 import com.google.gwt.user.client.ui.*;
064 import com.google.gwt.user.client.ui.DockPanel.*;
065
066 import com.google.gwt.user.client.ui.FlexTable.*;
067 import java.util.*;
068
069 /**
070 * This class will allow the user to link a fault to another fault. It
071 * does by means of a pop up dialog which will be displayed when the
072 * user clicks on the appropriate link on the interface
073 * @author Craige Bevil
074 * @version $Id: LinkFaultDialog.java,v 1.5 2007/12/17 10:34:56 cb Exp $
075 */
076
077 public class LinkFaultDialog extends FaultDBForm implements ClickListener {
078
079 /**
080 * This is the submit button widget
081 */
082
083 final private Button SubmitButton;
084
085 /**
086 * This is the cancel button widget
087 */
088
089 final private Button CancelButton;
090
091 /**
092 * This is the main dialog box which will be displayed
093 */
094
095 DialogBox LinkDialog = new DialogBox(false);
096
097 /**
098 * This is the fault id of the child fault which we will link to
099 * parent fault which will be entered by the user
100 */
101
102 private int ChildFaultId;
103
104 /**
105 * This is the entry box into which the user will enter the id of
106 * the fault to which this fault will be linked to
107 */
108
109 private LabelTextBox ParentLinkTextEntry;
110
111 /**
112 * Constructor
113 */
114
115 LinkFaultDialog (final FaultServiceAsync svc) {
116
117 final DockPanel panel = new DockPanel();
118
119 this.svc = svc;
120
121 ParentLinkTextEntry = new LabelTextBox(LabelTextBox.HORIZONTAL);
122
123 ParentLinkTextEntry.label.setText(internationalizationConstants.faultToLinkTo() + ":");
124 ParentLinkTextEntry.textBox.setWidth("5cm");
125
126 panel.add(ParentLinkTextEntry,DockPanel.NORTH);
127
128 // Now add the submit and cancel button
129
130 SubmitButton = new Button(internationalizationConstants.linkFault(),this);
131 CancelButton = new Button(internationalizationConstants.cancel(),this);
132
133 panel.add(SubmitButton,DockPanel.WEST);
134 panel.add(CancelButton,DockPanel.WEST);
135 panel.setSpacing(10);
136
137 // Now add the main panel to the dialog box
138
139 LinkDialog.setWidget(panel);
140
141 LinkDialog.setText(internationalizationConstants.linkFault());
142 }
143
144 /**
145 * This is the click handler which is called when the user calls
146 * presses one of the buttons on the dialog
147 * @param sender This is the widget which resulted in the event
148 * being generated.
149 */
150
151 public void onClick (final Widget sender) {
152
153 if (sender.equals(SubmitButton)) {
154
155 // Now we need to link the which was entered to the
156 // fault. First we need to check to see if the fault is
157 // actually in the fault database
158
159 if (!ParentLinkTextEntry.textBox.getText().matches("[0-9]+")) {
160 Window.alert(internationalizationConstants.defectNumberNotSpecifiedCorrectly());
161 return;
162 }
163
164 final int parentFaultId = Integer.parseInt(ParentLinkTextEntry.textBox.getText());
165
166 // If the user is trying to link the fault to itself then
167 // have a word
168
169 if (parentFaultId == ChildFaultId) {
170 Window.alert("You cannot link a fault to itself");
171 return;
172 }
173
174 svc.linkFault (parentFaultId,ChildFaultId,new AsyncCallback() {
175
176 /**
177 * On success we remove the dialog from the
178 * display and report that we were successful to
179 * the user
180 */
181
182 public void onSuccess (final Object result) {
183
184 LinkDialog.hide();
185 }
186
187 public void onFailure (Throwable ex)
188 {
189 Window.alert(internationalizationConstants.unableToMakeLink());
190 }
191 });
192
193 } else if (sender.equals(CancelButton)) {
194 LinkDialog.hide();
195 }
196 }
197
198 /**
199 * Displays the new dialog which will allow the user to link this
200 * fault with the fault specified.
201 *
202 * @param ChildFaultId This is the id. of the fault which we will link
203 * to the fault entered by the user should be linked to
204 */
205
206 public void showLinkDialog (final int ChildFaultId) {
207
208 this.ChildFaultId = ChildFaultId;
209
210 LinkDialog.show();
211 LinkDialog.center();
212
213 ParentLinkTextEntry.setFocus(true);
214
215 }
216 }
217