예제 #1
0
 private void setDefaultValue(FieldDefinition field, FormItem fi) {
   if (field.getDefaultValue() != null && field.getDefaultValue().trim().length() > 0) {
     String defValue = field.getDefaultValue().trim();
     if (defValue.toLowerCase().equals("$regionId".toLowerCase())) {
       defValue = null;
     }
     if (defValue != null && defValue.toLowerCase().equals("$subregionId".toLowerCase())) {
       defValue = null;
     }
     fi.setValue(defValue);
   }
 }
예제 #2
0
  public void setCalculatorProceed() {
    Set<String> fieldKeys = formitemMap.keySet();

    for (String key : fieldKeys) {
      final FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();
      if (!fieldDef.isCalculatorProceed()) continue;
      if (fieldDef.getCalculatorClass() != null) {
        final ICalculatorClass classCalculator =
            listValue.getCalculetorClass(fieldDef.getCalculatorClass());
        if (classCalculator != null) {
          classCalculator.calculate(formitemMap, item);
        }
      }
    }
  }
예제 #3
0
  public int getDelayInterval() {
    Set<String> fieldKeys = formitemMap.keySet();

    for (String key : fieldKeys) {
      final FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();
      final FormItem formItem = item.getFormItem();

      if (fieldDef.getFieldType() == FieldDefinition.FT_DATE
          && formItem instanceof CurrentTimeItem) {
        int valid = validateDate(formItem, fieldDef);
        if (valid != 0 && !fieldDef.isDonotcheckForDate()) return valid;
      }
    }
    return 0;
  }
예제 #4
0
  private void comboValueChanged(String[] depFieldNames, Object selectedvalue, String parent_type) {
    HashMap<String, String> listSqls = new HashMap<String, String>();

    for (int i = 0; i < depFieldNames.length; i++) {
      String key = depFieldNames[i];
      FieldDefinitionItem item = formitemMap.get(key);
      if (item == null) continue;
      FieldDefinition fieldDef = item.getFieldDef();
      if (fieldDef == null) continue;
      FormItem formItem = item.getFormItem();
      if (formItem == null) continue;
      // result.put(key, );
      formItem.setValue((String) null);
      setSelectItems(formItem, new ArrayList<ClSelectionItem>());
      if ((fieldDef.getFieldType() == FieldDefinition.FT_COMBO
              || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION
              || fieldDef.getFieldType() == FieldDefinition.FT_CHK_GRID)
          && fieldDef.getFieldSelectMethode() > 0) {

        String depFields = fieldDef.getDependencyFields();
        depFields = depFields == null ? "" : depFields;
        final String[] mydepFieldNames = depFields.split(";");
        final String myparent_type = fieldDef.getFieldSelectMethode() + "";
        if (mydepFieldNames.length > 0 && mydepFieldNames[0].length() > 0) {
          comboValueChanged(mydepFieldNames, null, myparent_type);
        }
        if (selectedvalue == null) continue;
        String value =
            fieldDef.getFieldSelectMethode() + "_" + parent_type + "_" + selectedvalue.toString();
        listSqls.put(key, value);
      }
    }
    getRemouteValues(null, -1, listSqls, false);
  }
예제 #5
0
  public HashMap<String, Object> getData() {
    HashMap<String, Object> values = new HashMap<String, Object>();
    Set<String> keys = formitemMap.keySet();
    for (String key : keys) {
      FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();
      Object value = item.getFormItem().getValue();
      if (fieldDef.getFieldType() == FieldDefinition.FT_COMBO
          || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION
          || fieldDef.getFieldType() == FieldDefinition.FT_CHK_GRID
          || fieldDef.getFieldType() == FieldDefinition.FT_MAP_ITEM
          || fieldDef.getFieldType() == FieldDefinition.FT_IMAGE_ITEM
          || fieldDef.getFieldType() == FieldDefinition.FT_CUSTOM) {
        if (value != null) {
          if (!fieldDef.isDisplayValueIgnored())
            value = new String[] {value.toString(), item.getFormItem().getDisplayValue()};
        }
      }

      if (fieldDef.getFieldType() == FieldDefinition.FT_DATE) {
        if (value != null) {
          Date dt = (Date) value;
          value = new String[] {dt.getTime() + "", dt.toString()};
        }
      }
      if (fieldDef.getFieldType() == FieldDefinition.FT_BOOLEAN) {
        if (value != null) {
          Boolean dt = false;
          try {
            if (value instanceof Boolean) dt = (Boolean) value;
            else dt = (Boolean) (Integer.parseInt(value.toString()) == 1);
          } catch (Exception e) {
            // TODO: handle exception
          }
          value = new String[] {(dt.booleanValue() ? 1 : 0) + "", dt.toString()};
        }
      }
      values.put(key, value);
    }
    return values;
  }
