DataViewer.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.traceviewer.ui;
00002
00003 import java.util.ArrayList;
00004 import java.util.Vector;
00005
00006 import org.eclipse.jface.viewers.ColumnLabelProvider;
00007 import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
00008 import org.eclipse.jface.viewers.IStructuredContentProvider;
00009 import org.eclipse.jface.viewers.TableViewer;
00010 import org.eclipse.jface.viewers.TableViewerColumn;
00011 import org.eclipse.jface.viewers.Viewer;
00012 import org.eclipse.jface.window.ToolTip;
00013 import org.eclipse.swt.SWT;
00014 import org.eclipse.swt.graphics.Image;
00015 import org.eclipse.swt.layout.GridData;
00016 import org.eclipse.swt.widgets.Composite;
00017 import org.eclipse.swt.widgets.Event;
00018 import org.eclipse.swt.widgets.Listener;
00019 import org.eclipse.swt.widgets.Table;
00020 import org.eclipse.ui.services.ISourceProviderService;
00021
00022 import edu.rice.cs.hpc.traceviewer.services.ProcessTimelineService;
00023 import edu.rice.cs.hpc.traceviewer.spaceTimeData.Position;
00024 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00025 import edu.rice.cs.hpc.traceviewer.data.timeline.ProcessTimeline;
00026 import edu.rice.cs.hpc.traceviewer.data.util.Constants;
00027 import edu.rice.cs.hpc.traceviewer.data.util.Debugger;
00028
00029
00030
00031
00032 public class DataViewer extends TableViewer
00033 {
00034 private SpaceTimeDataController stData;
00035
00036 private final TableViewerColumn viewerColumn;
00037
00038 private final ProcessTimelineService ptlService;
00039
00040 public DataViewer(Composite parent, final HPCDataView dataview)
00041 {
00042 super(parent, SWT.SINGLE | SWT.NO_SCROLL);
00043
00044 final Table dataTbl = this.getTable();
00045
00046 GridData data = new GridData(GridData.FILL_BOTH);
00047 dataTbl.setLayoutData(data);
00048
00049
00050
00051
00052 this.setContentProvider( new IStructuredContentProvider(){
00053
00054 public void dispose() {}
00055
00056 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { }
00057
00058 public Object[] getElements(Object inputElement) {
00059 if (inputElement instanceof ArrayList<?>) {
00060 Object o[] = ((ArrayList<?>) inputElement).toArray();
00061 return o;
00062 }
00063 return null;
00064 }
00065
00066 });
00067
00068 dataTbl.setVisible(false);
00069 final DataViewer dataviewer = this;
00070 dataTbl.addListener(SWT.Selection, new Listener(){
00071 public void handleEvent(Event event)
00072 {
00073 int dataIdx = dataTbl.getSelectionIndex();
00074 if (dataIdx != Constants.dataIdxNULL && dataIdx != stData.getDataIndex()) {
00075 stData.setDataIndex(dataIdx);
00076 }
00077 }
00078 });
00079
00080
00081
00082
00083
00084 final ColumnLabelProvider myLableProvider = new ColumnLabelProvider() {
00085 public Image getImage(Object element) {
00086 if (element instanceof String) {
00087 Image img = null;
00088 if (stData != null)
00089 img = stData.getColorTable().getImage((String)element);
00090 return img;
00091 }
00092
00093 return null;
00094 }
00095
00096 public String getText(Object element)
00097 {
00098 if (element instanceof String)
00099 return (String) element;
00100 return null;
00101 }
00102
00103 public String getToolTipText(Object element)
00104 {
00105 return this.getText(element);
00106 }
00107
00108 public int getToolTipDisplayDelayTime(Object object)
00109 {
00110 return 200;
00111 }
00112 };
00113 viewerColumn = new TableViewerColumn(this, SWT.NONE);
00114 viewerColumn.setLabelProvider(myLableProvider);
00115 viewerColumn.getColumn().setWidth(100);
00116 ColumnViewerToolTipSupport.enableFor(dataviewer, ToolTip.NO_RECREATE);
00117
00118 final ISourceProviderService service = (ISourceProviderService)dataview.getSite().
00119 getWorkbenchWindow().getService(ISourceProviderService.class);
00120 ptlService = (ProcessTimelineService) service.
00121 getSourceProvider(ProcessTimelineService.PROCESS_TIMELINE_PROVIDER);
00122 }
00123
00124
00125
00126
00127
00128
00129 public void updateView(SpaceTimeDataController _stData)
00130 {
00131 this.stData = _stData;
00132
00133 this.getTable().setVisible(true);
00134 }
00135
00136
00137
00138
00139
00140
00141 public void setSample(Position position, int depth, int dataIdx)
00142 {
00143 if (position.time == -20)
00144 return;
00145
00146
00147
00148
00149 int proc = 0;
00150 ProcessTimeline ptl = ptlService.getProcessTimeline(proc);
00151
00152 if (ptl != null) {
00153 int sample = ptl.findMidpointBefore(position.time, stData.isEnableMidpoint());
00154
00155 Vector<String> dataVec = new Vector<String>();
00156 if (sample >= 0) {
00157
00158 }
00159
00160 this.setInput(new ArrayList<String>(dataVec));
00161 this.selectData(dataIdx);
00162
00163 viewerColumn.getColumn().pack();
00164 }
00165 else {
00166 Debugger.printTrace("CSV traces: ");
00167 }
00168 }
00169
00171 public void setData(int dataIdx)
00172 {
00173 this.selectData(dataIdx);
00174 }
00175
00176
00177
00178
00179
00180 private void selectData(final int dataIdx)
00181 {
00182 this.getTable().select(dataIdx);
00183 this.getTable().redraw();
00184 }
00185 }