Search in sources :

Example 1 with EJRWTStackedItemRendererConfig

use of org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig in project rap by entirej.

the class EJRWTStackedItemRenderer method setStackValue.

private void setStackValue() {
    Object value = _baseValue.getValue();
    try {
        _modifyListener.enable = false;
        EJRWTStackedItemRendererType[] values = EJRWTStackedItemRendererType.values();
        for (EJRWTStackedItemRendererType type : values) {
            Control control = stackedPane.getControl(type.name());
            if (control != null && controlState(control)) {
                if (control instanceof Label) {
                    ((Label) control).setText("");
                } else if (control instanceof Text) {
                    ((Text) control).setText("");
                } else if (control instanceof Combo) {
                    ((Combo) control).setText("");
                } else if (control instanceof Button) {
                    EJRWTStackedItemRendererConfig config = _baseValue.getConfig();
                    ((Button) control).setText(config.getLabel() == null ? (_item.getProperties().getLabel() == null ? "" : _item.getProperties().getLabel()) : config.getLabel());
                    ((Button) control).setToolTipText(config.getTooltip() == null ? (_item.getProperties().getHint() == null ? "" : _item.getProperties().getHint()) : config.getTooltip());
                    if (config instanceof EJRWTStackedItemRendererConfig.Button) {
                        EJRWTStackedItemRendererConfig.Button button = (EJRWTStackedItemRendererConfig.Button) config;
                        if (button.getImage() != null && button.getImage().trim().length() > 0) {
                            ((Button) control).setImage(EJRWTImageRetriever.get(button.getImage()));
                        }
                    }
                }
            // check_box/combo
            }
        }
        if (value != null) {
            switch(_baseValue.getConfig().getType()) {
                case LABEL:
                    {
                        Label control = (Label) stackedPane.getControl(_baseValue.getConfig().getType().name());
                        control.setText(value.toString());
                        break;
                    }
                case TEXT:
                case TEXT_AREA:
                    {
                        Text control = (Text) stackedPane.getControl(_baseValue.getConfig().getType().name());
                        control.setText(value.toString());
                        break;
                    }
                case COMBO:
                    {
                        Combo control = (Combo) stackedPane.getControl(_baseValue.getConfig().getType().name());
                        List<ComboBoxValue> loadComboBoxValues = (List<ComboBoxValue>) ((ComboViewer) control.getData("VIEW")).getInput();
                        ComboBoxValue boxValue = null;
                        for (ComboBoxValue val : loadComboBoxValues) {
                            if (val.getItemValue() == null && value == null) {
                                boxValue = val;
                                break;
                            }
                            if (val.getItemValue() == null) {
                                continue;
                            }
                            if (!val.getItemValue().getClass().isAssignableFrom(value.getClass())) {
                                EJMessage message = EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_DATA_TYPE_FOR_ITEM, _item.getName(), val.getItemValue().getClass().getName(), value.getClass().getName());
                                throw new IllegalArgumentException(message.getMessage());
                            }
                            if (val.getItemValue().equals(value)) {
                                boxValue = val;
                                break;
                            }
                        }
                        if (boxValue != null) {
                            ((ComboViewer) control.getData("VIEW")).setSelection(new StructuredSelection(boxValue));
                        }
                        break;
                    }
                case NUMBER:
                    {
                        EJRWTStackedItemRendererConfig.Number config = (EJRWTStackedItemRendererConfig.Number) _baseValue.getConfig();
                        _numberType = getNumberType(_baseValue);
                        _decimalFormatter = createFormatter(_numberType, config.getFormat());
                        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());
                        }
                        Text control = (Text) stackedPane.getControl(_baseValue.getConfig().getType().name());
                        control.setText(_decimalFormatter.format(value));
                        break;
                    }
                case DATE:
                    {
                        createDateFormat();
                        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());
                        }
                        Text control = (Text) stackedPane.getControl(_baseValue.getConfig().getType().name());
                        control.setText(_dateFormat.format(value));
                        control.setMessage(_dateFormat.toFormatString());
                        break;
                    }
                case SPACER:
                    {
                        setLabel("");
                        break;
                    }
                case CHECKBOX:
                    {
                        setLabel("");
                        Control control = stackedPane.getControl(_baseValue.getConfig().getType().name());
                        EJRWTStackedItemRendererConfig.CheckBox config = ((EJRWTStackedItemRendererConfig.CheckBox) _baseValue.getConfig());
                        ((Button) control).setSelection(config.getCheckBoxCheckedValue() == value || (value != null && value.equals(config.getCheckBoxCheckedValue())));
                        break;
                    }
                case BUTTON:
                    {
                        setLabel("");
                        break;
                    }
                default:
                    break;
            }
        } else {
            switch(_baseValue.getConfig().getType()) {
                case DATE:
                    createDateFormat();
                    break;
                case NUMBER:
                    _numberType = getNumberType(_baseValue);
                    _decimalFormatter = createFormatter(_numberType, ((EJRWTStackedItemRendererConfig.Number) _baseValue.getConfig()).getFormat());
                    break;
            }
        }
    } finally {
        _modifyListener.enable = true;
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) EJRWTStackedItemRendererType(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType) EJMessage(org.entirej.framework.core.EJMessage) Date(java.util.Date) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) CheckBox(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig.CheckBox) EJRWTStackedItemRendererConfig(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Control (org.eclipse.swt.widgets.Control)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 EJRWTStackedItemRendererConfig (org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig)1 CheckBox (org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig.CheckBox)1 EJRWTStackedItemRendererType (org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType)1 EJMessage (org.entirej.framework.core.EJMessage)1