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.preferences.PrefPageTourTypeFilterList.java

License:Open Source License

private void createUI_10_FilterViewer(final Composite parent) {

    final TableLayoutComposite layouter = new TableLayoutComposite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).hint(200, SWT.DEFAULT).applyTo(layouter);

    final Table table = new Table(layouter, (SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION));
    table.setHeaderVisible(false);//  w  w w  . j  av  a 2 s. c om
    table.setLinesVisible(false);

    TableViewerColumn tvc;

    _filterViewer = new TableViewer(table);

    // column: name + image
    tvc = new TableViewerColumn(_filterViewer, SWT.NONE);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final TourTypeFilter filter = ((TourTypeFilter) cell.getElement());
            final int filterType = filter.getFilterType();

            String filterName = null;
            Image filterImage = null;

            // set filter name/image
            switch (filterType) {
            case TourTypeFilter.FILTER_TYPE_DB:
                final TourType tourType = filter.getTourType();
                filterName = tourType.getName();
                filterImage = UI.getInstance().getTourTypeImage(tourType.getTypeId());
                break;

            case TourTypeFilter.FILTER_TYPE_SYSTEM:
                filterName = filter.getSystemFilterName();
                filterImage = UI.IMAGE_REGISTRY.get(UI.IMAGE_TOUR_TYPE_FILTER_SYSTEM);
                break;

            case TourTypeFilter.FILTER_TYPE_TOURTYPE_SET:
                filterName = filter.getTourTypeSet().getName();
                filterImage = UI.IMAGE_REGISTRY.get(UI.IMAGE_TOUR_TYPE_FILTER);
                break;

            default:
                break;
            }

            cell.setText(filterName);
            cell.setImage(filterImage);
        }
    });
    layouter.addColumnData(new ColumnWeightData(1));

    _filterViewer.setContentProvider(new IStructuredContentProvider() {
        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(final Object inputElement) {
            return _filterList.toArray();
        }

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

    _filterViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            onSelectFilter();
        }
    });

    _filterViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            onRenameFilterSet();
        }
    });

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

                @Override
                public void dragFinished(final DragSourceEvent event) {

                    final LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();

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

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

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

                @Override
                public void dragStart(final DragSourceEvent event) {

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

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

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

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

        private Widget _tableItem;

        @Override
        public void dragOver(final DropTargetEvent dropEvent) {

            // keep table item
            _tableItem = 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 TourTypeFilter) {

                    final TourTypeFilter filterItem = (TourTypeFilter) selection.getFirstElement();

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

                    /*
                     * check if drag was startet from this filter, remove the filter item before
                     * the new filter is inserted
                     */
                    if (LocalSelectionTransfer.getTransfer().getSelectionSetTime() == _dragStartViewerLeft) {
                        _filterViewer.remove(filterItem);
                    }

                    int filterIndex;

                    if (_tableItem == null) {

                        _filterViewer.add(filterItem);
                        filterIndex = filterTable.getItemCount() - 1;

                    } else {

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

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

                    // reselect filter item
                    _filterViewer.setSelection(new StructuredSelection(filterItem));

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

                    _isModified = true;

                    return true;
                }
            }

            return false;
        }

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

            final ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
            if (selection instanceof StructuredSelection) {
                final Object dragFilter = ((StructuredSelection) selection).getFirstElement();
                if (target == dragFilter) {
                    return false;
                }
            }

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

            return true;
        }

    };

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

From source file:net.tourbook.preferences.PrefPageTourTypeFilterList.java

License:Open Source License

private void createUI_20_TourTypeViewer(final Composite parent) {

    final TableLayoutComposite layouter = new TableLayoutComposite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).hint(200, SWT.DEFAULT).applyTo(layouter);

    final Table table = new Table(layouter,
            (SWT.CHECK | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION));

    table.setHeaderVisible(false);//from   w  ww.  j  a v  a2s .c o m
    table.setLinesVisible(false);

    _tourTypeViewer = new CheckboxTableViewer(table);

    TableViewerColumn tvc;

    // column: name
    tvc = new TableViewerColumn(_tourTypeViewer, SWT.NONE);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final TourType tourType = ((TourType) cell.getElement());
            cell.setText(tourType.getName());
            cell.setImage(UI.getInstance().getTourTypeImage(tourType.getTypeId()));
        }
    });
    layouter.addColumnData(new ColumnWeightData(1));

    _tourTypeViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(final Object inputElement) {
            return _tourTypes.toArray();
        }

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

    _tourTypeViewer.addCheckStateListener(new ICheckStateListener() {
        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            _isModified = true;
        }
    });

    _tourTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            onSelectTourType();
        }
    });

    _tourTypeViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {

            /*
             * invert check state
             */
            final TourType tourType = (TourType) ((StructuredSelection) _tourTypeViewer.getSelection())
                    .getFirstElement();

            final boolean isChecked = _tourTypeViewer.getChecked(tourType);

            _tourTypeViewer.setChecked(tourType, !isChecked);

            //            getSelectedTourTypes();
        }
    });
}

