|
1 /* |
|
2 * Copyright (c) 2006 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.s60tools.appdep.ui.wizards; |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 import org.eclipse.jface.viewers.DoubleClickEvent; |
|
25 import org.eclipse.jface.viewers.IDoubleClickListener; |
|
26 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
27 import org.eclipse.jface.viewers.IStructuredSelection; |
|
28 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
29 import org.eclipse.jface.viewers.TableViewer; |
|
30 import org.eclipse.jface.wizard.IWizardPage; |
|
31 import org.eclipse.swt.SWT; |
|
32 import org.eclipse.swt.events.FocusEvent; |
|
33 import org.eclipse.swt.events.FocusListener; |
|
34 import org.eclipse.swt.layout.GridData; |
|
35 import org.eclipse.swt.layout.GridLayout; |
|
36 import org.eclipse.swt.widgets.Composite; |
|
37 import org.eclipse.swt.widgets.Text; |
|
38 import org.eclipse.swt.widgets.Widget; |
|
39 |
|
40 import com.nokia.s60tools.appdep.AppDepHelpContextIDs; |
|
41 import com.nokia.s60tools.appdep.core.AppDepSettings; |
|
42 import com.nokia.s60tools.appdep.plugin.AppDepPlugin; |
|
43 import com.nokia.s60tools.appdep.resources.Messages; |
|
44 import com.nokia.s60tools.appdep.util.LogUtils; |
|
45 import com.nokia.s60tools.ui.ProgrammaticSelection; |
|
46 |
|
47 |
|
48 /** |
|
49 * Wizard page showing the available SDKs. |
|
50 */ |
|
51 public class SelectSDKWizardPage extends AbstractSelectSDKWizardPage implements FocusListener{ |
|
52 |
|
53 /** |
|
54 * Wizard page's title. |
|
55 */ |
|
56 private Text sdkViewerTitle; |
|
57 |
|
58 /** |
|
59 * Viewer component for showing available targets. |
|
60 */ |
|
61 private TableViewer sdkViewer; |
|
62 |
|
63 /** |
|
64 * Content provider for the viewer component. |
|
65 */ |
|
66 private SelectSDKWizardPageContentProvider contentProvider; |
|
67 |
|
68 /** |
|
69 * Constructor. |
|
70 */ |
|
71 public SelectSDKWizardPage(){ |
|
72 super(Messages.getString("SelectSDKWizardPage.WizardPageName")); //$NON-NLS-1$ |
|
73 |
|
74 setTitle(Messages.getString("SelectSDKWizardPage.WizardPageTitle")); //$NON-NLS-1$ |
|
75 setDescription(Messages.getString("SelectSDKWizardPage.WizardPageDescription")); //$NON-NLS-1$ |
|
76 |
|
77 // User cannot finish the page before some valid |
|
78 // selection is made. |
|
79 setPageComplete(false); |
|
80 } |
|
81 |
|
82 /* (non-Javadoc) |
|
83 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
|
84 */ |
|
85 public void createControl(Composite parent) { |
|
86 |
|
87 Composite c = new Composite(parent, SWT.NONE); |
|
88 |
|
89 final int cols = 1; |
|
90 GridLayout gdl = new GridLayout(cols, false); |
|
91 GridData gd = new GridData(GridData.FILL_BOTH); |
|
92 c.setLayout(gdl); |
|
93 c.setLayoutData(gd); |
|
94 |
|
95 // |
|
96 // Creating controls |
|
97 // |
|
98 final int readOnlyLabelFieldStyleBits = SWT.READ_ONLY | SWT.NO_FOCUS; |
|
99 |
|
100 sdkViewerTitle = new Text(c, readOnlyLabelFieldStyleBits); |
|
101 |
|
102 sdkViewerTitle.setText(Messages.getString("SelectSDKWizardPage.SDKListViewerComponentTitle")); //$NON-NLS-1$ |
|
103 sdkViewerTitle.addFocusListener(this); |
|
104 |
|
105 sdkViewer = new TableViewer(c, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); |
|
106 sdkViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
107 |
|
108 // Providers cannot be created before all the controls have been created |
|
109 // Content provider uses the information provided by the checkbox control |
|
110 contentProvider = new SelectSDKWizardPageContentProvider(); |
|
111 sdkViewer.setContentProvider(contentProvider); |
|
112 sdkViewer.setLabelProvider(new SelectSDKWizardPageLabelProvider2()); |
|
113 sdkViewer.setInput(contentProvider); |
|
114 |
|
115 // Adding selection change listener |
|
116 sdkViewer.addSelectionChangedListener(new ISelectionChangedListener(){ |
|
117 /* (non-Javadoc) |
|
118 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
|
119 */ |
|
120 public void selectionChanged(SelectionChangedEvent event) { |
|
121 recalculateButtonStates(); |
|
122 } |
|
123 }); |
|
124 |
|
125 // Enabling flipping to next page with double-click |
|
126 sdkViewer.addDoubleClickListener(new IDoubleClickListener(){ |
|
127 |
|
128 /* (non-Javadoc) |
|
129 * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent) |
|
130 */ |
|
131 public void doubleClick(DoubleClickEvent event) { |
|
132 recalculateButtonStates(); |
|
133 // If allowed to flip next page... |
|
134 if(isPageComplete()){ |
|
135 IWizardPage nextPage = getNextPage(); |
|
136 // And refreshing contents |
|
137 ((IRefreshable)nextPage).refresh(); |
|
138 // Showing next page |
|
139 getContainer().showPage(nextPage); |
|
140 } |
|
141 }}); |
|
142 |
|
143 // By default collapsing the tree |
|
144 setInitialFocus(); |
|
145 |
|
146 // Setting control for this page |
|
147 setControl(c); |
|
148 |
|
149 // Setting context help IDs |
|
150 AppDepPlugin.setContextSensitiveHelpID(getControl(), AppDepHelpContextIDs.APPDEP_WIZARD_PAGE_SDK_SELECT); |
|
151 } |
|
152 |
|
153 |
|
154 /* (non-Javadoc) |
|
155 * @see com.nokia.s60tools.appdep.ui.wizards.S60ToolsWizardPage#setInitialFocus() |
|
156 */ |
|
157 public void setInitialFocus() { |
|
158 sdkViewer.getTable().setFocus(); |
|
159 } |
|
160 |
|
161 /* (non-Javadoc) |
|
162 * @see com.nokia.s60tools.appdep.ui.wizards.S60ToolsWizardPage#recalculateButtonStates() |
|
163 */ |
|
164 public void recalculateButtonStates() { |
|
165 |
|
166 try { |
|
167 SelectSDKWizard wiz = (SelectSDKWizard) getWizard(); |
|
168 AppDepSettings settings = wiz.getSettings(); |
|
169 IStructuredSelection selection = (IStructuredSelection )sdkViewer.getSelection(); |
|
170 Object obj = selection.getFirstElement(); |
|
171 |
|
172 // There is no selection made (e.g. coming with Back from previous page) |
|
173 if(obj == null){ |
|
174 // ...checking if we can create a selection based on the currently used SDK |
|
175 obj = contentProvider.find(settings.getCurrentlyUsedSdk().getSdkId()); |
|
176 if(obj != null){ |
|
177 // Match was found |
|
178 ProgrammaticSelection newSelection = null; |
|
179 newSelection = new ProgrammaticSelection(new Object[]{obj}); |
|
180 sdkViewer.setSelection(newSelection, true); |
|
181 selection = (IStructuredSelection )sdkViewer.getSelection(); |
|
182 if(selection == null){ |
|
183 // Trying to avoid internal errors, but this is something that should be trapped during |
|
184 // development time. Internal error messages are not localized. |
|
185 String errMsg = "Programmatic selection failed unexpectedly in class '" //$NON-NLS-1$ |
|
186 + SelectSDKWizardPage.class.getSimpleName() |
|
187 + "'."; //$NON-NLS-1$ |
|
188 LogUtils.logInternalErrorAndThrowException(errMsg); |
|
189 return; |
|
190 } |
|
191 } |
|
192 else{ |
|
193 // No match was found |
|
194 return; |
|
195 } |
|
196 } |
|
197 |
|
198 // Otherwise SDK is selected |
|
199 SdkTreeViewNode sdkNode = (SdkTreeViewNode) selection.toArray()[0]; // Getting all selected SDK node |
|
200 |
|
201 if(! sdkNode.getSdkInfo().epocRootExists()){ |
|
202 // Non-existing SDK node selected |
|
203 this.setMessage(null); |
|
204 this.setErrorMessage(Messages.getString("SelectSDKWizardPage.EPOCROOT_NotFound_ErrMsg")); //$NON-NLS-1$ |
|
205 // Flipping to next page and finishing is forbidden |
|
206 setPageComplete(false); |
|
207 wiz.disableCanFinish(); |
|
208 } |
|
209 else{ |
|
210 // Existing SDK node selected |
|
211 this.setMessage(Messages.getString("SelectSDKWizardPage.Press_Next_To_Continue")); //$NON-NLS-1$ |
|
212 this.setErrorMessage(null); |
|
213 // Flipping to next page is possible |
|
214 setPageComplete(true); |
|
215 // Finishing is forbidden |
|
216 wiz.disableCanFinish(); |
|
217 // Storing user selection and ... |
|
218 wiz.setUserSelection(sdkNode); |
|
219 } |
|
220 |
|
221 } catch (Exception e) { |
|
222 e.printStackTrace(); |
|
223 } |
|
224 |
|
225 } |
|
226 |
|
227 /* (non-Javadoc) |
|
228 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) |
|
229 */ |
|
230 public void focusGained(FocusEvent e) { |
|
231 Widget w = e.widget; |
|
232 if(w.equals(sdkViewerTitle)){ |
|
233 setInitialFocus(); |
|
234 } |
|
235 } |
|
236 |
|
237 /* (non-Javadoc) |
|
238 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) |
|
239 */ |
|
240 public void focusLost(FocusEvent e) { |
|
241 // No need to do anything |
|
242 } |
|
243 |
|
244 } |
|
245 |