Search in sources :

Example 1 with EJRWTStackedItemRendererType

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

the class EJRWTStackedItemRenderer method refreshForeground.

private void refreshForeground() {
    Color foreground = EJRWTVisualAttributeUtils.INSTANCE.getForeground(_visualAttributeProperties);
    EJRWTStackedItemRendererType[] values = EJRWTStackedItemRendererType.values();
    for (EJRWTStackedItemRendererType type : values) {
        Control control = stackedPane.getControl(type.name());
        if (control != null && controlState(control)) {
            EJRWTItemRendererVisualContext _visualContext = (EJRWTItemRendererVisualContext) control.getData("EJRWTItemRendererVisualContext");
            control.setForeground(foreground != null ? foreground : _visualContext.getForegroundColor());
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Color(org.eclipse.swt.graphics.Color) EJRWTStackedItemRendererType(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext)

Example 2 with EJRWTStackedItemRendererType

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

the class EJRWTStackedItemRenderer method refreshBackground.

private void refreshBackground() {
    Color background = EJRWTVisualAttributeUtils.INSTANCE.getBackground(_visualAttributeProperties);
    EJRWTStackedItemRendererType[] values = EJRWTStackedItemRendererType.values();
    for (EJRWTStackedItemRendererType type : values) {
        Control control = stackedPane.getControl(type.name());
        if (control != null && controlState(control)) {
            EJRWTItemRendererVisualContext _visualContext = (EJRWTItemRendererVisualContext) control.getData("EJRWTItemRendererVisualContext");
            control.setBackground(background != null ? background : _visualContext.getBackgroundColor());
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Color(org.eclipse.swt.graphics.Color) EJRWTStackedItemRendererType(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext)

Example 3 with EJRWTStackedItemRendererType

use of org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType 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)

Example 4 with EJRWTStackedItemRendererType

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

the class EJRWTStackedItemRenderer method clearValue.

@Override
public void clearValue() {
    _baseValue = null;
    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) {
                    ((Button) control).setSelection(false);
                }
            // check_box/combo
            }
        }
    } finally {
        _modifyListener.enable = true;
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) EJRWTStackedItemRendererType(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType)

Example 5 with EJRWTStackedItemRendererType

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

the class EJRWTStackedItemRenderer method refreshItemRendererProperty.

@Override
public void refreshItemRendererProperty(String propertyName) {
    if (EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY.equals(propertyName)) {
        if (controlState(_label) && _rendererProps != null) {
            String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
            if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                _label.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
            } else {
                _label.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_TEXT);
            }
        }
        if (controlState(stackedPane) && _rendererProps != null) {
            String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
            EJRWTStackedItemRendererType[] values = EJRWTStackedItemRendererType.values();
            for (EJRWTStackedItemRendererType type : values) {
                Control control = stackedPane.getControl(type.name());
                if (control != null && controlState(control)) {
                    if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                        control.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
                    } else {
                        // reset
                        control.setData(EJ_RWT.CUSTOM_VARIANT, control.getData(EJ_RWT.CUSTOM_VARIANT + "_DEF"));
                    // default
                    }
                }
            }
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) EJRWTStackedItemRendererType(org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType)

Aggregations

Control (org.eclipse.swt.widgets.Control)7 EJRWTStackedItemRendererType (org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererType)7 Button (org.eclipse.swt.widgets.Button)3 Combo (org.eclipse.swt.widgets.Combo)3 Text (org.eclipse.swt.widgets.Text)3 EJRWTItemRendererVisualContext (org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext)3 Color (org.eclipse.swt.graphics.Color)2 Label (org.eclipse.swt.widgets.Label)2 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 EJRWTStackedItemRendererConfig (org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig)1 CheckBox (org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig.CheckBox)1 EJMessage (org.entirej.framework.core.EJMessage)1