Example usage for com.vaadin.v7.ui Table getVisibleColumns

List of usage examples for com.vaadin.v7.ui Table getVisibleColumns

Introduction

In this page you can find the example usage for com.vaadin.v7.ui Table getVisibleColumns.

Prototype

public Object[] getVisibleColumns() 

Source Link

Document

Gets the array of visible column id:s, including generated columns.

Usage

From source file:de.symeda.sormas.ui.caze.AbstractTableField.java

License:Open Source License

/**
 * Property serves as a source for the items in the table.
 * A copy is created of all entries in the edit, so that the source data is not overwritten until the commit.
 *//*from   w w  w  .  j  a v a2  s.c o m*/
@SuppressWarnings("unchecked")
@Override
public void setPropertyDataSource(Property newDataSource) {

    if (newDataSource == dataSource || (newDataSource != null && newDataSource.equals(dataSource))) {
        return;
    }

    dataSource = newDataSource;

    Collection<E> entries = dataSource.getValue();
    if (entries == null) {
        throw new IllegalArgumentException("dataSource cannot be null");
    }

    Collection<E> clonedEntries;
    if (entries instanceof List) {
        clonedEntries = new ArrayList<>(entries.size());
    } else if (entries instanceof Set) {
        clonedEntries = new HashSet<>(entries.size());
    } else {
        throw new IllegalArgumentException("dataSource value must be List or Set: " + entries.getClass());
    }

    // Make a copy of all entries so that they can be freely edited
    // important: all fields must be placed on writeThrough!
    for (E entry : entries) {
        clonedEntries.add(cloneEntry(entry));
    }

    container = new BeanItemContainer<>(getEntryType(), clonedEntries);

    getContent();
    Table tbl = getTable();
    if (tbl.getContainerDataSource() != null) {
        // keep the visible Columns
        Object[] visibleColumns = tbl.getVisibleColumns();
        tbl.setContainerDataSource(container, Arrays.asList(visibleColumns));
    } else {
        tbl.setContainerDataSource(container);
    }
    applyTablePageLength();

    updateColumns();

    fireValueChange(false);

    // not set, we manage our own dataSource
    // super.setPropertyDataSource (newDataSource);
}

From source file:de.symeda.sormas.ui.epidata.EpiDataBurialsField.java

License:Open Source License

@Override
protected void updateColumns() {
    Table table = getTable();

    table.addGeneratedColumn(PERIOD, new Table.ColumnGenerator() {
        @Override//  w w  w  .ja va 2s .c  o m
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EpiDataBurialDto burial = (EpiDataBurialDto) itemId;
            if (burial.getBurialDateFrom() == null && burial.getBurialDateTo() == null) {
                return I18nProperties.getString(Strings.unknown);
            } else {
                StringBuilder periodBuilder = new StringBuilder();
                periodBuilder.append(burial.getBurialDateFrom() != null
                        ? DateHelper.formatLocalDate(burial.getBurialDateFrom())
                        : "?");
                periodBuilder.append(" - ");
                periodBuilder.append(
                        burial.getBurialDateTo() != null ? DateHelper.formatLocalDate(burial.getBurialDateTo())
                                : "?");
                return periodBuilder.toString();
            }
        }
    });

    table.addGeneratedColumn(CITY, new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EpiDataBurialDto burial = (EpiDataBurialDto) itemId;
            LocationDto location = burial.getBurialAddress();
            return location.getCity();
        }
    });

    table.addGeneratedColumn(DISTRICT, new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EpiDataBurialDto burial = (EpiDataBurialDto) itemId;
            LocationDto location = burial.getBurialAddress();
            return location.getDistrict();
        }
    });

    table.setVisibleColumns(EDIT_COLUMN_ID, EpiDataBurialDto.BURIAL_PERSON_NAME,
            EpiDataBurialDto.BURIAL_RELATION, PERIOD, CITY, DISTRICT, EpiDataBurialDto.BURIAL_ILL,
            EpiDataBurialDto.BURIAL_TOUCHING);

    table.setColumnExpandRatio(EDIT_COLUMN_ID, 0);
    table.setColumnExpandRatio(EpiDataBurialDto.BURIAL_PERSON_NAME, 0);
    table.setColumnExpandRatio(EpiDataBurialDto.BURIAL_RELATION, 0);
    table.setColumnExpandRatio(PERIOD, 0);
    table.setColumnExpandRatio(CITY, 0);
    table.setColumnExpandRatio(DISTRICT, 0);
    table.setColumnExpandRatio(EpiDataBurialDto.BURIAL_ILL, 0);
    table.setColumnExpandRatio(EpiDataBurialDto.BURIAL_TOUCHING, 0);

    for (Object columnId : table.getVisibleColumns()) {
        if (!columnId.equals(EDIT_COLUMN_ID)) {
            table.setColumnHeader(columnId,
                    I18nProperties.getPrefixCaption(EPI_DATA_BURIAL_TABLE_PREFIX, (String) columnId));
        }
    }
}

