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.PrefPageAppearanceColors.java

License:Open Source License

/**
 * create columns//from www.j a  v  a2  s .co  m
 */
private void defineAllColumns(final TreeColumnLayout treeLayout, final Tree tree) {

    final int numberOfHorizontalImages = 5;
    final int trailingOffset = 10;

    final int itemHeight = tree.getItemHeight();
    final int colorWidth = (itemHeight + GraphColorPainter.GRAPH_COLOR_SPACING) * numberOfHorizontalImages
            + trailingOffset;

    TreeColumn tc;
    TreeViewerColumn tvc;

    // 1. column: color item/color definition
    tvc = new TreeViewerColumn(_colorViewer, 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(_colorViewer, 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.setImage(_graphColorPainter.drawColorDefinitionImage((ColorDefinition) element,
                        numberOfHorizontalImages));

            } else if (element instanceof GraphColorItem) {

                cell.setImage(_graphColorPainter.drawGraphColorImage(//
                        (GraphColorItem) element, numberOfHorizontalImages));

            } else {

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

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

License:Open Source License

/**
 * column: profile name/*  w  ww  .  j av  a  2s . co  m*/
 */
private void defineColumn_10_ProfileName() {

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

    colDef.setColumnLabel(Messages.Pref_Map3Color_Column_ProfileName);
    colDef.setColumnHeaderText(Messages.Pref_Map3Color_Column_ProfileName);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(20));
    colDef.setIsDefaultColumn();
    colDef.setIsColumnMoveable(false);
    colDef.setCanModifyVisibility(false);
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final Object element = cell.getElement();

            if (element instanceof Map3ColorDefinition) {

                final Map3ColorDefinition colorDefinition = (Map3ColorDefinition) (element);

                cell.setText(colorDefinition.getVisibleName());

            } else if (element instanceof Map3GradientColorProvider) {

                cell.setText(((Map3GradientColorProvider) (element)).getMap3ColorProfile().getProfileName());

            } else {

                cell.setText(UI.EMPTY_STRING);
            }
        }
    });
}

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

License:Open Source License

/**
 * Column: Min value/*w w  w .  j a v  a 2s  . c  o m*/
 */
private void defineColumn_32_MinValue() {

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

    colDef.setColumnLabel(Messages.Pref_Map3Color_Column_MinValue_Label);
    colDef.setColumnHeaderText(Messages.Pref_Map3Color_Column_MinValue_Header);
    colDef.setColumnHeaderToolTipText(Messages.Pref_Map3Color_Column_MinValue_Label);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(8));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final Object element = cell.getElement();

            if (element instanceof Map3GradientColorProvider) {

                final Map3ColorProfile colorProfile = ((Map3GradientColorProvider) (element))
                        .getMap3ColorProfile();

                final ProfileImage profileImage = colorProfile.getProfileImage();
                final ArrayList<RGBVertex> vertices = profileImage.getRgbVertices();
                final RGBVertex firstVertex = vertices.get(0);

                cell.setText(Integer.toString(firstVertex.getValue()));

            } else {

                cell.setText(UI.EMPTY_STRING);
            }
        }
    });
}

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

License:Open Source License

/**
 * Column: Max value/*w  ww .jav a  2s  . com*/
 */
private void defineColumn_35_MaxValue() {

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

    colDef.setColumnLabel(Messages.Pref_Map3Color_Column_MaxValue_Label);
    colDef.setColumnHeaderText(Messages.Pref_Map3Color_Column_MaxValue_Header);
    colDef.setColumnHeaderToolTipText(Messages.Pref_Map3Color_Column_MaxValue_Label);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(8));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final Object element = cell.getElement();

            if (element instanceof Map3GradientColorProvider) {

                final Map3ColorProfile colorProfile = ((Map3GradientColorProvider) (element))
                        .getMap3ColorProfile();

                final ProfileImage profileImage = colorProfile.getProfileImage();
                final ArrayList<RGBVertex> vertices = profileImage.getRgbVertices();
                final RGBVertex lastVertex = vertices.get(vertices.size() - 1);

                cell.setText(Integer.toString(lastVertex.getValue()));

            } else {

                cell.setText(UI.EMPTY_STRING);
            }
        }
    });
}

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