예제 #6
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;
                        }
                      }
                    });
          }
        }
      }
    }
  }
예제 #7
0
 public int validateDate(FormItem formItem, FieldDefinition fieldDef) {
   if (docType == null) return 0;
   if (!fieldDef.getFieldName().equals(docType.getDatefield())) return 0;
   return validateDate(formItem);
 }
예제 #8
0
  public void setData(
      HashMap<String, String> values, long customer_id, HashMap<String, String> displayValues) {
    if (displayValues == null) displayValues = new HashMap<String, String>();
    newData = true;
    Set<String> fieldKeys = formitemMap.keySet();
    for (String key : fieldKeys) {
      FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();
      if (fieldDef.getFieldType() == FieldDefinition.FT_IMAGE_ITEM
          && displayValues.containsKey(key))
        ((ImageItem) item.getFormItem()).setDisplayValue(displayValues.get(key));

      if ((fieldDef.getFieldType() == FieldDefinition.FT_COMBO
          || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION
          || fieldDef.getFieldType() == FieldDefinition.FT_CHK_GRID)) {
        String val = fieldDef.getDefaultValue();
        if (val != null && val.trim().length() > 0) {
          val = val.trim();
          if (DocFlow.hasPermition("CAN_VIEW_ALL_REGIONS")
              && (val.toLowerCase().equals("$regionId".toLowerCase())
                  || val.toLowerCase().equals("$subregionId".toLowerCase()))) {
            if (values.get(key) != null) continue;
          }
          if (val.toLowerCase().equals("$regionId".toLowerCase())
              && DocFlow.user_obj.getUser().getRegionid() >= 0) {
            values.put(key, "" + DocFlow.user_obj.getUser().getRegionid());
            if (!item.getFieldDef().isFieldReadOnly())
              item.getFormItem().setDisabled(!DocFlow.hasPermition("CAN_VIEW_ALL_REGIONS"));
          }
          if (val.toLowerCase().equals("$subregionId".toLowerCase())
              && DocFlow.user_obj.getUser().getSubregionid() >= 0) {
            values.put(key, "" + DocFlow.user_obj.getUser().getSubregionid());
            if (!item.getFieldDef().isFieldReadOnly())
              item.getFormItem().setDisabled(!DocFlow.hasPermition("CAN_VIEW_ALL_REGIONS"));
          }
        }
      }
      setDefaultValue(fieldDef, item.getFormItem());
    }

    HashMap<String, String> listSqls = new HashMap<String, String>();
    for (String key : fieldKeys) {
      FieldDefinitionItem item = formitemMap.get(key);
      FieldDefinition fieldDef = item.getFieldDef();

      if (fieldDef.getFieldType() == FieldDefinition.FT_COMBO
          || fieldDef.getFieldType() == FieldDefinition.FT_SELECTION
          || fieldDef.getFieldType() == FieldDefinition.FT_CHK_GRID) {
        String value = "";
        if (fieldDef.getFieldSelectMethode() > 0) {
          value = fieldDef.getFieldSelectMethode() + "";
          String parentField = fieldDef.getParentField();
          parentField = parentField == null ? "" : parentField;
          if (parentField.length() != 0) {
            FieldDefinitionItem pItem = formitemMap.get(parentField);
            String parent_id = values.get(parentField);
            if (parent_id == null || parent_id.trim().length() == 0) {
              parent_id = "-1";
            }
            parent_id = parent_id.trim();

            if (pItem != null && pItem.getFieldDef() != null)
              value += "_" + pItem.getFieldDef().getFieldSelectMethode() + "_" + parent_id;
          }

        } else value = fieldDef.getFieldSelectionSQL();
        if (value == null || value.length() < 1) continue;
        listSqls.put(key, value);
      }
    }

    getRemouteValues(values, customer_id, listSqls, true);
  }
예제 #9
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);
 }