From source file:net.tourbook.preferences.PrefPageTourTypes.java

License:Open Source License

/**
 * create columns/*from   ww  w.  j a  v a  2s.c om*/
 */
private void defineAllColumns(final TreeColumnLayout treeLayout, final Tree tree) {

    final int numberOfHorizontalImages = 4;
    final int trailingOffset = 10;

    final int itemHeight = tree.getItemHeight();
    final int oneColorWidth = itemHeight + GraphColorPainter.GRAPH_COLOR_SPACING;

    final int colorImageWidth = (oneColorWidth * numberOfHorizontalImages) + trailingOffset;

    TreeColumn tc;
    TreeViewerColumn tvc;

    /*
     * 1. column: color item/color definition
     */
    {
        tvc = new TreeViewerColumn(_tourTypeViewer, SWT.TRAIL);
        tc = tvc.getColumn();
        tvc.setLabelProvider(new StyledCellLabelProvider() {
            @Override
            public void update(final ViewerCell cell) {

                final Object element = cell.getElement();

                if (element instanceof ColorDefinition) {

                    cell.setText(((ColorDefinition) (element)).getVisibleName());

                } else if (element instanceof GraphColorItem) {

                    cell.setText(((GraphColorItem) (element)).getName());

                } else {

                    cell.setText(UI.EMPTY_STRING);
                }
            }
        });
        treeLayout.setColumnData(tc, new ColumnWeightData(1, true));
    }

    /*
     * 2. column: color for definition/item
     */
    {
        tvc = new TreeViewerColumn(_tourTypeViewer, SWT.TRAIL);
        tc = tvc.getColumn();
        tvc.setLabelProvider(new StyledCellLabelProvider() {
            @Override
            public void update(final ViewerCell cell) {

                final Object element = cell.getElement();

                if (element instanceof ColorDefinition) {

                    final Image image = _graphColorPainter.drawColorDefinitionImage((ColorDefinition) element,
                            numberOfHorizontalImages);

                    cell.setImage(image);

                } else if (element instanceof GraphColorItem) {

                    final Image image = _graphColorPainter.drawGraphColorImage(//
                            (GraphColorItem) element, numberOfHorizontalImages);

                    cell.setImage(image);

                } else {

                    cell.setImage(null);
                }
            }
        });
        treeLayout.setColumnData(tc, new ColumnPixelData(colorImageWidth, true));
    }
}

From source file:net.tourbook.srtm.PrefPageSRTMColors.java

License:Open Source License

/**
 * column: id//from   w  w w  .  ja  v  a 2  s.  co m
 */
private void defineColumn_ProfileId() {

    final TableColumnDefinition colDef = new TableColumnDefinition(_columnManager, "profileId", SWT.TRAIL); //$NON-NLS-1$

    colDef.setColumnLabel(Messages.profileViewer_column_label_id);
    colDef.setColumnHeaderText(Messages.profileViewer_column_label_id_header);
    colDef.setColumnHeaderToolTipText(Messages.profileViewer_column_label_id_tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(10));
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final SRTMProfile vertexList = (SRTMProfile) cell.getElement();
            cell.setText(Integer.toString(vertexList.getProfileId()));
        }
    });
}

From source file:net.tourbook.srtm.PrefPageSRTMColors.java

License:Open Source License

/**
 * column: profile name/*from   ww  w  .j ava2 s  .c o m*/
 */
