defaultoperationstrategy.java

来自「CRM源码This file describes some issues tha」· Java 代码 · 共 401 行 · 第 1/2 页

JAVA
401
字号
/*
 * Copyright 2006-2007 Queplix Corp.
 *
 * Licensed under the Queplix Public License, Version 1.1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.queplix.com/solutions/commercial-open-source/queplix-public-license/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.queplix.core.client.frames.mainframe;

import com.queplix.core.client.app.rpc.RPC;
import com.queplix.core.client.app.vo.AccumulatedEntitiesRequestObject;
import com.queplix.core.client.app.vo.AccumulatedEntityDataResponse;
import com.queplix.core.client.app.vo.EntityData;
import com.queplix.core.client.app.vo.EntityDataResponseObject;
import com.queplix.core.client.app.vo.EntityDeleteRequestObject;
import com.queplix.core.client.app.vo.EntityIDRequestObject;
import com.queplix.core.client.app.vo.EntityMeta;
import com.queplix.core.client.app.vo.EntityUpdateRequestObject;
import com.queplix.core.client.app.vo.EntityUpdateResponseObject;
import com.queplix.core.client.app.vo.FamgMeta;
import com.queplix.core.client.app.vo.FieldData;
import com.queplix.core.client.app.vo.FieldDataRequest;
import com.queplix.core.client.app.vo.FieldMeta;
import com.queplix.core.client.app.vo.FieldOnDemandData;
import com.queplix.core.client.app.vo.FieldsHelper;
import com.queplix.core.client.app.vo.GridData;
import com.queplix.core.client.app.vo.GridSearchProperties;
import com.queplix.core.client.app.vo.MoreDataResponseObject;
import com.queplix.core.client.app.vo.NewEntityRequestObject;
import com.queplix.core.client.app.vo.RowData;
import com.queplix.core.client.app.vo.SearchGridRecordsResponseObject;
import com.queplix.core.client.app.vo.TextboxFieldData;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Default operation strategy implementation.
 * It simply performs the action using RPC, and provide set of response methods
 * that can be re-loaded
 *
 * @author Sergey Kozmin
 * @since 10.04.2007
 */
