use of org.eclipse.linuxtools.dataviewers.charts.provider.IChartField in project linuxtools by eclipse.
the class ChartDialog method produceChart.
/**
* Build the chart from configuration
*
* @return a new chart
*/
private Chart produceChart() {
IStructuredSelection selection = (IStructuredSelection) stViewer.getViewer().getSelection();
if (selection == StructuredSelection.EMPTY)
return null;
Object[] objects = selection.toArray();
ISTDataViewersField labelField = getLabelField(stViewer);
List<IChartField> selectedFields = new ArrayList<>();
for (Button button : columnButtons) {
if (button.getSelection()) {
selectedFields.add((IChartField) button.getData());
}
}
boolean barChartType = barGraphButton.getSelection();
boolean horizontalBars = !verticalBarsButton.getSelection();
if (barChartType) {
return ChartFactory.produceBarChart(objects, labelField, selectedFields, Messages.ChartConstants_BAR_GRAPH, horizontalBars);
} else {
return ChartFactory.producePieChart(objects, labelField, selectedFields, Messages.ChartConstants_PIE_CHART);
}
}
use of org.eclipse.linuxtools.dataviewers.charts.provider.IChartField in project linuxtools by eclipse.
the class ChartDialog method addColumnButtons.
/**
* Adds one check button for each column implementing the IChartField interface.
*
* @see IChartField
* @param comp
* @param listener
*/
private void addColumnButtons(Composite comp, SelectionListener listener) {
columnButtons = new LinkedList<>();
for (ISTDataViewersField field : stViewer.getAllFields()) {
if (field instanceof IChartField) {
IChartField cField = (IChartField) field;
Button b = new Button(comp, SWT.CHECK);
b.setText(cField.getColumnHeaderText());
b.setData(cField);
b.addSelectionListener(listener);
GridData dt = new GridData();
b.setLayoutData(dt);
columnButtons.add(b);
}
}
Label sep = new Label(comp, SWT.SEPARATOR | SWT.HORIZONTAL);
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
sep.setLayoutData(data);
Composite buttonComposite = new Composite(comp, SWT.NONE);
data = new GridData();
buttonComposite.setLayoutData(data);
FillLayout l = new FillLayout();
l.spacing = 5;
buttonComposite.setLayout(l);
final Button b1 = new Button(buttonComposite, SWT.PUSH);
b1.setText(Messages.ChartConstants_SELECT_ALL);
final Button b2 = new Button(buttonComposite, SWT.PUSH);
b2.setText(Messages.ChartConstants_DESELECT_ALL);
SelectionListener sl = new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
boolean b = (e.getSource() == b1);
for (Button button : columnButtons) {
button.setSelection(b);
}
validateInput();
}
};
b1.addSelectionListener(sl);
b2.addSelectionListener(sl);
}
Aggregations