Example usage for com.vaadin.v7.data Item getItemProperty

List of usage examples for com.vaadin.v7.data Item getItemProperty

Introduction

In this page you can find the example usage for com.vaadin.v7.data Item getItemProperty.

Prototype

public Property getItemProperty(Object id);

Source Link

Document

Gets the Property corresponding to the given Property ID stored in the Item.

Usage

From source file:com.haulmont.cuba.web.gui.components.table.TableDataContainer.java

License:Apache License

@Override
public Property getContainerProperty(Object itemId, Object propertyId) {
    final Item item = getItem(itemId);
    return item == null ? null : item.getItemProperty(propertyId);
}

From source file:de.symeda.sormas.ui.configuration.outbreak.OutbreakOverviewGrid.java

License:Open Source License

private String getCellDescription(CellReference cell) {
    Item item = cell.getItem();

    if (cell.getPropertyId() == REGION) {
        return "";
    }//from  w w w.ja v  a  2  s .c o m

    Set<DistrictReferenceDto> affectedDistricts = ((OutbreakRegionConfiguration) item
            .getItemProperty((Disease) cell.getPropertyId()).getValue()).getAffectedDistricts();

    if (affectedDistricts.isEmpty()) {
        return I18nProperties.getCaption(Captions.outbreakNoOutbreak);
    }

    StringBuilder affectedDistrictsStringBuilder = new StringBuilder();
    affectedDistrictsStringBuilder.append(I18nProperties.getCaption(Captions.outbreakAffectedDistricts))
            .append(": ");

    int index = 0;
    for (DistrictReferenceDto affectedDistrict : affectedDistricts) {
        affectedDistrictsStringBuilder.append(affectedDistrict.toString());
        if (index < affectedDistricts.size() - 1) {
            affectedDistrictsStringBuilder.append(", ");
        }
        index++;
    }

    return affectedDistrictsStringBuilder.toString();
}

From source file:de.symeda.sormas.ui.configuration.outbreak.OutbreakOverviewGrid.java

License:Open Source License

@SuppressWarnings("unchecked")
private void addItem(RegionReferenceDto region) {
    int totalDistricts = FacadeProvider.getDistrictFacade().getCountByRegion(region.getUuid());
    Item item = getContainerDataSource().addItem(region);
    item.getItemProperty(REGION).setValue(region);
    for (Disease disease : FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases()) {
        item.getItemProperty(disease)/*w  ww  . ja  va  2 s.c o  m*/
                .setValue(new OutbreakRegionConfiguration(disease, region, totalDistricts, new HashSet<>()));
    }
}

From source file:de.symeda.sormas.ui.configuration.outbreak.OutbreakOverviewGrid.java

License:Open Source License

@Override
public void itemClick(ItemClickEvent event) {
    Item clickedItem = event.getItem();

    if (event.getPropertyId() == REGION) {
        return;//from   ww  w  .  j a va2 s.  c  o  m
    }

    // Open the outbreak configuration window for the clicked row when
    // a) the user is allowed to configure all existing outbreaks or
    // b) the user is allowed to configure outbreaks in his assigned region and has clicked the respective row
    if (UserProvider.getCurrent().hasUserRight(UserRight.OUTBREAK_CONFIGURE_ALL)) {
        ControllerProvider.getOutbreakController().openOutbreakConfigurationWindow(
                (Disease) event.getPropertyId(), (OutbreakRegionConfiguration) clickedItem
                        .getItemProperty((Disease) event.getPropertyId()).getValue());
    } else if (UserProvider.getCurrent().hasUserRight(UserRight.OUTBREAK_CONFIGURE_RESTRICTED)) {
        if (user.getRegion().equals(clickedItem.getItemProperty(REGION).getValue())) {
            ControllerProvider.getOutbreakController().openOutbreakConfigurationWindow(
                    (Disease) event.getPropertyId(), (OutbreakRegionConfiguration) clickedItem
                            .getItemProperty((Disease) event.getPropertyId()).getValue());
        }
    } else {
        return;
    }
}

From source file:de.symeda.sormas.ui.utils.AbstractEditForm.java

License:Open Source License

