Пример #1
0
  /**
   * Updates the default property values of the widget with those contained in the template.
   *
   * @param widget The Widget to update
   */
  private void updateValuesFromTemplate(Widget widget) {
    if (template == null) {
      // Nothing to update
      return;
    }

    // Update the default values
    for (PropertyTemplate templateProperty : template.getPropertyTemplates()) {
      Property widgetProperty = widget.findProperty(templateProperty.getType());
      if (widgetProperty == null) {
        StringBuffer message = new StringBuffer();
        message.append("The property [");
        message.append(templateProperty.getType().getName());
        message.append("] is not defined within the widget [");
        message.append(widget.getLibraryName());
        message.append(":");
        message.append(widget.getTypeName());
        message.append("]");
        System.out.println(message.toString());
      } else {
        widgetProperty.setValue(templateProperty.getValue());
        widgetProperty.setReadonly(templateProperty.isReadonly());
      }
    }
  }
Пример #2
0
 /**
  * Creates a Property correctly initialized with the default value.
  *
  * @param propertyType The PropertyType
  * @return Property The newly created Property
  */
 private Property createProperty(PropertyType propertyType) {
   Property p = getModelFactory().createProperty();
   p.setTypeName(propertyType.getName());
   p.setLibraryName(propertyType.getLibrary().getName());
   p.setValue(propertyType.getDefaultValue());
   return p;
 }
Пример #3
0
  /**
   * Gets the text associated with a specific item. This is used in the Header.
   *
   * @param widget The Widget to get the text for
   * @param index The index
   * @return String The text
   */
  protected String getItemText(Widget widget, int index) {
    // The Column contains a ColumnHeader as the first item and a ColumnBody as the second ones
    Widget header = widget.getContents().get(0);
    Property p = header.findProperty(PropertyTypeConstants.COLUMN_NAME);
    String s = "";
    if (p != null) {
      s = p.getValue();
    }

    if (StringUtils.isEmpty(s)) {
      return "            ";
    }

    return s;
  }
  /**
   * New instance of condition read from a widget property
   *
   * @param widget
   */
  public EnabledIsBaseOnCondition(Widget widget) {
    Property enabledIsBasedOn =
        widget.findProperty(EnabledConstants.ENABLED_IS_BASE_ON_PROPERTY_NAME);
    if (enabledIsBasedOn != null) {
      this.simplified = !ADVANCED_VALUE.equals(enabledIsBasedOn.getValue());
    } else {
      this.simplified = true;
    }

    Property simplifedProperty =
        widget.findProperty(EnabledConstants.ENABLED_IS_BASE_ON_SIMPLIFED_PROPERTY_NAME);
    if (simplifedProperty != null && StringUtils.isNotBlank(simplifedProperty.getValue())) {
      this.simplifiedCondition = MdfNameFactory.createMdfName(simplifedProperty.getValue());
    } else {
      this.simplifiedCondition = null;
    }

    Property advancedProperty =
        widget.findProperty(EnabledConstants.ENABLED_IS_BASE_ON_ADVANCED_PROPERTY_NAME);
    if (advancedProperty != null) {
      this.advancedCondition = advancedProperty.getValue();
    } else {
      this.advancedCondition = "";
    }
  }
Пример #5
0
  /** property url should be src attribute with url as value */
  @Override
  public void transform(WidgetTransformerContext context, Property property) throws CoreException {

    String domainAttributValue =
        property
            .getWidget()
            .getPropertyValue(PropertyTypeConstants.DOMAIN_ATTRIBUTE_WITHOUT_VALIDATOR);

    if (domainAttributValue != null && domainAttributValue.length() > 0) {
      Property beanNameProperty =
          BeanPropertyUtils.findBeanNameProperty(context, property.getWidget());
      String beanNamePropertyValue = beanNameProperty.getValue();

      // Create the element <xsp:attribute name="src">...</xsp:attribute>
      Namespace ns = context.getTransformModel().findNamespace(XSP_NAMESPACE_URI);
      Element valElmt =
          context
              .getDocument()
              .createElementNS(ns.getUri(), TransformerConstants.ATTRIBUTE_ELEMENT_NAME);
      valElmt.setPrefix(ns.getPrefix());
      TransformUtils.appendChild(context, valElmt);
      // Create the attribute name="src"
      Attr a = context.getDocument().createAttribute(TransformerConstants.NAME_ATTRIBUTE_NAME);
      a.setValue("src");
      valElmt.setAttributeNode(a);

      // create the <bean:get-property bean="..." property="..."/>
      Namespace beanNamespace = context.getTransformModel().findNamespace(BEAN_URI);
      Element defElmt =
          context.getDocument().createElementNS(beanNamespace.getUri(), BEAN_GET_PROPERTY_ELEMENT);
      defElmt.setPrefix(beanNamespace.getPrefix());
      addAttribute(context, defElmt, BEAN_BEAN_ATTRIBUTE, beanNamePropertyValue);
      addAttribute(context, defElmt, BEAN_PROPERTY_ATTRIBUTE, domainAttributValue);
      valElmt.appendChild(defElmt);

    } else {
      String url = property.getValue();
      if (url != null && url.length() != 0) {
        addAttribute(context, "src", url);
      }
    }
  }
Пример #6
0
  /**
   * Creates the properties for the Event. Existing properties are reused so that their values are
   * conserved.
   */
  private void createProperties() {
    Map<String, Property> existingProperties = new HashMap<String, Property>();
    for (Property p : event.getProperties()) {
      existingProperties.put(p.getTypeName(), p);
    }

    // Clear the old properties
    event.getProperties().clear();

    for (PropertyType pt : event.getEventType().getPropertyTypes()) {
      Property p = existingProperties.get(pt.getName());
      if (p == null) {
        // Create a new property
        p = ModelFactory.eINSTANCE.createProperty();
        p.setTypeName(pt.getName());
        p.setLibraryName(pt.getLibrary().getName());
      }
      event.getProperties().add(p);
    }
  }
Пример #7
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;
  }