Search in sources :

Example 36 with EJMessage

use of org.entirej.framework.core.EJMessage in project rap by entirej.

the class EJRWTDateTimeItemRenderer method setValue.

@Override
public void setValue(Object value) {
    if (value != null && !Date.class.isAssignableFrom(value.getClass())) {
        EJMessage message = EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_DATA_TYPE_FOR_ITEM, _item.getName(), Date.class.getName(), value.getClass().getName());
        throw new IllegalArgumentException(message.getMessage());
    }
    _baseValue = value;
    if (_displayValueAsLabel) {
        if (controlState(_valueLabel)) {
            _valueLabel.setText(value != null ? _dateFormat.format(value) : "");
        }
    } else {
        if (controlState(_textField)) {
            setDateTime(_textField, value);
            setMandatoryBorder(_mandatory);
        }
    }
}
Also used : EJMessage(org.entirej.framework.core.EJMessage) Date(java.util.Date)

Example 37 with EJMessage

use of org.entirej.framework.core.EJMessage 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 38 with EJMessage

use of org.entirej.framework.core.EJMessage in project rap by entirej.

the class EJRWTDateItemRenderer method setValue.

@Override
public void setValue(Object value) {
    try {
        _modifyListener.enable = false;
        if (value != null && !Date.class.isAssignableFrom(value.getClass())) {
            EJMessage message = EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_DATA_TYPE_FOR_ITEM, _item.getName(), Date.class.getName(), value.getClass().getName());
            throw new IllegalArgumentException(message.getMessage());
        }
        _baseValue = value;
        if (_displayValueAsLabel) {
            if (controlState(_valueLabel)) {
                _valueLabel.setText(value != null ? _dateFormat.format(value) : "");
            }
        } else {
            if (controlState(_textField)) {
                _textField.setText(value != null ? _dateFormat.format(value) : "");
                setMandatoryBorder(_mandatory);
            }
        }
    } finally {
        _modifyListener.enable = true;
    }
}
Also used : EJMessage(org.entirej.framework.core.EJMessage) Date(java.util.Date)

Example 39 with EJMessage

use of org.entirej.framework.core.EJMessage in project rap by entirej.

the class EJRWTImageItemRenderer method setValue.

@Override
public void setValue(Object value) {
    _baseValue = value;
    if (_currentImage != null && !_currentImage.isDisposed()) {
        _currentImage.dispose();
        _currentImage = null;
    }
    if (_labelField != null && controlState(_labelField)) {
        if (value == null) {
            _labelField.setImage(_defaultImage);
        } else {
            if (value instanceof String) {
                URL resource = EJRWTImageRetriever.class.getClassLoader().getResource((String) value);
                if (resource != null) {
                    _currentImage = ImageDescriptor.createFromURL(resource).createImage();
                } else {
                    try {
                        _currentImage = ImageDescriptor.createFromURL((new URL((String) value))).createImage();
                    } catch (MalformedURLException e) {
                        EJMessage message = EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_DATA_TYPE_FOR_ITEM, _item.getName(), "String should follow URL Spec or Need to be In Classpath", (String) value);
                        throw new IllegalArgumentException(message.getMessage());
                    }
                }
            } else if (value instanceof URL) {
                _currentImage = ImageDescriptor.createFromURL((URL) value).createImage();
            } else if (value instanceof byte[]) {
                _currentImage = new Image(Display.getDefault(), new ByteArrayInputStream((byte[]) value));
            } else {
                EJMessage message = EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_DATA_TYPE_FOR_ITEM, _item.getName(), "URL or byte[] ", value.getClass().getName());
                throw new IllegalArgumentException(message.getMessage());
            }
            _labelField.setImage(_currentImage);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ByteArrayInputStream(java.io.ByteArrayInputStream) EJRWTImageRetriever(org.entirej.applicationframework.rwt.application.EJRWTImageRetriever) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) EJMessage(org.entirej.framework.core.EJMessage)

Example 40 with EJMessage

use of org.entirej.framework.core.EJMessage in project rap by entirej.

the class EJRWTNumberItemRenderer method setValue.

@Override
public void setValue(Object value) {
    try {
        _modifyListener.enable = false;
        if (value != null && !Number.class.isAssignableFrom(value.getClass())) {
            EJMessage message = EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_DATA_TYPE_FOR_ITEM, _item.getName(), Number.class.getName(), value.getClass().getName());
            throw new IllegalArgumentException(message.getMessage());
        }
        _baseValue = value;
        if (_displayValueAsLabel) {
            if (controlState(_valueLabel)) {
                _valueLabel.setText(value != null ? _decimalFormatter.format(value) : "");
            }
        } else {
            if (controlState(_textField)) {
                if (value != null) {
                    if (_maxLength > 0 && value.toString().length() > _maxLength) {
                        EJMessage message = new EJMessage("The value for item, " + _item.getReferencedItemProperties().getBlockName() + "." + _item.getReferencedItemProperties().getName() + " is too long for its field definition.");
                        throw new EJApplicationException(message);
                    }
                }
                _textField.setText(value != null ? _decimalFormatter.format(value) : "");
                setMandatoryBorder(_mandatory);
            }
        }
    } finally {
        _modifyListener.enable = true;
    }
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException) EJMessage(org.entirej.framework.core.EJMessage)

Aggregations

EJMessage (org.entirej.framework.core.EJMessage)44 EJForm (org.entirej.framework.core.EJForm)9 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)9 EJQuestion (org.entirej.framework.core.data.controllers.EJQuestion)9 EJQuestionButton (org.entirej.framework.core.enumerations.EJQuestionButton)9 EJApplicationException (org.entirej.framework.core.EJApplicationException)5 EJLovController (org.entirej.framework.core.data.controllers.EJLovController)4 EJLovDefinitionProperties (org.entirej.framework.core.properties.interfaces.EJLovDefinitionProperties)4 Date (java.util.Date)3 EJItemLovController (org.entirej.framework.core.data.controllers.EJItemLovController)3 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 EJCoreItemProperties (org.entirej.framework.core.properties.EJCoreItemProperties)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 URL (java.net.URL)1 ParseException (java.text.ParseException)1 Collection (java.util.Collection)1 List (java.util.List)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1