import java.util.Map;
import java.util.Map.Entry;
+import org.eclipse.core.runtime.ListenerList;
import org.eclipse.linuxtools.dataviewers.piechart.PieChart;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.piecharts.model.TmfPieChartStatisticsModel;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.piecharts.model.TmfPieChartStatisticsModel;
/**
* Creates a viewer containing 2 pie charts, one for showing information about
* the current selection, and the second one for showing information about the
* current time-range selection. It follows the MVC pattern, being a view.
*
- * This class is closely related with the IPieChartViewerState interface
- * that acts as a state machine for the general layout of the charts.
+ * This class is closely related with the IPieChartViewerState interface that
+ * acts as a state machine for the general layout of the charts.
*
* @author Alexis Cabana-Loriaux
* @since 2.0
private String fTimeRangePCname;
/**
- * The listener added to the charts every time they are created
+ * The listener for the mouse movement event.
+ */
+ private Listener fMouseMoveListener;
+
+ /**
+ * The listener for the mouse right click event.
*/
- private Listener fMouseListener;
+ private MouseListener fMouseClickListener;
+
+ /**
+ * The list of listener to notify when an event type is selected
+ */
+ private ListenerList fEventTypeSelectedListeners = new ListenerList(ListenerList.IDENTITY);
/**
* The name of the slice containing the too little slices
fTimeRangePC = null;
// Setup listeners for the tooltips
- fMouseListener = new Listener() {
+ fMouseMoveListener = new Listener() {
@Override
public void handleEvent(org.eclipse.swt.widgets.Event event) {
PieChart pc = (PieChart) event.widget;
switch (event.type) {
+ /* Get tooltip information on the slice */
case SWT.MouseMove:
int sliceIndex = pc.getSliceIndexFromPosition(0, event.x, event.y);
if (sliceIndex < 0) {
String percent = String.format("%.1f", percOfSlice); //$NON-NLS-1$
Long nbEvents = Long.valueOf((long) pc.getSeriesSet().getSeries()[sliceIndex].getXSeries()[0]);
- String text = Messages.TmfStatisticsView_PieChartToolTipTextName + " = " + //$NON-NLS-1$
- pc.getSeriesSet().getSeries()[sliceIndex].getId() + "\n"; //$NON-NLS-1$
+ String text = Messages.TmfStatisticsView_PieChartToolTipTextName + " = " + //$NON-NLS-1$
+ pc.getSeriesSet().getSeries()[sliceIndex].getId() + "\n"; //$NON-NLS-1$
- text += Messages.TmfStatisticsView_PieChartToolTipTextEventCount + " = "//$NON-NLS-1$
- + nbEvents.toString() + " (" + percent + "%)"; //$NON-NLS-1$ //$NON-NLS-2$
+ text += Messages.TmfStatisticsView_PieChartToolTipTextEventCount + " = "//$NON-NLS-1$
+ + nbEvents.toString() + " (" + percent + "%)"; //$NON-NLS-1$ //$NON-NLS-2$
pc.setToolTipText(text);
return;
default:
}
}
};
+
+ fMouseClickListener = new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ PieChart pc = (PieChart) e.widget;
+ int slicenb = pc.getSliceIndexFromPosition(0, e.x, e.y);
+ if (slicenb < 0 || slicenb >= pc.getSeriesSet().getSeries().length) {
+ // mouse is outside the chart
+ return;
+ }
+ Event selectionEvent = new Event();
+ selectionEvent.text = pc.getSeriesSet().getSeries()[slicenb].getId();
+ notifyEventTypeSelectionListener(selectionEvent);
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+ };
+
// at creation no content is selected
setCurrentState(new PieChartViewerStateNoContentSelected(this));
}
getGlobalPC().getAxisSet().getXAxis(0).getTitle().setText(""); //Hide the title over the legend //$NON-NLS-1$
getGlobalPC().getLegend().setVisible(true);
getGlobalPC().getLegend().setPosition(SWT.RIGHT);
- getGlobalPC().addListener(SWT.MouseMove, fMouseListener);
+ getGlobalPC().addListener(SWT.MouseMove, fMouseMoveListener);
+ getGlobalPC().addMouseListener(fMouseClickListener);
} else if (getGlobalPC().isDisposed() || fModel == null || fModel.getPieChartGlobalModel() == null) {
return;
}
Map<String, Long> totalEventCountForChart = getTotalEventCountForChart(true);
- if(totalEventCountForChart == null){
+ if (totalEventCountForChart == null) {
return;
}
getTimeRangePC().getAxisSet().getXAxis(0).getTitle().setText(""); //Hide the title over the legend //$NON-NLS-1$
getTimeRangePC().getLegend().setPosition(SWT.BOTTOM);
getTimeRangePC().getLegend().setVisible(true);
- getTimeRangePC().addListener(SWT.MouseMove, fMouseListener);
+ getTimeRangePC().addListener(SWT.MouseMove, fMouseMoveListener);
+ getTimeRangePC().addMouseListener(fMouseClickListener);
}
else if (getTimeRangePC().isDisposed()) {
return;
Map<String, Long> totalEventCountForChart = getTotalEventCountForChart(false);
- if(totalEventCountForChart == null){
+ if (totalEventCountForChart == null) {
return;
}
}
/* return the chart-friendly map given by the TmfPieChartStatisticsModel */
- private Map<String,Long> getTotalEventCountForChart(boolean isGlobal){
- if(fModel == null){
+ private Map<String, Long> getTotalEventCountForChart(boolean isGlobal) {
+ if (fModel == null) {
return null;
}
Map<ITmfTrace, Map<String, Long>> chartModel;
- if(isGlobal){
+ if (isGlobal) {
chartModel = fModel.getPieChartGlobalModel();
} else {
chartModel = fModel.getPieChartSelectionModel();
}
- if(chartModel == null){
+ if (chartModel == null) {
return null;
}
Map<String, Long> totalEventCountForChart = new HashMap<>();
- for(Entry<ITmfTrace, Map<String, Long>> entry : chartModel.entrySet()){
+ for (Entry<ITmfTrace, Map<String, Long>> entry : chartModel.entrySet()) {
Map<String, Long> traceEventCount = entry.getValue();
- if(traceEventCount == null){
+ if (traceEventCount == null) {
continue;
}
- for(Entry<String, Long> event : traceEventCount.entrySet()){
- if(totalEventCountForChart.containsKey(event.getKey())){
+ for (Entry<String, Long> event : traceEventCount.entrySet()) {
+ if (totalEventCountForChart.containsKey(event.getKey())) {
totalEventCountForChart.put(event.getKey(), totalEventCountForChart.get(event.getKey()) + event.getValue());
} else {
totalEventCountForChart.put(event.getKey(), event.getValue());
* Reinitializes the charts to their initial state, without any data
*/
synchronized public void reinitializeCharts() {
- if(isDisposed()){
+ if (isDisposed()) {
return;
}
/**
* Refresh this viewer
- * @param refreshGlobal if we have to refresh the global piechart
- * @param refreshSelection if we have to refresh the selection piechart
+ *
+ * @param refreshGlobal
+ * if we have to refresh the global piechart
+ * @param refreshSelection
+ * if we have to refresh the selection piechart
*/
public synchronized void refresh(boolean refreshGlobal, boolean refreshSelection) {
- if(fModel == null){
+ if (fModel == null) {
reinitializeCharts();
} else {
- if(refreshGlobal){
+ if (refreshGlobal) {
/* will update the global pc */
getCurrentState().newGlobalEntries(this);
}
- if(refreshSelection){
+ if (refreshSelection) {
// Check if the selection is empty
int nbEventsType = 0;
Map<String, Long> selectionModel = getTotalEventCountForChart(false);
for (Long l : selectionModel.values()) {
- if(l != 0){
+ if (l != 0) {
nbEventsType++;
}
}
}
}
+ /**
+ * @param l
+ * the listener to add
+ */
+ public void addEventTypeSelectionListener(Listener l) {
+ fEventTypeSelectedListeners.add(l);
+ }
+
+ /**
+ * @param l
+ * the listener to remove
+ */
+ public void removeEventTypeSelectionListener(Listener l) {
+ fEventTypeSelectedListeners.remove(l);
+ }
+
+ /* Notify all listeners that an event type has been selected */
+ private void notifyEventTypeSelectionListener(Event e) {
+ for (Object o : fEventTypeSelectedListeners.getListeners()) {
+ ((Listener) o).handleEvent(e);
+ }
+ }
+
// ------------------------------------------------------------------------
// Getters
// ------------------------------------------------------------------------
}
/**
- * @param model the model to set
+ * @param model
+ * the model to set
*/
public void setInput(TmfPieChartStatisticsModel model) {
fModel = model;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.piecharts.TmfPieChartViewer;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.piecharts.model.TmfPieChartStatisticsModel;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsFormatter;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
-import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfTreeContentProvider;
import org.eclipse.tracecompass.tmf.core.component.TmfComponent;
import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
-import org.eclipse.tracecompass.tmf.ui.TmfUiRefreshHandler;
import org.eclipse.tracecompass.tmf.ui.viewers.TmfViewer;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.piecharts.TmfPieChartViewer;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.piecharts.model.TmfPieChartStatisticsModel;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfBaseColumnData;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfBaseColumnDataProvider;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsFormatter;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfTreeContentProvider;
/**
* A basic viewer to display statistics in the statistics view.
return;
}
- TmfPieChartStatisticsModel pieChartModel = getPieChartModel();
- if (pieChartModel == null || pieChartModel.getPieChartGlobalModel() == null) {
- return;
- }
- /* If there's only one event type, don't show any piechart */
- boolean moreThanOne = false;
- for (Entry<ITmfTrace, Map<String, Long>> entry : pieChartModel.getPieChartGlobalModel().entrySet()) {
- if(entry.getValue() != null && entry.getValue().size() > 1) {
- moreThanOne = true;
- break;
- }
- }
-
- if (!moreThanOne) {
- setPieChartsVisible(false);
- } else {
- setPieChartsVisible(true);
- }
-
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
fTreeViewer = new TreeViewer(fSash, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
fPieChartViewer = new TmfPieChartViewer(fSash);
- fPieChartViewer.setVisible(false);
- fSash.setWeights(new int[] { 1, 1 });
+ fPieChartViewer.addEventTypeSelectionListener(new Listener() {
+
+ @Override
+ public void handleEvent(Event event) {
+ String eventTypeName = event.text;
+ if (getStatisticData().getRootNode() == null ||
+ fTreeViewer == null ||
+ fTreeViewer.getTree() == null) {
+ return;
+ }
+ /* Get all the nodes corresponding to the event name */
+ List<TmfStatisticsTreeNode> nodes = (List<TmfStatisticsTreeNode>) getStatisticData().getRootNode().findChildren(eventTypeName, true);
+ if (nodes.isEmpty()) {
+ /* Shouldn't happen, except for when selecting "Others" */
+ return;
+ }
+ /* Only select the first in the collection */
+ fTreeViewer.setSelection(new StructuredSelection(nodes.get(0)), true);
+ }
+ });
+
+ /* Make sure the sash is split in 2 equal parts */
+ fSash.setWeights(new int[] { 100, 100 });
fTreeViewer.setContentProvider(new TmfTreeContentProvider());
fTreeViewer.getTree().setHeaderVisible(true);
}
}
- private void setPieChartsVisible(final boolean visible) {
- if (fPieChartViewer.isDisposed()) {
- return;
- }
- TmfUiRefreshHandler.getInstance().queueUpdate(fPieChartViewer, new Runnable() {
- @Override
- public void run() {
- if (!fPieChartViewer.isDisposed()) {
- fPieChartViewer.setVisible(visible);
- fPieChartViewer.getParent().layout();
- }
- }
- });
- }
-
/**
* Resets the number of events within the time range
*/