License:Open Source License

/**
 * Column: Relative value marker/*w  ww .  j  a v a 2s.  c  o m*/
 */
private void defineColumn_40_ValueMarker() {

    final TreeColumnDefinition colDef = new TreeColumnDefinition(_columnManager, "relativeMarker", SWT.CENTER); //$NON-NLS-1$

    colDef.setColumnLabel(Messages.Pref_Map3Color_Column_AbsoluteRelativValue_Label);
    colDef.setColumnHeaderToolTipText(Messages.Pref_Map3Color_Column_AbsoluteRelativValue_Tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(3));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final Object element = cell.getElement();

            if (element instanceof Map3GradientColorProvider) {

                final Map3ColorProfile colorProfile = ((Map3GradientColorProvider) (element))
                        .getMap3ColorProfile();

                if (colorProfile.isAbsoluteValues()) {
                    cell.setText(Messages.Pref_Map3Color_Column_ValueMarker_Absolute);
                } else {
                    cell.setText(Messages.Pref_Map3Color_Column_ValueMarker_Relative);
                }

            } else {

                cell.setText(UI.EMPTY_STRING);
            }
        }
    });
}

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

License:Open Source License

/**
 * Column: Legend overwrite marker//from   ww w. j  a  v a2 s. co  m
 */
private void defineColumn_42_LegendMarker() {

    final TreeColumnDefinition colDef = new TreeColumnDefinition(_columnManager, "legendMinMaxOverwrite", //$NON-NLS-1$
            SWT.CENTER);

    colDef.setColumnLabel(Messages.Pref_Map3Color_Column_OverwriteLegendMinMax_Label);
    colDef.setColumnHeaderToolTipText(Messages.Pref_Map3Color_Column_OverwriteLegendMinMax_Label_Tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(3));
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final Object element = cell.getElement();

            if (element instanceof Map3GradientColorProvider) {

                final Map3ColorProfile colorProfile = ((Map3GradientColorProvider) (element))
                        .getMap3ColorProfile();

                if (colorProfile.isAbsoluteValues() && colorProfile.isOverwriteLegendValues()) {
                    cell.setText(Messages.Pref_Map3Color_Column_Legend_Marker);
                } else {
                    cell.setText(UI.EMPTY_STRING);
                }

            } else {

                cell.setText(UI.EMPTY_STRING);
            }
        }
    });
}

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

License:Open Source License

/**
 * column: id//from www.  j a va  2s  .  c o m
 */
private void defineColumn_99_ProfileId() {

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

    colDef.setColumnLabel(Messages.Pref_Map3Color_Column_Id_Label);
    colDef.setColumnHeaderText(Messages.Pref_Map3Color_Column_Id_Header);
    colDef.setColumnHeaderToolTipText(Messages.Pref_Map3Color_Column_Id_Tooltip);
    colDef.setDefaultColumnWidth(_pc.convertWidthInCharsToPixels(10));

    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final Object element = cell.getElement();

            if (element instanceof Map3ColorDefinition) {

                cell.setText(((Map3ColorDefinition) (element)).getGraphId().name());

            } else if (element instanceof Map3GradientColorProvider) {

                cell.setText(Integer.toString(
                        ((Map3GradientColorProvider) (element)).getMap3ColorProfile().getProfileId()));

            } else {

                cell.setText(UI.EMPTY_STRING);
            }
        }
    });
}

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

License:Open Source License