From source file:de.symeda.sormas.ui.epidata.EpiDataGatheringsField.java

License:Open Source License

@Override
protected void updateColumns() {
    Table table = getTable();

    table.addGeneratedColumn(CITY, new Table.ColumnGenerator() {
        @Override//w w w. j a v a  2s  . c  o m
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EpiDataGatheringDto gathering = (EpiDataGatheringDto) itemId;
            LocationDto location = gathering.getGatheringAddress();
            return location.getCity();
        }
    });

    table.addGeneratedColumn(DISTRICT, new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EpiDataGatheringDto gathering = (EpiDataGatheringDto) itemId;
            LocationDto location = gathering.getGatheringAddress();
            return location.getDistrict();
        }
    });

    table.addGeneratedColumn(GATHERING_DAY, new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EpiDataGatheringDto gathering = (EpiDataGatheringDto) itemId;
            if (gathering.getGatheringDate() != null) {
                return DateHelper.formatLocalDate(gathering.getGatheringDate());
            } else {
                return I18nProperties.getString(Strings.unknown);
            }
        }
    });

    table.setVisibleColumns(EDIT_COLUMN_ID, EpiDataGatheringDto.DESCRIPTION, GATHERING_DAY, CITY, DISTRICT);

    table.setColumnExpandRatio(EDIT_COLUMN_ID, 0);
    table.setColumnExpandRatio(EpiDataGatheringDto.DESCRIPTION, 0);
    table.setColumnExpandRatio(GATHERING_DAY, 0);
    table.setColumnExpandRatio(CITY, 0);
    table.setColumnExpandRatio(DISTRICT, 0);

    for (Object columnId : table.getVisibleColumns()) {
        if (!columnId.equals(EDIT_COLUMN_ID)) {
            table.setColumnHeader(columnId,
                    I18nProperties.getPrefixCaption(EpiDataGatheringDto.I18N_PREFIX, (String) columnId));
        }
    }
}

From source file:de.symeda.sormas.ui.epidata.EpiDataTravelsField.java

License:Open Source License

