Package org.geomajas.layer.feature.attribute

Examples of org.geomajas.layer.feature.attribute.ManyToOneAttribute


    final String newValue = "hello world";
    Map<String, PrimitiveAttribute<?>> mtoAttributes = new HashMap<String, PrimitiveAttribute<?>>();
    mtoAttributes.put(ManyToOneProperty.PARAM_TEXT_ATTR, new StringAttribute(newValue));
    AssociationValue assoValue = new AssociationValue(null, mtoAttributes);
    ManyToOneAttribute mtoAttribute = new ManyToOneAttribute(assoValue);

    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    attributes.put(MTO, mtoAttribute);
    featureModel.setAttributes(feature1, attributes);
View Full Code Here


    feature = layer.read(f1.getId().toString());
    Assert.assertEquals("new name", layer.getFeatureModel().getAttribute(feature, PARAM_TEXT_ATTR).getValue());
    Assert.assertEquals(5f, layer.getFeatureModel().getAttribute(feature, PARAM_FLOAT_ATTR).getValue());
    Assert.assertEquals(c.getTime(), layer.getFeatureModel().getAttribute(feature, PARAM_DATE_ATTR).getValue());
    Assert.assertEquals(false, layer.getFeatureModel().getAttribute(feature, PARAM_BOOLEAN_ATTR).getValue());
    ManyToOneAttribute manytoOne = (ManyToOneAttribute) layer.getFeatureModel().getAttribute(feature,
        PARAM_MANY_TO_ONE);
    Assert.assertNotNull(manytoOne.getValue());
    Assert.assertNotNull(manytoOne.getValue().getId()); // Test for ID
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void setAttributesManyToOne() throws Exception {
    String newValue = "A new value";
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    ManyToOneAttribute attr = HibernateTestManyToOne.getDefaultAttributeInstance1(new Long(1));
    attr.getValue().getAttributes().remove(PARAM_TEXT_ATTR);
    attr.getValue().getAttributes().put(PARAM_TEXT_ATTR, new StringAttribute(newValue));
    attributes.put(PARAM_MANY_TO_ONE, attr);
    featureModel.setAttributes(feature1, attributes);
    Assert.assertEquals("A new value", featureModel.getAttribute(feature1, ATTR__MANY_TO_ONE__DOT__TEXT).getValue());
  }
View Full Code Here

    Object persistent = layer.create(tranzient);
    String id = layer.getFeatureModel().getId(persistent);
    // retrieve feature
    Object read = layer.getElements(filterService.createFidFilter(new String[] { id }), 0, 1).next();
    // read primitives
    ManyToOneAttribute manyToOne = (ManyToOneAttribute) layer.getFeatureModel().getAttribute(read, "manyToOneAttr");
    StringAttribute s = (StringAttribute) manyToOne.getValue().getAllAttributes().get("stringAttr");
    Assert.assertEquals("one", s.getValue());
    // update primitives
    Map<String, Attribute> attribs = new HashMap<String, Attribute>();
    attribs.put("stringAttr", new StringAttribute("bean2"));
    ManyToOneAttribute manyToOne2 = (ManyToOneAttribute) manyToOne.clone();
    manyToOne2.getValue().getAllAttributes().put("stringAttr", new StringAttribute("one2"));
    attribs.put("manyToOneAttr", manyToOne2);
    layer.getFeatureModel().setAttributes(read, attribs);
    layer.saveOrUpdate(read);
    // retrieve feature again
    Object read2 = layer.getElements(filterService.createFidFilter(new String[] { id }), 0, 1).next();
    // check attributes
    Attribute stringAttr = layer.getFeatureModel().getAttribute(read2, "stringAttr");
    Assert.assertNotNull(stringAttr);
    Assert.assertTrue(stringAttr.isPrimitive());
    Assert.assertEquals("bean2", stringAttr.getValue());
    ManyToOneAttribute manyToOne3 = (ManyToOneAttribute) layer.getFeatureModel()
        .getAttribute(read, "manyToOneAttr");
    Assert.assertEquals("one2", manyToOne3.getValue().getAttributeValue("stringAttr"));

  }
