예제 #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;
                        }
                      }
                    });
          }
        }
      }
    }
  }
예제 #2
0
 public int validateDate(FormItem formItem, FieldDefinition fieldDef) {
   if (docType == null) return 0;
   if (!fieldDef.getFieldName().equals(docType.getDatefield())) return 0;
   return validateDate(formItem);
 }