Ejemplo n.º 1
0
 /** Refresh fields with values from tempModel or editedModel. */
 private void refreshDisplay() {
   Session s = Session.current;
   Model tmp = s.tempModel;
   int structIndex = -1;
   for (int j = 0; j < this.table.getChildCount(); j++) {
     structIndex++;
     View v = this.table.getChildAt(j);
     if (!FormViewFactory.isFieldView(v)) {
       // Check if it is a x2many label
       Model field = this.view.getStructure().get(structIndex);
       if (field.hasAttribute("type")) {
         String type = field.getString("type");
         if (type.equals("many2many") || type.equals("one2many")) {
           // This is the label of a x2many field
           // It is not present in structure and next
           // will be the true widget.
           // Get back in structure for next pass
           // to point on the x2many field (and not next one)
           structIndex--;
         }
       }
       continue;
     }
     Model field = this.view.getStructure().get(structIndex);
     FormViewFactory.setValue(v, field, this.view, tmp, s.editedModel, s.prefs, this);
   }
 }
Ejemplo n.º 2
0
  /** Update temp model to current values */
  private void updateTempModel() {
    Model tmp;
    Model origin;
    tmp = Session.current.tempModel;
    origin = Session.current.editedModel;
    int structIndex = -1;
    for (int j = 0; j < this.table.getChildCount(); j++) {
      structIndex++;
      View v = this.table.getChildAt(j);
      if (!FormViewFactory.isFieldView(v)) {
        // Check if it is a x2many label
        Model field = this.view.getStructure().get(structIndex);
        if (field.hasAttribute("type")) {
          String type = field.getString("type");
          if (type.equals("many2many") || type.equals("one2many")) {
            // This is the label of a x2many field
            // It is not present in structure and next
            // will be the true widget.
            // Get back in structure for next pass
            // to point on the x2many field (and not next one)
            structIndex--;
          }
        }
        // Ignore
        continue;
      }
      Model field = this.view.getStructure().get(structIndex);
      Object value = FormViewFactory.getValue(v, field, Session.current.prefs);
      if (value != FormViewFactory.NO_VALUE) {

        tmp.set(field.getString("name"), value);
      } else {
        // If NO_VALUE (not null) the value is ignored
        // but still set null to create the field if necessary
        String fieldName = field.getString("name");
        if (origin != null) {
          // Origin always has a value, it will be merged
        } else {
          // Origin doesn't have a value, set explicit null
          if (!tmp.hasAttribute(fieldName)) {
            tmp.set(fieldName, null);
          }
        }
      }
    }
  }
Ejemplo n.º 3
0
 private void initView() {
   for (Model view : this.view.getStructure()) {
     Session s = Session.current;
     if (view.hasAttribute("type")
         && (view.getString("type").equals("many2many")
             || view.getString("type").equals("one2many"))) {
       // Special case of x2many: they embed their own title
       // Thus occupies a full line
       TextView label = new TextView(this);
       if (view.hasAttribute("string")) {
         label.setText(view.getString("string"));
       } else {
         label.setText(view.getString("name"));
       }
       this.table.addView(label);
     }
     View v = FormViewFactory.getView(view, this.view, s.editedModel, s.prefs, this);
     if (view.hasAttribute("name") && view.getString("name").equals(Session.current.linkToSelf)) {
       // Hide many2one parent field
       v.setVisibility(View.GONE);
     }
     this.table.addView(v);
   }
 }