private void defineAllColumns(final TableColumnLayout tableLayout) {

    TableViewerColumn tvc;//from  w w  w.j  a  va2  s  . c o m
    TableColumn tc;

    /*
     * column: first name
     */
    tvc = new TableViewerColumn(_peopleViewer, SWT.LEAD);
    tc = tvc.getColumn();
    tc.setText(Messages.Pref_People_Column_first_name);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            cell.setText(((TourPerson) cell.getElement()).getFirstName());
        }
    });
    tableLayout.setColumnData(tc, new ColumnWeightData(5, convertWidthInCharsToPixels(5)));

    /*
     * column: last name
     */
    tvc = new TableViewerColumn(_peopleViewer, SWT.LEAD);
    tc = tvc.getColumn();
    tc.setText(Messages.Pref_People_Column_last_name);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            cell.setText(((TourPerson) cell.getElement()).getLastName());
        }
    });
    tableLayout.setColumnData(tc, new ColumnWeightData(5, convertWidthInCharsToPixels(5)));

    /*
     * column: birth day
     */
    tvc = new TableViewerColumn(_peopleViewer, SWT.TRAIL);
    tc = tvc.getColumn();
    tc.setText(Messages.Pref_People_Column_Birthday);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final long birthDayValue = ((TourPerson) cell.getElement()).getBirthDay();

            if (birthDayValue == 0) {
                cell.setText(UI.EMPTY_STRING);
            } else {
                cell.setText(TimeTools.getZonedDateTime(birthDayValue).format(TimeTools.Formatter_Date_S));
            }
        }
    });
    tableLayout.setColumnData(tc, new ColumnWeightData(5, convertWidthInCharsToPixels(5)));

    /*
     * column: device
     */
    tvc = new TableViewerColumn(_peopleViewer, SWT.LEAD);
    tc = tvc.getColumn();
    tc.setText(Messages.Pref_People_Column_device);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final TourPerson tourPerson = (TourPerson) cell.getElement();
            final String deviceId = tourPerson.getDeviceReaderId();

            if (deviceId != null) {
                for (final ExternalDevice device : _deviceList) {
                    if (device != null && deviceId.equals(device.deviceId)) {
                        cell.setText(device.visibleName);
                        return;
                    }
                }
            }

            cell.setText(UI.EMPTY_STRING);
        }
    });
    tableLayout.setColumnData(tc, new ColumnWeightData(4, convertWidthInCharsToPixels(4)));

    /*
     * column: height
     */
    tvc = new TableViewerColumn(_peopleViewer, SWT.TRAIL);
    tc = tvc.getColumn();
    tc.setText(Messages.Pref_People_Column_height);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final float height = ((TourPerson) cell.getElement()).getHeight();
            cell.setText(_nf2.format(height));
        }
    });
    tableLayout.setColumnData(tc, new ColumnPixelData(convertHorizontalDLUsToPixels(6 * 4), true));

    /*
     * column: weight
     */
    tvc = new TableViewerColumn(_peopleViewer, SWT.TRAIL);
    tc = tvc.getColumn();
    tc.setText(Messages.Pref_People_Column_weight);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final float weight = ((TourPerson) cell.getElement()).getWeight();
            cell.setText(_nf1.format(weight));
        }
    });
    tableLayout.setColumnData(tc, new ColumnPixelData(convertHorizontalDLUsToPixels(7 * 4), true));
}

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

License:Open Source License

private void createUI_10_List(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  . j a  v  a 2  s.  com
     * create table
     */
    final Table table = new Table(layoutContainer, SWT.FULL_SELECTION | SWT.BORDER);

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

    _statViewer = new TableViewer(table);

    /*
     * create columns
     */
    TableViewerColumn tvc;

    // column: map provider
    tvc = new TableViewerColumn(_statViewer, SWT.LEAD);
    tvc.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final TourbookStatistic statistic = (TourbookStatistic) cell.getElement();

            final String statisticName = statistic.plugin_VisibleName

            // THIS IS FOR DEBUGGING
            //                  + UI.SPACE3
            //                  + UI.SYMBOL_BRACKET_LEFT
            //                  + statistic.plugin_Category_Data
            //                  + UI.DASH_WITH_SPACE
            //                  + statistic.plugin_Category_Time
            //                  + UI.SYMBOL_BRACKET_RIGHT
            ;

            cell.setText(statisticName);
        }
    });
    tableLayout.setColumnData(tvc.getColumn(), new ColumnWeightData(4, true));

    /*
     * create table viewer
     */
    _statViewer.setContentProvider(new StatContentProvicer());
    _statViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            enableActions();
        }
    });
}

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

