⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qformcontrollerimpl.java

📁 CRM源码This file describes some issues that should be implemented in future and how it should be imple
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        int dataType = formElement.getBaseModel().getBaseMeta().getDataType();
        switch (dataType) {
            case FieldMeta.MEMO:
                //firefox workaround
                QMemo memo = (QMemo) formElement;
                if (memo.getModel().getMeta().isInline()) {
                    memo.getController().uploadDataToModel();
                }
            break;
        }
    }
    
    public void clearForm() {
        ArrayList ids = model.elementsKeys();
        model.clearActiveRowID();

        for (int i = 0, n = ids.size(); i < n; i++) {
            String elementID = (String) ids.get(i);
            model.clearElementData(elementID);
        }
    }

    public boolean setFormState(int formState) throws IncorrectFormStateSelected {
        try {
            return turnToState(getStateObject(formState));
        } catch (IncorrectFormActionPerformed incorrectFormActionPerformed) {
            throw new IncorrectFormStateSelected(incorrectFormActionPerformed, formState);
        }
    }

    public void resetAndSetFormState(int formState) throws IncorrectFormStateSelected {
        unitsList.clear();//clear all waiting processes
        resetAllStates();//reset all form states
        setFormState(formState);//set form to state with no case to not do that. 
    }

    private void resetAllStates() {
        searchState.resetState();
        selectedState.resetState();
        newState.resetState();
        editState.resetState();
        reportDesignState.resetState();
        previousState.resetState();
    }

    public boolean canFormChangeState() {
        return currentState.canFromExitState();
    }
    
    private QFormState getStateObject(int newQFormState) throws IncorrectFormActionPerformed {
        QFormState state;
        switch(newQFormState) {
            case FormState.NEW_STATE: state=newState; break;
            case FormState.EDIT_STATE: state=editState; break;
            case FormState.SEARCH_STATE: state=searchState; break;
            case FormState.SELECTED_STATE: state=selectedState; break;
            case FormState.REPORT_DESIGN_STATE: state=reportDesignState; break;
            case QFormState.PREVIOUS_STATE: state=previousState; break;
            default: throw new IncorrectFormActionPerformed(INCORRECT_STATE_CHANGE);
        }
        return state;
    }
    
    private boolean isEmptyRequired() {
        ArrayList ids = model.elementsKeys();
        String message = "The following required fields are empty: ";
        boolean noEmpty = true;
        for (int i = 0, n = ids.size(); i < n; i++) {
            String id = (String) ids.get(i);
            FieldData fieldData = model.getElementData(id);
            FieldMeta fieldMeta = model.getElementMeta(id);
            if( fieldData != null &&
                    fieldData.isEmpty() &&
                    fieldMeta.isRequired()) {
                message = message + "\n [" + fieldMeta.getCaption() + "]";
                noEmpty = false;
            }
        }
        if(!noEmpty) {
            DialogHelper.showModalMessageDialog(message + ". ");
        }
        return noEmpty;
    }
    
    public void needMoreData(FieldDataRequest request) {
        fireDataRequest(request);
    }
    
    private void search() {
        boolean searchSucc;
        try {
            searchSucc = setFormState(FormState.SEARCH_STATE);
        } catch (IncorrectFormStateSelected ex) {
            searchSucc = false;
        }
        if(!searchSucc) {
            DialogHelper.showModalMessageDialog("Could not search, because of internal error, wasn't able to set 'search' form state. ");
        } else {
            performAction(QFormController.Events.FORM_SEARCH_BUTTON_EVENT);
        }
    }
    
    public void searchByPkey(Long pkey) {
        clearForm();
        FieldData fieldData = model.getElementData(model.getPkeyID());
        FieldMeta fieldMeta = model.getElementMeta(model.getPkeyID());
        if(fieldMeta.getDataType() == FieldMeta.TEXTBOX) {
            ((TextboxFieldData)fieldData).setText(String.valueOf(pkey));
        }
        this.search();
    }
    
    public void searchByData(FieldData[] fieldData) {
        for(int i = 0; i < fieldData.length; i++) {
            model.setDataForElement(fieldData[i]);
        }
        search();
    }
    
    public void initFormElementsData() {
        uploadDataToModel();
    }

    public void whenScrolling() {
        view.hideContextMenu();
    }

    public void collectUISettings() {
        view.collectUISettings();
    }
    
    private class SearchFormState extends QFormStateAdapter {
        public int getState() {
            return SEARCH_STATE;
        }
        
        public void enterToState(int previusState) {
            view.allowModificationsForSearch();
            view.showChangeButton();
            view.enableAllCommonButtons();
            view.disableCommonChangeButton();
            view.setCustomButtonsEnabled(true);
        }

        public void actionPerformed(Event action) throws IncorrectFormActionPerformed {
            if(QFormController.Events.FORM_NEW_BUTTON_EVENT.equals(action)) {
                addUnitToChain(new NewUnit(context));
                fireExternalEvent(QFormController.Events.FORM_NEW_BUTTON_EVENT, true);
            } else if(QFormController.Events.FORM_CLEAR_BUTTON_EVENT.equals(action)) {
                clearForm();
                fireExternalEvent(QFormController.Events.FORM_CLEAR_BUTTON_EVENT, false);
            } else if(QFormController.Events.FORM_SEARCH_BUTTON_EVENT.equals(action)) {
                uploadDataToModel();
                addUnitToChain(new SearchUnit(context));
                fireExternalEvent(QFormController.Events.FORM_SEARCH_BUTTON_EVENT, true);
            } else {
                fireExternalEvent(action, true);
            }
        }
    }
    
    private class SelectedFormState extends QFormStateAdapter {
        public int getState() {
            return SELECTED_STATE;
        }
        
        public void enterToState(int previusState) {
            view.showChangeButton();
            view.denyModifications();
//            view.populateForm();
            view.enableAllCommonButtons();
            view.setCustomButtonsEnabled(true);
        }

        public void actionPerformed(Event action) throws IncorrectFormActionPerformed {
            if(QFormController.Events.FORM_NEW_BUTTON_EVENT.equals(action)) {
                addUnitToChain(new NewUnit(context));
                fireExternalEvent(QFormController.Events.FORM_NEW_BUTTON_EVENT, true);
            } else if(QFormController.Events.FORM_CHANGE_BUTTON_EVENT.equals(action)) {
                addUnitToChain(new LockForEditUnit(context));
                fireExternalEvent(QFormController.Events.FORM_CHANGE_BUTTON_EVENT, true);
            } else if(QFormController.Events.FORM_CLEAR_BUTTON_EVENT.equals(action)) {
                clearForm();
                turnToState(searchState);
                fireExternalEvent(QFormController.Events.FORM_CLEAR_BUTTON_EVENT, false);
            } else if(QFormController.Events.FORM_SEARCH_BUTTON_EVENT.equals(action)) {
                addUnitToChain(new SearchUnit(context));
                fireExternalEvent(QFormController.Events.FORM_SEARCH_BUTTON_EVENT, true);
            } else {
                fireExternalEvent(action, true);
            }
        }
    }
    
    private class EditFormState extends QFormStateAdapter implements BaseChainUnit.ChainAcceptanceListener {
        private int criticalListenersCounter = 0;
        
        public int getState() {
            return EDIT_STATE;
        }
        
        public void enterToState(int previusState) {
            view.showUpdateButton();
            view.enableAllCommonButtons();
            view.disableCommonNewButton();
            view.disableCommonSearchButton();
            view.allowModificationsForEdit();
            view.setCustomButtonsEnabled(true);
        }

        public void actionPerformed(Event action) throws IncorrectFormActionPerformed {
            if(QFormController.Events.FORM_UPDATE_BUTTON_EVENT.equals(action)) {
                uploadDataToModel();
                if(isEmptyRequired()) {
                    UpdateUnit updateUnit = new UpdateUnit(context);
                    updateUnit.addChainAcceptanceListener(this);
                    criticalListenersCounter++;
                    addUnitToChain(updateUnit);
                    fireExternalEvent(QFormController.Events.FORM_UPDATE_BUTTON_EVENT, true);
                }
            } else if(QFormController.Events.FORM_CLEAR_BUTTON_EVENT.equals(action)) {
                if(DialogHelper.showModalQuestionDialog(getRecordEditingMessage()) == DialogHelper.YES) {
                    clearForm();
                    turnToState(searchState);
                    fireExternalEvent(QFormController.Events.FORM_CLEAR_BUTTON_EVENT, false);
                }
            } else {
                fireExternalEvent(action, true);
            }
        }
        
        public boolean canFromExitState() {
            return criticalListenersCounter == 0;
        }
        
        public void resetState() {
            criticalListenersCounter = 0;
        }
        
        public void accepted() {
            criticalListenersCounter--;
        }
    }
    
    private class NewFormState extends QFormStateAdapter implements BaseChainUnit.ChainAcceptanceListener {
        private int criticalListenersCounter = 0;
        
        public int getState() {
            return NEW_STATE;
        }
        
        public void enterToState(int previusState) {
            view.showUpdateButton();
            view.enableAllCommonButtons();
            view.disableCommonNewButton();
            view.disableCommonSearchButton();
            view.setEnabledForNew();
            view.setCustomButtonsEnabled(true);
        }

        public void actionPerformed(Event action) throws IncorrectFormActionPerformed {
            if(QFormController.Events.FORM_UPDATE_BUTTON_EVENT.equals(action)) {
                uploadDataToModel();
                if(isEmptyRequired()) {
                    UpdateUnit updateUnit = new UpdateUnit(context);
                    updateUnit.addChainAcceptanceListener(this);
                    criticalListenersCounter++;
                    addUnitToChain(updateUnit);
                    fireExternalEvent(QFormController.Events.FORM_UPDATE_BUTTON_EVENT, true);
                }
            } else if(QFormController.Events.FORM_CLEAR_BUTTON_EVENT.equals(action)) {
                if(DialogHelper.showModalQuestionDialog(getRecordEditingMessage()) == DialogHelper.YES) {
                    clearForm();
                    turnToState(searchState);
                    fireExternalEvent(QFormController.Events.FORM_CLEAR_BUTTON_EVENT, false);
                }
            } else {
                fireExternalEvent(action, true);
            }
        }
        
        public boolean canFromExitState() {
            return criticalListenersCounter == 0;
        }
        
        public void resetState() {
            criticalListenersCounter = 0;
        }
        
        public void accepted() {
            criticalListenersCounter--;
        }
    }
    
    private class ReportDesignFormState extends QFormStateAdapter {
        public int getState() {
            return REPORT_DESIGN_STATE;
        }
        
        public void enterToState(int previusState) {
            view.showChangeButton();
            view.disableCommonChangeButton();
            view.disableCommonNewButton();
            view.disableCommonSearchButton();
            view.disableCommonClearButton();
            view.allowModificationsForReportDesign();
            view.setCustomButtonsEnabled(false);
        }
    }

    /**
     * just return form to previous state
     */
    private class PreviousFormState extends QFormStateAdapter {
        public int getState() {
            return PREVIOUS_STATE;
        }

        public void enterToState(int previusState) {
            turnToState(previousState);
        }
    }
    
    private class ActionContext implements ChainUnitContext {
        public void changeState(int newQFormState) throws IncorrectFormActionPerformed {
            turnToState(getStateObject(newQFormState));
        }
    }
    
    public void onTabActivated() {
        if (model.getFormMeta().isAutoSearch()) {
            (new Timer() {
                public void run() {
                    fireExternalEvent(QFormController.Events.FORM_SEARCH_BUTTON_EVENT, true);
                }
            }).schedule(50);
        }
    }
}

⌨️ 快捷键说明

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