📄 entityviewhelper.java
字号:
case ControlSType.GRID_TYPE: {
ret = buildInformGridMeta(datasetID, datasetCaption, entityName, linkedEntityName, ls, ctx);
break;
}
case ControlSType.M2M_TYPE: {
ret = buildMultiselectMeta(datasetID, datasetCaption, linkedEntityName, Collections.<FieldData>emptyList(),
dataset.getDynamic(), ls, ctx);
break;
}
case ControlSType.LINK_TYPE: {
ret = buildEntityLinkMeta(datasetID, datasetCaption, entityName, linkedEntityName, ctx);
break;
}
default: {
throw new IllegalControlTypeException("Couldn't find field meta type for xml type:" + type.getType()
+ " (" + type.toString() + ")");
}
}
}
ret.setRequired(dataset.getRequired());
// descriptive is always false for datasets
ret.setDescriptive(false);
// clear attribute
ret.setClearAttribute(dataset.getClear());
}
return ret;
}
private static BaseFieldMeta buildInformGridMeta(String datasetID,
String datasetCaption,
String entityName,
String linkedEntityName,
LogonSession ls,
ActionContext ctx) {
if(StringHelper.isEmpty(linkedEntityName)) {
throw new IncorrectEntityDescriptionException(entityName,
"Couldn't find linked entity for inform grid dataset."
+ "Entity name [" + entityName + "], dataset name ["
+ datasetID + "]. ");
}
FieldMeta[] itemsList = EntityViewHelper.getMetaInfoForEntity(
linkedEntityName, FieldsModificator.GRID, true, ls,
ctx);
long[] selectedIDs = new long[itemsList.length];
for(int i = 0; i < itemsList.length; i++) {
selectedIDs[i] = i;
}
GridMeta meta = new GridMeta(itemsList, selectedIDs);
FormMeta baseFormMeta = new FormMeta(new EntityMeta(linkedEntityName, itemsList), datasetCaption);
return new InFormGridFieldMeta(datasetID, datasetCaption, linkedEntityName, meta, meta, baseFormMeta);
}
private static BaseFieldMeta buildEntityLinkMeta(String datasetID,
String datasetCaption,
String entityName,
String linkedEntityName,
ActionContext ctx)
throws IncorrectEntityDescriptionException {
EntityLinkFieldMeta ret;
DatasetDescriptor descriptor = getDatasetMetadata(entityName, datasetID, ctx);
if(descriptor.getBindingEntityFkeyFieldNameToLinked() == null ||
descriptor.getBindingEntityFkeyFieldNameToLocation() == null ||
descriptor.getLinkedEntityPkeyFieldName() == null) {
throw new IncorrectEntityDescriptionException(entityName,
"Couldn't find foreign key which bound [" + entityName + "] entity and [" + linkedEntityName + "] entity. ");
} else {
ret = new EntityLinkFieldMeta(datasetID, datasetCaption, linkedEntityName, descriptor.getLinkedEntityFieldName());
}
return ret;
}
/**
* Retrieve foreign key for the two bound entities.
*
* @param entityName first bound entity
* @param bindingEntityName second bound entity
* @param ctx servlet context
* @return foreign key for the second bound entity. If return is null object, then there is no known connection between entities.
* It can be necessarily to re-run installation tools.
*/
private static Fkeys retriveFkColumnName(String entityName, String bindingEntityName, ActionContext ctx) {
EntityViewConfigManagerLocal evcm = ctx.getEntityViewConfigManager();
//get two entities and trying to find foreign key, that bound it. If key is found, get the field name.
Entity thisEn = evcm.getEntityViewConfig(entityName);
Entity bindingEn = evcm.getEntityViewConfig(bindingEntityName);
String bindingTableName = bindingEn.getDbobject();
Fkeys[] forenKeys = thisEn.getFkeys();
Fkeys fk = null;
for(Fkeys forenKey : forenKeys) {
//compare binding entity name and binding table name
if(forenKey.getFkEntity() != null && forenKey.getFkEntity().equalsIgnoreCase(bindingEntityName)) {
fk = forenKey;
break;
}
if(forenKey.getFkTable() != null && forenKey.getFkTable().equalsIgnoreCase(bindingTableName)) {
fk = forenKey;
break;
}
}
return fk;
}
public static MultiselectFieldMeta buildMultiselectMeta(String datasetID, String caption, String linkedEntityName,
List<FieldData> additionalFilters, Boolean dynamic, LogonSession ls,
ActionContext ctx)
throws EQLException, IncorrectEntityDescriptionException {
if(StringHelper.isEmpty(linkedEntityName)) {
throw new IncorrectEntityDescriptionException(linkedEntityName, "Incorrect \"linked-entity\" attribute, " +
"can not find linked entity and build metadata. ");
} else {
LinkedList<SubsetItemMeta> options = getOptionsForSubsetMeta(linkedEntityName, additionalFilters,
null, ls, ctx);
return new MultiselectFieldMeta(datasetID, linkedEntityName, caption, new SubsetMeta(options.toArray(
new SubsetItemMeta[options.size()])), dynamic);
}
}
/**
* Gets the option list for subset meta.
* @param linkedEntityName requesting entityty
* @param additionalFilters additional filters
* @param eqlFilters
* @param ls logon session
* @param ctx servlet context
* @return options list
* @throws EQLException if eql exception is occured
*/
public static LinkedList<SubsetItemMeta> getOptionsForSubsetMeta(
String linkedEntityName, List<FieldData> additionalFilters,
String eqlFilters, LogonSession ls, ActionContext ctx)
throws EQLException {
//retrieve all possible variants
RequestProperties props = new RequestProperties();
props.setPage((int) StringHelper.EMPTY_NUMBER);
Reqs request = EntityFacade.buildReqsFromThisEntityFields(additionalFilters, linkedEntityName,
eqlFilters, props, ls, ctx);
IntegratedRecordSet result = EntityFacade.performRequest(request, linkedEntityName, ls, ctx, FieldsModificator.FORM);
// Pasting results into multiselect metadata.
// Get the pkey and the value, value is taken from the listref field
LinkedList<SubsetItemMeta> options = new LinkedList<SubsetItemMeta>();
List<IntegratedRecord> records = result.getRecordSet();
for(IntegratedRecord record : records) {
Map<String, FieldData> fields = record.getFieldSet();
String key = result.getPkeyFieldName();
try {
String idData = EntitySerializeHelper.getStringRepresentationForGrid(fields.get(key), result.getRecordMeta().get(key), ls, ctx);
String captionData = EntitySerializeHelper.getStringRepresentationForGrid(fields.get(result.getListRefFieldName()),
result.getRecordMeta().get(result.getListRefFieldName()), ls, ctx);
long id = Long.parseLong(idData);
options.add(new SubsetItemMeta(id, captionData));
} catch (NumberFormatException e) {
logger.ERROR("Could not add multiselect value to list, because of incorrect value format. ", e);
}
}
return options;
}
private static FieldMeta createFieldMetaFromEfield(Efield field, Efield pkeyField, boolean withCaptions, LogonSession ls,
ActionContext ctx)
throws IllegalControlTypeException, EQLException, IncorrectEntityDescriptionException {
BaseFieldMeta ret;
if(field == null) {
throw new IllegalControlTypeException("Couldn't fill field meta data, because field objectis null. ");
}
ControlSType type = field.getControl();
String fieldID = field.getName();//field name is field id within entity
String fieldCaption;
if(withCaptions) {
fieldCaption = getFieldCaption(ls.getUser().getLangID(), field.getEntityName(), field.getName(), ctx);
} else {
fieldCaption = "";
}
if(type == null) {//no control property. there is only one control type: edit type
ret = new TextBoxFieldMeta(fieldID, fieldCaption);
} else {
switch(type.getType()) {
case ControlSType.CALENDAR_TYPE: {
ret = new DateFieldMeta(fieldID, fieldCaption);
break;
}
case ControlSType.CHECKBOX_TYPE: {
ret = new CheckBoxMeta(fieldID, fieldCaption);
break;
}
case ControlSType.EDIT_TYPE: {
ret = new TextBoxFieldMeta(fieldID, fieldCaption, field.getPattern(), field.getMasked());
break;
}
case ControlSType.ENTITY_TYPE: {
GridMeta gridMeta;
String entityName;
Listref listref = field.getListref();
if(listref != null) {
entityName = listref.getEntity();
FieldMeta[] fieldMetas = getMetaInfoForEntity(entityName, FieldsModificator.GRID, true, ls, ctx);
long[] selectedIDs = new long[fieldMetas.length];
for(int i = 0; i < fieldMetas.length; i++) {
selectedIDs[i] = i;
}
gridMeta = new GridMeta(fieldMetas, selectedIDs);
} else {
throw new IncorrectEntityDescriptionException(field.getEntityName(), "Control ["
+ field.getName() + "] has type ControlSType.ENTITY_TYPE, but hasn't listref entity. ");
}
ret = new EntityReferenceMeta(fieldID, fieldCaption, gridMeta, entityName);
break;
}
case ControlSType.INLINE_MEMO_TYPE: {
ret = new TextareaFieldMeta(fieldID, fieldCaption);
break;
}
case ControlSType.MEMO_TYPE: {
String memoTypeString = StringUtil.nullToEmpty(field.getMemotype());
int memoType = MemoFieldMeta.PREPPEND_TYPE;
if(memoTypeString.equalsIgnoreCase("append")) {
memoType = MemoFieldMeta.APPEND_TYPE;
} else if(memoTypeString.equalsIgnoreCase("edit")) {
memoType = MemoFieldMeta.EDIT_TYPE;
}
String pkeyFieldCaption = getFieldCaption(ls.getUser().getLangID(), pkeyField.getEntityName(), pkeyField.getName(), ctx);
ret = new MemoFieldMeta(fieldID, fieldCaption, pkeyFieldCaption, "Select " + fieldCaption, memoType);
break;
}
case ControlSType.HISTORY_TYPE: {
String pkeyFieldCaption = getFieldCaption(ls.getUser().getLangID(), pkeyField.getEntityName(), pkeyField.getName(), ctx);
ret = new HistoryFieldMeta(fieldID, fieldCaption, pkeyFieldCaption, fieldCaption);
break;
}
case ControlSType.SELECT_TYPE: {
ret = retrieveMetaForListbox(field, fieldID, fieldCaption, ctx, ls);
break;
}
case ControlSType.TEXTAREA_TYPE: {
ret = new TextareaFieldMeta(fieldID, fieldCaption);
break;
}
default: {
throw new IllegalControlTypeException("Couldn't find field meta type for xml type:" + type.getType()
+ " (" + type.toString() + ")");
}
}
}
ret.setRequired(field.getRequired());
ret.setDescriptive(field.getDescriptive());
ret.setReadOnly(field.getReadonly());
ret.setSearchable(field.getSearchable());
ret.setHasDefSrcAttribute(!StringHelper.isEmpty(field.getEqlDefsrc()));
ret.setInline(field.getInline());
return ret;
}
public static long[] getSelectedIndexes(String entityName, FieldsModificator entityType, ActionContext ctx, LogonSession ls) {
EntityViewConfigManagerLocal entityManager = ctx.getEntityViewConfigManager();
Entity entity = entityManager.getEntityViewConfig(entityName);
Efield[] selectedFields = getFieldsToBeProcessessed(entity.getEfield(), entityName, entityType, ls, ctx);
Efield[] fullFields = getFieldsToBeProcessessed(entity.getEfield(), entityName, FieldsModificator.FORM, ls, ctx);
long[] ret = new long[selectedFields.length];
for(int i = 0; i < selectedFields.length; i++) {
int index = getIndexInArray(selectedFields[i], fullFields);
if(index >= 0) {
ret[i] = index;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -