[Esbox-commits] r391 - trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views
pauloromulo at garage.maemo.org
pauloromulo at garage.maemo.org
Sat Jan 26 18:51:38 EET 2008
Author: pauloromulo
Date: 2008-01-26 18:51:34 +0200 (Sat, 26 Jan 2008)
New Revision: 391
Modified:
trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/ValgrindView.java
Log:
Valgrind integration.
Modified: trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/ValgrindView.java
===================================================================
--- trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/ValgrindView.java 2008-01-26 16:43:36 UTC (rev 390)
+++ trunk/org.indt.esbox.ui/src/org/indt/esbox/ui/views/ValgrindView.java 2008-01-26 16:51:34 UTC (rev 391)
@@ -11,45 +11,199 @@
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 org.eclipse.core.runtime.IAdaptable;
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.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.DrillDownAdapter;
import org.eclipse.ui.part.ViewPart;
import org.indt.esbox.ui.UIActivator;
public class ValgrindView extends ViewPart {
+
+ private TreeViewer viewer;
+ private DrillDownAdapter drillDownAdapter;
+ //private Action action1;
+ private Action removeAction;
+ private TreeParent invisibleRoot;
- Action filterAction;
+ class TreeObject implements IAdaptable {
+ private String name;
+ private TreeParent parent;
+
+ public TreeObject(String name) {
+ this.name = name;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setParent(TreeParent parent) {
+ this.parent = parent;
+ }
+ public TreeParent getParent() {
+ return parent;
+ }
+ public String toString() {
+ return getName();
+ }
+ public Object getAdapter(Class key) {
+ return null;
+ }
+ }
- @Override
- public void createPartControl(Composite parent) {
- createActions();
- createMenu();
+ class TreeParent extends TreeObject {
+ private ArrayList children;
+ public TreeParent(String name) {
+ super(name);
+ children = new ArrayList();
+ }
+ public void addChild(TreeObject child) {
+ children.add(child);
+ child.setParent(this);
+ }
+ public void removeChild(TreeObject child) {
+ children.remove(child);
+ child.setParent(null);
+ }
+ public TreeObject [] getChildren() {
+ return (TreeObject [])children.toArray(new TreeObject[children.size()]);
+ }
+ public boolean hasChildren() {
+ return children.size()>0;
+ }
+ }
+
+ class ViewContentProvider implements IStructuredContentProvider,
+ ITreeContentProvider {
+ public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+ }
+ public void dispose() {
+ }
+ public Object[] getElements(Object parent) {
+ if (parent.equals(getViewSite())) {
+ if (invisibleRoot==null) {
+ try {
+ initialize();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return getChildren(invisibleRoot);
+ }
+ return getChildren(parent);
+ }
+ public Object getParent(Object child) {
+ if (child instanceof TreeObject) {
+ return ((TreeObject)child).getParent();
+ }
+ return null;
+ }
+ public Object [] getChildren(Object parent) {
+ if (parent instanceof TreeParent) {
+ return ((TreeParent)parent).getChildren();
+ }
+ return new Object[0];
+ }
+ public boolean hasChildren(Object parent) {
+ if (parent instanceof TreeParent)
+ return ((TreeParent)parent).hasChildren();
+ return false;
+ }
+
+ private void initialize() throws IOException {
+ BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("/home/romulo/valgrind.out")));
+ invisibleRoot = new TreeParent("");
+ TreeParent root = new TreeParent("");
+ String line = "";
+ while( (line = in.readLine()) != null) {
+ if (line.startsWith("==") && !line.endsWith("==")) {
+ if (isRoot(line)) {
+ root = new TreeParent(line.trim());
+ invisibleRoot.addChild(root);
+ } else {
+ root.addChild(new TreeObject(line));
+ }
+ }
+ }
+
+ }
+ private boolean isRoot(String line) {
+ return !(line.contains(" at ") || line.contains(" by "));
+ }
}
+
+ class ViewLabelProvider extends LabelProvider {
- private void createActions() {
- filterAction = new Action("Filter") {
+ public String getText(Object obj) {
+ return obj.toString();
+ }
+ public Image getImage(Object obj) {
+ String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
+ return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
+ }
+ }
+
+ class NameSorter extends ViewerSorter {
+ }
+
+ /**
+ * The constructor.
+ */
+ public ValgrindView() {
+ }
+
+ /**
+ * This is a callback that will allow us
+ * to create the viewer and initialize it.
+ */
+ public void createPartControl(Composite parent) {
+ viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ drillDownAdapter = new DrillDownAdapter(viewer);
+ viewer.setContentProvider(new ViewContentProvider());
+ viewer.setLabelProvider(new ViewLabelProvider());
+ viewer.setSorter(new NameSorter());
+ viewer.setInput(getViewSite());
+ makeActions();
+ createMenu();
+ }
+
+ private void makeActions() {
+ 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();
- }
+ for (Object o : invisibleRoot.children) {
+ TreeParent tp = (TreeParent) o;
+ invisibleRoot.removeChild(tp);
+ }
+ viewer.refresh();
+ }
};
+ removeAction.setText("Delete");
+ removeAction.setToolTipText("Delete Current Sample");
+ removeAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+ getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
}
private void createMenu() {
- IMenuManager mgr = getViewSite().getActionBars().getMenuManager();
- mgr.add(filterAction);
+ IToolBarManager toolBar = getViewSite().getActionBars().getToolBarManager();
+ toolBar.add(removeAction);
}
@Override
More information about the Esbox-commits
mailing list