Search in sources :

Example 1 with IChartField

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);
    }
}
Also used : Button(org.eclipse.swt.widgets.Button) IChartField(org.eclipse.linuxtools.dataviewers.charts.provider.IChartField) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISTDataViewersField(org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField)

Example 2 with IChartField

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);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) IChartField(org.eclipse.linuxtools.dataviewers.charts.provider.IChartField) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FillLayout(org.eclipse.swt.layout.FillLayout) ISTDataViewersField(org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ISTDataViewersField (org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField)2 IChartField (org.eclipse.linuxtools.dataviewers.charts.provider.IChartField)2 Button (org.eclipse.swt.widgets.Button)2 ArrayList (java.util.ArrayList)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridData (org.eclipse.swt.layout.GridData)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1