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

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

Introduction

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

Prototype

public void setText(String text) 

Source Link

Document

Set the text for the cell.

Usage

From source file:net.tourbook.ui.views.TourWaypointView.java

License:Open Source License

/**
 * column: time// www .  j ava  2 s . c om
 */
private void defineColumn_Time() {

    final ColumnDefinition colDef = TableColumnFactory.WAYPOINT_TIME.createColumn(_columnManager, _pc);
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final TourWayPoint wp = (TourWayPoint) cell.getElement();
            final long time = wp.getTime();

            cell.setText(time == 0 //
                    ? UI.EMPTY_STRING
                    : TimeTools.getZonedDateTime(time).format(TimeTools.Formatter_Time_M));
        }
    });
}

From source file:net.tourbook.ui.views.TourWaypointView.java

License:Open Source License

/**
 * Column: Url// w w w  .  ja  va2s. c o m
 */
private void defineColumn_Url() {

    final ColumnDefinition colDef = TableColumnFactory.MARKER_URL.createColumn(_columnManager, _pc);
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final TourWayPoint marker = (TourWayPoint) cell.getElement();

            String columnText = UI.EMPTY_STRING;

            final String urlText = marker.getUrlText();
            final String urlAddress = marker.getUrlAddress();

            final boolean isText = urlText != null && urlText.length() > 0;
            final boolean isAddress = urlAddress != null && urlAddress.length() > 0;

            if (isText || isAddress) {

                if (isAddress == false) {

                    // only text is in the link -> this is not a internet address but create a link of it

                    columnText = urlText;

                } else {

                    columnText = urlAddress;
                }
            }

            cell.setText(columnText);
        }
    });
}

From source file:net.tourbook.util.DialogModifyColumns.java

License:Open Source License

