Search in sources :

Example 21 with EJDataRecord

use of org.entirej.framework.core.data.EJDataRecord 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 22 with EJDataRecord

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

the class EJRWTButtonItemRenderer method createColumnLabelProvider.

@Override
public ColumnLabelProvider createColumnLabelProvider(final EJScreenItemProperties item, EJScreenItemController controller) {
    final Image image;
    String pictureName = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_PICTURE);
    if (pictureName != null && pictureName.length() > 0) {
        image = EJRWTImageRetriever.get(pictureName);
    } else {
        image = null;
    }
    ColumnLabelProvider provider = new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return image;
        }

        @Override
        public Color getBackground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
                if (background != null) {
                    return background;
                }
            }
            return super.getBackground(element);
        }

        @Override
        public Color getForeground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
                if (foreground != null) {
                    return foreground;
                }
            }
            return super.getForeground(element);
        }

        private EJCoreVisualAttributeProperties getAttributes(final EJScreenItemProperties item, Object element) {
            EJCoreVisualAttributeProperties properties = null;
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                properties = record.getItem(item.getReferencedItemName()).getVisualAttribute();
            }
            if (properties == null) {
                properties = _visualAttributeProperties;
            }
            return properties;
        }

        @Override
        public Font getFont(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, super.getFont(element));
            }
            return super.getFont(element);
        }

        @Override
        public String getText(Object element) {
            String label = item.getLabel();
            return label != null ? label : "";
        }
    };
    return provider;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 23 with EJDataRecord

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

the class EJRWTCheckBoxItemRenderer method createColumnLabelProvider.

@Override
public ColumnLabelProvider createColumnLabelProvider(final EJScreenItemProperties item, final EJScreenItemController controller) {
    EJItemProperties itemProperties = controller.getReferencedItemProperties();
    EJFrameworkExtensionProperties itemRendererProperties = itemProperties.getItemRendererProperties();
    final Object checkedValue = getValueAsObject(itemProperties.getDataTypeClass(), itemRendererProperties.getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.CHECKED_VALUE));
    final Object uncheckedValue = getValueAsObject(itemProperties.getDataTypeClass(), itemRendererProperties.getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.UNCHECKED_VALUE));
    final boolean otherValueMappingValue = EJRWTCheckBoxRendererDefinitionProperties.CHECKED.equals(itemRendererProperties.getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.OTHER_VALUE_MAPPING));
    final boolean defaultState = EJRWTCheckBoxRendererDefinitionProperties.CHECKED.equals(otherValueMappingValue);
    ColumnLabelProvider provider = new ColumnLabelProvider() {

        @Override
        public Color getBackground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(properties);
                if (background != null) {
                    return background;
                }
            }
            return super.getBackground(element);
        }

        @Override
        public Color getForeground(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(properties);
                if (foreground != null) {
                    return foreground;
                }
            }
            return super.getForeground(element);
        }

        private EJCoreVisualAttributeProperties getAttributes(final EJScreenItemProperties item, Object element) {
            EJCoreVisualAttributeProperties properties = null;
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                properties = record.getItem(item.getReferencedItemName()).getVisualAttribute();
            }
            if (properties == null) {
                properties = _visualAttributeProperties;
            }
            return properties;
        }

        @Override
        public Font getFont(Object element) {
            EJCoreVisualAttributeProperties properties = getAttributes(item, element);
            if (properties != null) {
                return EJRWTVisualAttributeUtils.INSTANCE.getFont(properties, super.getFont(element));
            }
            return super.getFont(element);
        }

        @Override
        public String getText(Object element) {
            return "";
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof EJDataRecord) {
                EJDataRecord record = (EJDataRecord) element;
                Object value = record.getValue(item.getReferencedItemName());
                if (value != null) {
                    if (value.equals(checkedValue)) {
                        return EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_CHECK_SELECTED);
                    } else if (value.equals(uncheckedValue)) {
                        return EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_CHECK_UNSELECTED);
                    } else {
                        if (otherValueMappingValue) {
                            return EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_CHECK_SELECTED);
                        } else {
                            return EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_CHECK_UNSELECTED);
                        }
                    }
                } else {
                    if (defaultState) {
                        return EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_CHECK_SELECTED);
                    } else {
                        return EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_CHECK_UNSELECTED);
                    }
                }
            }
            return EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_CHECK_UNSELECTED);
        }
    };
    return provider;
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJScreenItemProperties(org.entirej.framework.core.properties.interfaces.EJScreenItemProperties) Color(org.eclipse.swt.graphics.Color) EJItemProperties(org.entirej.framework.core.properties.interfaces.EJItemProperties) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Example 24 with EJDataRecord

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

the class EJRWTCheckBoxItemRenderer method getColumnSorter.

@Override
public EJRWTAbstractTableSorter getColumnSorter(final EJScreenItemProperties item, EJScreenItemController controller) {
    EJItemProperties itemProperties = controller.getReferencedItemProperties();
    EJFrameworkExtensionProperties itemRendererProperties = itemProperties.getItemRendererProperties();
    final Object checkedValue = getValueAsObject(itemProperties.getDataTypeClass(), itemRendererProperties.getStringProperty(EJRWTCheckBoxRendererDefinitionProperties.CHECKED_VALUE));
    return new EJRWTAbstractTableSorter() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof EJDataRecord && e2 instanceof EJDataRecord) {
                EJDataRecord d1 = (EJDataRecord) e1;
                EJDataRecord d2 = (EJDataRecord) e2;
                if (d1 != null && d2 != null) {
                    Object value1 = d1.getValue(item.getReferencedItemName());
                    Object value2 = d2.getValue(item.getReferencedItemName());
                    if (checkedValue.equals(value1) && !checkedValue.equals(value2)) {
                        return 1;
                    }
                    if (!checkedValue.equals(value1) && checkedValue.equals(value2)) {
                        return -1;
                    }
                }
            }
            return 0;
        }
    };
}
Also used : EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) Viewer(org.eclipse.jface.viewers.Viewer) EJItemProperties(org.entirej.framework.core.properties.interfaces.EJItemProperties) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJRWTAbstractTableSorter(org.entirej.applicationframework.rwt.table.EJRWTAbstractTableSorter)

Example 25 with EJDataRecord

use of org.entirej.framework.core.data.EJDataRecord 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)

Aggregations

EJDataRecord (org.entirej.framework.core.data.EJDataRecord)52 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)18 EJScreenItemProperties (org.entirej.framework.core.properties.interfaces.EJScreenItemProperties)16 EJCoreVisualAttributeProperties (org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)15 Color (org.eclipse.swt.graphics.Color)12 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)12 Viewer (org.eclipse.jface.viewers.Viewer)11 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)11 ArrayList (java.util.ArrayList)10 EJCoreMainScreenItemProperties (org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)10 EJMessage (org.entirej.framework.core.EJMessage)9 EJRWTAbstractTableSorter (org.entirej.applicationframework.rwt.table.EJRWTAbstractTableSorter)8 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)8 JsonObject (org.eclipse.rap.json.JsonObject)7 GridData (org.eclipse.swt.layout.GridData)7 EJFrameworkExtensionPropertyListEntry (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry)7 EJItemGroupProperties (org.entirej.framework.core.properties.interfaces.EJItemGroupProperties)7 HashMap (java.util.HashMap)6 ISelection (org.eclipse.jface.viewers.ISelection)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6