| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2015 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 | * Alexis Cabana-Loriaux - Initial API and implementation |
| 11 | * |
| 12 | *******************************************************************************/ |
| 13 | |
| 14 | package org.eclipse.tracecompass.tmf.ui.viewers.piecharts; |
| 15 | |
| 16 | import org.eclipse.swt.SWT; |
| 17 | import org.eclipse.swt.widgets.Display; |
| 18 | |
| 19 | /** |
| 20 | * Implementation of the IPieChartViewerState interface to represent the state |
| 21 | * of the layout when there is no content currently selected. |
| 22 | * |
| 23 | * @author Alexis Cabana-Loriaux |
| 24 | * @since 2.0 |
| 25 | * |
| 26 | */ |
| 27 | public class PieChartViewerStateNoContentSelected implements IPieChartViewerState { |
| 28 | |
| 29 | /** |
| 30 | * Default constructor |
| 31 | * |
| 32 | * @param context |
| 33 | * The current context |
| 34 | */ |
| 35 | public PieChartViewerStateNoContentSelected(final TmfPieChartViewer context) { |
| 36 | if (context.isDisposed()) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | Display.getDefault().asyncExec(new Runnable() { |
| 41 | @Override |
| 42 | public void run() { |
| 43 | synchronized (context) { |
| 44 | if (!context.isDisposed()) { |
| 45 | // Have to get rid of the time-range PieChart |
| 46 | if (context.getTimeRangePC() != null) { |
| 47 | if (!context.getTimeRangePC().isDisposed()) { |
| 48 | context.getTimeRangePC().dispose(); |
| 49 | } |
| 50 | context.setTimeRangePC(null); |
| 51 | } |
| 52 | |
| 53 | context.updateGlobalPieChart(); |
| 54 | // update the global chart so it takes all the place |
| 55 | context.getGlobalPC().getLegend().setPosition(SWT.RIGHT); |
| 56 | context.layout(); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | }); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void newSelection(final TmfPieChartViewer context) { |
| 65 | context.setCurrentState(new PieChartViewerStateContentSelected(context)); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void newEmptySelection(final TmfPieChartViewer context) { |
| 70 | // do nothing |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void newGlobalEntries(final TmfPieChartViewer context) { |
| 75 | Display.getDefault().asyncExec(new Runnable() { |
| 76 | @Override |
| 77 | public void run() { |
| 78 | synchronized (context) { |
| 79 | if (!context.isDisposed()) { |
| 80 | context.updateGlobalPieChart(); |
| 81 | context.getGlobalPC().redraw(); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | }); |
| 86 | } |
| 87 | } |