private void updateAttributes(AssociationValue associationValue, ListGridRecord record) {
   for (AttributeInfo attributeInfo : featureInfo.getAttributes()) {
     Attribute<?> attr = associationValue.getAllAttributes().get(attributeInfo.getName());
     if (attr.isPrimitive()) {
       Object value = attr.getValue();
       if (value != null) {
         if (value instanceof Boolean) {
           record.setAttribute(attributeInfo.getName(), (Boolean) value); // "false" != false
         } else {
           record.setAttribute(attributeInfo.getName(), value.toString());
         }
       } else {
         record.setAttribute(attributeInfo.getName(), "");
       }
     } else {
       AssociationAttributeInfo associationAttributeInfo =
           (AssociationAttributeInfo) attributeInfo;
       String displayName = associationAttributeInfo.getFeature().getDisplayAttributeName();
       Object value = attr.getValue();
       if (value != null) {
         if (displayName == null) {
           displayName = associationAttributeInfo.getFeature().getAttributes().get(0).getName();
         }
         switch (associationAttributeInfo.getType()) {
           case MANY_TO_ONE:
             ManyToOneAttribute manyToOneAttribute = (ManyToOneAttribute) attr;
             Object displayValue =
                 manyToOneAttribute.getValue().getAllAttributes().get(displayName).getValue();
             if (displayValue != null) {
               record.setAttribute(attributeInfo.getName(), displayValue.toString());
             } else {
               record.setAttribute(attributeInfo.getName(), "");
             }
             break;
           case ONE_TO_MANY:
             OneToManyAttribute oneToManyAttribute = (OneToManyAttribute) attr;
             List<String> values = new ArrayList<String>();
             for (AssociationValue assoc : oneToManyAttribute.getValue()) {
               Object o = assoc.getAllAttributes().get(displayName).getValue();
               if (o != null) {
                 values.add(o.toString());
               }
             }
             record.setAttribute(attributeInfo.getName(), StringUtil.join(values, ","));
             break;
         }
       } else {
         record.setAttribute(attributeInfo.getName(), "");
       }
     }
   }
   record.setAttribute(VALUE_HOLDER_RECORD_ATTRIBUTE, associationValue);
 }
  /** Actually create or update the fields. */
  private void updateFields() {
    if (featureInfo != null) {
      // Create a header field for each attribute definition:
      List<ListGridField> fields = new ArrayList<ListGridField>();
      if (idInTable) {
        ListGridField gridField = new ListGridField(ID_NAME, "ID");
        gridField.setAlign(Alignment.LEFT);
        gridField.setCanEdit(false);
        fields.add(gridField);
      }

      for (AttributeInfo attributeInfo : featureInfo.getAttributes()) {
        if (!attributeInfo.isHidden()
            && (attributeInfo.isIdentifying() || allAttributesDisplayed)) {
          fields.add(createAttributeGridField(attributeInfo));
        }
      }
      setFields(fields.toArray(new ListGridField[fields.size()]));
      setCanResizeFields(true);
    }
  }
Exemplo n.º 3
0
  public ReferralLayerBlock(Layer<?> referral) {
    super(referral);
    this.layer = (VectorLayer) referral;

    final ChangedHandler filterChangedHandler = new FilterChangedHandler();
    dateForm1 = new ReferralDateFilterForm(filterChangedHandler);
    dateForm2 = new ReferralDateFilterForm(filterChangedHandler);

    FeatureInfo featureInfo = layer.getLayerInfo().getFeatureInfo();

    AssociationAttributeInfo statusInfo =
        (AssociationAttributeInfo)
            featureInfo.getAttributesMap().get(KtunaxaConstant.ATTRIBUTE_STATUS);
    AssociationAttributeInfo agencyTypeInfo =
        (AssociationAttributeInfo)
            featureInfo.getAttributesMap().get(KtunaxaConstant.ATTRIBUTE_EXTERNAL_AGENCY_TYPE);
    AssociationAttributeInfo typeInfo =
        (AssociationAttributeInfo)
            featureInfo.getAttributesMap().get(KtunaxaConstant.ATTRIBUTE_TYPE);

    clearStatus.setStartRow(false);
    clearStatus.setEndRow(false);
    clearStatus.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            status.clearValue();
            filterChangedHandler.onChanged(null);
          }
        });
    clearAgency.setStartRow(false);
    clearAgency.setEndRow(false);
    clearAgency.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            agency.clearValue();
            filterChangedHandler.onChanged(null);
          }
        });
    clearType.setStartRow(false);
    clearType.setEndRow(false);
    clearType.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            type.clearValue();
            filterChangedHandler.onChanged(null);
          }
        });

    form.setWidth100();
    status.getItem().setTitle("Status");
    status.getItem().addChangedHandler(filterChangedHandler);
    status.init(statusInfo, new DefaultAttributeProvider(layer, statusInfo.getName()));
    agency.getItem().setTitle("External Agency Type");
    agency.getItem().addChangedHandler(filterChangedHandler);
    agency.init(agencyTypeInfo, new DefaultAttributeProvider(layer, agencyTypeInfo.getName()));
    type.getItem().setTitle("Type");
    type.getItem().addChangedHandler(filterChangedHandler);
    type.init(typeInfo, new DefaultAttributeProvider(layer, typeInfo.getName()));
    form.setNumCols(4);
    form.setFields(
        status.getItem(), clearStatus, agency.getItem(), clearAgency, type.getItem(), clearType);
    addMember(form);
    addMember(dateForm1);
    addMember(dateForm2);
  }