View Full Code Here

  }

  public Object createNested() throws LayerException {
    Object o = layer.getFeatureModel().newInstance();
    OneToManyAttribute many = new OneToManyAttribute(new ArrayList<AssociationValue>());
    ManyToOneAttribute one = new ManyToOneAttribute(new AssociationValue(null, new HashMap<String, Attribute<?>>(),
        false));
    one.getValue().getAllAttributes().put("stringAttr", new StringAttribute("one"));

    // create 2 manyInMany
    OneToManyAttribute manyInMany = new OneToManyAttribute(new ArrayList<AssociationValue>());
    AssociationValue manyInMany1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany1.getAllAttributes().put("stringAttr", new StringAttribute("manyInMany1"));
    manyInMany.getValue().add(manyInMany1);
    AssociationValue manyInMany2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInMany2.getAllAttributes().put("stringAttr", new StringAttribute("manyInMany2"));
    manyInMany.getValue().add(manyInMany2);

    // create oneInMany
    ManyToOneAttribute oneInMany = new ManyToOneAttribute();
    AssociationValue oneInManyValue = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    oneInManyValue.getAllAttributes().put("stringAttr", new StringAttribute("oneInMany"));
    oneInMany.setValue(oneInManyValue);

    // create 2 manyInOne
    OneToManyAttribute manyInOne = new OneToManyAttribute(new ArrayList<AssociationValue>());
    AssociationValue manyInOne1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInOne1.getAllAttributes().put("stringAttr", new StringAttribute("manyInOne1"));
    manyInOne.getValue().add(manyInOne1);
    AssociationValue manyInOne2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    manyInOne2.getAllAttributes().put("stringAttr", new StringAttribute("manyInOne2"));
    manyInOne.getValue().add(manyInOne2);

    // create oneInOne
    ManyToOneAttribute oneInOne = new ManyToOneAttribute();
    AssociationValue oneInOneValue = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    oneInOneValue.getAllAttributes().put("stringAttr", new StringAttribute("oneInOne"));
    oneInOne.setValue(oneInOneValue);

    // create 2 many
    AssociationValue many1 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    AssociationValue many2 = new AssociationValue(null, new HashMap<String, Attribute<?>>(), false);
    // add manyInMany to many1
View Full Code Here

    return o;
  }

  public Object createExistingManyToOne() throws LayerException {
    Object o = layer.getFeatureModel().newInstance();
    ManyToOneAttribute one = new ManyToOneAttribute(new AssociationValue(new LongAttribute(1L),
        new HashMap<String, Attribute<?>>(), false));
    Map<String, Attribute> attributes = new HashMap<String, Attribute>();
    attributes.put("manyToOneAttr", one);
    layer.getFeatureModel().setAttributes(o, attributes);
    return o;
View Full Code Here

      date = format.parse("01/01/2009");
    } catch (ParseException e) {
      date = new Date();
    }
    attributes.put("dateAttr", new DateAttribute(date));
    return new ManyToOneAttribute(new AssociationValue(new LongAttribute(id), attributes));
  }
View Full Code Here

      public void onSuccess(List<Attribute<?>> attributes) {
        // Add the values to the list:
        ListGridRecord[] list = new ListGridRecord[attributes.size()];
        for (int i = 0; i < attributes.size(); i++) {
          ManyToOneAttribute manyToOneAttribute = (ManyToOneAttribute) attributes.get(i);
          ListGridRecord record = new ListGridRecord();
          // set value field to id as text field !
          record.setAttribute(ASSOCIATION_ITEM_VALUE_FIELD_NAME, manyToOneAttribute.getValue().getId()
              .getValue().toString());
          record.setAttribute(ASSOCIATION_ITEM_VALUE_OBJECT_NAME, manyToOneAttribute.getValue());
          for (String name : manyToOneAttribute.getValue().getAllAttributes().keySet()) {
            Attribute<?> attribute = manyToOneAttribute.getValue().getAllAttributes().get(name);
            record.setAttribute(name, attribute.getValue());
          }
          list[i] = record;
        }
        dsResponse.setData(list);
View Full Code Here

   */
  public static AssociationAttribute<?> createEmptyAssociationAttribute(AssociationAttributeInfo info) {
    AssociationAttribute<?> association = null;
    switch (info.getType()) {
      case MANY_TO_ONE:
        association = new ManyToOneAttribute();
        break;
      case ONE_TO_MANY:
        association = new OneToManyAttribute();
    }
    association.setEditable(info.isEditable());
View Full Code Here

          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(), "");
View Full Code Here

TOP

Related Classes of org.geomajas.layer.feature.attribute.ManyToOneAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.