defaultoperationstrategy.java
来自「CRM源码This file describes some issues tha」· Java 代码 · 共 401 行 · 第 1/2 页
JAVA
401 行
}
public void searchRecords(Collection entitiesFilters,
GridSearchProperties props,
boolean isLocalSearch) {
String formId = operationContext.getMetaData().getFormID(formIndex);
AccumulatedEntitiesRequestObject searchRequest =
new AccumulatedEntitiesRequestObject(formId, entitiesFilters,
props);
RPC.QAsyncCallback callback = new SearchBusinessCommand(this, formIndex, isLocalSearch);
RPC.getRPC().searchWithMultipleFormConstraints(searchRequest, callback);
}
protected void searchRecordsResponse(boolean success,
GridData gridData,
int totalRecordsCount,
int currentPage,
boolean localSearch) {
if (success) {
operationContext.getGridOperations().activateGrid(formIndex);
operationContext.getGridOperations().setDataForGrid(gridData, totalRecordsCount, currentPage, formIndex);
RowData[] rows = gridData.getRows();
if (rows.length == 1) {
operationContext.setOperationStatus(OperationTypes.SEARCH_RECORDS, true, formIndex);
operationContext.getFormOperations().selectRecord(rows[0].getId(), formIndex);
operationContext.getGridOperations().selectGridRecord(rows[0].getId(), formIndex);
} else if (rows.length >= 2) {
operationContext.setOperationStatus(OperationTypes.SEARCH_RECORDS, false, formIndex);
} else if (rows.length < 0) {
operationContext.setOperationStatus(OperationTypes.SEARCH_RECORDS, false, formIndex);
}
} else {
operationContext.setOperationStatus(OperationTypes.SEARCH_RECORDS, success, formIndex);
}
}
public void handleLinkEvent(String fromLinkFieldId) {
FormOperations formOperations = operationContext.getFormOperations();
FamgMeta formMeta = operationContext.getMetaData().getFamgMeta(formIndex);
EntityMeta entityMeta = formMeta.getForm().getEntityMeta();
FieldMeta srcFieldMetaMeta = entityMeta.getField(fromLinkFieldId);
FamgMeta.Index toIndex = srcFieldMetaMeta.getLinkedForm();
operationContext.getGridOperations().activateGrid(toIndex);
formOperations.activateForm(toIndex);
FieldData data = formOperations.getFieldData(formIndex, fromLinkFieldId);
if (data != null && !data.isEmpty()) {
Long recordId = FieldsHelper.extractReferencedRecordId(srcFieldMetaMeta, data);
//check if a record to be searched and
//check if we can switch to search state, otherwise do nothing,
if (recordId != null) {
//clear form
operationContext.performOperation(OperationTypes.CLEAR_FORM, toIndex);
//if form was cleared => form state == FormState.SEARCH_STATE
if (formOperations.getFormState(toIndex) == FormState.SEARCH_STATE) {
//create id filter
ArrayList idFilter = new ArrayList();
FamgMeta toFormMeta = operationContext.getMetaData().getFamgMeta(toIndex);
String pkeyFieldName = toFormMeta.getForm().getPkeyID();
idFilter.add(new EntityData(toFormMeta.getEntityName(),
recordId, new FieldData[] {new TextboxFieldData(
pkeyFieldName, recordId.toString())}));
//do local search
GridSearchProperties props = operationContext.getGridOperations().getGridSearchProperties(toIndex);
searchRecords(idFilter, props, true);
}
}
}
}
public void handleControlDataRequest(FieldDataRequest request) {
RPC.QAsyncCallback callback = new BusinessCommand(this,
BusinessCommandType.CONTROL_DATA_REQUEST);
RPC.getRPC().getMoreData(request, callback);
}
protected void handleControlDataResponse(FieldOnDemandData resp) {
operationContext.getFormOperations().setOnDemandData(formIndex, resp);
}
public void handleCustomMenuEvent(String eventId) {
//to be implemented in descendant classes
}
public void handleCustomButtonEvent(String buttonId) {
//to be implemented in descendant classes
}
private void handleSaveResponse(int commandType, boolean success,
Object result) {
EntityData[] entitiesToFill = null;
EntityData[] externalFields = null;
List gridData = null;
RowData updatedRow = null;
if (success) {
EntityUpdateResponseObject response = (EntityUpdateResponseObject) result;
entitiesToFill = response.getEntitiesList();
externalFields = response.getExternalFieldsList();
gridData = response.getGridData();
updatedRow = response.getUpdatedRow();
}
if(commandType == BusinessCommandType.UPDATE) {
updateRecordResponse(success, entitiesToFill, externalFields,
gridData, updatedRow);
} else if(commandType == BusinessCommandType.INSERT) {
updateRecordResponse(success, entitiesToFill, externalFields,
gridData, updatedRow);
}
}
/**
* This method is to be overwriten if customn command types added.
* @param commandType command type
* @param commandObject command object. In default implementation is
* RPC callback object BusinessCommand
* @param success was performed succesfully
* @param result result object
*/
public void execute(int commandType, Object commandObject, boolean success,
Object result) {
BusinessCommand command = (BusinessCommand) commandObject;
switch(commandType) {
case BusinessCommandType.CREATE_PROTOTYPE: {
FieldData[] fields = null;
Long id = null;
if (success) {
EntityDataResponseObject response = (EntityDataResponseObject) result;
fields = response.getEntityData().getFields();
id = response.getEntityData().getRowID();
}
createRecordProtorypeResponse(success, fields, id);
break;
}
case BusinessCommandType.CONTROL_DATA_REQUEST: {
if (success) {
MoreDataResponseObject response = (MoreDataResponseObject) result;
handleControlDataResponse(response.getFieldData());
}
break;
}
case BusinessCommandType.LOCK_AND_EDIT: {
EntityData[] entitiesToFill = null;
EntityData[] externalFields = null;
List gridData = null;
if (success) {
AccumulatedEntityDataResponse response = (AccumulatedEntityDataResponse) result;
entitiesToFill = response.getEntitiesList();
externalFields = response.getExternalFieldsList();
gridData = response.getGridData();
}
lockAndEditResponse(success, entitiesToFill, externalFields,
gridData);
break;
}
case BusinessCommandType.INSERT://don't break have one handler here
case BusinessCommandType.UPDATE: {
handleSaveResponse(command.getCommandType(), success, result);
break;
}
case BusinessCommandType.SEARCH: {
SearchBusinessCommand com = (SearchBusinessCommand) command;
GridData gridData = null;
int totalRecordsCount = -1;
int currentPage = -1;
if (success) {
SearchGridRecordsResponseObject response = (SearchGridRecordsResponseObject) result;
gridData = response.getGridData();
totalRecordsCount = response.getTotalRecordsCount();
currentPage = response.getCurrentPage();
}
searchRecordsResponse(success, gridData, totalRecordsCount,
currentPage, com.isLocalSearch());
break;
}
case BusinessCommandType.DELETE: {
deleteRecordResponse(success);
break;
}
}
}
public void handleError(int commandType, Object commandObject,
Throwable error) {
BusinessCommand command = (BusinessCommand) commandObject;
switch(commandType) {
case BusinessCommandType.CREATE_PROTOTYPE: {
break;
}
default : command.defaultHandleError(error);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?