|
1 /* |
|
2 * Copyright (c) 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 com.nokia.mj.impl.rt.ui.ConfirmData; |
|
22 |
|
23 import org.eclipse.swt.SWT; |
|
24 import org.eclipse.swt.events.DisposeEvent; |
|
25 import org.eclipse.swt.events.DisposeListener; |
|
26 import org.eclipse.swt.events.SelectionEvent; |
|
27 import org.eclipse.swt.events.SelectionListener; |
|
28 import org.eclipse.swt.layout.GridData; |
|
29 import org.eclipse.swt.widgets.Button; |
|
30 import org.eclipse.swt.widgets.Composite; |
|
31 import org.eclipse.swt.widgets.Label; |
|
32 |
|
33 /** |
|
34 * Displays error message. |
|
35 */ |
|
36 public class RuntimeConfirmationView extends ConfirmationViewBase |
|
37 { |
|
38 private String iAppName = null; |
|
39 private ConfirmData iConfirmData = null; |
|
40 private Button[] iAnswerButtons = null; |
|
41 |
|
42 /** Constructor */ |
|
43 protected RuntimeConfirmationView() |
|
44 { |
|
45 super(); |
|
46 } |
|
47 |
|
48 /** Constructor */ |
|
49 protected RuntimeConfirmationView(InstallerUiEswt aInstallerUi, |
|
50 Composite aParent, String aAppName, |
|
51 ConfirmData aConfirmData) |
|
52 { |
|
53 super(aInstallerUi, aParent, 8); |
|
54 iAppName = aAppName; |
|
55 iConfirmData = aConfirmData; |
|
56 setTitle(InstallerUiTexts.get(InstallerUiTexts.INSTALL_FAILED)); |
|
57 String[] answerOptions = iConfirmData.getAnswerOptions(); |
|
58 switch (answerOptions.length) |
|
59 { |
|
60 case 1: setCommands(answerOptions[0], null); break; |
|
61 case 2: setCommands(answerOptions[0], answerOptions[1]); break; |
|
62 default: setCommands(null, null); break; |
|
63 } |
|
64 } |
|
65 |
|
66 /** |
|
67 * This method is called once before view is opened. |
|
68 */ |
|
69 protected void createView() |
|
70 { |
|
71 // Add title. |
|
72 if (iInstallerUi.getInstallInfo() != null) |
|
73 { |
|
74 Label titleLabel = createLabel(iAppName, getColumns() - 1, SWT.WRAP); |
|
75 titleLabel.setFont(iInstallerUi.getBoldFont()); |
|
76 // Add security icon. |
|
77 iCertificates = iInstallerUi.getInstallInfo().getCertificates(); |
|
78 createSecurityButton(); |
|
79 } |
|
80 else |
|
81 { |
|
82 Label titleLabel = createLabel(iAppName, getColumns(), SWT.WRAP); |
|
83 titleLabel.setFont(iInstallerUi.getBoldFont()); |
|
84 } |
|
85 |
|
86 GridData gridData = null; |
|
87 int horizontalSpan = getColumns(); |
|
88 int labelStyle = SWT.WRAP; |
|
89 |
|
90 // Begin widgets creation. |
|
91 |
|
92 // Add question label. |
|
93 Label errorLabel = createLabel( |
|
94 iConfirmData.getQuestion(), horizontalSpan, labelStyle); |
|
95 |
|
96 |
|
97 // Add user answer buttons. |
|
98 String[] answerOptions = iConfirmData.getAnswerOptions(); |
|
99 if (answerOptions.length > 2) |
|
100 { |
|
101 iAnswerButtons = new Button[answerOptions.length]; |
|
102 for (int i = 0; i < iAnswerButtons.length; i++) |
|
103 { |
|
104 final int answerIndex = i; |
|
105 iAnswerButtons[i] = new Button(getComposite(), SWT.PUSH); |
|
106 iAnswerButtons[i].setText(answerOptions[i]); |
|
107 gridData = new GridData(GridData.FILL_HORIZONTAL); |
|
108 gridData.horizontalSpan = horizontalSpan; |
|
109 iAnswerButtons[i].setLayoutData(gridData); |
|
110 iAnswerButtons[i].addDisposeListener(new DisposeListener () |
|
111 { |
|
112 public void widgetDisposed(DisposeEvent aEvent) |
|
113 { |
|
114 answer(answerIndex); |
|
115 } |
|
116 }); |
|
117 iAnswerButtons[i].addSelectionListener(new SelectionListener () |
|
118 { |
|
119 public void widgetDefaultSelected(SelectionEvent aEvent) |
|
120 { |
|
121 widgetSelected(aEvent); |
|
122 } |
|
123 public void widgetSelected(SelectionEvent aEvent) |
|
124 { |
|
125 answer(answerIndex); |
|
126 } |
|
127 }); |
|
128 } |
|
129 // Set the default answer option. |
|
130 iParent.setDefaultButton( |
|
131 iAnswerButtons[iConfirmData.getAnswerSuggestion()]); |
|
132 iAnswerButtons[iConfirmData.getAnswerSuggestion()].setFocus(); |
|
133 } |
|
134 |
|
135 // End of widgets creation. |
|
136 } |
|
137 |
|
138 /** |
|
139 * This method is called when user answers to the dialog. |
|
140 */ |
|
141 protected void answer(int aAnswerIndex) |
|
142 { |
|
143 iConfirmData.setAnswer(aAnswerIndex); |
|
144 super.confirmOk(); |
|
145 } |
|
146 |
|
147 /** |
|
148 * This method is called when user accepts the dialog. |
|
149 */ |
|
150 protected void confirmOk() |
|
151 { |
|
152 iConfirmData.setAnswer(0); |
|
153 super.confirmOk(); |
|
154 } |
|
155 |
|
156 /** |
|
157 * This method is called when user cancels the dialog. |
|
158 */ |
|
159 protected void confirmCancel() |
|
160 { |
|
161 iConfirmData.setAnswer(1); |
|
162 super.confirmCancel(); |
|
163 } |
|
164 |
|
165 /** |
|
166 * This method is called after user has answered |
|
167 * to confirmation. |
|
168 */ |
|
169 protected void getDataFromView() |
|
170 { |
|
171 // nop |
|
172 } |
|
173 |
|
174 /** |
|
175 * Returns SWT style for this view. |
|
176 */ |
|
177 protected int getStyle() |
|
178 { |
|
179 return SWT.V_SCROLL; |
|
180 } |
|
181 } |