License:Open Source License

private void createUI_20_TagViewer(final Composite parent) {

    /*/*from  w ww . j  av  a2s .c  om*/
     * create tree layout
     */

    final Composite layoutContainer = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults()//
            .grab(true, true).hint(200, 100).applyTo(layoutContainer);

    final TreeColumnLayout treeLayout = new TreeColumnLayout();
    layoutContainer.setLayout(treeLayout);

    /*
     * create viewer
     */
    final Tree tree = new Tree(layoutContainer, SWT.H_SCROLL | SWT.V_SCROLL
    //            | SWT.BORDER
            | SWT.MULTI | SWT.FULL_SELECTION);

    tree.setHeaderVisible(false);
    tree.setLinesVisible(getPreferenceStore().getBoolean(ITourbookPreferences.VIEW_LAYOUT_DISPLAY_LINES));

    _tagViewer = new TreeViewer(tree);

    _tagViewer.setContentProvider(new TagViewerContentProvicer());
    _tagViewer.setComparator(new TagViewerComparator());
    _tagViewer.setUseHashlookup(true);

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

            final Object selection = ((IStructuredSelection) _tagViewer.getSelection()).getFirstElement();

            if (selection instanceof TVIPrefTag) {

                // tag is selected

                onRenameTourTag();

            } else if (selection instanceof TVIPrefTagCategory) {

                // expand/collapse current item

                final TreeViewerItem tourItem = (TreeViewerItem) selection;

                if (_tagViewer.getExpandedState(tourItem)) {
                    _tagViewer.collapseToLevel(tourItem, 1);
                } else {
                    _tagViewer.expandToLevel(tourItem, 1);
                }
            }
        }
    });

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

    _tagViewer.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 = _tagViewer.getSelection();

                    //                  System.out.println("dragStart");
                    transfer.setSelection(selection);
                    transfer.setSelectionSetTime(_dragStartTime = event.time & 0xFFFFFFFFL);

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

    _tagViewer.addDropSupport(DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() },
            new TagDropAdapter(this, _tagViewer));

    /*
     * create columns
     */
    TreeViewerColumn tvc;
    TreeColumn tvcColumn;

    // column: tags + tag categories
    tvc = new TreeViewerColumn(_tagViewer, SWT.TRAIL);
    tvcColumn = tvc.getColumn();
    tvc.setLabelProvider(new StyledCellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {

            final StyledString styledString = new StyledString();

            final Object element = cell.getElement();
            if (element instanceof TVIPrefTag) {

                final TourTag tourTag = ((TVIPrefTag) element).getTourTag();

                styledString.append(tourTag.getTagName(), UI.TAG_STYLER);
                cell.setImage(tourTag.isRoot() ? _imgTagRoot : _imgTag);

            } else if (element instanceof TVIPrefTagCategory) {

                final TVIPrefTagCategory tourTagCategoryItem = (TVIPrefTagCategory) element;
                final TourTagCategory tourTagCategory = tourTagCategoryItem.getTourTagCategory();

                cell.setImage(_imgTagCategory);

                styledString.append(tourTagCategory.getCategoryName(), UI.TAG_CATEGORY_STYLER);

                // get number of categories
                final int categoryCounter = tourTagCategory.getCategoryCounter();
                final int tagCounter = tourTagCategory.getTagCounter();
                if (categoryCounter == -1 && tagCounter == -1) {

                    //                  styledString.append("  ...", StyledString.COUNTER_STYLER);

                } else {

                    String categoryString = UI.EMPTY_STRING;
                    if (categoryCounter > 0) {
                        categoryString = "/" + categoryCounter; //$NON-NLS-1$
                    }
                    styledString.append("   " + tagCounter + categoryString, StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
                }

            } else {
                styledString.append(element.toString());
            }

            cell.setText(styledString.getString());
            cell.setStyleRanges(styledString.getStyleRanges());
        }
    });
    treeLayout.setColumnData(tvcColumn, new ColumnWeightData(100, true));
}