public static String obtainColumnModelString(final String beanName, final String beanClassName) throws Exception { String colModels = JqgColModelStrings.get(beanName); if (null != colModels) { return colModels; } // 自动创建 StringBuilder builder = new StringBuilder(); builder.append("[\r\n"); List<JqgColModel> colModel = obtainColumnModels(beanName); for (JqgColModel cm : colModel) { builder.append(cm.toString()); builder.append(",\r\n"); } builder.delete(builder.length() - 3, builder.length()); builder.append("]"); JqgColModelStrings.put(beanName, builder.toString()); return builder.toString(); }
public static synchronized List<JqgColModel> createColModel( final String beanName, final String beanClassName) { List<JqgColModel> colModels = new ArrayList<JqgColModel>(); Class<?> clazz = RDBManager.getLocalSpaceConfig().getOrmBeanClass(beanName); // 分两类custom custom_element: $.remex.jgq.jRemexRefEle, // custom_value:$.remex.jgq.jRemexRefVal,custom_type:'jqgEditType' // 如果是JqgColModel本书,则在程序中定义配置 if (clazz == JqgColModel.class) { for (int i = 0; i < JSonJqgColModels.length; i++) { // JSONObject jcm = JSONObject.fromObject(JSonJqgColModels[i]); // JqgColModel colModel = (JqgColModel) JSONObject.toBean(jcm, JqgColModel.class); JqgColModel colModel = JsonHelper.toJavaObject(JSonJqgColModels[i], JqgColModel.class); colModel.setBeanName(beanName); colModel.setFieldName(colModel.getName()); colModel.setBeanClassName(clazz.getName()); colModel.setIdx(colModel.getName()); colModel.setColModelIndex(i); colModels.add(colModel); } } else { // 否则根据class的数据属性创建模型 Map<String, Type> baseFields = SqlType.getFields(clazz, FieldType.TBase); for (String fieldName : baseFields.keySet()) { JqgColModel colModel = new JqgColModel(); colModel.setBeanName(beanName); ViewUtil.buildCommConfig(clazz, fieldName, colModel); ViewUtil.buildEditConfig(clazz, fieldName, baseFields.get(fieldName), colModel); colModels.add(colModel); } Map<String, Type> objectFields = SqlType.getFields(clazz, FieldType.TObject); for (String fieldName : objectFields.keySet()) { JqgColModel colModel = new JqgColModel(); colModel.setBeanName(beanName); ViewUtil.buildCommConfig(clazz, fieldName, colModel); ViewUtil.buildEditConfig(clazz, fieldName, objectFields.get(fieldName), colModel); colModels.add(colModel); colModel.setHidden(true); // 参照列隐藏起来。 // 创建显示列 if (!ViewUtil.NoRefColumn.contains(fieldName)) { JqgColModel colModel_ref = new JqgColModel(); colModel_ref.setColModelIndex(colModel.getColModelIndex()); colModel_ref.setWidth(colModel.getWidth()); colModel_ref.setBeanName(beanName); ViewUtil.buildRefDisplayColumn(fieldName, objectFields.get(fieldName), colModel_ref); colModels.add(colModel_ref); } } } // 排序 Collections.sort(colModels); return colModels; }