@Override
protected void updateColumns() {
    Table table = getTable();

    table.addGeneratedColumn(PERIOD, new Table.ColumnGenerator() {
        @Override//  w ww. j a va  2 s.c om
        public Object generateCell(Table source, Object itemId, Object columnId) {
            EpiDataTravelDto travel = (EpiDataTravelDto) itemId;
            if (travel.getTravelDateFrom() == null && travel.getTravelDateTo() == null) {
                return I18nProperties.getString(Strings.unknown);
            } else {
                StringBuilder periodBuilder = new StringBuilder();
                periodBuilder.append(travel.getTravelDateFrom() != null
                        ? DateHelper.formatLocalDate(travel.getTravelDateFrom())
                        : "?");
                periodBuilder.append(" - ");
                periodBuilder.append(
                        travel.getTravelDateTo() != null ? DateHelper.formatLocalDate(travel.getTravelDateTo())
                                : "?");
                return periodBuilder.toString();
            }
        }
    });

    table.setVisibleColumns(EDIT_COLUMN_ID, EpiDataTravelDto.TRAVEL_TYPE, EpiDataTravelDto.TRAVEL_DESTINATION,
            PERIOD);

    table.setColumnExpandRatio(EDIT_COLUMN_ID, 0);
    table.setColumnExpandRatio(EpiDataTravelDto.TRAVEL_TYPE, 0);
    table.setColumnExpandRatio(EpiDataTravelDto.TRAVEL_DESTINATION, 0);
    table.setColumnExpandRatio(PERIOD, 0);

    for (Object columnId : table.getVisibleColumns()) {
        if (!columnId.equals(EDIT_COLUMN_ID)) {
            table.setColumnHeader(columnId,
                    I18nProperties.getPrefixCaption(EpiDataTravelDto.I18N_PREFIX, (String) columnId));
        }
    }
}

From source file:de.symeda.sormas.ui.hospitalization.PreviousHospitalizationsField.java

License:Open Source License

@Override
protected void updateColumns() {

    Table table = getTable();

    table.addGeneratedColumn(PERIOD, new Table.ColumnGenerator() {
        @Override//from  w ww .  j a v a  2  s .c  o  m
        public Object generateCell(Table source, Object itemId, Object columnId) {
            PreviousHospitalizationDto prevHospitalization = (PreviousHospitalizationDto) itemId;
            if (prevHospitalization.getAdmissionDate() == null
                    && prevHospitalization.getDischargeDate() == null) {
                return I18nProperties.getString(Strings.unknown);
            } else {
                StringBuilder periodBuilder = new StringBuilder();
                periodBuilder.append(prevHospitalization.getAdmissionDate() != null
                        ? DateHelper.formatLocalDate(prevHospitalization.getAdmissionDate())
                        : "?");
                periodBuilder.append(" - ");
                periodBuilder.append(prevHospitalization.getDischargeDate() != null
                        ? DateHelper.formatLocalDate(prevHospitalization.getDischargeDate())
                        : "?");
                return periodBuilder.toString();
            }
        }
    });

    table.addGeneratedColumn(COMMUNITY, new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            PreviousHospitalizationDto prevHospitalization = (PreviousHospitalizationDto) itemId;
            return prevHospitalization.getCommunity();
        }
    });

    table.addGeneratedColumn(DISTRICT, new Table.ColumnGenerator() {
        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            PreviousHospitalizationDto prevHospitalization = (PreviousHospitalizationDto) itemId;
            return prevHospitalization.getDistrict();
        }
    });

    table.setVisibleColumns(EDIT_COLUMN_ID, PERIOD, PreviousHospitalizationDto.HEALTH_FACILITY, COMMUNITY,
            DISTRICT, PreviousHospitalizationDto.DESCRIPTION, PreviousHospitalizationDto.ISOLATED);

    table.setColumnExpandRatio(EDIT_COLUMN_ID, 0);
    table.setColumnExpandRatio(PERIOD, 0);
    table.setColumnExpandRatio(PreviousHospitalizationDto.HEALTH_FACILITY, 0);
    table.setColumnExpandRatio(COMMUNITY, 0);
    table.setColumnExpandRatio(DISTRICT, 0);
    table.setColumnExpandRatio(PreviousHospitalizationDto.DESCRIPTION, 0);
    table.setColumnExpandRatio(PreviousHospitalizationDto.ISOLATED, 0);

    for (Object columnId : table.getVisibleColumns()) {
        if (!columnId.equals(EDIT_COLUMN_ID)) {
            table.setColumnHeader(columnId,
                    I18nProperties.getPrefixCaption(PreviousHospitalizationDto.I18N_PREFIX, (String) columnId));
        }
    }
}