Search in sources :

Example 1 with EJRWTAbstractActionText

use of org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText in project rap by entirej.

the class EJRWTTextItemRenderer method createComponent.

@Override
public void createComponent(Composite composite) {
    String alignmentProperty = _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_ALIGNMENT);
    if (alignmentProperty == null) {
        alignmentProperty = _rendererProps.getStringProperty("ALLIGNMENT");
    }
    String hint = _screenItemProperties.getHint();
    if (_displayValueAsLabel) {
        labelField = new EJRWTAbstractLabel(composite) {

            @Override
            public Label createLabel(Composite parent) {
                return _valueLabel = newVlaueLabel(parent);
            }

            @Override
            public Control createCustomActionLabel(Composite parent) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public Control createActionLabel(Composite parent) {
                // TODO Auto-generated method stub
                return null;
            }
        };
        _valueLabel.setData(_itemProperties.getName());
        _valueLabel.setData(EJ_RWT.CUSTOM_VARIANT, getCSSKey());
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            _valueLabel.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        if (hint != null && hint.trim().length() > 0) {
            _valueLabel.setToolTipText(hint);
        }
        setValueLabelAlign(alignmentProperty);
        _visualContext = new EJRWTItemRendererVisualContext(_valueLabel.getBackground(), _valueLabel.getForeground(), _valueLabel.getFont());
        setInitialValue(_baseValue);
    } else {
        final String alignmentProp = alignmentProperty;
        _actionControl = new EJRWTAbstractActionText(composite) {

            @Override
            public Text createText(Composite parent) {
                int style = SWT.BORDER;
                if (_displayValueAsProtected) {
                    style = style | SWT.PASSWORD;
                }
                _textField = newTextField(parent, getComponentStyle(alignmentProp, style));
                _textField.setData(EJ_RWT.CUSTOM_VARIANT, getCSSKey());
                String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
                if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                    _textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
                }
                return _textField;
            }

            @Override
            public Control createCustomActionLabel(Composite parent) {
                return createCustomButtonControl(parent);
            }

            @Override
            public Control createActionLabel(Composite parent) {
                Label label = new Label(parent, SWT.NONE);
                label.setImage(EJRWTImageRetriever.get(EJRWTImageRetriever.IMG_FIND_LOV));
                label.addFocusListener(EJRWTTextItemRenderer.this);
                label.addMouseListener(new MouseListener() {

                    private static final long serialVersionUID = 529634857284996692L;

                    @Override
                    public void mouseUp(MouseEvent arg0) {
                        _item.getItemLovController().displayLov(EJLovDisplayReason.LOV);
                    }

                    @Override
                    public void mouseDown(MouseEvent arg0) {
                    }

                    @Override
                    public void mouseDoubleClick(MouseEvent arg0) {
                    }
                });
                final EJFrameworkExtensionProperties rendererProp = EJCoreProperties.getInstance().getApplicationDefinedProperties();
                final EJFrameworkExtensionProperties propertyGroup = rendererProp.getPropertyGroup(EJRWTSingleRecordBlockDefinitionProperties.ACTION_GROUP);
                String lovKey = "SHIFT+ARROW_DOWN";
                if (propertyGroup != null) {
                    lovKey = propertyGroup.getStringProperty(EJRWTSingleRecordBlockDefinitionProperties.ACTION_LOV_KEY);
                }
                if (lovKey == null) {
                    lovKey = "SHIFT+ARROW_DOWN";
                }
                String[] keys = new String[] { lovKey, "ENTER", "RETURN", "CR" };
                label.setData(EJ_RWT.ACTIVE_KEYS, keys);
                getTextControl().setData(EJ_RWT.ACTIVE_KEYS, keys);
                addKeyListener(new KeyListener() {

                    @Override
                    public void keyReleased(KeyEvent arg0) {
                        if ((arg0.stateMask & SWT.SHIFT) != 0 && arg0.keyCode == SWT.ARROW_DOWN && isLovActivated()) {
                            _item.getItemLovController().displayLov(EJLovDisplayReason.LOV);
                        }
                        if (arg0.keyCode == 13 && (SWT.MULTI != (_textField.getStyle() & SWT.MULTI) || (arg0.stateMask & SWT.CONTROL) != 0)) {
                            commitValue();
                        }
                    }

                    @Override
                    public void keyPressed(KeyEvent arg0) {
                    }
                });
                return label;
            }
        };
        if (_maxLength > 0) {
            _textField.setTextLimit(_maxLength);
        }
        if (hint != null && hint.trim().length() > 0) {
            _textField.setToolTipText(hint);
        }
        _visualContext = new EJRWTItemRendererVisualContext(_textField.getBackground(), _textField.getForeground(), _textField.getFont());
        _textField.setData(_item.getReferencedItemProperties().getName());
        _textField.addFocusListener(this);
        _mandatoryDecoration = new ControlDecoration(_actionControl, SWT.TOP | SWT.LEFT);
        _errorDecoration = new ControlDecoration(_actionControl, SWT.TOP | SWT.LEFT);
        _errorDecoration.setImage(getDecorationImage(FieldDecorationRegistry.DEC_ERROR));
        _mandatoryDecoration.setImage(getDecorationImage(FieldDecorationRegistry.DEC_REQUIRED));
        _mandatoryDecoration.setShowHover(true);
        _mandatoryDecoration.setDescriptionText(_screenItemProperties.getLabel() == null || _screenItemProperties.getLabel().isEmpty() ? "Required Item" : String.format("%s is required", _screenItemProperties.getLabel()));
        if (_isValid) {
            _errorDecoration.hide();
        }
        if (message != null) {
            setMessage(message);
        }
        _mandatoryDecoration.hide();
        _textField.addModifyListener(_modifyListener);
        // TODO: Move to client side validation on Rap 2.4
        if (_valueCase != null && _valueCase != VALUE_CASE.DEFAULT) {
            _textField.addVerifyListener(new VerifyListener() {

                @Override
                public void verifyText(VerifyEvent event) {
                    String caseValue = toCaseValue(event.text);
                    if (!event.text.equals(caseValue)) {
                        event.text = caseValue;
                    }
                }
            });
        }
        setInitialValue(_baseValue);
        _textField.setMessage(defaultMessage == null ? "" : defaultMessage);
        setMessage(message);
    }
}
Also used : EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) MouseEvent(org.eclipse.swt.events.MouseEvent) VerifyListener(org.eclipse.swt.events.VerifyListener) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) EJRWTAbstractActionText(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText) Text(org.eclipse.swt.widgets.Text) EJRWTAbstractActionText(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText) KeyEvent(org.eclipse.swt.events.KeyEvent) Control(org.eclipse.swt.widgets.Control) MouseListener(org.eclipse.swt.events.MouseListener) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) KeyListener(org.eclipse.swt.events.KeyListener) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Aggregations

ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 VerifyEvent (org.eclipse.swt.events.VerifyEvent)1 VerifyListener (org.eclipse.swt.events.VerifyListener)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 EJRWTAbstractActionText (org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionText)1 EJRWTAbstractLabel (org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel)1 EJRWTItemRendererVisualContext (org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext)1 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)1