Search in sources :

Example 1 with ISTDataViewersField

use of org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField 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 ISTDataViewersField

use of org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField in project linuxtools by eclipse.

the class STCopyAction method run.

@Override
public void run() {
    Clipboard cb = new Clipboard(Display.getDefault());
    IStructuredSelection selections = (IStructuredSelection) stViewer.getViewer().getSelection();
    Iterator<?> iterator = selections.iterator();
    StringBuilder sb = new StringBuilder();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        boolean needTab = false;
        for (ISTDataViewersField field : stViewer.getAllFields()) {
            if (needTab) {
                sb.append("\t");
            }
            needTab = true;
            if (field.getValue(obj) != null) {
                sb.append(field.getValue(obj));
            }
        }
        sb.append("\n");
    }
    cb.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
Also used : Clipboard(org.eclipse.swt.dnd.Clipboard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISTDataViewersField(org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField)

Example 3 with ISTDataViewersField

use of org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField in project linuxtools by eclipse.

the class STDataViewersSortDialog method updateUI.

private void updateUI(int[] priorities, int[] directions) {
    Item[] columns = sorter.getColumns();
    List<String> allItems = new ArrayList<>();
    List<Integer> allDirections = new ArrayList<>();
    for (int i = 0; i < columns.length; i++) {
        if (priorities == null || directions == null) {
            allItems.add(columns[i].getText());
            ISTDataViewersField field = (ISTDataViewersField) columns[i].getData();
            allDirections.add(field.getDefaultDirection());
        } else {
            allItems.add(columns[priorities[i]].getText());
            allDirections.add(directions[priorities[i]]);
        }
    }
    for (int i = 0; i < priorityCombos.length; i++) {
        priorityCombos[i].removeAll();
        priorityCombos[i].setItems(allItems.toArray(new String[allItems.size()]));
        priorityCombos[i].select(0);
        allItems.remove(0);
        ascendingButtons[i].setSelection(allDirections.get(0) == STDataViewersComparator.ASCENDING);
        descendingButtons[i].setSelection(allDirections.get(0) == STDataViewersComparator.DESCENDING);
        allDirections.remove(0);
    }
}
Also used : Item(org.eclipse.swt.widgets.Item) ArrayList(java.util.ArrayList) ISTDataViewersField(org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField)

Example 4 with ISTDataViewersField

use of org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField in project linuxtools by eclipse.

the class STHeaderListener method widgetSelected.

@Override
public void widgetSelected(SelectionEvent e) {
    final Item column = (Item) e.widget;
    final ISTDataViewersField field = (ISTDataViewersField) column.getData();
    resortTable(column, field);
}
Also used : Item(org.eclipse.swt.widgets.Item) ISTDataViewersField(org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField)

Example 5 with ISTDataViewersField

use of org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField 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)5 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IChartField (org.eclipse.linuxtools.dataviewers.charts.provider.IChartField)2 Button (org.eclipse.swt.widgets.Button)2 Item (org.eclipse.swt.widgets.Item)2 Clipboard (org.eclipse.swt.dnd.Clipboard)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