|
Added
Link Here
|
| 0 |
- |
1 |
/******************************************************************************* |
|
|
2 |
* Copyright (c) 2012 Red Hat, Inc. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Camilo Bernal <cabernal@redhat.com> - Initial Implementation. |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.linuxtools.internal.perf.ui; |
| 12 |
|
| 13 |
import java.util.ArrayList; |
| 14 |
|
| 15 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
| 16 |
import org.eclipse.jface.viewers.TableViewer; |
| 17 |
import org.eclipse.jface.viewers.TableViewerColumn; |
| 18 |
import org.eclipse.linuxtools.internal.perf.model.PMSymbolMatch; |
| 19 |
import org.eclipse.swt.SWT; |
| 20 |
import org.eclipse.swt.events.SelectionAdapter; |
| 21 |
import org.eclipse.swt.events.SelectionEvent; |
| 22 |
import org.eclipse.swt.layout.GridData; |
| 23 |
import org.eclipse.swt.layout.GridLayout; |
| 24 |
import org.eclipse.swt.widgets.Composite; |
| 25 |
import org.eclipse.swt.widgets.Table; |
| 26 |
import org.eclipse.swt.widgets.TableColumn; |
| 27 |
import org.eclipse.ui.part.ViewPart; |
| 28 |
|
| 29 |
public class PerfDiffView extends ViewPart { |
| 30 |
|
| 31 |
private static final String ID = "org.eclipse.linuxtools.internal.perf.views.SessionDiffView"; |
| 32 |
private TableViewer tableviewer; |
| 33 |
private ArrayList<PMSymbolMatch> result = new ArrayList<PMSymbolMatch>(); |
| 34 |
|
| 35 |
@Override |
| 36 |
public void createPartControl(Composite parent) { |
| 37 |
|
| 38 |
GridLayout layout = new GridLayout(1, false); |
| 39 |
parent.setLayout(layout); |
| 40 |
|
| 41 |
tableviewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL |
| 42 |
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); |
| 43 |
|
| 44 |
createColumns(parent, tableviewer); |
| 45 |
|
| 46 |
final Table table = tableviewer.getTable(); |
| 47 |
table.setHeaderVisible(true); |
| 48 |
table.setLinesVisible(true); |
| 49 |
tableviewer.setContentProvider(new ArrayContentProvider()); |
| 50 |
|
| 51 |
// Layout for the table |
| 52 |
GridData gridData = new GridData(); |
| 53 |
gridData.verticalAlignment = GridData.FILL; |
| 54 |
gridData.horizontalSpan = 2; |
| 55 |
gridData.grabExcessHorizontalSpace = true; |
| 56 |
gridData.grabExcessVerticalSpace = true; |
| 57 |
gridData.horizontalAlignment = GridData.FILL; |
| 58 |
|
| 59 |
tableviewer.setContentProvider(new ArrayContentProvider()); |
| 60 |
tableviewer.getControl().setLayoutData(gridData); |
| 61 |
} |
| 62 |
|
| 63 |
private void createColumns(final Composite parent, final TableViewer viewer) { |
| 64 |
String[] titles = { "Function", "New Overhead (%)", "Old Overhead (%)", |
| 65 |
"Result", "Event", "" }; |
| 66 |
int[] bounds = { 100, 133, 135, 100, 100, 1 }; |
| 67 |
|
| 68 |
final PerfDiffTableSorter tableSorter = new PerfDiffTableSorter(); |
| 69 |
final Table table = tableviewer.getTable(); |
| 70 |
|
| 71 |
for (int i = 0; i < titles.length; i++) { |
| 72 |
final int index = i; |
| 73 |
createTableViewerColumn(titles[i], bounds[i], index, tableSorter, |
| 74 |
table); |
| 75 |
} |
| 76 |
|
| 77 |
tableviewer.setLabelProvider(new PerfDiffLabelProvider()); |
| 78 |
tableviewer.setSorter(tableSorter); |
| 79 |
} |
| 80 |
|
| 81 |
private TableViewerColumn createTableViewerColumn(String title, int bound, |
| 82 |
final int colIndex, final PerfDiffTableSorter tableSorter, |
| 83 |
final Table table) { |
| 84 |
final TableViewerColumn viewerColumn = new TableViewerColumn( |
| 85 |
tableviewer, SWT.NONE); |
| 86 |
final TableColumn column = viewerColumn.getColumn(); |
| 87 |
column.setText(title); |
| 88 |
column.setWidth(bound); |
| 89 |
column.setResizable(true); |
| 90 |
column.setMoveable(true); |
| 91 |
column.addSelectionListener(new SelectionAdapter() { |
| 92 |
public void widgetSelected(SelectionEvent e) { |
| 93 |
tableSorter.setColumnIndex(colIndex); |
| 94 |
int dir = table.getSortDirection(); |
| 95 |
|
| 96 |
if (table.getSortColumn() == column) { |
| 97 |
dir = (dir == SWT.UP) ? SWT.DOWN : SWT.UP; |
| 98 |
} else { |
| 99 |
dir = SWT.DOWN; |
| 100 |
} |
| 101 |
|
| 102 |
table.setSortDirection(dir); |
| 103 |
table.setSortColumn(column); |
| 104 |
tableviewer.refresh(); |
| 105 |
} |
| 106 |
}); |
| 107 |
return viewerColumn; |
| 108 |
} |
| 109 |
|
| 110 |
@Override |
| 111 |
public void setFocus() { |
| 112 |
tableviewer.getControl().setFocus(); |
| 113 |
} |
| 114 |
|
| 115 |
public void setResult(ArrayList<PMSymbolMatch> result) { |
| 116 |
this.result = result; |
| 117 |
} |
| 118 |
|
| 119 |
public void refreshView() { |
| 120 |
tableviewer.setInput(result.toArray()); |
| 121 |
tableviewer.refresh(); |
| 122 |
} |
| 123 |
} |