private void createUI10ColumnsViewer(final Composite parent) {

    final TableColumnLayout tableLayout = new TableColumnLayout();
    final Composite layoutContainer = new Composite(parent, SWT.NONE);
    layoutContainer.setLayout(tableLayout);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(layoutContainer);

    /*/* w  w w  .ja  v a  2 s  .c o m*/
     * create table
     */
    final Table table = new Table(layoutContainer, SWT.CHECK | SWT.FULL_SELECTION | SWT.BORDER);

    table.setLayout(new TableLayout());
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    _columnViewer = new CheckboxTableViewer(table);

    /*
     * create columns
     */
    TableViewerColumn tvc;
    TableColumn tvcColumn;

    // column: label
    tvc = new TableViewerColumn(_columnViewer, SWT.LEAD);
    tvcColumn = tvc.getColumn();
    tvcColumn.setText(Messages.ColumnModifyDialog_column_column);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final ColumnDefinition colDef = (ColumnDefinition) cell.getElement();
            cell.setText(colDef.getColumnLabel());

            // paint columns in a different color which can't be hidden
            if (colDef.canModifyVisibility() == false) {
                cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
            }
        }
    });
    tableLayout.setColumnData(tvcColumn, new ColumnWeightData(1, true));

    // column: unit
    tvc = new TableViewerColumn(_columnViewer, SWT.LEAD);
    tvcColumn = tvc.getColumn();
    tvcColumn.setText(Messages.ColumnModifyDialog_column_unit);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final ColumnDefinition colDef = (ColumnDefinition) cell.getElement();
            cell.setText(colDef.getColumnUnit());

            // paint columns in a different color which can't be hidden
            if (colDef.canModifyVisibility() == false) {
                cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
            }
        }
    });
    tableLayout.setColumnData(tvcColumn, new ColumnPixelData(_pc.convertWidthInCharsToPixels(13), true));

    // column: width
    tvc = new TableViewerColumn(_columnViewer, SWT.TRAIL);
    tvcColumn = tvc.getColumn();
    tvcColumn.setText(Messages.ColumnModifyDialog_column_width);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final ColumnDefinition colDef = (ColumnDefinition) cell.getElement();
            cell.setText(Integer.toString(colDef.getColumnWidth()));

            // paint columns in a different color which can't be hidden
            if (colDef.canModifyVisibility() == false) {
                cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));
            }
        }
    });
    tableLayout.setColumnData(tvcColumn, new ColumnPixelData(_pc.convertWidthInCharsToPixels(10), true));

    _columnViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public Object[] getElements(final Object inputElement) {
            return _allColumnsInDialog.toArray();
        }

        public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
        }
    });

    _columnViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(final DoubleClickEvent event) {

            final Object firstElement = ((IStructuredSelection) _columnViewer.getSelection()).getFirstElement();
            if (firstElement != null) {

                // check/uncheck current item

                _columnViewer.setChecked(firstElement, !_columnViewer.getChecked(firstElement));
            }
        }
    });

    _columnViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(final CheckStateChangedEvent event) {

            final ColumnDefinition colDef = (ColumnDefinition) event.getElement();

            if (colDef.canModifyVisibility()) {

                // keep the checked status
                colDef.setIsCheckedInDialog(event.getChecked());

                // select the checked item
                _columnViewer.setSelection(new StructuredSelection(colDef));

            } else {

                // column can't be unchecked
                _columnViewer.setChecked(colDef, true);
            }
        }
    });

    _columnViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(final SelectionChangedEvent event) {
            enableUpDownButtons();
        }
    });

    /*
     * set drag adapter
     */
    _columnViewer.addDragSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() },
            new DragSourceListener() {

                public void dragFinished(final DragSourceEvent event) {

                    final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();

                    if (event.doit == false) {
                        return;
                    }

                    transfer.setSelection(null);
                    transfer.setSelectionSetTime(0);
                }

                public void dragSetData(final DragSourceEvent event) {
                    // data are set in LocalSelectionTransfer
                }

                public void dragStart(final DragSourceEvent event) {

                    final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();
                    final ISelection selection = _columnViewer.getSelection();

                    _dndCheckedElements = _columnViewer.getCheckedElements();

                    transfer.setSelection(selection);
                    transfer.setSelectionSetTime(_dndDragStartViewerLeft = event.time & 0xFFFFFFFFL);

                    event.doit = !selection.isEmpty();
                }
            });

    /*
     * set drop adapter
     */
    final ViewerDropAdapter viewerDropAdapter = new ViewerDropAdapter(_columnViewer) {

        private Widget _dragOverItem;

        @Override
        public void dragOver(final DropTargetEvent dropEvent) {

            // keep table item
            _dragOverItem = dropEvent.item;

            super.dragOver(dropEvent);
        }

        @Override
        public boolean performDrop(final Object data) {

            if (data instanceof StructuredSelection) {
                final StructuredSelection selection = (StructuredSelection) data;

                if (selection.getFirstElement() instanceof ColumnDefinition) {

                    final ColumnDefinition colDef = (ColumnDefinition) selection.getFirstElement();

                    final int location = getCurrentLocation();
                    final Table filterTable = _columnViewer.getTable();

                    /*
                     * check if drag was startet from this item, remove the item before the new
                     * item is inserted
                     */
                    if (LocalSelectionTransfer.getTransfer().getSelectionSetTime() == _dndDragStartViewerLeft) {
                        _columnViewer.remove(colDef);
                    }

                    int filterIndex;

                    if (_dragOverItem == null) {

                        _columnViewer.add(colDef);
                        filterIndex = filterTable.getItemCount() - 1;

                    } else {

                        // get index of the target in the table
                        filterIndex = filterTable.indexOf((TableItem) _dragOverItem);
                        if (filterIndex == -1) {
                            return false;
                        }

                        if (location == LOCATION_BEFORE) {
                            _columnViewer.insert(colDef, filterIndex);
                        } else if (location == LOCATION_AFTER || location == LOCATION_ON) {
                            _columnViewer.insert(colDef, ++filterIndex);
                        }
                    }

                    // reselect filter item
                    _columnViewer.setSelection(new StructuredSelection(colDef));

                    // set focus to selection
                    filterTable.setSelection(filterIndex);
                    filterTable.setFocus();

                    // recheck items
                    _columnViewer.setCheckedElements(_dndCheckedElements);

                    enableUpDownButtons();

                    return true;
                }
            }

            return false;
        }

        @Override
        public boolean validateDrop(final Object target, final int operation, final TransferData transferType) {

            final LocalSelectionTransfer transferData = LocalSelectionTransfer.getTransfer();

            // check if dragged item is the target item
            final ISelection selection = transferData.getSelection();
            if (selection instanceof StructuredSelection) {
                final Object dragFilter = ((StructuredSelection) selection).getFirstElement();
                if (target == dragFilter) {
                    return false;
                }
            }

            if (transferData.isSupportedType(transferType) == false) {
                return false;
            }

            // check if target is between two items
            if (getCurrentLocation() == LOCATION_ON) {
                return false;
            }

            return true;
        }

    };

    _columnViewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() },
            viewerDropAdapter);
}