public class DefaultOperationStrategy implements BusinessOperationStrategy,
        BusinessCommandExecutor {
    private OperationContext operationContext;
    private String formId;
    private FamgMeta.Index formIndex;

    public void init(OperationContext operationContext, String formId,
                     FamgMeta.Index formIndex) {
        this.operationContext = operationContext;
        this.formId = formId;
        this.formIndex = formIndex;
    }

    protected OperationContext getOperationContext() {
        return operationContext;
    }

    public String getFormId() {
        return formId;
    }

    public FamgMeta.Index getFormIndex() {
        return formIndex;
    }

    public void createRecordProtorype(Collection data) {
        String formId = operationContext.getMetaData().getFormID(formIndex);

        RPC.QAsyncCallback callback = new BusinessCommand(this,
                BusinessCommandType.CREATE_PROTOTYPE);
        NewEntityRequestObject request = new NewEntityRequestObject(formId, data);
        RPC.getRPC().createEntity(request, callback);
    }

    /**
     * If success equals to false, fields and rowId equal to nulls.
     * @param success was creation succesfull
     * @param fields updated fields
     * @param rowId updated row id
     */
    protected void createRecordProtorypeResponse(boolean success,
                                                 FieldData[] fields, Long rowId) {
        operationContext.setOperationStatus(OperationTypes.CREATE_RECORD_PROTOTYPE, success, formIndex);
        if(success) {
            operationContext.getFormOperations().setFormData(fields, rowId, formIndex, true);
            operationContext.getGridOperations().clearGridSelection(formIndex);
        }
    }

    public void lockAndEditRecord(Long rowId) {
        String formId = operationContext.getMetaData().getFormID(formIndex);

        RPC.QAsyncCallback callback = new BusinessCommand(this,
                BusinessCommandType.LOCK_AND_EDIT);
        EntityIDRequestObject request = new EntityIDRequestObject(formId, rowId);
        RPC.getRPC().getLockForEditRecord(request, callback);
    }


    protected void lockAndEditResponse(boolean success,
                                       EntityData[] entitiesList,
                                       EntityData[] externalFieldsList,
                                       Collection gridData) {
        if(success) {
            operationContext.setData(entitiesList, externalFieldsList, gridData);
        }
        operationContext.setOperationStatus(OperationTypes.LOCK_AND_EDIT_RECORD,
                success, formIndex);//todo see FormsDataInjector comment, about the dedicated form. that is why we need to send status response after we set data
    }

    public void updateRecord(Long rowId, Collection data) {
        saveRecord(rowId, data, BusinessCommandType.UPDATE);
    }

    /**
     * update or insert records
     * @param rowId updating row id
     * @param data updating data
     * @param callbackType type of the callback, can
* be {@link com.queplix.core.client.frames.mainframe.BusinessCommand#UPDATE} or {@link com.queplix.core.client.frames.mainframe.BusinessCommand#INSERT}
     */
    protected void saveRecord(Long rowId, Collection data, int callbackType) {
        if(callbackType != BusinessCommandType.UPDATE
                && callbackType != BusinessCommandType.INSERT) {
            throw new IllegalArgumentException("You could not update the record"
                    + " with command types another from INSERT or UPDATE.");
        }
        RPC.QAsyncCallback callback = new BusinessCommand(this,
                callbackType);
        String formId = operationContext.getMetaData().getFormID(formIndex);
        EntityUpdateRequestObject entityDataRequestObject =
                new EntityUpdateRequestObject(formId, data, rowId);
        
        if(callbackType == BusinessCommandType.UPDATE) {
            RPC.getRPC().updateRecord(entityDataRequestObject, callback);
        } else {
            RPC.getRPC().insertRecord(entityDataRequestObject, callback);
        }
    }

    protected void updateRecordResponse(boolean success,
                                        EntityData[] entitiesList,
                                        EntityData[] externalFieldsList,
                                        Collection gridData,
                                        RowData updatedRow) {
        saveRecordResponse(success, entitiesList, externalFieldsList, gridData,
                updatedRow);
    }

    public void insertRecord(Long rowId, Collection data) {
        saveRecord(rowId, data, BusinessCommandType.INSERT);
    }

    protected void insertRecordResponse(boolean success,
                                        EntityData[] entitiesList,
                                        EntityData[] externalFieldsList,
                                        Collection gridData,
                                        RowData updatedRow) {
        saveRecordResponse(success, entitiesList, externalFieldsList, gridData,
                updatedRow);
    }

    protected void saveRecordResponse(boolean success,
                                      EntityData[] entitiesList,
                                      EntityData[] externalFieldsList,
                                      Collection gridData, RowData updatedRow) {
        operationContext.setOperationStatus(OperationTypes.UPDATE_RECORD, success, formIndex);
        if(success) {
            operationContext.setData(entitiesList, externalFieldsList, gridData);
            operationContext.getGridOperations().setDataForGridRow(updatedRow, formIndex);
            operationContext.getGridOperations().selectGridRecord(updatedRow.getId(), formIndex);
            operationContext.getGridOperations().activateGrid(formIndex);
        }
    }

    public void deleteRecord(Collection rowIds) {
        RPC.QAsyncCallback callback = new BusinessCommand(this,
                BusinessCommand.DELETE);
        String formId = operationContext.getMetaData().getFormID(formIndex);
        EntityDeleteRequestObject request = new EntityDeleteRequestObject(formId, rowIds);
        RPC.getRPC().deleteRecord(request, callback);
    }

    public void deleteRecordResponse(boolean success) {
        operationContext.setOperationStatus(OperationTypes.DELETE_RECORDS, success, formIndex);
        if(success) {
            operationContext.getFormOperations().clearForm(formIndex, true);
        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?