|
1 /* |
|
2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 package com.nokia.mj.impl.installer.ui.eswt2; |
|
20 |
|
21 import org.eclipse.swt.SWT; |
|
22 import org.eclipse.swt.layout.GridData; |
|
23 import org.eclipse.swt.widgets.Composite; |
|
24 import org.eclipse.swt.widgets.Label; |
|
25 import org.eclipse.swt.widgets.Text; |
|
26 |
|
27 /** |
|
28 * UsernamePasswordView asks username and password from the user. |
|
29 */ |
|
30 public class UsernamePasswordView extends ConfirmationViewBase |
|
31 { |
|
32 private Text iUsernameText = null; |
|
33 private Text iPasswordText = null; |
|
34 private String iUrl = null; |
|
35 private String iUsername = null; |
|
36 private String iPassword = null; |
|
37 private String iAppName = null; |
|
38 private Object iAppNameWaitObject = new Object(); |
|
39 |
|
40 /** Constructor */ |
|
41 protected UsernamePasswordView() |
|
42 { |
|
43 super(); |
|
44 } |
|
45 |
|
46 /** Constructor */ |
|
47 protected UsernamePasswordView(InstallerUiEswt aInstaller, Composite aParent) |
|
48 { |
|
49 super(aInstaller, aParent, 1); |
|
50 setTitle(InstallerUiTexts.get(InstallerUiTexts.CONNECT_TO)); |
|
51 setCommands(InstallerUiTexts.get(InstallerUiTexts.OK), |
|
52 InstallerUiTexts.get(InstallerUiTexts.CANCEL)); |
|
53 } |
|
54 |
|
55 /** Set application name. */ |
|
56 public void setAppName(String aAppName) |
|
57 { |
|
58 // Notify iAppNameWaitObject that iAppName is now available. |
|
59 synchronized (iAppNameWaitObject) |
|
60 { |
|
61 iAppName = aAppName; |
|
62 iAppNameWaitObject.notify(); |
|
63 } |
|
64 } |
|
65 |
|
66 /** Get username and password. */ |
|
67 public String[] getUsernamePassword(String aUrl) |
|
68 { |
|
69 if (isDisposed()) |
|
70 { |
|
71 return null; |
|
72 } |
|
73 // If iAppName is null, wait until it gets set. |
|
74 synchronized (iAppNameWaitObject) |
|
75 { |
|
76 if (iAppName == null) |
|
77 { |
|
78 try |
|
79 { |
|
80 iAppNameWaitObject.wait(); |
|
81 } |
|
82 catch (InterruptedException ie) |
|
83 { |
|
84 } |
|
85 } |
|
86 } |
|
87 iUrl = aUrl; |
|
88 |
|
89 // Use confirm() from super class to display the view. |
|
90 boolean confirmation = confirm(); |
|
91 |
|
92 // And return the result to the client. |
|
93 String[] result = null; |
|
94 if (confirmation && iUsername != null && iPassword != null) |
|
95 { |
|
96 result = new String[] { iUsername, iPassword }; |
|
97 } |
|
98 return result; |
|
99 } |
|
100 |
|
101 protected void createView() |
|
102 { |
|
103 |
|
104 int labelStyle = SWT.WRAP; |
|
105 |
|
106 Label titleLabel = createLabel |
|
107 (InstallerUiTexts.get(InstallerUiTexts.CONNECT_TO), labelStyle); |
|
108 titleLabel.setFont(iInstallerUi.getBoldFont()); |
|
109 |
|
110 Label urlLabel = createLabel(iUrl, labelStyle); |
|
111 |
|
112 Label authLabel = createLabel |
|
113 (InstallerUiTexts.get |
|
114 (InstallerUiTexts.DOWNLOAD_APPLICATION, new String[] { iAppName }), |
|
115 labelStyle); |
|
116 |
|
117 Label usernameLabel = createLabel |
|
118 (InstallerUiTexts.get(InstallerUiTexts.USERNAME), labelStyle); |
|
119 |
|
120 iUsernameText = new Text(getComposite(), SWT.BORDER); |
|
121 iUsernameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
122 addSoftKeyListenerFor(iUsernameText); |
|
123 |
|
124 Label passwordLabel = createLabel |
|
125 (InstallerUiTexts.get(InstallerUiTexts.PASSWORD), labelStyle); |
|
126 |
|
127 iPasswordText = new Text(getComposite(), SWT.PASSWORD | SWT.BORDER); |
|
128 iPasswordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
129 addSoftKeyListenerFor(iPasswordText); |
|
130 } |
|
131 |
|
132 /** |
|
133 * This method is called after user has answered |
|
134 * to confirmation. |
|
135 */ |
|
136 protected void getDataFromView() |
|
137 { |
|
138 iUsername = iUsernameText.getText(); |
|
139 iPassword = iPasswordText.getText(); |
|
140 } |
|
141 |
|
142 /** |
|
143 * Returns SWT style for this view. |
|
144 */ |
|
145 protected int getStyle() |
|
146 { |
|
147 return SWT.V_SCROLL; |
|
148 } |
|
149 } |