[Esbox-commits] r388 - in trunk/org.indt.esbox.ui/src/org/indt/esbox/ui: preferences views
raul at garage.maemo.org
raul at garage.maemo.org
Fri Jan 25 21:54:47 EET 2008
Author: raul
Date: 2008-01-25 21:54:39 +0200 (Fri, 25 Jan 2008)
New Revision: 388
Modified:
trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxSbrshPreferencePage.java
trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/OProfileView.java
Log:
Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxSbrshPreferencePage.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxSbrshPreferencePage.java 2008-01-24 18:22:29 UTC (rev 387)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/preferences/ESboxSbrshPreferencePage.java 2008-01-25 19:54:39 UTC (rev 388)
@@ -137,7 +137,7 @@
if ( !this.getClass().equals(obj.getClass()) )
return false;
SbrshEntry entry = (SbrshEntry)obj;
- return entry.device.equals(device) && entry.host.equals(host) && type.equals(type);
+ return entry.device.equals(device) && entry.host.equals(host) && entry.type.equals(type);
}
}
Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/OProfileView.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/OProfileView.java 2008-01-24 18:22:29 UTC (rev 387)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/OProfileView.java 2008-01-25 19:54:39 UTC (rev 388)
@@ -11,47 +11,265 @@
package org.indt.esbox.ui.views;
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.cdt.internal.ui.util.PixelConverter;
+import org.eclipse.cdt.internal.ui.util.SWTUtil;
import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.indt.esbox.ui.UIActivator;
public class OProfileView extends ViewPart {
+
+ /**
+ * Table that contains the oprofile entries
+ */
+ protected Table table;
+
+ protected TableViewer tableViewer;
+
+ /**
+ * Used on table
+ */
+ protected TableColumn[] columns;
+
+ protected String[] columnNames;
+
+ /**
+ *
+ */
+ private static class OProfileEntry {
+
+ public List<String> entries;
+
+ public OProfileEntry() {
+ entries = new ArrayList<String>();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if ( !this.getClass().equals(obj.getClass()) )
+ return false;
+ OProfileEntry entry = (OProfileEntry)obj;
+ return entry.entries.equals(entries);
+ }
+
+ }
+
+ private static class OProfileTableSorter extends ViewerSorter {
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ return getComparator().compare(((OProfileEntry) e1).entries, ((OProfileEntry) e2).entries);
+ }
+
+ @Override
+ protected Comparator getComparator() {
+
+ return new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return (-1) * (((List<String>) o1).get(0)).compareTo(((List<String>) o1).get(0));
+ }
+ };
+ }
+ }
+
+ private class OProfileLabelProvider extends LabelProvider implements ITableLabelProvider, IFontProvider {
- private Action filterAction;
+ public OProfileLabelProvider() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+ */
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ */
+ public String getText(Object element) {
+ return getColumnText(element, 0);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
+ */
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
+ */
+ public String getColumnText(Object element, int columnIndex) {
+ OProfileEntry entry = (OProfileEntry) element;
+ if (columnIndex >= entry.entries.size())
+ return "";
+ else
+ return entry.entries.get(columnIndex);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
+ */
+ public Font getFont(Object element) {
+ return null;
+ }
+ }
+
+ private Action removeAction;
@Override
public void createPartControl(Composite parent) {
createActions();
createMenu();
-
+ createTable(parent);
}
private void createActions() {
- filterAction = new Action("Filter") {
+ removeAction = new Action() {
public void run() {
- //TODO
- new ListSelectionDialog(
- getShell(),
- new String[] { "Choice 1", "Choice 2", "Choice 3" },
- new ArrayContentProvider(),
- new LabelProvider(),
- "Choose Your Filter Option(s)"
- ).open();
+ table.removeAll();
}
};
+ removeAction.setText("Delete");
+ removeAction.setToolTipText("Delete Current Sample");
+ removeAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+ getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
+// filterAction = new Action("Filter") {
+// public void run() {
+// //TODO
+// new ListSelectionDialog(
+// getShell(),
+// new String[] { "Choice 1", "Choice 2", "Choice 3" },
+// new ArrayContentProvider(),
+// new LabelProvider(),
+// "Choose Your Filter Option(s)"
+// ).open();
+// }
+// };
}
private void createMenu() {
- IMenuManager mgr = getViewSite().getActionBars().getMenuManager();
- mgr.add(filterAction);
+ IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
+ toolBar.add(removeAction);
}
+
+ public void createTable(Composite parent) {
+ Composite tablePane = new Composite(parent, SWT.NONE);
+ GridLayout tablePaneLayout = new GridLayout();
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+
+ tablePaneLayout.marginHeight = 0;
+ tablePaneLayout.marginWidth = 0;
+
+ tablePane.setLayout(tablePaneLayout);
+ tablePane.setLayoutData(gridData);
+
+ tableViewer = new TableViewer(tablePane, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER );
+ tableViewer.setSorter(new OProfileTableSorter());
+ tableViewer.setLabelProvider(new OProfileLabelProvider());
+
+ table = tableViewer.getTable();
+
+ TableLayout tblLayout = new TableLayout();
+ gridData = new GridData(GridData.FILL_BOTH);
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.heightHint = SWTUtil.getTableHeightHint(table, 8);
+ gridData.widthHint = new PixelConverter(parent).convertWidthInCharsToPixels(60);
+
+ table.setLayoutData(gridData);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ //adds a selection listener. This listener guarantees that just one item is checked (and also selected).
+ table.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ }
+ });
+
+ initTable();
+
+ table.pack();
+
+ try {
+ fillTable();
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+
+ public void initTable() {
+ columnNames = new String[] { "Samples", "Cum. Samples (%)", "%", "Cum. (%)", "Line Info", "Image Name", "Application Name", "Symbol Name" };
+ columns = new TableColumn[columnNames.length];
+
+ for(int i = 0; i < columnNames.length; i++) {
+ columns[i] = new TableColumn(table,SWT.LEFT);
+ columns[i].setText(columnNames[i]);
+ columns[i].setWidth(150);
+ }
+
+ }
+
+ public void fillTable() throws IOException {
+ BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("/home/raul/oprofile_output/opreport_e.txt")));
+
+ String line = "";
+ while( (line = in.readLine()) != null) {
+ StringTokenizer tokens = new StringTokenizer(line);
+
+ if(tokens.countTokens() > 0) {
+ String token = tokens.nextToken();
+ try {
+ // check if the first token is a number (sample) to make
+ // sure that first line of profile is reached.
+ Integer.parseInt(token);
+
+ OProfileEntry entry = new OProfileEntry();
+ entry.entries.add(token);
+ while(tokens.hasMoreElements()) {
+ entry.entries.add(tokens.nextToken());
+ }
+ tableViewer.add(entry);
+ } catch (NumberFormatException e) {
+
+ }
+ }
+
+ }
+ }
+
@Override
public void setFocus() {
//TODO
More information about the Esbox-commits
mailing list