Exemplo n.º 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());
      }
    }
  }
Exemplo n.º 2
0
  /**
   * Creates the contents of the Widget. These are nested Widgets.
   *
   * @param widget The Widget to create the contents for
   */
  @SuppressWarnings("unchecked")
  private void createContents(Widget widget) {
    for (Iterator it = template.getContents().iterator(); it.hasNext(); ) {
      WidgetTemplate wt = (WidgetTemplate) it.next();
      WidgetFactory wf = new WidgetFactory();
      Widget w = wf.create(wt);
      createEvents(w, wt);

      widget.getContents().add(w);
    }
  }
Exemplo n.º 3
0
  /**
   * Creates a Widget given a template.
   *
   * @param template The WidgetTemplate to use to create the Widget
   * @return Widget The newly created Widget
   */
  public Widget create(WidgetTemplate template) {
    Assert.isNotNull(template);

    this.template = template;

    Widget widget = create(template.getType());
    createEvents(widget, template);
    createContents(widget);
    updateValuesFromTemplate(widget);

    return widget;
  }
Exemplo n.º 4
0
 /**
  * Creates the events for the Widget.
  *
  * @param widget The Widget to create the events for
  * @param wt The WidgetTemplate
  */
 private void createEvents(Widget widget, WidgetTemplate wt) {
   for (EventTemplate et : wt.getEventTemplates()) {
     String eventName = et.getEventType();
     Event event = getModelFactory().createEvent();
     FunctionType ft = et.getFunctionType();
     event.setEventName(eventName);
     event.setFunctionName(ft.getName());
     event.setNature(EventNature.get(et.getNature()));
     if (!hasEvent(widget, eventName)) {
       widget.getEvents().add(event);
       createParameters(event, et); // from the template
       // add missing parameters defined in the model.
       for (ParameterType pt : et.getFunctionType().getParameters()) {
         String name = pt.getName();
         if (event.findParameter(name) == null) {
           Parameter p = getModelFactory().createParameter();
           p.setName(name);
           p.setValue(pt.getDefaultValue());
           event.getParameters().add(p);
         }
       }
     }
   }
 }