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

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

Introduction

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

Prototype

public Object getElement() 

Source Link

Document

Get the element this row represents.

Usage

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: tour type text//from   www .  java 2  s  .  co m
 */
private void defineColumn_Photo_TourCameras() {

    final ColumnDefinition colDef = TableColumnFactory.PHOTO_TOUR_CAMERA.createColumn(_columnManager, _pc);
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final Object element = cell.getElement();
            if (element instanceof TourPhotoLink) {

                final TourPhotoLink link = (TourPhotoLink) element;

                cell.setText(link.tourCameras);

                setBgColor(cell, link);
            }
        }
    });
}

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: duration time/*ww  w.  java 2  s  . co m*/
 */
private void defineColumn_Time_TourDurationTime() {

    final ColumnDefinition colDef = TableColumnFactory.TIME_TOUR_DURATION_TIME.createColumn(_columnManager,
            _pc);
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(final ViewerCell cell) {

            final TourPhotoLink link = (TourPhotoLink) cell.getElement();

            final Period period = link.tourPeriod;

            int periodSum = 0;
            for (final int value : period.getValues()) {
                periodSum += value;
            }

            if (periodSum == 0) {
                // < 1 h
                cell.setText(Messages.Photos_AndTours_Label_DurationLess1Hour);
            } else {
                // > 1 h
                cell.setText(period.toString(_durationFormatter));
            }

            setBgColor(cell, link);
        }
    });
}

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: tour end date/*from www .j av  a 2s .c  o m*/
 */
private void defineColumn_Time_TourEndDate() {

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

            final TourPhotoLink link = (TourPhotoLink) cell.getElement();
            final long historyTime = link.historyEndTime;

            cell.setText(historyTime == Long.MIN_VALUE //
                    ? TimeTools.getZonedDateTime(link.tourEndTime).format(TimeTools.Formatter_Date_S)
                    : TimeTools.getZonedDateTime(historyTime).format(TimeTools.Formatter_Date_S));

            setBgColor(cell, link);
        }
    });
}

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: tour end time//from   w  w  w  .  j  a  v a  2  s  . com
 */
private void defineColumn_Time_TourEndTime() {

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

            final TourPhotoLink link = (TourPhotoLink) cell.getElement();
            final long historyTime = link.historyEndTime;

            cell.setText(historyTime == Long.MIN_VALUE //
                    ? TimeTools.getZonedDateTime(link.tourEndTime).format(TimeTools.Formatter_Time_M)
                    : TimeTools.getZonedDateTime(historyTime).format(TimeTools.Formatter_Time_M));

            setBgColor(cell, link);
        }
    });
}

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: tour start date//w  ww .ja v  a2 s  . c  o  m
 */
private void defineColumn_Time_TourStartDate() {

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

            final TourPhotoLink link = (TourPhotoLink) cell.getElement();
            final long historyTime = link.historyStartTime;

            cell.setText(historyTime == Long.MIN_VALUE //
                    ? TimeTools.getZonedDateTime(link.tourStartTime).format(TimeTools.Formatter_Date_S)
                    : TimeTools.getZonedDateTime(historyTime).format(TimeTools.Formatter_Date_S));

            setBgColor(cell, link);
        }
    });
}

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: tour start time/*from   w  w w  .  jav  a  2  s .co m*/
 */
private void defineColumn_Time_TourStartTime() {

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

            final TourPhotoLink link = (TourPhotoLink) cell.getElement();
            final long historyTime = link.historyStartTime;

            cell.setText(historyTime == Long.MIN_VALUE //
                    ? TimeTools.getZonedDateTime(link.tourStartTime).format(TimeTools.Formatter_Time_M)
                    : TimeTools.getZonedDateTime(historyTime).format(TimeTools.Formatter_Time_M));

            setBgColor(cell, link);
        }
    });
}

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: tour type image/*from   w  w w. j  a v a 2s  .c o m*/
 */
private void defineColumn_Tour_TypeImage() {

    final ColumnDefinition colDef = TableColumnFactory.TOUR_TYPE.createColumn(_columnManager, _pc);
    colDef.setIsDefaultColumn();
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final Object element = cell.getElement();
            if (element instanceof TourPhotoLink) {

                final TourPhotoLink link = (TourPhotoLink) element;

                if (link.isHistoryTour) {

                    cell.setImage(net.tourbook.ui.UI.IMAGE_REGISTRY.get(IMAGE_PHOTO_PHOTO));

                } else {

                    final long tourTypeId = link.tourTypeId;
                    if (tourTypeId == -1) {

                        cell.setImage(null);

                    } else {

                        final Image tourTypeImage = net.tourbook.ui.UI.getInstance()
                                .getTourTypeImage(tourTypeId);

                        /*
                         * when a tour type image is modified, it will keep the same image
                         * resource only the content is modified but in the rawDataView the
                         * modified image is not displayed compared with the tourBookView which
                         * displays the correct image
                         */
                        cell.setImage(tourTypeImage);
                    }
                }
            }
        }
    });
}

