|
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 import java.util.ArrayList; |
|
24 import java.util.List; |
|
25 |
|
26 import org.eclipse.jface.viewers.ISelection; |
|
27 import org.eclipse.jface.viewers.IStructuredSelection; |
|
28 import org.eclipse.jface.viewers.TableViewer; |
|
29 import org.eclipse.swt.SWT; |
|
30 import org.eclipse.swt.events.FocusEvent; |
|
31 import org.eclipse.swt.events.FocusListener; |
|
32 import org.eclipse.swt.events.ModifyEvent; |
|
33 import org.eclipse.swt.events.ModifyListener; |
|
34 import org.eclipse.swt.events.SelectionEvent; |
|
35 import org.eclipse.swt.events.SelectionListener; |
|
36 import org.eclipse.swt.layout.GridData; |
|
37 import org.eclipse.swt.layout.GridLayout; |
|
38 import org.eclipse.swt.widgets.Button; |
|
39 import org.eclipse.swt.widgets.Composite; |
|
40 import org.eclipse.swt.widgets.Shell; |
|
41 import org.eclipse.swt.widgets.Table; |
|
42 import org.eclipse.swt.widgets.TableItem; |
|
43 import org.eclipse.swt.widgets.Text; |
|
44 import org.eclipse.swt.widgets.Widget; |
|
45 |
|
46 import com.nokia.s60tools.appdep.AppDepHelpContextIDs; |
|
47 import com.nokia.s60tools.appdep.common.ProductInfoRegistry; |
|
48 import com.nokia.s60tools.appdep.plugin.AppDepPlugin; |
|
49 import com.nokia.s60tools.appdep.resources.Messages; |
|
50 import com.nokia.s60tools.appdep.ui.views.data.ComponentListNode; |
|
51 import com.nokia.s60tools.ui.S60ToolsTable; |
|
52 import com.nokia.s60tools.ui.S60ToolsTableColumnData; |
|
53 import com.nokia.s60tools.ui.S60ToolsTableFactory; |
|
54 import com.nokia.s60tools.ui.dialogs.S60ToolsListBoxDialog; |
|
55 import com.nokia.s60tools.ui.wizards.S60ToolsWizardPage; |
|
56 |
|
57 /** |
|
58 * Select component wizard page implementation. |
|
59 */ |
|
60 public class SelectComponentWizardPage extends S60ToolsWizardPage implements ModifyListener, |
|
61 FocusListener, |
|
62 SelectionListener, |
|
63 IRefreshable{ |
|
64 // |
|
65 // Constants |
|
66 // |
|
67 private final int DUPLICATE_COMP_DLG_WIDTH = 350; |
|
68 private final int DUPLICATE_COMP_DLG_HEIGHT = 250; |
|
69 |
|
70 // |
|
71 // Members |
|
72 // |
|
73 private Text searchFieldTitle = null; |
|
74 private Text searchField = null; |
|
75 private Text buildTypeTitle = null; |
|
76 private Text buildTypeValue = null; |
|
77 private TableViewer componentViewer = null; |
|
78 private S60ToolsTable componentViewerAsS60Table = null; |
|
79 private Text showSISTitle = null; |
|
80 private Button showSISCheckBox = null; |
|
81 |
|
82 private SelectComponentWizardPageContentProvider contentProvider = null; |
|
83 private List<String> duplicateComponentList = null; |
|
84 private boolean showDuplicateComponentInfo; |
|
85 |
|
86 /** |
|
87 * Constructor. |
|
88 * @param showDuplicateComponentInfo <code>true</code> if we want to inform user about duplicate components, |
|
89 * otherwise <code>false</code>. |
|
90 */ |
|
91 public SelectComponentWizardPage(boolean showDuplicateComponentInfo){ |
|
92 super(Messages.getString("SelectComponentWizardPage.Window_Title")); //$NON-NLS-1$ |
|
93 setTitle(Messages.getString("SelectComponentWizardPage.Title")); //$NON-NLS-1$ |
|
94 setDescription(Messages.getString("SelectComponentWizardPage.SelectComponent_User_InfoMessage")); //$NON-NLS-1$ |
|
95 |
|
96 // This is used to store information about the possible duplicate components |
|
97 duplicateComponentList = new ArrayList<String>(); |
|
98 this.showDuplicateComponentInfo = showDuplicateComponentInfo; |
|
99 |
|
100 // User cannot finish the page before a selection is made. |
|
101 setPageComplete(false); |
|
102 } |
|
103 |
|
104 /* (non-Javadoc) |
|
105 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
|
106 */ |
|
107 public void createControl(Composite parent) { |
|
108 |
|
109 GridData gd = new GridData(GridData.FILL_BOTH); |
|
110 Composite c = createGridLayoutComposite(parent, SWT.NONE, 1, gd); |
|
111 |
|
112 final int readOnlyLabelFieldStyleBits = SWT.READ_ONLY | SWT.NO_FOCUS; |
|
113 |
|
114 searchFieldTitle = new Text(c, readOnlyLabelFieldStyleBits); |
|
115 searchFieldTitle.setText(Messages.getString("SelectComponentWizardPage.Search_Field_Title")); //$NON-NLS-1$ |
|
116 searchFieldTitle.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
117 searchFieldTitle.addFocusListener(this); |
|
118 |
|
119 searchField = new Text(c, SWT.SINGLE | SWT.BORDER); |
|
120 searchField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
121 searchField.addModifyListener(this); |
|
122 |
|
123 // Adding two column composite for build type info text. |
|
124 GridData gd2 = new GridData(GridData.FILL_HORIZONTAL); |
|
125 Composite titleAreaComposite = createGridLayoutComposite(c, SWT.NONE, 2, gd2); |
|
126 |
|
127 buildTypeTitle = new Text(titleAreaComposite, readOnlyLabelFieldStyleBits); |
|
128 buildTypeTitle.setText(Messages.getString("SelectComponentWizardPage.BuildTypeTitle_Text")); //$NON-NLS-1$ |
|
129 buildTypeTitle.setLayoutData(new GridData(GridData.BEGINNING)); |
|
130 buildTypeTitle.addFocusListener(this); |
|
131 |
|
132 buildTypeValue = new Text(titleAreaComposite, readOnlyLabelFieldStyleBits); |
|
133 buildTypeValue.setText(""); // Value for this is set during run time //$NON-NLS-1$ |
|
134 buildTypeValue.setLayoutData(new GridData(GridData.BEGINNING)); |
|
135 buildTypeValue.addFocusListener(this); |
|
136 |
|
137 componentViewerAsS60Table = createComponentTableViewer(c); |
|
138 componentViewer = componentViewerAsS60Table.getHostingViewer(); |
|
139 componentViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
140 contentProvider = new SelectComponentWizardPageContentProvider(this); |
|
141 componentViewer.setContentProvider(contentProvider); |
|
142 componentViewer.setLabelProvider(new SelectComponentWizardPageLabelProvider()); |
|
143 componentViewer.setInput(contentProvider); |
|
144 componentViewer.addSelectionChangedListener(new SelectComponentWizardPageTableViewerSelectionChangedListener(this)); |
|
145 componentViewer.addDoubleClickListener(new SelectComponentWizardPageTableViewerDoubleClickListener(this)); |
|
146 componentViewer.setSorter(new ComponentTableViewerSorter()); |
|
147 componentViewer.getTable().addFocusListener(this); |
|
148 |
|
149 //Add check box and label for SIS components if this is a SIS wizard |
|
150 final ISelectSDKWizard wiz = (ISelectSDKWizard) getWizard(); |
|
151 if (wiz.getSettings().isInSISFileAnalysisMode()) { |
|
152 |
|
153 Composite cSIS = new Composite(c, SWT.NONE); |
|
154 |
|
155 int colsSIS = 2; |
|
156 GridLayout gdlSIS = new GridLayout(colsSIS, false); |
|
157 GridData gdSIS = new GridData(); |
|
158 cSIS.setLayout(gdlSIS); |
|
159 cSIS.setLayoutData(gdSIS); |
|
160 |
|
161 showSISCheckBox = new Button(cSIS, SWT.CHECK); |
|
162 showSISCheckBox.setLayoutData(new GridData()); |
|
163 // Add listener to button, to set components visible or not (Show only SIS components or not) |
|
164 showSISCheckBox.addSelectionListener(this); |
|
165 showSISCheckBox.setSelection(true); |
|
166 |
|
167 showSISTitle = new Text(cSIS, readOnlyLabelFieldStyleBits); |
|
168 showSISTitle.setText(Messages.getString("SelectComponentWizardPage.ShowOnlySISFiles_Msg")); //$NON-NLS-1$ |
|
169 showSISTitle.setLayoutData(new GridData()); |
|
170 } |
|
171 |
|
172 // Setting control for this page |
|
173 setControl(c); |
|
174 |
|
175 // Setting context help ID |
|
176 AppDepPlugin.setContextSensitiveHelpID(getControl(), AppDepHelpContextIDs.APPDEP_WIZARD_PAGE_COMP_SELECT); |
|
177 } |
|
178 |
|
179 /** |
|
180 * Creates new composite object using GridLayout. |
|
181 * @param parent parent composite |
|
182 * @param style Style bits for the composite. |
|
183 * @param cols column count |
|
184 * @param gd grid data attached to composite |
|
185 * @return new composite object using GridLayout. |
|
186 */ |
|
187 private Composite createGridLayoutComposite(Composite parent, int style, int cols, GridData gd) { |
|
188 Composite c = new Composite(parent, style); |
|
189 GridLayout gdl = new GridLayout(cols, false); |
|
190 c.setLayout(gdl); |
|
191 c.setLayoutData(gd); |
|
192 |
|
193 return c; |
|
194 } |
|
195 |
|
196 /** |
|
197 * Creates viewer component for showing selected SIS files. |
|
198 * @param parent Parent composite for the created composite. |
|
199 * @return New <code>S60ToolsTable</code> object instance. |
|
200 */ |
|
201 protected S60ToolsTable createComponentTableViewer(Composite parent) { |
|
202 |
|
203 ArrayList<S60ToolsTableColumnData> columnDataArr = new ArrayList<S60ToolsTableColumnData>(); |
|
204 |
|
205 // |
|
206 // NOTE: Column indices must start from zero (0) and |
|
207 // the columns must be added in ascending numeric |
|
208 // order. |
|
209 // |
|
210 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("SelectComponentWizardPage.Name_ColumnText"), //$NON-NLS-1$ |
|
211 200, |
|
212 ComponentListNode.NAME_COLUMN_INDEX, |
|
213 ComponentTableViewerSorter.CRITERIA_NAME, |
|
214 true)); |
|
215 |
|
216 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("SelectComponentWizardPage.Target_ColumnText"), //$NON-NLS-1$ |
|
217 60, |
|
218 ComponentListNode.TARGET_TYPE_COLUMN_INDEX, |
|
219 ComponentTableViewerSorter.CRITERIA_TARGET_TYPE, |
|
220 SWT.CENTER)); |
|
221 |
|
222 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("SelectComponentWizardPage.DateModified_ColumnText"), //$NON-NLS-1$ |
|
223 120, |
|
224 ComponentListNode.DATE_CACHED_COLUMN_INDEX, |
|
225 ComponentTableViewerSorter.CRITERIA_DATE_CACHED)); |
|
226 |
|
227 S60ToolsTableColumnData[] arr |
|
228 = columnDataArr.toArray( |
|
229 new S60ToolsTableColumnData[0]); |
|
230 |
|
231 int showItemCountInColumn = 0; |
|
232 S60ToolsTable tbl = S60ToolsTableFactory.create(parent, arr, showItemCountInColumn); |
|
233 |
|
234 TableViewer tblViewer = new TableViewer(tbl.getTableInstance()); |
|
235 tbl.setHostingViewer(tblViewer); |
|
236 |
|
237 return tbl; |
|
238 } |
|
239 |
|
240 /** |
|
241 * Refreshes wizard page components. |
|
242 */ |
|
243 public void refresh() { |
|
244 //Updating build type value field if it is changed |
|
245 String currBuildType = buildTypeValue.getText(); |
|
246 SelectSDKWizard wizard = (SelectSDKWizard) getWizard(); |
|
247 String buildTypedialogSetting = wizard.getDialogSetting(SelectSDKWizard.BUILD_TYPE_DESCR_DLG_SETTING_KEY); |
|
248 if(!currBuildType.equals(buildTypedialogSetting)){ |
|
249 buildTypeValue.setText(buildTypedialogSetting); |
|
250 buildTypeValue.pack(); |
|
251 } |
|
252 // Refreshing controls |
|
253 componentViewer.refresh(); |
|
254 componentViewerAsS60Table.refreshHostingViewer(contentProvider.getElementCount()); |
|
255 } |
|
256 |
|
257 /* (non-Javadoc) |
|
258 * @see com.nokia.s60tools.appdep.ui.wizards.S60ToolsWizardPage#setInitialFocus() |
|
259 */ |
|
260 public void setInitialFocus(){ |
|
261 // Clearing search text field |
|
262 searchField.setText(""); //$NON-NLS-1$ |
|
263 // Informing about duplicate components if showDuplicateComponentInfo is set. |
|
264 informUserAboutDuplicateComponentsIfExists(); |
|
265 searchField.setFocus(); |
|
266 } |
|
267 |
|
268 /** |
|
269 * Checks and informs user with dialog if there are duplicate components |
|
270 */ |
|
271 private void informUserAboutDuplicateComponentsIfExists() { |
|
272 // Only showing message if wanted and there is reason for it because of duplicate components |
|
273 if(showDuplicateComponentInfo && duplicateComponentList.size() > 0){ |
|
274 Shell sh = AppDepPlugin.getCurrentlyActiveWbWindowShell(); |
|
275 |
|
276 String listBoxContentMsg = Messages.getString("SelectComponentWizardPage.Duplicate_Components_InfoMsg_Header") + "\n";//$NON-NLS-1$ //$NON-NLS-2$ |
|
277 |
|
278 for (String cmpName : duplicateComponentList) { |
|
279 listBoxContentMsg += "\n- " + cmpName; //$NON-NLS-1$ |
|
280 } |
|
281 |
|
282 listBoxContentMsg += "\n\n" + Messages.getString("SelectComponentWizardPage.Duplicate_Components_InfoMsg_Footer");//$NON-NLS-1$ //$NON-NLS-2$ |
|
283 |
|
284 String textAboveListBoxMessagesStr = Messages.getString("SelectComponentWizardPage.Duplicate_Components_WarningMsg"); //$NON-NLS-1$ |
|
285 |
|
286 String dialogTitle = ProductInfoRegistry.getProductName(); //$NON-NLS-1$ |
|
287 S60ToolsListBoxDialog mbox = new S60ToolsListBoxDialog(sh, |
|
288 dialogTitle, |
|
289 listBoxContentMsg, |
|
290 false, // not resizable |
|
291 true, // has vertical scroll bar |
|
292 true, // has horizontal scroll bar |
|
293 DUPLICATE_COMP_DLG_WIDTH, // default width |
|
294 DUPLICATE_COMP_DLG_HEIGHT, // default height |
|
295 false, //No Cancel button |
|
296 textAboveListBoxMessagesStr |
|
297 ); |
|
298 mbox.create(); |
|
299 mbox.open(); |
|
300 } |
|
301 } |
|
302 |
|
303 /* (non-Javadoc) |
|
304 * @see com.nokia.s60tools.ui.wizards.S60ToolsWizardPage#recalculateButtonStates() |
|
305 */ |
|
306 public void recalculateButtonStates() { |
|
307 ISelection selection = componentViewer.getSelection(); |
|
308 Object obj = ((IStructuredSelection)selection).getFirstElement(); |
|
309 |
|
310 ISelectSDKWizard wiz = (ISelectSDKWizard) getWizard(); |
|
311 |
|
312 if(obj == null){ |
|
313 wiz.updateAnalyzedComponentSelection(null, null); |
|
314 wiz.disableCanFinish(); |
|
315 return; |
|
316 } |
|
317 |
|
318 setMessage(Messages.getString("SelectComponentWizardPage.OnFinish_User_InfoMessage")); //$NON-NLS-1$ |
|
319 setErrorMessage(null); |
|
320 ComponentListNode compListNodeObj = (ComponentListNode) obj; |
|
321 wiz.updateAnalyzedComponentSelection(compListNodeObj.toString(), compListNodeObj.getBuildTargetType()); |
|
322 wiz.enableCanFinish(ISelectSDKWizard.FINISH_COMPONENT_SELECTED); |
|
323 } |
|
324 |
|
325 /* (non-Javadoc) |
|
326 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) |
|
327 */ |
|
328 public void modifyText(ModifyEvent event) { |
|
329 if(event.widget.equals(searchField)){ |
|
330 contentProvider.setFilter(searchField.getText());; |
|
331 refresh(); |
|
332 } |
|
333 |
|
334 } |
|
335 |
|
336 /* (non-Javadoc) |
|
337 * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent) |
|
338 */ |
|
339 public void focusGained(FocusEvent e) { |
|
340 Widget w = e.widget; |
|
341 if(w.equals(searchFieldTitle)){ |
|
342 searchField.setFocus(); |
|
343 } |
|
344 else if(w.equals(buildTypeTitle) || w.equals(buildTypeValue)){ |
|
345 componentViewer.getTable().setFocus(); |
|
346 } |
|
347 } |
|
348 |
|
349 /* (non-Javadoc) |
|
350 * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent) |
|
351 */ |
|
352 public void focusLost(FocusEvent e) { |
|
353 // No need to do anything |
|
354 } |
|
355 |
|
356 /** |
|
357 * Gets the items currently visible in the table viewer's table |
|
358 * and selects the first item that is visible in the table. |
|
359 */ |
|
360 public void selectFirstVisibleComponentFromList(){ |
|
361 Table table = componentViewer.getTable(); |
|
362 TableItem[] items = table.getItems(); |
|
363 if(items.length > 0){ |
|
364 table.setSelection(0); |
|
365 } |
|
366 recalculateButtonStates(); |
|
367 } |
|
368 |
|
369 /** |
|
370 * Gets data member used to store information about duplicate component instances. |
|
371 * @return Data member used to store information about duplicate component instances. |
|
372 */ |
|
373 public List<String> getDuplicateComponentListInstance() { |
|
374 return duplicateComponentList; |
|
375 } |
|
376 |
|
377 /** |
|
378 * Checks if only SIS components should be shown. |
|
379 * @return <code>true</code> If user has been selected "Show only components from SIS files" |
|
380 */ |
|
381 public boolean showOnlySISComponents() { |
|
382 final ISelectSDKWizard wiz = (ISelectSDKWizard) getWizard(); |
|
383 if (wiz.getSettings().isInSISFileAnalysisMode()) { |
|
384 return showSISCheckBox.getSelection(); |
|
385 } |
|
386 else{ |
|
387 return false; |
|
388 } |
|
389 } |
|
390 |
|
391 /* (non-Javadoc) |
|
392 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
|
393 */ |
|
394 public void widgetDefaultSelected(SelectionEvent event) { |
|
395 //Not needed, but Interface implementation needs this. |
|
396 } |
|
397 |
|
398 /* Occurs when "Show only components from SIS file" -check box was clicked. |
|
399 * Occurrence will update component list. |
|
400 * (non-Javadoc) |
|
401 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
402 */ |
|
403 public void widgetSelected(SelectionEvent event) { |
|
404 contentProvider.setFilter(searchField.getText());; |
|
405 refresh(); |
|
406 } |
|
407 |
|
408 /** |
|
409 * Sets show duplicate component info flag. |
|
410 * This is reset to true in case user goes back in wizard. |
|
411 * @param showDuplicateComponentInfo <code>true</code> if we want to inform user about duplicate components. |
|
412 */ |
|
413 public void setShowDuplicateComponentInfo(boolean showDuplicateComponentInfo) { |
|
414 this.showDuplicateComponentInfo = showDuplicateComponentInfo; |
|
415 } |
|
416 |
|
417 } // class SelectComponentWizardPage |