From source file:net.vectorcomputing.photo.ui.widgets.PhotoCatalogsCellLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (element instanceof IPhotoCatalog) {
        IPhotoCatalog catalog = (IPhotoCatalog) element;
        int index = cell.getColumnIndex();
        switch (index) {
        case 0://from w ww . j  a v a 2  s.  co  m
            cell.setText(catalog.getFileStore().getName());
            break;
        case 1:
            cell.setText(Integer.toString(catalog.getPhotos().size()));
            break;
        case 2:
            IPhotoCatalogUpdateStatistics stats = catalog.getUpdateStatistics();
            if (stats != null) {
                Calendar endTime = stats.getEndTime();
                if (endTime != null) {
                    cell.setText(endTime.toString());
                }
            }
            break;
        default:
            break;
        }
    }
}

From source file:net.vectorcomputing.photo.ui.widgets.PhotoFactoriesCellLabelProvider.java

License:Apache License

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (element instanceof IPhotoFactoryDescriptor) {
        IPhotoFactoryDescriptor factory = (IPhotoFactoryDescriptor) element;
        int index = cell.getColumnIndex();
        switch (index) {
        case 0:/* w w  w.  j  ava 2s  .c o  m*/
            cell.setText(factory.getId());
            break;
        case 1:
            cell.setText(factory.getName());
            break;
        default:
            break;
        }
    }
}

From source file:net.zehrer.no2.ui.provider.NoColumnLabelProvider.java

License:Open Source License

@Override
public void update(ViewerCell cell) {
    cell.setText(table.indexOf((TableItem) cell.getItem()) + 1 + "");
    cell.setBackground(this.color);
}

From source file:oic.simulator.serviceprovider.view.DevicePlatformInfoView.java

License:Open Source License

public void createColumns(TableViewer tableViewer, PropertiesType propType) {
    TableViewerColumn propName = new TableViewerColumn(tableViewer, SWT.NONE);
    propName.getColumn().setWidth(columnWidth[0]);
    propName.getColumn().setText(columnHeaders[0]);
    propName.setLabelProvider(new StyledCellLabelProvider() {
        @Override/*from ww  w  .  j a  v a 2  s  .c o m*/
        public void update(ViewerCell cell) {
            MetaProperty prop = (MetaProperty) cell.getElement();
            cell.setText(prop.getPropName());
            super.update(cell);
        }
    });

    TableViewerColumn propValue = new TableViewerColumn(tableViewer, SWT.NONE);
    propValue.getColumn().setWidth(columnWidth[1]);
    propValue.getColumn().setText(columnHeaders[1]);
    propValue.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            MetaProperty prop = (MetaProperty) element;
            if (null != prop) {
                return prop.getPropValue();
            } else {
                return "";
            }
        }
    });
    if (propType == PropertiesType.DEVICE) {
        propValue.setEditingSupport(new PropValueEditor(deviceTblViewer, propType));
    } else {
        propValue.setEditingSupport(new PropValueEditor(platformTblViewer, propType));
    }
}

From source file:oic.simulator.serviceprovider.view.dialogs.SimpleResourceAddAttributePage.java

License:Open Source License

public void createAttributeColumns(TableViewer tableViewer) {

    TableViewerColumn attName = new TableViewerColumn(tableViewer, SWT.NONE);
    attName.getColumn().setWidth(attTblColWidth[0]);
    attName.getColumn().setText(attTblHeaders[0]);
    attName.setLabelProvider(new StyledCellLabelProvider() {
        @Override//from   ww w  . java2s  .  co  m
        public void update(ViewerCell cell) {
            Object e = cell.getElement();
            if (null == e) {
                return;
            }
            AttributeHelper att = (AttributeHelper) e;
            cell.setText(att.getAttributeName());

        }
    });

    TableViewerColumn attType = new TableViewerColumn(tableViewer, SWT.NONE);
    attType.getColumn().setWidth(attTblColWidth[1]);
    attType.getColumn().setText(attTblHeaders[1]);
    attType.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Object e = cell.getElement();
            if (null == e) {
                return;
            }
            AttributeHelper att = (AttributeHelper) e;
            cell.setText(att.getAttributeType());
        }
    });

    TableViewerColumn attRange = new TableViewerColumn(tableViewer, SWT.NONE);
    attRange.getColumn().setWidth(attTblColWidth[2]);
    attRange.getColumn().setText(attTblHeaders[2]);
    attRange.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Object e = cell.getElement();
            if (null == e) {
                return;
            }
            AttributeHelper att = (AttributeHelper) e;
            if (att.getValidValuesType() != ValidValuesType.RANGE) {
                cell.setText("Nil");
            } else {
                String min = att.getMin();
                String max = att.getMax();
                if (null != min && null != max) {
                    cell.setText("[" + att.getMin() + " to " + att.getMax() + "]");
                } else {
                    cell.setText("Nil");
                }
            }
        }
    });

    TableViewerColumn attAllwdValues = new TableViewerColumn(tableViewer, SWT.NONE);
    attAllwdValues.getColumn().setWidth(attTblColWidth[3]);
    attAllwdValues.getColumn().setText(attTblHeaders[3]);
    attAllwdValues.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Object e = cell.getElement();
            if (null == e) {
                return;
            }
            AttributeHelper att = (AttributeHelper) e;
            if (att.getValidValuesType() != ValidValuesType.VALUESET) {
                cell.setText("Nil");
            } else {
                cell.setText(att.getAllowedValues().toString());
            }
        }
    });

    TableViewerColumn attDflValue = new TableViewerColumn(tableViewer, SWT.NONE);
    attDflValue.getColumn().setWidth(attTblColWidth[4]);
    attDflValue.getColumn().setText(attTblHeaders[4]);
    attDflValue.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Object e = cell.getElement();
            if (null == e) {
                return;
            }
            AttributeHelper att = (AttributeHelper) e;
            cell.setText(att.getAttributeDflValue());
        }
    });
}

From source file:oic.simulator.serviceprovider.view.MetaPropertiesView.java

License:Open Source License

public void createColumns(final TableViewer tableViewer) {
    TableViewerColumn propName = new TableViewerColumn(tableViewer, SWT.NONE);
    propName.getColumn().setWidth(columnWidth[0]);
    propName.getColumn().setText(columnHeaders[0]);
    propName.setLabelProvider(new StyledCellLabelProvider() {
        @Override/*from w w  w .j  av  a2s. c o  m*/
        public void update(ViewerCell cell) {
            MetaProperty prop = (MetaProperty) cell.getElement();
            cell.setText(prop.getPropName());
            super.update(cell);
        }
    });

    TableViewerColumn propValue = new TableViewerColumn(tableViewer, SWT.NONE);
    propValue.getColumn().setWidth(columnWidth[1]);
    propValue.getColumn().setText(columnHeaders[1]);
    propValue.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            MetaProperty prop = (MetaProperty) cell.getElement();
            cell.setText(prop.getPropValue());
            super.update(cell);
        }
    });
    propValue.setEditingSupport(new PropValueEditor(tableViewer));
}

From source file:oic.simulator.serviceprovider.view.ResourceObserverView.java

License:Open Source License

public void createColumns(TableViewer tableViewer) {
    TableViewerColumn addressColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    addressColumn.getColumn().setWidth(columnWidth[0]);
    addressColumn.getColumn().setText(columnHeaders[0]);
    addressColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override/*w  w  w  .j  ava  2  s .  com*/
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            if (element instanceof Map.Entry) {
                @SuppressWarnings("unchecked")
                Map.Entry<Integer, ObserverDetail> observer = (Map.Entry<Integer, ObserverDetail>) element;
                cell.setText(observer.getValue().getObserverInfo().getAddress());
            }
        }
    });

    TableViewerColumn portColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    portColumn.getColumn().setWidth(columnWidth[1]);
    portColumn.getColumn().setText(columnHeaders[1]);
    portColumn.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(ViewerCell cell) {
            Object element = cell.getElement();
            if (element instanceof Map.Entry) {
                @SuppressWarnings("unchecked")
                Map.Entry<Integer, ObserverDetail> observer = (Map.Entry<Integer, ObserverDetail>) element;
                cell.setText(String.valueOf(observer.getValue().getObserverInfo().getPort()));
            }
        }
    });

    TableViewerColumn notifyColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    notifyColumn.getColumn().setWidth(columnWidth[2]);
    notifyColumn.getColumn().setText(columnHeaders[2]);
    notifyColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return "";
        }

        @Override
        public Image getImage(Object element) {
            @SuppressWarnings("unchecked")
            Map.Entry<Integer, ObserverDetail> observer = (Map.Entry<Integer, ObserverDetail>) element;
            if (observer.getValue().isClicked()) {
                return Activator.getDefault().getImageRegistry().get(Constants.NOTIFY_BUTTON_SELECTED);
            }
            return Activator.getDefault().getImageRegistry().get(Constants.NOTIFY_BUTTON_UNSELECTED);
        }
    });
    notifyColumn.setEditingSupport(new NotifyEditor(tableViewer));
}