private void defineColumn_ProfileName() {

    final TableColumnDefinition colDef = new TableColumnDefinition(_columnManager, "profileName", SWT.LEAD); //$NON-NLS-1$

    colDef.setColumnLabel(Messages.profileViewer_column_label_name);
    colDef.setColumnHeaderText(Messages.profileViewer_column_label_name_header);
    colDef.setColumnHeaderToolTipText(Messages.profileViewer_column_label_name_tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(20));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final SRTMProfile vertexList = (SRTMProfile) cell.getElement();
            cell.setText(vertexList.getProfileName());
        }
    });
}

From source file:net.tourbook.srtm.PrefPageSRTMColors.java

License:Open Source License

/**
 * column: resolution/*w  ww. j  a  v  a 2  s  .c  om*/
 */
private void defineColumn_Resolution() {

    final TableColumnDefinition colDef = new TableColumnDefinition(_columnManager, "resolution", SWT.LEAD); //$NON-NLS-1$

    colDef.setColumnLabel(Messages.profileViewer_column_label_resolution);
    colDef.setColumnHeaderText(Messages.profileViewer_column_label_resolution_header);
    colDef.setColumnHeaderToolTipText(Messages.profileViewer_column_label_resolution_tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(20));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final SRTMProfile profile = (SRTMProfile) cell.getElement();
            cell.setText(getResolutionUI(profile));
        }
    });
}

From source file:net.tourbook.srtm.PrefPageSRTMColors.java

License:Open Source License

/**
 * column: shadow state//from   w  w  w .  j a v  a2s  . c o m
 */
private void defineColumn_ShadowState() {

    final TableColumnDefinition colDef = new TableColumnDefinition(_columnManager, "shadowState", SWT.LEAD); //$NON-NLS-1$

    colDef.setColumnLabel(Messages.profileViewer_column_label_isShadow);
    colDef.setColumnHeaderText(Messages.profileViewer_column_label_isShadow_header);
    colDef.setColumnHeaderToolTipText(Messages.profileViewer_column_label_isShadow_tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(5));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final SRTMProfile profile = (SRTMProfile) cell.getElement();
            cell.setText(profile.isShadowState() ? Messages.app_ui_Y : Messages.app_ui_N);
        }
    });
}

From source file:net.tourbook.srtm.PrefPageSRTMColors.java

License:Open Source License

/**
 * column: shadow value/*from   www. j  a v a2s. c  o  m*/
 */
private void defineColumn_ShadowValue() {

    final TableColumnDefinition colDef = new TableColumnDefinition(_columnManager, "shadowValue", SWT.LEAD); //$NON-NLS-1$

    colDef.setColumnLabel(Messages.profileViewer_column_label_shadowValue);
    colDef.setColumnHeaderText(Messages.profileViewer_column_label_shadowValue_header);
    colDef.setColumnHeaderToolTipText(Messages.profileViewer_column_label_shadowValue_tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(10));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final SRTMProfile profile = (SRTMProfile) cell.getElement();
            cell.setText(Float.toString(profile.getShadowValue()));
        }
    });
}

From source file:net.tourbook.srtm.PrefPageSRTMColors.java

License:Open Source License

/**
 * column: image path/*ww  w.  j a v a 2 s .co m*/
 */
private void defineColumn_TileImagePath() {

    final TableColumnDefinition colDef = new TableColumnDefinition(_columnManager, "tileImagePath", SWT.LEAD); //$NON-NLS-1$
    colDef.setColumnLabel(Messages.profileViewer_column_label_imagePath);
    colDef.setColumnHeaderText(Messages.profileViewer_column_label_imagePath_header);
    colDef.setColumnHeaderToolTipText(Messages.profileViewer_column_label_imagePath_tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(20));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final SRTMProfile vertexList = (SRTMProfile) cell.getElement();
            cell.setText(vertexList.getTilePath());
        }
    });
}

From source file:net.tourbook.tour.DialogMarker.java

License:Open Source License

/**
 * column: hidden column to show first visible column with right alignment
 *///  w ww.  j  av  a2 s.co m
private void defineColumn_1stHidden(final TableColumnLayout tableLayout) {

    final TableViewerColumn tvc = new TableViewerColumn(_markerViewer, SWT.TRAIL);
    final TableColumn tc = tvc.getColumn();

    tvc.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {
            cell.setText(UI.EMPTY_STRING);
        }
    });
    tableLayout.setColumnData(tc, new ColumnPixelData(0, false));
}