1:
2: package ;
3:
4: import ;
5: import ;
6: import ;
7: import ;
8: import ;
9: import ;
10: import ;
11: import ;
12: import ;
13: import ;
14: import ;
15: import ;
16: import ;
17:
18:
22:
... public class InteractiveSplashHandler extends AbstractSplashHandler {
23:
24:
private final static int F_LABEL_HORIZONTAL_INDENT = 175;
25:
26:
private final static int F_BUTTON_WIDTH_HINT = 80;
27:
28:
private final static int F_TEXT_WIDTH_HINT = 175;
29:
30:
private final static int F_COLUMN_COUNT = 3;
31:
32:
private Composite fCompositeLogin;
33:
34:
private Text fTextUsername;
35:
36:
private Text fTextPassword;
37:
38:
private Button fButtonOK;
39:
40:
private Button fButtonCancel;
41:
42:
private boolean fAuthenticated;
43:
44:
47:
... public InteractiveSplashHandler() {
48:
fCompositeLogin = null;
49:
fTextUsername = null;
50:
fTextPassword = null;
51:
fButtonOK = null;
52:
fButtonCancel = null;
53:
fAuthenticated = false;
54:
}
55:
56:
61:
... public void init(final Shell splash) {
62:
63:
super.init(splash);
64:
65:
configureUISplash();
66:
67:
createUI();
68:
69:
createUIListeners();
70:
71:
splash.layout(true);
72:
73:
74:
doEventLoop();
75:
}
76:
77:
80:
... private void doEventLoop() {
81:
Shell splash = getSplash();
82:
... while (fAuthenticated == false) {
83:
... if (splash.getDisplay().readAndDispatch() == false) {
84:
splash.getDisplay().sleep();
85:
}
86:
}
87:
}
88:
89:
92:
... private void createUIListeners() {
93:
94:
createUIListenersButtonOK();
95:
96:
createUIListenersButtonCancel();
97:
}
98:
99:
102:
... private void createUIListenersButtonCancel() {
103:
... fButtonCancel.addSelectionListener(new SelectionAdapter() {
104:
... public void widgetSelected(SelectionEvent e) {
105:
handleButtonCancelWidgetSelected();
106:
}
107:
});
108:
}
109:
110:
113:
... private void handleButtonCancelWidgetSelected() {
114:
115:
getSplash().getDisplay().close();
116:
System.exit(0);
117:
}
118:
119:
122:
... private void createUIListenersButtonOK() {
123:
... fButtonOK.addSelectionListener(new SelectionAdapter() {
124:
... public void widgetSelected(SelectionEvent e) {
125:
handleButtonOKWidgetSelected();
126:
}
127:
});
128:
}
129:
130:
133:
... private void handleButtonOKWidgetSelected() {
134:
String username = fTextUsername.getText();
135:
String password = fTextPassword.getText();
136:
137:
138:
if ((username.length() > 0) &&
139:
... (password.length() > 0)) {
140:
fAuthenticated = true;
141:
} else {
142:
MessageDialog.openError(
143:
getSplash(),
144:
"Authentication Failed",
145:
"A username and password must be specified to login.");
146:
}
147:
}
148:
149:
152:
... private void createUI() {
153:
154:
createUICompositeLogin();
155:
156:
createUICompositeBlank();
157:
158:
createUILabelUserName();
159:
160:
createUITextUserName();
161:
162:
createUILabelPassword();
163:
164:
createUITextPassword();
165:
166:
createUILabelBlank();
167:
168:
createUIButtonOK();
169:
170:
createUIButtonCancel();
171:
}
172:
173:
176:
... private void createUIButtonCancel() {
177:
178:
fButtonCancel = new Button(fCompositeLogin, SWT.PUSH);
179:
fButtonCancel.setText("Cancel");
180:
181:
GridData data = new GridData(SWT.NONE, SWT.NONE, false, false);
182:
data.widthHint = F_BUTTON_WIDTH_HINT;
183:
data.verticalIndent = 10;
184:
fButtonCancel.setLayoutData(data);
185:
}
186:
187:
190:
... private void createUIButtonOK() {
191:
192:
fButtonOK = new Button(fCompositeLogin, SWT.PUSH);
193:
fButtonOK.setText("OK");
194:
195:
GridData data = new GridData(SWT.NONE, SWT.NONE, false, false);
196:
data.widthHint = F_BUTTON_WIDTH_HINT;
197:
data.verticalIndent = 10;
198:
fButtonOK.setLayoutData(data);
199:
}
200:
201:
204:
... private void createUILabelBlank() {
205:
Label label = new Label(fCompositeLogin, SWT.NONE);
206:
label.setVisible(false);
207:
}
208:
209:
212:
... private void createUITextPassword() {
213:
214:
int style = SWT.PASSWORD | SWT.BORDER;
215:
fTextPassword = new Text(fCompositeLogin, style);
216:
217:
GridData data = new GridData(SWT.NONE, SWT.NONE, false, false);
218:
data.widthHint = F_TEXT_WIDTH_HINT;
219:
data.horizontalSpan = 2;
220:
fTextPassword.setLayoutData(data);
221:
}
222:
223:
226:
... private void createUILabelPassword() {
227:
228:
Label label = new Label(fCompositeLogin, SWT.NONE);
229:
label.setText("&Password:");
230:
231:
GridData data = new GridData();
232:
data.horizontalIndent = F_LABEL_HORIZONTAL_INDENT;
233:
label.setLayoutData(data);
234:
}
235:
236:
239:
... private void createUITextUserName() {
240:
241:
fTextUsername = new Text(fCompositeLogin, SWT.BORDER);
242:
243:
GridData data = new GridData(SWT.NONE, SWT.NONE, false, false);
244:
data.widthHint = F_TEXT_WIDTH_HINT;
245:
data.horizontalSpan = 2;
246:
fTextUsername.setLayoutData(data);
247:
}
248:
249:
252:
... private void createUILabelUserName() {
253:
254:
Label label = new Label(fCompositeLogin, SWT.NONE);
255:
label.setText("&User Name:");
256:
257:
GridData data = new GridData();
258:
data.horizontalIndent = F_LABEL_HORIZONTAL_INDENT;
259:
label.setLayoutData(data);
260:
}
261:
262:
265:
... private void createUICompositeBlank() {
266:
Composite spanner = new Composite(fCompositeLogin, SWT.NONE);
267:
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
268:
data.horizontalSpan = F_COLUMN_COUNT;
269:
spanner.setLayoutData(data);
270:
}
271:
272:
275:
... private void createUICompositeLogin() {
276:
277:
fCompositeLogin = new Composite(getSplash(), SWT.BORDER);
278:
GridLayout layout = new GridLayout(F_COLUMN_COUNT, false);
279:
fCompositeLogin.setLayout(layout);
280:
}
281:
282:
285:
... private void configureUISplash() {
286:
287:
FillLayout layout = new FillLayout();
288:
getSplash().setLayout(layout);
289:
290:
getSplash().setBackgroundMode(SWT.INHERIT_DEFAULT);
291:
}
292:
293:
}