| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009, 2010 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Francois Chouinard - Initial API and implementation |
| 11 | * Patrick Tasse - Factored out events table |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | package org.eclipse.linuxtools.tmf.ui.views; |
| 15 | |
| 16 | import org.eclipse.linuxtools.tmf.event.TmfEvent; |
| 17 | import org.eclipse.linuxtools.tmf.experiment.TmfExperiment; |
| 18 | import org.eclipse.linuxtools.tmf.signal.TmfExperimentSelectedSignal; |
| 19 | import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler; |
| 20 | import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable; |
| 21 | import org.eclipse.swt.widgets.Composite; |
| 22 | import org.eclipse.swt.widgets.Table; |
| 23 | |
| 24 | /** |
| 25 | * <b><u>TmfEventsView</u></b> |
| 26 | * <p> |
| 27 | * |
| 28 | * TODO: Implement me. Please. |
| 29 | * TODO: Handle column selection, sort, ... generically (nothing less...) |
| 30 | * TODO: Implement hide/display columns |
| 31 | */ |
| 32 | public class TmfEventsView extends TmfView { |
| 33 | |
| 34 | public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.events"; |
| 35 | |
| 36 | private TmfExperiment<TmfEvent> fExperiment; |
| 37 | private TmfEventsTable fEventsTable; |
| 38 | private static final int DEFAULT_CACHE_SIZE = 1000; |
| 39 | private final int fCacheSize; |
| 40 | private String fTitlePrefix; |
| 41 | |
| 42 | // ------------------------------------------------------------------------ |
| 43 | // Constructor |
| 44 | // ------------------------------------------------------------------------ |
| 45 | |
| 46 | public TmfEventsView(int cacheSize) { |
| 47 | super("TmfEventsView"); |
| 48 | fCacheSize = cacheSize; |
| 49 | } |
| 50 | |
| 51 | public TmfEventsView() { |
| 52 | this(DEFAULT_CACHE_SIZE); |
| 53 | } |
| 54 | |
| 55 | // ------------------------------------------------------------------------ |
| 56 | // ViewPart |
| 57 | // ------------------------------------------------------------------------ |
| 58 | |
| 59 | @SuppressWarnings("unchecked") |
| 60 | @Override |
| 61 | public void createPartControl(Composite parent) { |
| 62 | fEventsTable = createEventsTable(parent, fCacheSize); |
| 63 | |
| 64 | fTitlePrefix = getTitle(); |
| 65 | |
| 66 | // If an experiment is already selected, update the table |
| 67 | fExperiment = (TmfExperiment<TmfEvent>) TmfExperiment.getCurrentExperiment(); |
| 68 | if (fExperiment != null) { |
| 69 | experimentSelected(new TmfExperimentSelectedSignal<TmfEvent>(fEventsTable, fExperiment)); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void dispose() { |
| 75 | if (fEventsTable != null) { |
| 76 | fEventsTable.dispose(); |
| 77 | } |
| 78 | super.dispose(); |
| 79 | } |
| 80 | |
| 81 | protected TmfEventsTable createEventsTable(Composite parent, int cacheSize) { |
| 82 | return new TmfEventsTable(parent, cacheSize); |
| 83 | } |
| 84 | |
| 85 | /* (non-Javadoc) |
| 86 | * @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
| 87 | */ |
| 88 | @Override |
| 89 | public void setFocus() { |
| 90 | fEventsTable.setFocus(); |
| 91 | } |
| 92 | |
| 93 | /* (non-Javadoc) |
| 94 | * @see java.lang.Object#toString() |
| 95 | */ |
| 96 | @Override |
| 97 | public String toString() { |
| 98 | return "[TmfEventsView]"; |
| 99 | } |
| 100 | |
| 101 | protected void createColumnHeaders(Table table) { |
| 102 | fEventsTable.createColumnHeaders(table); |
| 103 | } |
| 104 | |
| 105 | protected String[] extractItemFields(TmfEvent event) { |
| 106 | return fEventsTable.extractItemFields(event); |
| 107 | } |
| 108 | |
| 109 | // ------------------------------------------------------------------------ |
| 110 | // Signal handlers |
| 111 | // ------------------------------------------------------------------------ |
| 112 | |
| 113 | @SuppressWarnings("unchecked") |
| 114 | @TmfSignalHandler |
| 115 | public void experimentSelected(TmfExperimentSelectedSignal<TmfEvent> signal) { |
| 116 | // Update the trace reference |
| 117 | fExperiment = (TmfExperiment<TmfEvent>) signal.getExperiment(); |
| 118 | setPartName(fTitlePrefix + " - " + fExperiment.getName()); |
| 119 | |
| 120 | if (fEventsTable != null) { |
| 121 | fEventsTable.setTrace(fExperiment); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | } |