Search in sources :

Example 1 with FormFieldType

use of com.qlangtech.tis.plugin.annotation.FormFieldType in project tis by qlangtech.

the class OfflineDatasourceAction method createNewSelectedTab.

/**
 * 通过表名和列创建新tab实例,如果SelectedTab对象中有其他字段但是没有设置默认值,创建过程中就会出错
 *
 * @param pluginFormPropertyTypes
 * @param tab2cols
 * @return
 */
private ISelectedTab createNewSelectedTab(PluginFormProperties pluginFormPropertyTypes, Map.Entry<String, List<ColumnMetaData>> tab2cols) {
    return pluginFormPropertyTypes.accept(new PluginFormProperties.IVisitor() {

        @Override
        public ISelectedTab visit(SuFormProperties props) {
            // try {
            // } catch (Exception e) {
            // throw new RuntimeException("create subform,table:" + tab2cols.getKey()
            // + ",cols size:" + tab2cols.getValue().size(), e);
            // }
            ISelectedTab subForm = props.newSubDetailed();
            PropertyType pp = null;
            ppDftValGetter: for (Map.Entry<String, PropertyType> pentry : props.getKVTuples()) {
                pp = pentry.getValue();
                if (pp.isIdentity()) {
                    pp.setVal(subForm, tab2cols.getKey());
                    continue;
                }
                if (pp.formField.type() == FormFieldType.MULTI_SELECTABLE) {
                    pp.setVal(subForm, tab2cols.getValue().stream().map((c) -> c.getName()).collect(Collectors.toList()));
                    continue ppDftValGetter;
                }
                if (pp.isInputRequired()) {
                    if (StringUtils.isNotEmpty(pp.dftVal())) {
                        if (pp.isDescribable()) {
                            List<? extends Descriptor> descriptors = pp.getApplicableDescriptors();
                            for (Descriptor desc : descriptors) {
                                if (StringUtils.equals(pp.dftVal(), desc.getDisplayName())) {
                                    // desc.getPluginFormPropertyTypes();
                                    pp.setVal(subForm, desc.newInstance(null, Collections.emptyMap(), Optional.empty()).instance);
                                    continue ppDftValGetter;
                                }
                            }
                        } else {
                            pp.setVal(subForm, pp.dftVal());
                            continue ppDftValGetter;
                        }
                    } else {
                        // pp.getEnumConstants()
                        FormFieldType fieldType = pp.formField.type();
                        if (fieldType == FormFieldType.SELECTABLE || fieldType == FormFieldType.ENUM) {
                            Object enumPp = pp.getExtraProps().get(Descriptor.KEY_ENUM_PROP);
                            com.alibaba.fastjson.JSONArray enums = null;
                            if (enumPp instanceof com.alibaba.fastjson.JSONArray) {
                                enums = (com.alibaba.fastjson.JSONArray) enumPp;
                            } else if (enumPp instanceof JsonUtil.UnCacheString) {
                                enums = ((JsonUtil.UnCacheString<com.alibaba.fastjson.JSONArray>) enumPp).getValue();
                            } else {
                                throw new IllegalStateException("unsupport type:" + pp.getClass().getName());
                            }
                            for (int i = 0; i < enums.size(); i++) {
                                com.alibaba.fastjson.JSONObject opt = enums.getJSONObject(i);
                                pp.setVal(subForm, opt.get(Option.KEY_VALUE));
                                continue ppDftValGetter;
                            }
                        }
                    }
                    throw new IllegalStateException("have not prepare for table:" + tab2cols.getKey() + " creating,prop name:'" + pentry.getKey() + "',subform class:" + subForm.getClass().getName());
                }
            }
            return subForm;
        }
    });
}
Also used : FormFieldType(com.qlangtech.tis.plugin.annotation.FormFieldType) JSONArray(org.json.JSONArray) PropertyType(com.qlangtech.tis.extension.impl.PropertyType) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) Descriptor(com.qlangtech.tis.extension.Descriptor) JSONObject(org.json.JSONObject) SuFormProperties(com.qlangtech.tis.extension.impl.SuFormProperties)

Aggregations

Descriptor (com.qlangtech.tis.extension.Descriptor)1 PluginFormProperties (com.qlangtech.tis.extension.PluginFormProperties)1 PropertyType (com.qlangtech.tis.extension.impl.PropertyType)1 SuFormProperties (com.qlangtech.tis.extension.impl.SuFormProperties)1 FormFieldType (com.qlangtech.tis.plugin.annotation.FormFieldType)1 JsonUtil (com.qlangtech.tis.trigger.util.JsonUtil)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1