/**
 * Adds the field to the form by using addField(fieldId, fieldType), but additionally sets up a ValueChangeListener
 * that makes sure the value that is about to be selected is added to the list of allowed values. This is intended
 * to be used for Disease fields that might contain a disease that is no longer active in the system and thus will
 * not be returned by DiseaseHelper.isActivePrimaryDisease(disease).
 *///from   w w  w . j a  v  a 2s  . c  o  m
@SuppressWarnings("rawtypes")
protected ComboBox addDiseaseField(String fieldId, boolean showNonPrimaryDiseases) {
    ComboBox field = addField(fieldId, ComboBox.class);
    if (showNonPrimaryDiseases) {
        addNonPrimaryDiseasesTo(field);
    }
    // Make sure that the ComboBox still contains a pre-selected inactive disease
    field.addValueChangeListener(e -> {
        Object value = e.getProperty().getValue();
        if (value != null && !field.containsId(value)) {
            Item newItem = field.addItem(value);
            newItem.getItemProperty(SormasFieldGroupFieldFactory.CAPTION_PROPERTY_ID)
                    .setValue(value.toString());
        }
    });
    return field;
}

From source file:de.symeda.sormas.ui.utils.AbstractEditForm.java

License:Open Source License

protected void addNonPrimaryDiseasesTo(ComboBox diseaseField) {
    List<Disease> diseases = FacadeProvider.getDiseaseConfigurationFacade().getAllActiveDiseases();
    for (Disease disease : diseases) {
        if (diseaseField.getItem(disease) != null) {
            continue;
        }//from  w w w .ja v a  2 s. c  om

        Item newItem = diseaseField.addItem(disease);
        newItem.getItemProperty(SormasFieldGroupFieldFactory.CAPTION_PROPERTY_ID).setValue(disease.toString());
    }
}

From source file:de.symeda.sormas.ui.utils.DateFilter.java

License:Open Source License

@Override
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {

    if (DataHelper.isNullOrEmpty(filterString)) {
        return true;
    }//  w w  w  .  j  a  va 2 s.  c o  m

    Date date = (Date) item.getItemProperty(propertyId).getValue();

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

    Date[] dateBounds = DateHelper.findDateBounds(filterString);

    if (dateBounds != null) {
        if (!date.before(dateBounds[0]) && !date.after(dateBounds[1])) {
            // not outside bounds
            return true;
        }
    }

    Integer[] dayAndMonth = DateHelper.findDatePrefix(filterString);
    if (dayAndMonth != null) {

        LocalDate localDate = new LocalDate(date);
        if (dayAndMonth[0] != null) {
            if (localDate.getDayOfMonth() != dayAndMonth[0]) {
                // day does not match
                return false;
            }
        }
        if (dayAndMonth[1] != null) {
            if (localDate.getMonthOfYear() != dayAndMonth[1]) {
                // month does not match
                return false;
            }
        }

        // available data matches
        return true;
    }

    return false;
}

