Search in sources :

Example 1 with EJLovController

use of org.entirej.framework.core.data.controllers.EJLovController in project rap by entirej.

the class EJRWTStackedItemRenderer method loadComboBoxValues.

private List<ComboBoxValue> loadComboBoxValues(EJRWTStackedItemRendererConfig.Combo config) {
    // Initialise both the field and the values.
    List<ComboBoxValue> _comboValues = new ArrayList<ComboBoxValue>();
    String lovDefName = config.getLovDefinition();
    if (lovDefName == null || lovDefName.trim().length() == 0) {
        return _comboValues;
    }
    String defName = lovDefName;
    String defItemName = config.getItemName();
    if (defItemName == null || defItemName.trim().length() == 0) {
        EJMessage message = new EJMessage("No LovDefinition item has been chosen for the ComboBox renderer properties on item: " + _itemProperties.getName());
        _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
        return _comboValues;
    }
    if (_item.getBlock().getProperties().isReferenceBlock()) {
        defName = String.format("%s.%s", _item.getBlock().getProperties().getName(), defName);
    }
    EJLovDefinitionProperties lovDef = _item.getForm().getProperties().getLovDefinitionProperties(defName);
    if (lovDef == null) {
        return _comboValues;
    }
    EJLovController lovController = _item.getForm().getLovController(defName);
    if (lovController == null) {
        return _comboValues;
    }
    try {
        lovController.executeQuery(new EJItemLovController(_item.getBlock().getBlockController().getFormController(), _item, ((EJCoreItemProperties) _itemProperties).getLovMappingPropertiesOnUpdate()));
        if (!_item.getProperties().isMandatory()) {
            ComboBoxValue emptyValue = new ComboBoxValue(null, defItemName, config);
            _comboValues.add(emptyValue);
        }
        Collection<EJDataRecord> records = lovController.getRecords();
        for (EJDataRecord ejDataRecord : records) {
            if (!ejDataRecord.containsItem(defItemName)) {
                EJMessage message = new EJMessage("The item name '" + defItemName + "', does not exist within the lov definitions underlying block. Lov Definition: " + defName);
                _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
                return new ArrayList<ComboBoxValue>();
            }
            ComboBoxValue comboValue = new ComboBoxValue(ejDataRecord, defItemName, config);
            _comboValues.add(comboValue);
        }
    } catch (Exception e) {
        _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleException(e, true);
    }
    return _comboValues;
}
Also used : EJLovDefinitionProperties(org.entirej.framework.core.properties.interfaces.EJLovDefinitionProperties) EJItemLovController(org.entirej.framework.core.data.controllers.EJItemLovController) EJCoreItemProperties(org.entirej.framework.core.properties.EJCoreItemProperties) ArrayList(java.util.ArrayList) EJLovController(org.entirej.framework.core.data.controllers.EJLovController) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJMessage(org.entirej.framework.core.EJMessage) ParseException(java.text.ParseException)

Example 2 with EJLovController

use of org.entirej.framework.core.data.controllers.EJLovController in project rap by entirej.

the class EJRWTComboItemRenderer method connectLOVItems.

private void connectLOVItems() {
    String lovDefName = _rendererProps.getStringProperty(EJRWTComboBoxRendererDefinitionProperties.LOV_DEFINITION_NAME);
    if (lovDefName == null || lovDefName.trim().length() == 0) {
        return;
    }
    String defName = lovDefName;
    EJInternalForm form = _item.getForm();
    if (lovDefName.indexOf('.') != -1) {
        defName = lovDefName.substring(0, lovDefName.indexOf('.'));
    } else {
        EJMessage message = new EJMessage("No LovDefinition item has been chosen for the ComboBox renderer properties on item: " + _itemProperties.getName());
        form.getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
        return;
    }
    if (_item.getBlock().getProperties().isReferenceBlock()) {
        defName = String.format("%s.%s", _item.getBlock().getProperties().getName(), defName);
    }
    EJLovDefinitionProperties lovDef = form.getProperties().getLovDefinitionProperties(defName);
    if (lovDef == null) {
        return;
    }
    Collection<EJItemProperties> allItemProperties = lovDef.getBlockProperties().getAllItemProperties();
    for (EJItemProperties ejItemProperties : allItemProperties) {
        String defaultValue = ejItemProperties.getDefaultQueryValue();
        if (defaultValue == null || defaultValue.trim().length() == 0) {
            continue;
        }
        String paramTypeCode = defaultValue.substring(0, defaultValue.indexOf(':'));
        String paramValue = defaultValue.substring(defaultValue.indexOf(':') + 1);
        final Logger logger = LoggerFactory.getLogger(EJRWTComboItemRenderer.class);
        if ("APP_PARAMETER".equals(paramTypeCode)) {
            EJApplicationLevelParameter param = form.getApplicationLevelParameter(paramValue);
            if (param != null) {
                param.addParameterChangedListener(new ParameterChangedListener() {

                    @Override
                    public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
                        logger.debug("APP_PARAMETER:parameterChanged %s.%s", _item.getBlock().getProperties().getName(), _item.getName());
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                _loadComboBoxValues();
                                refreshCombo();
                            }
                        });
                    }
                });
            }
        } else if ("FORM_PARAMETER".equals(paramTypeCode)) {
            EJFormParameter param = form.getFormParameter(paramValue);
            if (param != null) {
                param.addParameterChangedListener(new ParameterChangedListener() {

                    @Override
                    public void parameterChanged(String parameterName, Object oldValue, Object newValue) {
                        logger.debug("FORM_PARAMETER.parameterChanged %s.%s", _item.getBlock().getProperties().getName(), _item.getName());
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                _loadComboBoxValues();
                                refreshCombo();
                            }
                        });
                    }
                });
            }
        } else if ("BLOCK_ITEM".equals(paramTypeCode)) {
            final String blockName = paramValue.substring(0, paramValue.indexOf('.'));
            String itemName = paramValue.substring(paramValue.indexOf('.') + 1);
            EJInternalEditableBlock block = form.getBlock(blockName);
            if (block != null) {
                final String itemBlock = _item.getBlock().getProperties().getName();
                _lovInitialiedOnValueSet = true;
                if (!itemBlock.equals(blockName) || _item.getScreenType() == EJScreenType.MAIN) {
                    block.getBlockController().addNewRecordFocusedListener(new EJNewRecordFocusedListener() {

                        @Override
                        public void focusedGained(EJDataRecord focusedRecord) {
                            logger.debug(String.format("BLOCK RECORD Changed %s", blockName));
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    _loadComboBoxValues();
                                    refreshCombo();
                                }
                            });
                        }
                    });
                }
                block.addDataItemValueChangedListener(itemName, new EJDataItemValueChangedListener() {

                    @Override
                    public void dataItemValueChanged(String itemName, EJDataRecord changedRecord, EJScreenType screenType) {
                        if (blockName.equals(itemBlock)) {
                            if (screenType == _item.getScreenType()) {
                                logger.debug(String.format("BLOCK_ITEM.valueChanged %s.%s", blockName, itemName));
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        _loadComboBoxValues();
                                        refreshCombo();
                                    }
                                });
                            }
                        } else {
                            if (screenType == EJScreenType.MAIN) {
                                logger.debug(String.format("BLOCK_ITEM.valueChanged %s.%s", blockName, itemName));
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        _loadComboBoxValues();
                                        refreshCombo();
                                    }
                                });
                            }
                        }
                    }
                });
            }
        }
    }
    EJLovController lovController = form.getLovController(defName);
    if (lovController == null) {
        return;
    }
}
Also used : EJScreenType(org.entirej.framework.core.enumerations.EJScreenType) EJFormParameter(org.entirej.framework.core.data.controllers.EJFormParameter) Logger(org.slf4j.Logger) EJApplicationLevelParameter(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter) EJLovController(org.entirej.framework.core.data.controllers.EJLovController) EJInternalForm(org.entirej.framework.core.internal.EJInternalForm) EJMessage(org.entirej.framework.core.EJMessage) EJLovDefinitionProperties(org.entirej.framework.core.properties.interfaces.EJLovDefinitionProperties) ParameterChangedListener(org.entirej.framework.core.data.controllers.EJApplicationLevelParameter.ParameterChangedListener) EJDataItemValueChangedListener(org.entirej.framework.core.renderers.eventhandlers.EJDataItemValueChangedListener) EJInternalEditableBlock(org.entirej.framework.core.internal.EJInternalEditableBlock) EJNewRecordFocusedListener(org.entirej.framework.core.renderers.eventhandlers.EJNewRecordFocusedListener) EJItemProperties(org.entirej.framework.core.properties.interfaces.EJItemProperties) EJDataRecord(org.entirej.framework.core.data.EJDataRecord)