From source file:net.tourbook.tour.photo.TourPhotoLinkView.java

License:Open Source License

/**
 * column: tour type text/*from ww  w. ja  v  a2  s .c  o  m*/
 */
private void defineColumn_Tour_TypeText() {

    final ColumnDefinition colDef = TableColumnFactory.TOUR_TYPE_TEXT.createColumn(_columnManager, _pc);
    colDef.setLabelProvider(new CellLabelProvider() {
        @Override
        public void update(final ViewerCell cell) {
            final Object element = cell.getElement();
            if (element instanceof TourPhotoLink) {

                final TourPhotoLink link = (TourPhotoLink) element;
                if (link.isHistoryTour) {

                    cell.setText(Messages.Photos_AndTours_Label_HistoryTour);

                } else {

                    final long tourTypeId = link.tourTypeId;
                    if (tourTypeId == -1) {
                        cell.setText(UI.EMPTY_STRING);
                    } else {
                        cell.setText(net.tourbook.ui.UI.getTourTypeLabel(tourTypeId));
                    }
                }

                setBgColor(cell, link);
            }
        }
    });
}

From source file:net.tourbook.ui.views.collateTours.CollatedToursView.java

License:Open Source License

/**
 * Tree column: Collate event/*from  w  w w. ja va 2 s.  co m*/
 */
private void defineColumn_1stColumn_CollateEvent() {

    final TreeColumnDefinition colDef = TreeColumnFactory.TOUR_COLLATE_EVENT.createColumn(_columnManager, _pc);

    colDef.setIsDefaultColumn();
    colDef.setCanModifyVisibility(false);

    colDef.setLabelProvider(new TourInfoToolTipStyledCellLabelProvider() {

        @Override
        public Long getTourId(final ViewerCell cell) {

            if (_isToolTipInCollation == false) {
                return null;
            }

            return getCellTourId(cell);
        }

        @Override
        public void update(final ViewerCell cell) {

            final Object element = cell.getElement();
            final TVICollatedTour tourItem = (TVICollatedTour) element;

            if (element instanceof TVICollatedTour_Tour) {

                // tour item
                cell.setText(TimeTools//
                        .getZonedDateTime(tourItem.colTourStartTime).format(TimeTools.Formatter_Date_S));

            } else if (element instanceof TVICollatedTour_Event) {

                final TVICollatedTour_Event collatedEvent = (TVICollatedTour_Event) element;

                // collated event

                final StyledString styledString = new StyledString();

                /*
                 * Event start
                 */
                String startText;

                if (collatedEvent.isFirstEvent) {
                    startText = Messages.Collate_Tours_Label_TimeScale_BeforePresent;
                } else {
                    startText = collatedEvent.eventStart.format(TimeTools.Formatter_Date_S);
                }
                styledString.append(startText, DATE_STYLER);

                /*
                 * Event end
                 */
                styledString.append(UI.DASH_WITH_SPACE);
                final ZonedDateTime eventEnd = collatedEvent.eventEnd;
                if (eventEnd == null) {

                    // this can be null when the collation process is canceled by the user

                    styledString.append(UI.SYMBOL_QUESTION_MARK, DATE_STYLER);

                } else {

                    String endText;

                    if (collatedEvent.isLastEvent) {
                        endText = Messages.Collate_Tours_Label_TimeScale_Today;
                    } else {
                        endText = eventEnd.format(TimeTools.Formatter_Date_S);
                    }

                    styledString.append(endText, DATE_STYLER);
                }

                /*
                 * Number of tours for each event
                 */
                styledString.append(UI.SPACE3);
                styledString.append(_nf0.format(tourItem.colCounter), StyledString.QUALIFIER_STYLER);

                cell.setText(styledString.getString());
                cell.setStyleRanges(styledString.getStyleRanges());
            }

            setCellColor(cell, element);
        }
    });
}

From source file:net.tourbook.ui.views.collateTours.CollatedToursView.java

License:Open Source License

/**
 * column: altitude down (m)//  ww  w .  j  a  v a 2 s  .  com
 */
private void defineColumn_Altitude_Down() {

    final TreeColumnDefinition colDef = TreeColumnFactory.ALTITUDE_DOWN.createColumn(_columnManager, _pc);

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

            final Object element = cell.getElement();

            final double dbAltitudeDown = ((TVICollatedTour) element).colAltitudeDown;
            final double value = -dbAltitudeDown / net.tourbook.ui.UI.UNIT_VALUE_ALTITUDE;

            colDef.printValue_0(cell, value);

            setCellColor(cell, element);
        }
    });
}