|
1 /* |
|
2 * Copyright (c) 2009 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 package com.nokia.s60tools.appdep.ui.dialogs; |
|
19 |
|
20 import java.io.File; |
|
21 import java.util.ArrayList; |
|
22 import java.util.HashMap; |
|
23 import java.util.Iterator; |
|
24 import java.util.List; |
|
25 import java.util.Map; |
|
26 |
|
27 import org.eclipse.jface.dialogs.IDialogConstants; |
|
28 import org.eclipse.jface.dialogs.IMessageProvider; |
|
29 import org.eclipse.jface.dialogs.TitleAreaDialog; |
|
30 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
31 import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
32 import org.eclipse.jface.viewers.IStructuredSelection; |
|
33 import org.eclipse.jface.viewers.ITableLabelProvider; |
|
34 import org.eclipse.jface.viewers.LabelProvider; |
|
35 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
36 import org.eclipse.jface.viewers.TableViewer; |
|
37 import org.eclipse.jface.viewers.Viewer; |
|
38 import org.eclipse.swt.SWT; |
|
39 import org.eclipse.swt.events.SelectionEvent; |
|
40 import org.eclipse.swt.events.SelectionListener; |
|
41 import org.eclipse.swt.graphics.Image; |
|
42 import org.eclipse.swt.graphics.Point; |
|
43 import org.eclipse.swt.layout.GridData; |
|
44 import org.eclipse.swt.layout.GridLayout; |
|
45 import org.eclipse.swt.widgets.Button; |
|
46 import org.eclipse.swt.widgets.Composite; |
|
47 import org.eclipse.swt.widgets.Control; |
|
48 import org.eclipse.swt.widgets.FileDialog; |
|
49 import org.eclipse.swt.widgets.Shell; |
|
50 import org.eclipse.swt.widgets.Widget; |
|
51 |
|
52 import com.nokia.s60tools.appdep.AppDepHelpContextIDs; |
|
53 import com.nokia.s60tools.appdep.plugin.AppDepPlugin; |
|
54 import com.nokia.s60tools.appdep.resources.ImageKeys; |
|
55 import com.nokia.s60tools.appdep.resources.ImageResourceManager; |
|
56 import com.nokia.s60tools.appdep.resources.Messages; |
|
57 import com.nokia.s60tools.appdep.util.AppDepConsole; |
|
58 import com.nokia.s60tools.appdep.util.SISFileUtils; |
|
59 import com.nokia.s60tools.ui.S60ToolsTable; |
|
60 import com.nokia.s60tools.ui.S60ToolsTableColumnData; |
|
61 import com.nokia.s60tools.ui.S60ToolsTableFactory; |
|
62 import com.nokia.s60tools.ui.S60ToolsUIConstants; |
|
63 |
|
64 |
|
65 |
|
66 /** |
|
67 * Dialog for adding components from SIS file for analysis. |
|
68 */ |
|
69 public class AddSISFilesDialog extends TitleAreaDialog implements SelectionListener{ |
|
70 |
|
71 // |
|
72 // Private classes |
|
73 // |
|
74 |
|
75 /** |
|
76 * Label provider for table viewer component. |
|
77 */ |
|
78 class SISFilesViewerLabelProvider extends LabelProvider implements ITableLabelProvider{ |
|
79 |
|
80 /* (non-Javadoc) |
|
81 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) |
|
82 */ |
|
83 public Image getColumnImage(Object element, int columnIndex) { |
|
84 return null; // No images used |
|
85 } |
|
86 |
|
87 /* (non-Javadoc) |
|
88 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) |
|
89 */ |
|
90 public String getColumnText(Object element, int columnIndex) { |
|
91 String label = element.toString(); |
|
92 |
|
93 SISFileEntry entryData = (SISFileEntry) element; |
|
94 |
|
95 switch (columnIndex) { |
|
96 |
|
97 case SISFileEntry.NAME_COLUMN_INDEX: |
|
98 label = entryData.getFileName(); |
|
99 break; |
|
100 |
|
101 case SISFileEntry.LOCATION_COLUMN_INDEX: |
|
102 label = entryData.getLocation(); |
|
103 break; |
|
104 |
|
105 default: |
|
106 AppDepConsole.getInstance().println(Messages.getString("GeneralMessages.Unexpected_Column_Index_ErrMsg") + ": " + columnIndex, AppDepConsole.MSG_ERROR); //$NON-NLS-1$ //$NON-NLS-2$ |
|
107 break; |
|
108 } |
|
109 |
|
110 return label; |
|
111 } |
|
112 |
|
113 } |
|
114 |
|
115 // |
|
116 // Private constants |
|
117 // |
|
118 |
|
119 /** |
|
120 * Columns in the container area. |
|
121 */ |
|
122 private static final int COLUMN_COUNT = 2; |
|
123 |
|
124 /** |
|
125 * Dialog width. |
|
126 */ |
|
127 private static final int DIALOG_WIDTH = 425; |
|
128 |
|
129 /** |
|
130 * Dialog height. |
|
131 */ |
|
132 private static final int DIALOG_HEIGHT = 425; |
|
133 |
|
134 /** |
|
135 * Percentage as decimal number how much table viewer is taking space hirizontally. |
|
136 */ |
|
137 private static final double TABLE_VIEWER_WIDTH_PERCENTAGE = 0.8; |
|
138 |
|
139 /** |
|
140 * Default guiding message shown to the user in add new mode. |
|
141 */ |
|
142 private static final String DEFAULT_MESSAGE = Messages.getString("AddSISFilesDialog.Default_InfoMessage"); //$NON-NLS-1$ |
|
143 |
|
144 /** |
|
145 * Complete message shown to the user in add new mode. |
|
146 */ |
|
147 private static final String COMPLETE_MESSAGE = Messages.getString("AddSISFilesDialog.Complete_InfoMessage"); //$NON-NLS-1$ |
|
148 |
|
149 // |
|
150 // Member data |
|
151 // |
|
152 |
|
153 /** |
|
154 * Flag used to make sure that create() and open() are called in correct order. |
|
155 */ |
|
156 private boolean isCreateCalled = false; |
|
157 |
|
158 /** |
|
159 * Stores the currently selected SIS file entries. |
|
160 */ |
|
161 Map<String, SISFileEntry> sisFileEntries; |
|
162 |
|
163 // |
|
164 // UI Controls |
|
165 // |
|
166 |
|
167 /** |
|
168 * Container area for individual fields for the user for entering information. |
|
169 */ |
|
170 private Composite container; |
|
171 |
|
172 /** |
|
173 * Reference to OK button that can be disabled/enabled |
|
174 * due to information entered.. |
|
175 */ |
|
176 private Button okActionBtn; |
|
177 |
|
178 /** |
|
179 * Button for opening file dialog for selecting SIS file(s). |
|
180 */ |
|
181 private Button addButton; |
|
182 |
|
183 /** |
|
184 * Button for removing currently selected SIS file from table viewer, |
|
185 */ |
|
186 private Button removeButton; |
|
187 |
|
188 /** |
|
189 * Button for removing all SIS files from table viewer, |
|
190 */ |
|
191 private Button removeAllButton; |
|
192 |
|
193 /** |
|
194 * Viewer showing currently selected SIS file entries. |
|
195 */ |
|
196 private TableViewer sisFilesViewer; |
|
197 |
|
198 |
|
199 /** |
|
200 * Constructor. Used to open dialog in order to add new entry. |
|
201 * @param parentShell Parent shell for the dialog. |
|
202 */ |
|
203 public AddSISFilesDialog(Shell parentShell) { |
|
204 super(parentShell); |
|
205 sisFileEntries = new HashMap<String, SISFileEntry>(); |
|
206 // Setting banner image |
|
207 String bannerImage = ImageKeys.WIZARD_BANNER; |
|
208 setTitleImage(ImageResourceManager.getImage(bannerImage)); |
|
209 } |
|
210 |
|
211 /* (non-Javadoc) |
|
212 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
|
213 */ |
|
214 protected void createButtonsForButtonBar(Composite parent) { |
|
215 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, |
|
216 true); |
|
217 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, |
|
218 true); |
|
219 okActionBtn = getButton(IDialogConstants.OK_ID); |
|
220 disableOk(); |
|
221 } |
|
222 |
|
223 /* (non-Javadoc) |
|
224 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) |
|
225 */ |
|
226 protected void configureShell(Shell shell) { |
|
227 super.configureShell(shell); |
|
228 shell.setText(Messages.getString("AddSISFilesDialog.DialogTitleText")); //$NON-NLS-1$ |
|
229 } |
|
230 |
|
231 /* (non-Javadoc) |
|
232 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
|
233 */ |
|
234 protected Control createDialogArea(Composite parent) { |
|
235 |
|
236 Composite dialogAreaComposite = (Composite) super.createDialogArea(parent); |
|
237 |
|
238 // |
|
239 // Creating container and layout for it |
|
240 // |
|
241 container = new Composite(dialogAreaComposite, SWT.NONE); |
|
242 GridLayout gdl = new GridLayout(COLUMN_COUNT, false); |
|
243 // Settings margins according Carbide branding guideline |
|
244 gdl.marginLeft = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
245 gdl.marginRight = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
246 gdl.marginTop = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
247 gdl.marginBottom = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
248 container.setLayout(gdl); |
|
249 container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
250 |
|
251 // |
|
252 // Creating table viewer for showing SIS file entries |
|
253 // |
|
254 |
|
255 sisFilesViewer = createSISFilesTableViewer(container); |
|
256 GridData sisFilesViewerGd = new GridData(GridData.FILL_BOTH); |
|
257 // Spanning as many rows as there are actions buttons on the right |
|
258 sisFilesViewerGd.verticalSpan = 3; |
|
259 sisFilesViewerGd.widthHint = (int) (TABLE_VIEWER_WIDTH_PERCENTAGE * DIALOG_WIDTH); |
|
260 sisFilesViewer.getControl().setLayoutData(sisFilesViewerGd); |
|
261 sisFilesViewer.setSorter(new SISFileEntryTableViewerSorter()); |
|
262 // Adding selection change listener |
|
263 sisFilesViewer.addSelectionChangedListener(new ISelectionChangedListener(){ |
|
264 |
|
265 /* (non-Javadoc) |
|
266 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
|
267 */ |
|
268 public void selectionChanged(SelectionChangedEvent event) { |
|
269 IStructuredSelection selection = (IStructuredSelection) event.getSelection(); |
|
270 // Just settings remove button enable/disable state based on the selection state |
|
271 if(selection != null && selection.getFirstElement() != null){ |
|
272 removeButton.setEnabled(true); |
|
273 } |
|
274 else{ |
|
275 removeButton.setEnabled(false); |
|
276 } |
|
277 } |
|
278 |
|
279 }); |
|
280 |
|
281 // |
|
282 // Creating buttons |
|
283 // |
|
284 |
|
285 int buttonGridDataStyleBits = GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_BEGINNING; |
|
286 addButton = createButtonControl(Messages.getString("AddSISFilesDialog.Add_BtnCaptionText"), true, new GridData(buttonGridDataStyleBits)); //$NON-NLS-1$ |
|
287 removeButton = createButtonControl(Messages.getString("AddSISFilesDialog.Remove_BtnCaptionText"), false, new GridData(buttonGridDataStyleBits)); //$NON-NLS-1$ |
|
288 removeAllButton = createButtonControl(Messages.getString("AddSISFilesDialog.RemoveAll_BtnCaptionText"), false, new GridData(buttonGridDataStyleBits)); //$NON-NLS-1$ |
|
289 |
|
290 // |
|
291 // Setting providers for table viewer |
|
292 // |
|
293 |
|
294 // Creating content provider |
|
295 IStructuredContentProvider sisFilesViewerContentProvider = new IStructuredContentProvider(){ |
|
296 |
|
297 /* (non-Javadoc) |
|
298 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
299 */ |
|
300 public Object[] getElements(Object inputElement) { |
|
301 return sisFileEntries.values().toArray(); |
|
302 } |
|
303 |
|
304 /* (non-Javadoc) |
|
305 * @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
306 */ |
|
307 public void dispose() { |
|
308 // Not needed but needs to be implemented |
|
309 } |
|
310 |
|
311 public void inputChanged(Viewer viewer, Object oldInput, |
|
312 Object newInput) { |
|
313 // Not used but needs to be implemented |
|
314 } |
|
315 |
|
316 }; |
|
317 |
|
318 // Setting content provider |
|
319 sisFilesViewer.setContentProvider(sisFilesViewerContentProvider); |
|
320 sisFilesViewer.setInput(sisFilesViewerContentProvider); |
|
321 |
|
322 // Label provider |
|
323 sisFilesViewer.setLabelProvider(new SISFilesViewerLabelProvider()); |
|
324 |
|
325 // Setting context-sensitive help ID |
|
326 AppDepPlugin.setContextSensitiveHelpID(dialogAreaComposite, AppDepHelpContextIDs.APPDEP_DIALOG_ADD_SIS_FILES); |
|
327 |
|
328 // Dialog are composite ready |
|
329 return dialogAreaComposite; |
|
330 } |
|
331 |
|
332 /** |
|
333 * Creates button with given label text. |
|
334 * @param labelText Label for the button. |
|
335 * @param isEnabled Set to <code>true</code> if button is enabled initially, otherwise <code>false</code>. |
|
336 * @param gridData Grid data to be applied to the button. |
|
337 * @return new instance of Button object. |
|
338 */ |
|
339 private Button createButtonControl(String labelText, boolean isEnabled, GridData gridData) { |
|
340 Button btn = new Button(container, SWT.PUSH ); |
|
341 btn.setText(labelText); |
|
342 btn.addSelectionListener(this); |
|
343 // What room is left horizontally from table viewer is given for buttons |
|
344 gridData.widthHint = (int) (0.95 * (1-TABLE_VIEWER_WIDTH_PERCENTAGE) * DIALOG_WIDTH); |
|
345 btn.setLayoutData(gridData); |
|
346 btn.setEnabled(isEnabled); |
|
347 return btn; |
|
348 } |
|
349 |
|
350 /* (non-Javadoc) |
|
351 * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize() |
|
352 */ |
|
353 protected Point getInitialSize() { |
|
354 return new Point(DIALOG_WIDTH, DIALOG_HEIGHT); |
|
355 } |
|
356 |
|
357 /* (non-Javadoc) |
|
358 * @see org.eclipse.jface.dialogs.Dialog#create() |
|
359 */ |
|
360 public void create() { |
|
361 super.create(); |
|
362 // Currently just does creation by super call and stores status |
|
363 isCreateCalled = true; |
|
364 } |
|
365 |
|
366 /* (non-Javadoc) |
|
367 * @see org.eclipse.jface.window.Window#open() |
|
368 */ |
|
369 public int open(){ |
|
370 try { |
|
371 // Making sure that create is called |
|
372 if(!isCreateCalled){ |
|
373 create(); |
|
374 } |
|
375 showDefaultMessage(); |
|
376 } catch (Exception e) { |
|
377 e.printStackTrace(); |
|
378 } |
|
379 return super.open(); |
|
380 } |
|
381 |
|
382 /** |
|
383 * Resets possible error messages and show the default message. |
|
384 */ |
|
385 private void showDefaultMessage() { |
|
386 setErrorMessage(null); |
|
387 setMessage(DEFAULT_MESSAGE, IMessageProvider.INFORMATION); |
|
388 } |
|
389 |
|
390 /** |
|
391 * Informs user that parameters are valid and dialog can be |
|
392 * dismissed with OK button.. |
|
393 */ |
|
394 private void setCompleteOkMessage() { |
|
395 setErrorMessage(null); |
|
396 setMessage(COMPLETE_MESSAGE, IMessageProvider.INFORMATION); |
|
397 } |
|
398 |
|
399 /** |
|
400 * Disables OK button. |
|
401 * This method is guarded against call during construction |
|
402 * when button row has not been created yet and widget is <code>null</code>. |
|
403 */ |
|
404 private void disableOk() { |
|
405 if(okActionBtn != null){ |
|
406 okActionBtn.setEnabled(false); |
|
407 } |
|
408 } |
|
409 |
|
410 /** |
|
411 * Enables OK button. |
|
412 * This method is guarded against call during construction |
|
413 * when button row has not been created yet and widget is <code>null</code>. |
|
414 */ |
|
415 private void enableOk() { |
|
416 if(okActionBtn != null){ |
|
417 okActionBtn.setEnabled(true); |
|
418 } |
|
419 } |
|
420 |
|
421 /* (non-Javadoc) |
|
422 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
|
423 */ |
|
424 public void widgetDefaultSelected(SelectionEvent e) { |
|
425 // Not needed in here, but needs to be implemented |
|
426 } |
|
427 |
|
428 /* (non-Javadoc) |
|
429 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
430 */ |
|
431 public void widgetSelected(SelectionEvent e) { |
|
432 Widget widget = e.widget; |
|
433 |
|
434 if(widget.equals(addButton)){ |
|
435 queryAndAddNewEntries(); |
|
436 } |
|
437 else if(widget.equals(removeAllButton)){ |
|
438 removeAllEntries(); |
|
439 } |
|
440 else if(widget.equals(removeButton)){ |
|
441 // We have made sure by enabling/disabling button in selection |
|
442 // changed listener code that we have valid selection. |
|
443 removeSelectedEntries(); |
|
444 } |
|
445 } |
|
446 |
|
447 /** |
|
448 * Launches SIS file selection and adds the selected and valid |
|
449 * SIS files to the entries. |
|
450 */ |
|
451 private void queryAndAddNewEntries() { |
|
452 List<String> illegalSISfilesList = new ArrayList<String>(); |
|
453 String[] selectedSISFiles = invokeAddSISFilesDialog(getShell()); |
|
454 for (int i = 0; i < selectedSISFiles.length; i++) { |
|
455 String absolutePathFilename = selectedSISFiles[i]; |
|
456 if(checkSISFileValidity(absolutePathFilename, illegalSISfilesList)){ |
|
457 addEntry(absolutePathFilename); |
|
458 } |
|
459 } |
|
460 // Report user about the illegal SIS files that are not added to the table viewer |
|
461 notifyIllegalSISFile(illegalSISfilesList); |
|
462 } |
|
463 |
|
464 /** |
|
465 * Shows an error dialog to user if there are any items |
|
466 * in given list of illegal SIS files. |
|
467 * @param illegalSISfilesList List of illegal SIS files. |
|
468 */ |
|
469 private void notifyIllegalSISFile(List<String> illegalSISfilesList) { |
|
470 if(illegalSISfilesList.size() > 0){ |
|
471 String errMsg = Messages.getString("AddSISFilesDialog.NotSupportedSISFileDialog_ErrMsg"); //$NON-NLS-1$ |
|
472 for (int i = 0; i < illegalSISfilesList.size(); i++) { |
|
473 String fileName = illegalSISfilesList.get(i); |
|
474 errMsg = errMsg + "\n" + fileName; //$NON-NLS-1$ |
|
475 } |
|
476 AppDepMessageBox msgBox = new AppDepMessageBox(getShell(), errMsg, SWT.ICON_ERROR); |
|
477 msgBox.open(); |
|
478 } |
|
479 } |
|
480 |
|
481 /** |
|
482 * Checks validity of SIS file and in case file is not valid |
|
483 * adds it into list of illegal SIS files passed as parameter. |
|
484 * @param absolutePathFilename absolute file name to a SIS file. |
|
485 * @param illegalSISfilesList list of illegal SIS files |
|
486 * @return <code>true</code> if file was a valid and supported SIS file. |
|
487 */ |
|
488 private boolean checkSISFileValidity(String absolutePathFilename, List<String> illegalSISfilesList) { |
|
489 boolean valid_9x_SISFile = SISFileUtils.isValid_9x_SISFile(absolutePathFilename); |
|
490 if(!valid_9x_SISFile){ |
|
491 illegalSISfilesList.add(absolutePathFilename); |
|
492 } |
|
493 return valid_9x_SISFile; |
|
494 } |
|
495 |
|
496 /** |
|
497 * Removes the currently selected entries. |
|
498 * Precondition for calling this method to make sure |
|
499 * that a valid selection exists. |
|
500 */ |
|
501 private void removeSelectedEntries() { |
|
502 IStructuredSelection selection = (IStructuredSelection) sisFilesViewer.getSelection(); |
|
503 for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { |
|
504 SISFileEntry fileEntry = (SISFileEntry) iterator.next(); |
|
505 sisFileEntries.remove(fileEntry.getFullPathFileName()); |
|
506 } |
|
507 notifyEntriesModified(); |
|
508 } |
|
509 |
|
510 /** |
|
511 * Removes all entries from SIS files table viewer. |
|
512 */ |
|
513 private void removeAllEntries() { |
|
514 sisFileEntries.clear(); |
|
515 notifyEntriesModified(); |
|
516 } |
|
517 |
|
518 /** |
|
519 * Adds SIS file entry and update buttons statuses. |
|
520 * @param absolutePathFilename absolute pathname to SIS file to be added. |
|
521 */ |
|
522 private void addEntry(String absolutePathFilename) { |
|
523 File file = new File(absolutePathFilename); |
|
524 String location = file.getParentFile().getAbsolutePath(); |
|
525 String sisFileName = file.getName(); |
|
526 SISFileEntry fileEntry = new SISFileEntry(location, sisFileName); |
|
527 sisFileEntries.put(fileEntry.getFullPathFileName(), fileEntry); |
|
528 notifyEntriesModified(); |
|
529 } |
|
530 |
|
531 /** |
|
532 * Updates buttons statuses according the current |
|
533 * status of table entry viewer contents. |
|
534 */ |
|
535 private void notifyEntriesModified() { |
|
536 if(sisFileEntries.size() > 0){ |
|
537 removeAllButton.setEnabled(true); |
|
538 enableOk(); |
|
539 setCompleteOkMessage(); |
|
540 } |
|
541 else{ |
|
542 removeAllButton.setEnabled(false); |
|
543 showDefaultMessage(); |
|
544 } |
|
545 sisFilesViewer.refresh(); |
|
546 } |
|
547 |
|
548 /** |
|
549 * Creates viewer component for showing selected SIS files. |
|
550 * @param parent Parent composite for the created composite. |
|
551 * @return New <code>TableViewer</code> object instance. |
|
552 */ |
|
553 protected TableViewer createSISFilesTableViewer(Composite parent) { |
|
554 |
|
555 ArrayList<S60ToolsTableColumnData> columnDataArr = new ArrayList<S60ToolsTableColumnData>(); |
|
556 |
|
557 // |
|
558 // NOTE: Column indices must start from zero (0) and |
|
559 // the columns must be added in ascending numeric |
|
560 // order. |
|
561 // |
|
562 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("AddSISFilesDialog.Name_ColumnTitleText"), //$NON-NLS-1$ |
|
563 140, |
|
564 SISFileEntry.NAME_COLUMN_INDEX, |
|
565 SISFileEntryTableViewerSorter.CRITERIA_NAME)); |
|
566 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("AddSISFilesDialog.Location_ColumnTitleText"), //$NON-NLS-1$ |
|
567 140, |
|
568 SISFileEntry.LOCATION_COLUMN_INDEX, |
|
569 SISFileEntryTableViewerSorter.CRITERIA_LOCATION)); |
|
570 |
|
571 S60ToolsTableColumnData[] arr |
|
572 = columnDataArr.toArray( |
|
573 new S60ToolsTableColumnData[0]); |
|
574 |
|
575 S60ToolsTable tbl = S60ToolsTableFactory.create(parent, arr); |
|
576 |
|
577 TableViewer tblViewer = new TableViewer(tbl.getTableInstance()); |
|
578 tbl.setHostingViewer(tblViewer); |
|
579 |
|
580 return tblViewer; |
|
581 } |
|
582 |
|
583 /** |
|
584 * Opens the Open File(s) dialog. |
|
585 * @param sh parent shell |
|
586 * @return file name(s) selected, or <code>null</code> if canceled or errors occurs. |
|
587 */ |
|
588 public static String [] invokeAddSISFilesDialog(Shell sh){ |
|
589 //Open file dialog |
|
590 FileDialog fdia = new FileDialog(sh, SWT.MULTI); |
|
591 fdia.setText(Messages.getString("AddSISFilesDialog.SISFileBrowseDialog_TitleText")); //$NON-NLS-1$ |
|
592 String [] extensions = new String[] {"*.SIS", "*.SISX"}; //$NON-NLS-1$ //$NON-NLS-2$ |
|
593 fdia.setFilterExtensions(extensions); |
|
594 String file = fdia.open(); |
|
595 //If there is at least one file selected |
|
596 if(file != null){ |
|
597 //get all selected file names |
|
598 String [] files = fdia.getFileNames(); |
|
599 String path = fdia.getFilterPath();//Path (dir) where file(s) are |
|
600 String [] filesWithPath = new String[files.length]; |
|
601 //Create absolute file paths <path>\<filename> |
|
602 for (int i = 0; i < files.length; i++) { |
|
603 filesWithPath[i] = path + File.separatorChar + files[i]; |
|
604 } |
|
605 return filesWithPath; |
|
606 } |
|
607 else{ |
|
608 //User has canceled the operation |
|
609 return null; |
|
610 } |
|
611 } |
|
612 |
|
613 /** |
|
614 * Returns currently selected SIS files as string array containing absolute path names. |
|
615 * @return currently selected SIS files. |
|
616 */ |
|
617 public String[] getSelectedSISFiles() { |
|
618 return sisFileEntries.keySet().toArray(new String[0]); |
|
619 } |
|
620 |
|
621 /** |
|
622 * Sets initial set of SIS file to be shown for the user. |
|
623 * Should be called before calling <code>open()</code> method. |
|
624 * @param initialSISFileSet initial file set to be shown for the user. |
|
625 */ |
|
626 public void setInitialSISFileSet(String[] initialSISFileSet) { |
|
627 if(initialSISFileSet != null && initialSISFileSet.length > 0){ |
|
628 enableOk(); // Enabling OK because there is some content available |
|
629 setCompleteOkMessage(); |
|
630 for (int i = 0; i < initialSISFileSet.length; i++) { |
|
631 String fileFullPathName = initialSISFileSet[i]; |
|
632 addEntry(fileFullPathName); |
|
633 } |
|
634 } |
|
635 } |
|
636 |
|
637 } |