Example usage for org.eclipse.jface.viewers ViewerCell getViewerRow

List of usage examples for org.eclipse.jface.viewers ViewerCell getViewerRow

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerCell getViewerRow.

Prototype

public ViewerRow getViewerRow() 

Source Link

Usage

From source file:rabbit.ui.internal.viewers.TreePathDurationLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    TreePath path = cell.getViewerRow().getTreePath();
    String text = null;//from  w  w w.j  av a2s.  c o  m
    if (getValueProvider().shouldPaint(cell.getElement())) {
        text = DurationFormat.format(getValueProvider().getValue(path));
    }
    cell.setText(text);

    if (colorProvider != null) { // TOOD test
        cell.setBackground(colorProvider.getBackground(cell.getElement()));
        cell.setForeground(colorProvider.getForeground(cell.getElement()));
    }
}

From source file:rabbit.ui.internal.viewers.TreePathDurationLabelProviderTest.java

License:Apache License

@Test
public void updateShouldSetTheCellTextToBlankIfThePathShouldNotBePainted() throws Exception {
    ViewerCell cell = newCell(0, new Object());

    IValueProvider valueProvider = mock(IValueProvider.class);
    given(valueProvider.shouldPaint(cell.getElement())).willReturn(FALSE);
    given(valueProvider.getValue(cell.getViewerRow().getTreePath())).willReturn(Long.valueOf(1024));

    TreePathDurationLabelProvider labelProvider = new TreePathDurationLabelProvider(valueProvider);

    labelProvider.update(cell);/*from  w ww.j av  a  2 s.  c o m*/
    assertThat(nullToEmpty(cell.getText()), is(""));
}

From source file:rabbit.ui.internal.viewers.TreePathDurationLabelProviderTest.java

License:Apache License

@Test
public void updateShouldSetTheCellTextToTheValueOfThePathIfThePathIsToBePainted() throws Exception {
    long value = 1024;
    ViewerCell cell = newCell(0, new Object());

    IValueProvider valueProvider = mock(IValueProvider.class);
    given(valueProvider.shouldPaint(cell.getElement())).willReturn(TRUE);
    given(valueProvider.getValue(cell.getViewerRow().getTreePath())).willReturn(value);

    TreePathDurationLabelProvider labelProvider = new TreePathDurationLabelProvider(valueProvider);

    labelProvider.update(cell);/*from  w  w  w  . ja  v a 2  s .  co m*/
    assertThat(cell.getText(), is(DurationFormat.format(value)));
}

From source file:rabbit.ui.internal.viewers.TreePathIntLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    TreePath path = cell.getViewerRow().getTreePath();
    String text = null;/*www  . j  a v a2  s.co m*/
    if (getValueProvider().shouldPaint(cell.getElement())) {
        text = String.valueOf(getValueProvider().getValue(path));
    }
    cell.setText(text);

    if (colorProvider != null) {
        cell.setBackground(colorProvider.getBackground(cell.getElement()));
        cell.setForeground(colorProvider.getForeground(cell.getElement()));
    }
}

From source file:rabbit.ui.internal.viewers.TreePathIntLabelProviderTest.java

License:Apache License

@Test
public void updateShouldSetTheCellTextToBlankIfThePathShouldNotBePainted() throws Exception {
    ViewerCell cell = newCell(0, new Object());

    IValueProvider valueProvider = mock(IValueProvider.class);
    given(valueProvider.shouldPaint(cell.getElement())).willReturn(FALSE);
    given(valueProvider.getValue(cell.getViewerRow().getTreePath())).willReturn(Long.valueOf(1024));

    TreePathIntLabelProvider labelProvider = new TreePathIntLabelProvider(valueProvider);

    labelProvider.update(cell);/*www.  ja v a  2s . c o  m*/
    assertThat(nullToEmpty(cell.getText()), is(""));
}

From source file:rabbit.ui.internal.viewers.TreePathIntLabelProviderTest.java

License:Apache License

@Test
public void updateShouldSetTheCellTextToTheValueOfThePathIfThePathIsToBePainted() throws Exception {
    long value = 1024;
    ViewerCell cell = newCell(0, new Object());

    IValueProvider valueProvider = mock(IValueProvider.class);
    given(valueProvider.shouldPaint(cell.getElement())).willReturn(TRUE);
    given(valueProvider.getValue(cell.getViewerRow().getTreePath())).willReturn(value);

    TreePathIntLabelProvider labelProvider = new TreePathIntLabelProvider(valueProvider);

    labelProvider.update(cell);/*from w  w  w  .  j av  a 2s.c  om*/
    assertThat(cell.getText(), is(String.valueOf(value)));
}

From source file:uk.ac.gda.common.rcp.jface.viewers.ObservableMapCellControlProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    TableItem item = (TableItem) cell.getItem();
    Control control = null;/* w ww.j ava2 s  . c  om*/

    Object e = cell.getElement();
    Object itemData = item.getData(uniqueKey);
    if (itemData != null && itemData instanceof TableEditor) {
        control = ((TableEditor) itemData).getEditor();
    }
    if (control == null) {
        control = controlFactory.createControl((Composite) cell.getViewerRow().getControl());
        TableEditor editor = new TableEditor(item.getParent());
        editor.grabHorizontal = true;
        editor.grabVertical = true;
        editor.setEditor(control, item, cell.getColumnIndex());
        editor.layout();
        //we need to dispose the TableEditor and ProgressBar when the TableItem is disposed otherwise there will be a build up
        //of TableEditor and ProgressBars being constructed as the list changes which will only
        //be disposed when the table is disposed. 
        item.setData(uniqueKey, editor);
        item.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                Object data = e.widget.getData(uniqueKey);
                if (data != null) {
                    TableEditor tableEditor = (TableEditor) data;
                    tableEditor.getEditor().dispose();
                    tableEditor.dispose();
                }
            }
        });
    }
    Object value = attributeMaps[0].get(e);
    controlFactory.updateControl(control, value);
}

From source file:uk.ac.gda.ui.doe.DOEView.java

License:Open Source License

private void createTableColumns() {

    // Dispose columns not the first.
    for (; tableViewer.getTable().getColumnCount() > 1;)
        tableViewer.getTable().getColumns()[1].dispose();

    // Create experiment name column if required.
    if (tableViewer.getTable().getColumnCount() < 1) {
        final TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE, 0);
        col.getColumn().setText("Experiment");
        col.setLabelProvider(new ColumnLabelProvider() {
            @Override//from   w ww .  j  a  va  2  s.c om
            public void update(ViewerCell cell) {
                final TableItem item = (TableItem) cell.getViewerRow().getItem();
                final Table table = tableViewer.getTable();
                int row = table.indexOf(item) + 1;
                cell.setText(" " + row);
            }
        });
        col.getColumn().setWidth(120);
    }

    if (info == null)
        return;

    final Map<String, Class<?>> columns = new LinkedHashMap<String, Class<?>>();
    for (RangeInfo i : info)
        columns.putAll(i.getColumnClasses());

    final String[] columnLabels = getColumnLabels(columns);
    final String[] columnProperties = getColumnProperties(columns);

    for (int icolumn = 1; icolumn < columnLabels.length; icolumn++) {

        final TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE, icolumn);
        col.getColumn().setText(columnLabels[icolumn]);

        col.setLabelProvider(new FieldColumnProvider(columnProperties));
        col.getColumn().setWidth(100);

    }

    tableViewer.setColumnProperties(columnProperties);
    tableViewer.setInput(new Object());

}