Ejemplo n.º 1
0
  public FormDefinitionPanel(
      FormDefinition definition,
      FieldDefinitionListValue listValue,
      DocType docType,
      DocPanelSettingDataComplete dataComplete) {
    super();
    this.listValue = listValue;
    this.dataComplete = dataComplete;
    this.docType = docType;
    this.setWidth100();
    this.setHeight100();
    ArrayList<FormGroup> formGroups = definition.getFormGroups();
    formitemMap = new HashMap<String, FieldDefinitionItem>();
    ArrayList<MyDynamicForm> dynFields = new ArrayList<MyDynamicForm>();
    for (FormGroup formGroup : formGroups) {
      ArrayList<FieldDefinition> fields = formGroup.getFieldDefinitions();
      MyDynamicForm dynamicForm = new MyDynamicForm();
      dynamicForm.setNewLine(formGroup.getNewLine() == 1);
      ArrayList<FormItem> items = new ArrayList<FormItem>();
      for (FieldDefinition fieldDefinition : fields) {
        FieldDefinitionItem fi = createField(fieldDefinition);
        if (fi != null) {
          items.add(fi.getFormItem());
          if (fieldDefinition.isFieldReadOnly()) fi.getFormItem().setCanEdit(false);
          formitemMap.put(fieldDefinition.getFieldName(), fi);
        }
      }

      //
      dynamicForm.setAlign(Alignment.LEFT);
      switch (formGroup.getLabelOrientation()) {
        case FormGroup.FTORIENTATION_LEFT:
          dynamicForm.setTitleOrientation(TitleOrientation.LEFT);
          break;
        case FormGroup.FTORIENTATION_TOP:
          dynamicForm.setTitleOrientation(TitleOrientation.TOP);
          break;
        case FormGroup.FTORIENTATION_RIGHT:
          dynamicForm.setTitleOrientation(TitleOrientation.RIGHT);
          break;
        default:
          break;
      }

      int numofColumns = 0;
      if (definition.isHorizontal()) {
        numofColumns = formGroup.getNumofColumns() > 0 ? formGroup.getNumofColumns() : 1;
      } else {

        numofColumns = formGroup.getNumofColumns() > 0 ? formGroup.getNumofColumns() : items.size();
      }
      numofColumns =
          numofColumns * (formGroup.getLabelOrientation() == FormGroup.FTORIENTATION_TOP ? 1 : 2);
      dynamicForm.setNumCols(numofColumns);

      if (formGroup.getGroupHeight() != null && !formGroup.getGroupHeight().isEmpty()) {
        dynamicForm.setHeight(formGroup.getGroupHeight());
      }

      if (formGroup.getGroupWidth() != null && !formGroup.getGroupWidth().isEmpty()) {
        dynamicForm.setWidth(formGroup.getGroupWidth());
      }
      dynamicForm.setFields(items.toArray(new FormItem[] {}));
      dynFields.add(dynamicForm);
      if (formGroup.getGroupTitle() != null && formGroup.getGroupTitle().length() > 0) {
        dynamicForm.setIsGroup(true);
        dynamicForm.setGroupTitle(
            DocFlow.getCaption(formGroup.getFieldCaptionId(), formGroup.getGroupTitle()));
      }
      // this.addMember(dynamicForm);
      listValue.setFieldDefinitionListValue(formitemMap, this);
    }
    Layout container = this;
    if (definition.isHorizontal()) {
      container = createNewPanel();
    }

    for (MyDynamicForm dynamicForm : dynFields) {
      if (dynamicForm.isNewLine()) {
        container = createNewPanel();
      }
      container.addMember(dynamicForm);
    }

    Set<String> fieldKeys = formitemMap.keySet();

    for (String key : fieldKeys) {
      final FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();
      if (fieldDef.getCalculatorClass() != null) {
        final ICalculatorClass classCalculator =
            listValue.getCalculetorClass(fieldDef.getCalculatorClass());
        if (classCalculator != null) {
          item.getFormItem()
              .addChangedHandler(
                  new ChangedHandler() {
                    @Override
                    public void onChanged(ChangedEvent event) {
                      classCalculator.calculate(formitemMap, item);
                    }
                  });
        }
      }
      if (fieldDef.isClearComboValue()) {
        PickerIcon eraserValuePicker =
            new PickerIcon(
                new Picker("eraser.png"),
                new FormItemClickHandler() {
                  public void onFormItemClick(FormItemIconClickEvent event) {
                    item.getFormItem().setValue((Object) null);
                    fireChangedEvent(item.getFormItem());
                  }
                });
        item.getFormItem().setIcons(eraserValuePicker);
      }

      if ((fieldDef.getFieldType() == FieldDefinition.FT_COMBO
          || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION)) {
        if (fieldDef.getFieldSelectMethode() > 0) {
          String depFields = fieldDef.getDependencyFields();
          depFields = depFields == null ? "" : depFields;
          final String[] depFieldNames = depFields.split(";");
          final String parent_type = fieldDef.getFieldSelectMethode() + "";
          if (depFieldNames.length > 0 && depFieldNames[0].length() > 0) {
            item.getFormItem()
                .addChangedHandler(
                    new ChangedHandler() {
                      @Override
                      public void onChanged(ChangedEvent event) {
                        if (settingMyself) return;
                        try {
                          settingMyself = true;
                          comboValueChanged(depFieldNames, event.getValue(), parent_type);
                        } finally {
                          settingMyself = false;
                        }
                      }
                    });
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
 private FieldDefinitionItem createField(FieldDefinition field) {
   FormItem fi = null;
   switch (field.getFieldType()) {
     case FieldDefinition.FT_STRING:
       fi = new TextItem();
       break;
     case FieldDefinition.FT_INTEGER:
       fi = new IntegerItem();
       break;
     case FieldDefinition.FT_DOUBLE:
       fi = new FloatItem();
       break;
     case FieldDefinition.FT_BOOLEAN:
       fi = new CheckboxItem();
       break;
     case FieldDefinition.FT_TEXTAREA:
       fi = new TextAreaItem();
       // fi.setWidth("10000px");
       break;
     case FieldDefinition.FT_STATICTEXT:
       fi = new StaticTextItem();
       break;
     case FieldDefinition.FT_COMBO:
       fi = new ComboBoxItem();
       if (field.isNoUnknownValueComboValue())
         ((ComboBoxItem) fi).setAddUnknownValues(!field.isNoUnknownValueComboValue());
       break;
     case FieldDefinition.FT_SELECTION:
       fi = new SelectItem();
       if (field.isNoUnknownValueComboValue())
         ((SelectItem) fi).setAddUnknownValues(!field.isNoUnknownValueComboValue());
       break;
     case FieldDefinition.FT_DATE:
       fi = new CurrentTimeItem();
       break;
     case FieldDefinition.FT_CHK_GRID:
       fi = new ChkGridItem();
       break;
     case FieldDefinition.FT_MAP_ITEM:
       fi = new MapButton(this, field);
       break;
     case FieldDefinition.FT_IMAGE_ITEM:
       fi = new ImageItem(this, field);
       break;
     case FieldDefinition.FT_CUSTOM:
       fi = new CanvasItem();
       break;
     default:
       break;
   }
   if (fi == null) {
     return null;
   }
   fi.setTitle(DocFlow.getCaption(field.getFieldCaptionId(), field.getFieldCaption()));
   if (field.getFieldWidth() != null && !field.getFieldWidth().isEmpty()) {
     fi.setWidth(field.getFieldWidth());
   }
   if (field.getFieldHeight() != null && !field.getFieldHeight().isEmpty()) {
     fi.setHeight(field.getFieldHeight());
   }
   if (field.isFieldReadOnly()) {
     if (field.getFieldType() == FieldDefinition.FT_COMBO
         || field.getFieldType() == FieldDefinition.FT_SELECTION
         || field.getFieldType() == FieldDefinition.FT_DATE) fi.setCanEdit(false);
     else fi.setCanEdit(false);
   }
   setDefaultValue(field, fi);
   if (field.isHidden()) fi.setVisible(false);
   if (field.isDisabled()) {
     fi.setDisabled(true);
   }
   return new FieldDefinitionItem(field, fi);
 }