Example 3 with EJLovController

use of org.entirej.framework.core.data.controllers.EJLovController in project rap by entirej.

the class EJRWTListItemRenderer method loadListBoxValues.

private void loadListBoxValues() {
    // Initialise both the field and the values.
    _lovInitialied = true;
    _listValues.clear();
    _listKays.clear();
    String lovDefName = _rendererProps.getStringProperty(EJRWTListBoxRendererDefinitionProperties.LOV_DEFINITION_NAME);
    if (lovDefName == null || lovDefName.trim().length() == 0) {
        return;
    }
    String defName = lovDefName;
    String defItemName = "";
    if (lovDefName.indexOf('.') != -1) {
        defName = lovDefName.substring(0, lovDefName.indexOf('.'));
        defItemName = lovDefName.substring(lovDefName.indexOf('.') + 1);
    } else {
        EJMessage message = new EJMessage("No LovDefinition item has been chosen for the ListBox renderer properties on item: " + _itemProperties.getName());
        _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
        return;
    }
    if (_item.getBlock().getProperties().isReferenceBlock()) {
        defName = String.format("%s.%s", _item.getBlock().getProperties().getName(), defName);
    }
    EJLovDefinitionProperties lovDef = _item.getForm().getProperties().getLovDefinitionProperties(defName);
    if (lovDef == null) {
        return;
    }
    EJLovController lovController = _item.getForm().getLovController(defName);
    if (lovController == null) {
        return;
    }
    try {
        lovController.executeQuery(new EJItemLovController(_item.getBlock().getBlockController().getFormController(), _item, ((EJCoreItemProperties) _itemProperties).getLovMappingPropertiesOnUpdate()));
        Collection<EJDataRecord> records = lovController.getRecords();
        for (EJDataRecord ejDataRecord : records) {
            if (!ejDataRecord.containsItem(defItemName)) {
                EJMessage message = new EJMessage("The item name '" + defItemName + "', does not exist within the lov definitions underlying block. Lov Definition: " + defName);
                _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
                return;
            }
            ListBoxValue listValue = new ListBoxValue(ejDataRecord, defItemName);
            String itemValueAsString = listValue.getItemValueAsString();
            _listValues.put(itemValueAsString, listValue);
            _listKays.add(itemValueAsString);
        }
    } catch (Exception e) {
        _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleException(e, true);
    }
}
Also used : EJLovDefinitionProperties(org.entirej.framework.core.properties.interfaces.EJLovDefinitionProperties) EJItemLovController(org.entirej.framework.core.data.controllers.EJItemLovController) EJCoreItemProperties(org.entirej.framework.core.properties.EJCoreItemProperties) EJLovController(org.entirej.framework.core.data.controllers.EJLovController) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJMessage(org.entirej.framework.core.EJMessage) MalformedURLException(java.net.MalformedURLException)

Example 4 with EJLovController

use of org.entirej.framework.core.data.controllers.EJLovController in project rap by entirej.

the class EJRWTComboItemRenderer method _loadComboBoxValues.

