|
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.views.listview; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 import org.eclipse.jface.action.Action; |
|
25 import org.eclipse.jface.action.IMenuListener; |
|
26 import org.eclipse.jface.action.IMenuManager; |
|
27 import org.eclipse.jface.action.IToolBarManager; |
|
28 import org.eclipse.jface.action.MenuManager; |
|
29 import org.eclipse.jface.action.Separator; |
|
30 import org.eclipse.jface.viewers.DoubleClickEvent; |
|
31 import org.eclipse.jface.viewers.IDoubleClickListener; |
|
32 import org.eclipse.jface.viewers.ISelection; |
|
33 import org.eclipse.jface.viewers.IStructuredSelection; |
|
34 import org.eclipse.jface.viewers.TableViewer; |
|
35 import org.eclipse.swt.SWT; |
|
36 import org.eclipse.swt.custom.SashForm; |
|
37 import org.eclipse.swt.widgets.Composite; |
|
38 import org.eclipse.swt.widgets.Menu; |
|
39 import org.eclipse.ui.IActionBars; |
|
40 import org.eclipse.ui.IViewPart; |
|
41 import org.eclipse.ui.IViewReference; |
|
42 import org.eclipse.ui.IWorkbenchActionConstants; |
|
43 import org.eclipse.ui.IWorkbenchPage; |
|
44 import org.eclipse.ui.PartInitException; |
|
45 import org.eclipse.ui.part.ViewPart; |
|
46 |
|
47 import com.nokia.s60tools.appdep.AppDepHelpContextIDs; |
|
48 import com.nokia.s60tools.appdep.core.AppDepSettings; |
|
49 import com.nokia.s60tools.appdep.core.model.ComponentPropertiesData; |
|
50 import com.nokia.s60tools.appdep.plugin.AppDepPlugin; |
|
51 import com.nokia.s60tools.appdep.resources.Messages; |
|
52 import com.nokia.s60tools.appdep.ui.actions.ExportReportListViewAction; |
|
53 import com.nokia.s60tools.appdep.ui.actions.SelectAllFromTableViewerComponentListViewAction; |
|
54 import com.nokia.s60tools.appdep.ui.actions.SetNewRootComponentListViewAction; |
|
55 import com.nokia.s60tools.appdep.ui.utils.UiUtils; |
|
56 import com.nokia.s60tools.appdep.ui.views.main.MainView; |
|
57 import com.nokia.s60tools.ui.ICopyActionHandler; |
|
58 import com.nokia.s60tools.ui.S60ToolsTable; |
|
59 import com.nokia.s60tools.ui.S60ToolsTableColumnData; |
|
60 import com.nokia.s60tools.ui.S60ToolsTableFactory; |
|
61 import com.nokia.s60tools.ui.actions.CopyFromTableViewerAction; |
|
62 |
|
63 /** |
|
64 * This class comprises the IsUsed By -component List view of the tool. |
|
65 */ |
|
66 public class ListView extends ViewPart { |
|
67 |
|
68 /** |
|
69 * We can get view ID at runtime once the view is instantiated, but we |
|
70 * also need static access to ID in order to be able to invoke the view. |
|
71 */ |
|
72 public static final String ID = "com.nokia.s60tools.appdep.ui.views.listview.ListView"; //$NON-NLS-1$ |
|
73 |
|
74 // |
|
75 // Controls and related classes (providers etc.) |
|
76 // |
|
77 |
|
78 private SashForm listViewSashForm; |
|
79 |
|
80 private TableViewer listItemsViewer; |
|
81 private Action actionCompPropertiesDataCopy; |
|
82 private Action actionSelectAll; |
|
83 private Action actionSetAsNewRoot; |
|
84 private ExportReportListViewAction actionExportReport; |
|
85 private ListViewContentProvider listViewContentProvider; |
|
86 |
|
87 /** |
|
88 * Name of the component to query 'Is Use By' relationships for. |
|
89 */ |
|
90 private String componentName; |
|
91 |
|
92 /** |
|
93 * Name of the function to query 'Is Use By' relationships for. |
|
94 */ |
|
95 private String functionName; |
|
96 |
|
97 /** |
|
98 * The constructor. |
|
99 */ |
|
100 public ListView() { |
|
101 } |
|
102 |
|
103 /** |
|
104 * This is a callback that will allow us |
|
105 * to create the componentTreeViewer and initialize it. |
|
106 */ |
|
107 public void createPartControl(Composite parent) { |
|
108 |
|
109 // |
|
110 // Creating controls |
|
111 // |
|
112 |
|
113 // The left side contains component hierarchy tree view |
|
114 listViewSashForm = new SashForm(parent, SWT.HORIZONTAL); |
|
115 |
|
116 // List view viewer |
|
117 listItemsViewer = createListViewTableViewer(listViewSashForm); |
|
118 |
|
119 listViewContentProvider = new ListViewContentProvider(); |
|
120 listItemsViewer.setContentProvider(listViewContentProvider); |
|
121 listItemsViewer.setLabelProvider(new ListViewLabelProvider()); |
|
122 listItemsViewer.setInput(listViewContentProvider); |
|
123 listItemsViewer.setSorter(new ComponentListViewSorter()); |
|
124 listItemsViewer.addSelectionChangedListener(new ListViewSelectionChangedListener(this)); |
|
125 // On double-click setting clicked component as new root component |
|
126 listItemsViewer.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 IStructuredSelection sel = (IStructuredSelection) event.getSelection(); |
|
133 if(sel.size() == 1){ |
|
134 Object firstElement = sel.getFirstElement(); |
|
135 if(firstElement instanceof ComponentPropertiesData){ |
|
136 ComponentPropertiesData propData = (ComponentPropertiesData)firstElement; |
|
137 String selectedComponentName = propData.getFilename(); |
|
138 try { |
|
139 MainView view = MainView.getViewInstance(); |
|
140 UiUtils.setComponentAsNewRootInMainView(view , selectedComponentName, propData.getTargetPlatform()); |
|
141 } catch (PartInitException e) { |
|
142 e.printStackTrace(); |
|
143 } |
|
144 } |
|
145 } |
|
146 } // doubleClick |
|
147 |
|
148 } // new IDoubleClickListener() |
|
149 ); |
|
150 |
|
151 // |
|
152 // Doing other initializations |
|
153 // |
|
154 createActions(); |
|
155 hookContextMenu(); |
|
156 contributeToActionBars(); |
|
157 |
|
158 // Updating initial state of menu actions |
|
159 updateViewActionEnabledStates(); |
|
160 |
|
161 // Setting context help IDs |
|
162 AppDepPlugin.setContextSensitiveHelpID(listItemsViewer.getControl(), |
|
163 AppDepHelpContextIDs.APPDEP_COMPONENT_LIST_VIEW); |
|
164 } |
|
165 |
|
166 /** |
|
167 * Creates table viewer for import functions tab item. |
|
168 * @return New <code>TableViewer</code> object instance. |
|
169 */ |
|
170 private TableViewer createListViewTableViewer(Composite parent) { |
|
171 |
|
172 ArrayList<S60ToolsTableColumnData> columnDataArr = new ArrayList<S60ToolsTableColumnData>(); |
|
173 |
|
174 // |
|
175 // NOTE: Column indeces must start from zero (0) and |
|
176 // the columns must be added in ascending numeric |
|
177 // order. |
|
178 // |
|
179 |
|
180 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.Name_TableColumnTitle"), //$NON-NLS-1$ |
|
181 150, |
|
182 ComponentPropertiesData.NAME_COLUMN_INDEX, |
|
183 ComponentListViewSorter.CRITERIA_NAME)); |
|
184 |
|
185 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.BinaryFormat_TableColumnTitle"), //$NON-NLS-1$ |
|
186 150, |
|
187 ComponentPropertiesData.BIN_FORMAT_COLUMN_INDEX, |
|
188 ComponentListViewSorter.CRITERIA_BIN_FORMAT)); |
|
189 |
|
190 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.UID1_TableColumnTitle"), //$NON-NLS-1$ |
|
191 80, |
|
192 ComponentPropertiesData.UID1_COLUMN_INDEX, |
|
193 ComponentListViewSorter.CRITERIA_UID1)); |
|
194 |
|
195 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.UID2_TableColumnTitle"), //$NON-NLS-1$ |
|
196 80, |
|
197 ComponentPropertiesData.UID2_COLUMN_INDEX, |
|
198 ComponentListViewSorter.CRITERIA_UID2)); |
|
199 |
|
200 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.UID3_TableColumnTitle"), //$NON-NLS-1$ |
|
201 80, |
|
202 ComponentPropertiesData.UID3_COLUMN_INDEX, |
|
203 ComponentListViewSorter.CRITERIA_UID3)); |
|
204 |
|
205 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.SecureId_TableColumnTitle"), //$NON-NLS-1$ |
|
206 80, |
|
207 ComponentPropertiesData.SECURE_ID_COLUMN_INDEX, |
|
208 ComponentListViewSorter.CRITERIA_SECURE_ID)); |
|
209 |
|
210 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.VendorID_TableColumnTitle"), //$NON-NLS-1$ |
|
211 80, |
|
212 ComponentPropertiesData.VENDOR_ID_COLUMN_INDEX, |
|
213 ComponentListViewSorter.CRITERIA_VENDOR_ID)); |
|
214 |
|
215 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.MinHeapSize_TableColumnTitle"), //$NON-NLS-1$ |
|
216 100, |
|
217 ComponentPropertiesData.MIN_HEAP_COLUMN_INDEX, |
|
218 ComponentListViewSorter.CRITERIA_MIN_HEAP)); |
|
219 |
|
220 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.MaxHeapSize_TableColumnTitle"), //$NON-NLS-1$ |
|
221 100, |
|
222 ComponentPropertiesData.MAX_HEAP_COLUMN_INDEX, |
|
223 ComponentListViewSorter.CRITERIA_MAX_HEAP)); |
|
224 |
|
225 columnDataArr.add(new S60ToolsTableColumnData(Messages.getString("ListView.StackSize_TableColumnTitle"), //$NON-NLS-1$ |
|
226 100, |
|
227 ComponentPropertiesData.STACK_SIZE_COLUMN_INDEX, |
|
228 ComponentListViewSorter.CRITERIA_STACK_SIZE)); |
|
229 |
|
230 S60ToolsTableColumnData[] arr |
|
231 = (S60ToolsTableColumnData[]) columnDataArr.toArray( |
|
232 new S60ToolsTableColumnData[0]); |
|
233 |
|
234 S60ToolsTable tbl = S60ToolsTableFactory.create(parent, arr); |
|
235 |
|
236 TableViewer tblViewer = new TableViewer(tbl.getTableInstance()); |
|
237 tbl.setHostingViewer(tblViewer); |
|
238 |
|
239 return tblViewer; |
|
240 } |
|
241 |
|
242 /** |
|
243 * Creating context menu. |
|
244 */ |
|
245 private void hookContextMenu() { |
|
246 MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
|
247 menuMgr.setRemoveAllWhenShown(true); |
|
248 menuMgr.addMenuListener(new IMenuListener() { |
|
249 public void menuAboutToShow(IMenuManager manager) { |
|
250 ListView.this.fillViewContextMenu(manager); |
|
251 } |
|
252 }); |
|
253 Menu menu = menuMgr.createContextMenu(listItemsViewer.getControl()); |
|
254 listItemsViewer.getControl().setMenu(menu); |
|
255 getSite().registerContextMenu(menuMgr, listItemsViewer); |
|
256 } |
|
257 |
|
258 /** |
|
259 * Contributing items to view menu and toolbar. |
|
260 */ |
|
261 private void contributeToActionBars() { |
|
262 IActionBars bars = getViewSite().getActionBars(); |
|
263 fillViewPullDownMenu(bars.getMenuManager()); |
|
264 fillViewToolBar(bars.getToolBarManager()); |
|
265 } |
|
266 |
|
267 /** |
|
268 * Fills view menu. |
|
269 * @param manager Menu manager. |
|
270 */ |
|
271 private void fillViewPullDownMenu(IMenuManager manager) { |
|
272 } |
|
273 |
|
274 /** |
|
275 * Fills view's context menu. |
|
276 * @param manager Menu manager. |
|
277 */ |
|
278 private void fillViewContextMenu(IMenuManager manager) { |
|
279 manager.add(actionCompPropertiesDataCopy); |
|
280 manager.add(actionSelectAll); |
|
281 manager.add(new Separator()); |
|
282 manager.add(actionSetAsNewRoot); |
|
283 manager.add(actionExportReport); |
|
284 // Other plug-ins can contribute there actions here |
|
285 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
286 } |
|
287 |
|
288 /** |
|
289 * Fills view's toolbar. |
|
290 * @param manager Menu manager. |
|
291 */ |
|
292 private void fillViewToolBar(IToolBarManager manager) { |
|
293 } |
|
294 |
|
295 /** |
|
296 * Creating actions for the view. |
|
297 */ |
|
298 private void createActions() { |
|
299 |
|
300 ComponentPropertiesClipboardCopyHandler copyHandler = new ComponentPropertiesClipboardCopyHandler(); |
|
301 actionCompPropertiesDataCopy = new CopyFromTableViewerAction(listItemsViewer, |
|
302 new ICopyActionHandler[]{ copyHandler } |
|
303 ); |
|
304 actionSelectAll = new SelectAllFromTableViewerComponentListViewAction(this); |
|
305 actionSetAsNewRoot = new SetNewRootComponentListViewAction(this); |
|
306 actionExportReport = new ExportReportListViewAction(this); |
|
307 } |
|
308 |
|
309 /** |
|
310 * Passing the focus request to the listItemsViewer's control. |
|
311 */ |
|
312 public void setFocus() { |
|
313 listItemsViewer.getControl().setFocus(); |
|
314 } |
|
315 |
|
316 /** |
|
317 * Allows other classes to update content description. |
|
318 * @param newContentDescription New description. |
|
319 */ |
|
320 public void updateDescription(String newContentDescription){ |
|
321 setContentDescription(newContentDescription); |
|
322 IToolBarManager tbManager = getViewSite().getActionBars().getToolBarManager(); |
|
323 tbManager.update(true); |
|
324 } |
|
325 |
|
326 /** |
|
327 * Refreshes the view. |
|
328 */ |
|
329 public void refresh(){ |
|
330 listItemsViewer.refresh(); |
|
331 } |
|
332 |
|
333 /** |
|
334 * Returns currently selected element from list view. |
|
335 * @return Returns currently selected element or <code>null</code> |
|
336 * if there are no selection made. |
|
337 */ |
|
338 public Object getComponentListSelectedElement() { |
|
339 ISelection selection = listItemsViewer.getSelection(); |
|
340 Object obj = ((IStructuredSelection)selection).getFirstElement(); |
|
341 return obj; |
|
342 } |
|
343 |
|
344 /* (non-Javadoc) |
|
345 * @see org.eclipse.ui.part.WorkbenchPart#dispose() |
|
346 */ |
|
347 public void dispose() { |
|
348 super.dispose(); |
|
349 } |
|
350 |
|
351 /** |
|
352 * Sets input for the list view. |
|
353 * @param usingCompPropArrayList List of component properties data to set. |
|
354 */ |
|
355 public void setInput(List<ComponentPropertiesData> usingCompPropArrayList) { |
|
356 listItemsViewer.setInput(usingCompPropArrayList); |
|
357 actionExportReport.setIsUsedByData(usingCompPropArrayList); |
|
358 } |
|
359 |
|
360 /** |
|
361 * Gets component list viewer. |
|
362 * @return component list viewer. |
|
363 */ |
|
364 public TableViewer getComponentListViewer(){ |
|
365 return listItemsViewer; |
|
366 } |
|
367 |
|
368 /** |
|
369 * Sets name of the component that was searched for using components. |
|
370 * @param componentName Component name |
|
371 */ |
|
372 public void setComponentName(String componentName) { |
|
373 this.componentName = componentName; |
|
374 } |
|
375 |
|
376 /** |
|
377 * Gets name of the component that was searched for using components. |
|
378 * @return name of the component that was searched for using components. |
|
379 */ |
|
380 public String getComponentName() { |
|
381 return componentName; |
|
382 |
|
383 } |
|
384 |
|
385 /** |
|
386 * Enables to get reference of the main view |
|
387 * from the classes that do not actually |
|
388 * have reference to the main view instance. |
|
389 * @throws PartInitException |
|
390 */ |
|
391 private static ListView getViewInstance() throws PartInitException{ |
|
392 |
|
393 IWorkbenchPage page = AppDepPlugin.getCurrentlyActivePage(); |
|
394 |
|
395 IViewPart viewPart = null; |
|
396 |
|
397 IViewReference[] viewRefs = page.getViewReferences(); |
|
398 if(viewRefs == null){ |
|
399 return null; |
|
400 } |
|
401 for (int i = 0; i < viewRefs.length; i++) { |
|
402 IViewReference reference = viewRefs[i]; |
|
403 String id = reference.getId(); |
|
404 if(id.equalsIgnoreCase(ListView.ID)){ |
|
405 viewPart = reference.getView(true); |
|
406 } |
|
407 } |
|
408 if(viewPart == null){ |
|
409 return null; |
|
410 } |
|
411 return ((ListView) viewPart); |
|
412 } |
|
413 |
|
414 /** |
|
415 * Clears list view (By updating it with empty List). |
|
416 */ |
|
417 public static void clear(){ |
|
418 try { |
|
419 ListView view = getViewInstance(); |
|
420 if(view != null){ |
|
421 ArrayList<ComponentPropertiesData> emptyData = new ArrayList<ComponentPropertiesData>(); |
|
422 view.setInput(emptyData); |
|
423 } |
|
424 |
|
425 } catch (Exception e) { |
|
426 e.printStackTrace(); |
|
427 } |
|
428 } |
|
429 |
|
430 /** |
|
431 * Gets the name of the function that was searched for using components. |
|
432 * @return the name of the function that was searched for using components. |
|
433 */ |
|
434 public String getFunctionName() { |
|
435 return functionName; |
|
436 } |
|
437 |
|
438 /** |
|
439 * Sets the name of the function that was searched for using components. |
|
440 * @param functionName the functionName to set |
|
441 */ |
|
442 public void setFunctionName(String functionName) { |
|
443 this.functionName = functionName; |
|
444 } |
|
445 |
|
446 /** |
|
447 * Checks if the component list has currently any selections. |
|
448 * @return <code>true</code> if has, otherwise <code>false</code>. |
|
449 */ |
|
450 private boolean hasComponentListSelection() { |
|
451 int selectionCount = getListViewSelectionCount(); |
|
452 return (selectionCount > 0); |
|
453 } |
|
454 |
|
455 /** |
|
456 * Checks if only single component is selected. |
|
457 * @return <code>true</code> if has, otherwise <code>false</code>. |
|
458 */ |
|
459 private boolean hasComponentListSingleSelection() { |
|
460 int selectionCount = getListViewSelectionCount(); |
|
461 return (selectionCount == 1); |
|
462 } |
|
463 |
|
464 /** |
|
465 * Gets component list viewer selection count. |
|
466 * @return component list viewer selection count. |
|
467 */ |
|
468 private int getListViewSelectionCount() { |
|
469 return listItemsViewer.getTable().getSelectionCount(); |
|
470 } |
|
471 |
|
472 /** |
|
473 * Checks if all components has been selected. |
|
474 * @return <code>true</code> if all selected, otherwise <code>false</code>. |
|
475 */ |
|
476 private boolean isAllComponentsSelected() { |
|
477 return (getListViewItemCount() == getListViewSelectionCount()); |
|
478 } |
|
479 |
|
480 /** |
|
481 * Gets count of all elements in component list view. |
|
482 * @return count of all elements in component list view. |
|
483 */ |
|
484 private int getListViewItemCount() { |
|
485 return listItemsViewer.getTable().getItemCount(); |
|
486 } |
|
487 |
|
488 /** |
|
489 * Checks if the component list has currently any components. |
|
490 * @return <code>true</code> if has, otherwise <code>false</code>. |
|
491 */ |
|
492 private boolean hasComponentsOnList() { |
|
493 return (listItemsViewer.getTable().getItemCount() > 0); |
|
494 } |
|
495 |
|
496 /** |
|
497 * Sets enabled/disabled states for actions commands |
|
498 * on this view, based on the current application state. |
|
499 * This method should be called whenever an operation is |
|
500 * started or stopped that might have effect on action |
|
501 * button states. |
|
502 */ |
|
503 public void updateViewActionEnabledStates(){ |
|
504 |
|
505 // Resolving current state |
|
506 boolean isRootComponentSelectedForAnalysis = AppDepSettings.isRootComponentSelectedForAnalysis(); |
|
507 boolean isValidComponentSelection = isRootComponentSelectedForAnalysis && (getComponentListSelectedElement() != null); |
|
508 boolean isComponentListActionsEnabled = isValidComponentSelection && hasComponentsOnList(); |
|
509 boolean hasComponentListSelection = isComponentListActionsEnabled && hasComponentListSelection(); |
|
510 boolean isAllComponentsSelected = isComponentListActionsEnabled && isAllComponentsSelected(); |
|
511 boolean hasComponentListSingleSelection = isComponentListActionsEnabled && hasComponentListSingleSelection(); |
|
512 |
|
513 // Updating action enable/disable statuses |
|
514 setEnableState(actionCompPropertiesDataCopy, hasComponentListSelection); |
|
515 setEnableState(actionSelectAll, isComponentListActionsEnabled && !isAllComponentsSelected); |
|
516 setEnableState(actionSetAsNewRoot, hasComponentListSingleSelection); |
|
517 setEnableState(actionExportReport, hasComponentListSingleSelection); |
|
518 } |
|
519 |
|
520 /** |
|
521 * Sets given enable state for an action if it is non <code>null</code>. |
|
522 * @param action Action to set enable status for. |
|
523 * @param enableStatus <code>true</code> if enabled, otherwise <code>false</code>. |
|
524 */ |
|
525 private void setEnableState(Action action, boolean enableStatus) { |
|
526 if(action != null){ |
|
527 action.setEnabled(enableStatus); |
|
528 } |
|
529 } |
|
530 } |