I have two sections. In the left section I am using checkbox tableviewer for displaying list of file names. The right section is for showing graphs(I am using JFreechart). I have a handler which is used for dynamically adding tabs to the right side section. IF I am in first tab and made some checkbox selections in left side tableviewer ,the graph is displayed in right side. When I create a new tab(right side) , the left side tableviewer should reset.
When I select the first tab again and I want to see the previous selection in left side section.Can anyone please give some ideas how to save/restore the views based on the tab change?
Left side section code for file viewer:
@PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
tableViewer = new CheckboxTableViewer(parent, SWT.BORDER);
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}
public void setTableInput(File[] selectedFiles) {
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setLabelProvider(new FileLabelProvider());
prevSelectedFiles = selectedFiles;
tableViewer.setInput(selectedFiles);
tableViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
filesSelected = tableViewer.getCheckedElements();
// some code to display graph
}}}
Right side code(Graph)
@PostConstruct
public void postConstruct(final Composite parent) {
final JFreeChart chart = createChart(dataset, title);
new ChartComposite(parent, SWT.NONE, chart, true);
}
private JFreeChart createChart(TimeSeriesCollection dataset, String string) {
final JFreeChart chart = ChartFactory.createTimeSeriesChart(
"REPORT GENERATION", "TimeStamp", "ms", dataset, true, true,
false);
chart.setBackgroundPaint(Color.WHITE);
final XYPlot plot = (XYPlot) chart.getPlot();
plot.setDataset(0, dataset);
plot.setBackgroundPaint(Color.WHITE);
plot.setDomainGridlinePaint(Color.BLACK);
plot.setRangeGridlinePaint(Color.BLACK);
Shape shape = new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot
.getRenderer();
renderer.setSeriesShape(0, shape);
renderer.setSeriesShape(1, shape);
renderer.setSeriesShape(2, shape);
renderer.setBaseShapesVisible(true);
renderer.setSeriesOutlinePaint(0, Color.GRAY);
renderer.setSeriesOutlinePaint(1, Color.GRAY);
renderer.setSeriesOutlinePaint(2, Color.GRAY);
renderer.setUseFillPaint(true);
renderer.setSeriesFillPaint(0, Color.red);
renderer.setSeriesFillPaint(1, Color.green);
renderer.setSeriesFillPaint(2, Color.blue);
renderer.setSeriesPaint(0, Color.red);
renderer.setSeriesPaint(1, Color.green);
renderer.setSeriesPaint(2, Color.blue);
NumberAxis yaxis = (NumberAxis) plot.getRangeAxis();
yaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
yaxis.setAutoRangeIncludesZero(false);
plot.setRangeAxis(yaxis);
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setAutoTickUnitSelection(true);
// axis.setTickUnit(new DateTickUnit(DateTickUnitType.SECOND,120));
axis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
// DateAxis.createStandardDateTickUnits();
axis.setTickMarksVisible(true);
axis.setTickLabelsVisible(true);
return chart;
}
public void setValue(ArrayList<TreeMap<Timestamp, Long>> statisticalValues, String protocolName, String statistics) {
// //System.out
// .println("setting the value for timeseries-->" + i);
TimeSeries ts = null;
for (TreeMap<Timestamp, Long> entries : statisticalValues) {
ts = new TimeSeries(protocolName + "_" + statistics,
Second.class);
for (Entry<Timestamp, Long> seriesData : entries.entrySet()) {
ts.addOrUpdate(new Second(seriesData.getKey()),
seriesData.getValue());
}
}
dataset.addSeries(ts);
}
The handler responsible for dynamic creation of tab(Grapgh part):
public class DynamicPartsHandler {
@Execute
public void execute(EPartService partService, EModelService modelService,
MApplication application,Shell shell) {
String partName = "Graph";
MPart part = partService
.createPart("com.wincor.commtrace.project.partDescriptor.1");
MPartStack stack = (MPartStack) modelService.find(
"com.wincor.commtrace.project.partstack.2", application);
stack.getChildren().add(part);
part.setLabel(partName);
part.setVisible(true);
part.setCloseable(true);
partService.showPart(part, PartState.ACTIVATE);
}
}
Thanks in advance