private void _loadComboBoxValues() {
    // Initialise both the field and the values.
    _lovInitialied.set(true);
    _comboValues.clear();
    String lovDefName = _rendererProps.getStringProperty(EJRWTComboBoxRendererDefinitionProperties.LOV_DEFINITION_NAME);
    if (lovDefName == null || lovDefName.trim().length() == 0) {
        return;
    }
    String defName = lovDefName;
    String defItemName = "";
    if (lovDefName.indexOf('.') != -1) {
        defName = lovDefName.substring(0, lovDefName.indexOf('.'));
        defItemName = lovDefName.substring(lovDefName.indexOf('.') + 1);
    } else {
        EJMessage message = new EJMessage("No LovDefinition item has been chosen for the ComboBox renderer properties on item: " + _itemProperties.getName());
        _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
        return;
    }
    if (_item.getBlock().getProperties().isReferenceBlock()) {
        defName = String.format("%s.%s", _item.getBlock().getProperties().getName(), defName);
    }
    EJLovDefinitionProperties lovDef = _item.getForm().getProperties().getLovDefinitionProperties(defName);
    if (lovDef == null) {
        return;
    }
    EJLovController lovController = _item.getForm().getLovController(defName);
    if (lovController == null) {
        return;
    }
    try {
        lovController.executeQuery(new EJItemLovController(_item.getBlock().getBlockController().getFormController(), _item, ((EJCoreItemProperties) _itemProperties).getLovMappingPropertiesOnUpdate()));
        if (!_item.getProperties().isMandatory()) {
            ComboBoxValue emptyValue = new ComboBoxValue(null, defItemName);
            _comboValues.add(emptyValue);
        }
        Collection<EJDataRecord> records = lovController.getRecords();
        for (EJDataRecord ejDataRecord : records) {
            if (!ejDataRecord.containsItem(defItemName)) {
                EJMessage message = new EJMessage("The item name '" + defItemName + "', does not exist within the lov definitions underlying block. Lov Definition: " + defName);
                _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleMessage(message);
                return;
            }
            ComboBoxValue comboValue = new ComboBoxValue(ejDataRecord, defItemName);
            _comboValues.add(comboValue);
        }
    } catch (Exception e) {
        _item.getForm().getFrameworkManager().getApplicationManager().getApplicationMessenger().handleException(e, true);
    }
}
Also used : EJLovDefinitionProperties(org.entirej.framework.core.properties.interfaces.EJLovDefinitionProperties) EJItemLovController(org.entirej.framework.core.data.controllers.EJItemLovController) EJCoreItemProperties(org.entirej.framework.core.properties.EJCoreItemProperties) EJLovController(org.entirej.framework.core.data.controllers.EJLovController) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJMessage(org.entirej.framework.core.EJMessage)

Aggregations

EJMessage (org.entirej.framework.core.EJMessage)4 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)4 EJLovController (org.entirej.framework.core.data.controllers.EJLovController)4 EJLovDefinitionProperties (org.entirej.framework.core.properties.interfaces.EJLovDefinitionProperties)4 EJItemLovController (org.entirej.framework.core.data.controllers.EJItemLovController)3 EJCoreItemProperties (org.entirej.framework.core.properties.EJCoreItemProperties)3 MalformedURLException (java.net.MalformedURLException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 EJApplicationLevelParameter (org.entirej.framework.core.data.controllers.EJApplicationLevelParameter)1 ParameterChangedListener (org.entirej.framework.core.data.controllers.EJApplicationLevelParameter.ParameterChangedListener)1 EJFormParameter (org.entirej.framework.core.data.controllers.EJFormParameter)1 EJScreenType (org.entirej.framework.core.enumerations.EJScreenType)1 EJInternalEditableBlock (org.entirej.framework.core.internal.EJInternalEditableBlock)1 EJInternalForm (org.entirej.framework.core.internal.EJInternalForm)1 EJItemProperties (org.entirej.framework.core.properties.interfaces.EJItemProperties)1 EJDataItemValueChangedListener (org.entirej.framework.core.renderers.eventhandlers.EJDataItemValueChangedListener)1 EJNewRecordFocusedListener (org.entirej.framework.core.renderers.eventhandlers.EJNewRecordFocusedListener)1 Logger (org.slf4j.Logger)1