Exemplo n.º 1
0
  private void updateProperties(
      Map<String, PropertyType> refPropTypes, List<Property> propsTobeUpdated) {
    List<Property> propsToBeRemoved = new ArrayList<Property>();
    List<PropertyType> propsToBeAdded = new ArrayList<PropertyType>();
    propsToBeAdded.addAll(refPropTypes.values());

    Set<String> duplicates = new HashSet<String>();

    for (Property p : propsTobeUpdated) {
      PropertyType pt = p.getType();
      if (pt == null) {
        // PropertyType no longer exists
        propsToBeRemoved.add(p);
      } else {
        String name = pt.getName();
        if (refPropTypes.containsKey(name)) {
          propsToBeAdded.remove(pt);
        } else {
          propsToBeRemoved.add(p);
        }
        if (duplicates.contains(name)) {
          propsToBeRemoved.add(p);
        } else {
          duplicates.add(name);
        }
      }
    }

    // Removes all obsolete properties
    if (propsToBeRemoved.size() > 0) {
      propsTobeUpdated.removeAll(propsToBeRemoved);
    }

    // Adds new properties
    for (PropertyType pt : propsToBeAdded) {
      Property newProp = createProperty(pt);
      propsTobeUpdated.add(newProp);
    }
  }
  @Override
  public List<Property> filter(Widget widget) {

    // These are the WidgetType's of the Label and Field
    MetaModel mm = MetaModelRegistry.getMetaModel();
    String library = widget.getLibraryName();
    WidgetType wt = mm.findWidgetType(library, widget.getTypeName());

    // Add all the PropertyTypes which exist
    Set<PropertyType> allowedTypes = new HashSet<PropertyType>();
    allowedTypes.addAll(wt.getAllPropertyTypes().values());

    // hide some properties
    allowedTypes.remove(mm.findPropertyType(library, PropertyTypeConstants.EDITABLE));

    List<Property> result = new ArrayList<Property>();
    for (Property p : widget.getProperties()) {
      if (allowedTypes.contains(p.getType())) {
        result.add(p);
      }
    }
    return result;
  }