From source file:de.symeda.sormas.ui.utils.RoleFilter.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   w w  w .jav  a2  s .  c  o m
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
    final Property<?> p = item.getItemProperty(getPropertyId());
    if (null == p) {
        return false;
    }
    Collection<UserRole> roles = (Collection<UserRole>) p.getValue();
    for (UserRole role : roles) {
        if (compareEquals(roleToFilter, role)) {
            return true;
        }
    }

    // all cases should have been processed above
    return false;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getNpcPhrasesDiff(List<GSpreadSheetsNpcPhrase> phrases, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        hc = new HierarchicalContainer();
        hc.addContainerProperty("shText", String.class, null);
        hc.addContainerProperty("shNic", String.class, null);
        hc.addContainerProperty("shDate", Date.class, null);
        hc.addContainerProperty("dbText", String.class, null);
        hc.addContainerProperty("dbNic", String.class, null);
        hc.addContainerProperty("dbDate", Date.class, null);
    }// w w  w  .jav a 2  s.c  o m
    hc.removeAllItems();
    List<NpcPhraseDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsNpcPhrase.class);
    Map<Long, GSpreadSheetsNpcPhrase> phrasesMap = new HashMap<>();
    List<GSpreadSheetsNpcPhrase> allPhrases = crit.list();
    for (GSpreadSheetsNpcPhrase phrase : allPhrases) {
        phrasesMap.put(phrase.getRowNum(), phrase);
    }
    for (GSpreadSheetsNpcPhrase phrase : phrases) {
        GSpreadSheetsNpcPhrase result = phrasesMap.get(phrase.getRowNum());
        if (result != null) {
            if (!phrase.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(phrase.getRowNum(), phrase.getTextEn(),
                        result.getTextEn());
            }
            if (phrase.getChangeTime() != null && result.getChangeTime() != null
                    && phrase.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (phrase.getChangeTime() != null && result.getChangeTime() != null
                    && phrase.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && phrase.getChangeTime() == null) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && phrase.getChangeTime() != null) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && phrase.getChangeTime() == null
                    && (phrase.getTextRu() != null) && (result.getTextRu() != null)
                    && !phrase.getTextRu().equals(result.getTextRu())) {
                diffs.add(new NpcPhraseDiff(phrase, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (NpcPhraseDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsPhrase().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsPhrase().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsPhrase().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbPhrase().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbPhrase().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbPhrase().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}

From source file:org.esn.esobase.data.DBService.java

@Transactional
public HierarchicalContainer getNpcnamessDiff(List<GSpreadSheetsNpcName> names, HierarchicalContainer hc)
        throws OriginalTextMismatchException {
    if (hc == null) {
        hc = new HierarchicalContainer();
        hc.addContainerProperty("shText", String.class, null);
        hc.addContainerProperty("shNic", String.class, null);
        hc.addContainerProperty("shDate", Date.class, null);
        hc.addContainerProperty("dbText", String.class, null);
        hc.addContainerProperty("dbNic", String.class, null);
        hc.addContainerProperty("dbDate", Date.class, null);
    }/*from ww w. j  a  v a 2s  .c  o  m*/
    hc.removeAllItems();
    List<NpcNameDiff> diffs = new ArrayList<>();
    Session session = (Session) em.getDelegate();
    Criteria crit = session.createCriteria(GSpreadSheetsNpcName.class);
    Map<Long, GSpreadSheetsNpcName> namesMap = new HashMap<>();
    List<GSpreadSheetsNpcName> allNames = crit.list();
    for (GSpreadSheetsNpcName name : allNames) {
        namesMap.put(name.getRowNum(), name);
    }
    for (GSpreadSheetsNpcName name : names) {
        GSpreadSheetsNpcName result = namesMap.get(name.getRowNum());
        if (result != null) {
            if (!name.getTextEn().equals(result.getTextEn())) {
                throw new OriginalTextMismatchException(name.getRowNum(), name.getTextEn(), result.getTextEn());
            }
            if (name.getChangeTime() != null && result.getChangeTime() != null
                    && name.getChangeTime().before(result.getChangeTime())) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (name.getChangeTime() != null && result.getChangeTime() != null
                    && name.getChangeTime().after(result.getChangeTime())) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() != null && name.getChangeTime() == null) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_SPREADSHEET));
            } else if (result.getChangeTime() == null && name.getChangeTime() != null) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (result.getChangeTime() == null && name.getChangeTime() == null
                    && (name.getTextRu() != null) && (result.getTextRu() != null)
                    && !name.getTextRu().equals(result.getTextRu())) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            } else if (name.getSex() != result.getSex()) {
                diffs.add(new NpcNameDiff(name, result, SYNC_TYPE.TO_DB));
            }
        }
    }
    for (NpcNameDiff diff : diffs) {
        Item item = hc.addItem(diff);
        item.getItemProperty("shText").setValue(diff.getSpreadsheetsName().getTextRu());
        item.getItemProperty("shNic").setValue(diff.getSpreadsheetsName().getTranslator());
        item.getItemProperty("shDate").setValue(diff.getSpreadsheetsName().getChangeTime());
        item.getItemProperty("dbText").setValue(diff.getDbName().getTextRu());
        item.getItemProperty("dbNic").setValue(diff.getDbName().getTranslator());
        item.getItemProperty("dbDate").setValue(diff.getDbName().getChangeTime());
        item.getItemProperty("syncType").setValue(diff.getSyncType().toString());
        hc.setChildrenAllowed(item, false);
    }
    return hc;
}