Search in sources :

Example 1 with EJRWTAbstractActionDateTime

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

the class EJRWTDateTimeItemRenderer method createComponent.

@Override
public void createComponent(Composite composite) {
    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(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_DATETIME);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            _valueLabel.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        _valueLabel.setData(_itemProperties.getName());
        if (hint != null && hint.trim().length() > 0) {
            _valueLabel.setToolTipText(hint);
        }
        _visualContext = new EJRWTItemRendererVisualContext(_valueLabel.getBackground(), _valueLabel.getForeground(), _valueLabel.getFont());
        setInitialValue(_baseValue);
    } else {
        _actionControl = new EJRWTAbstractActionDateTime(composite) {

            private static final long serialVersionUID = 2592484612013403481L;

            @Override
            public DateTime createText(Composite parent) {
                int style = SWT.BORDER;
                String details = _rendererProps.getStringProperty(EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS);
                if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS_LONG.equals(details)) {
                    style = style | SWT.LONG;
                } else if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS_MEDIUM.equals(details)) {
                    style = style | SWT.MEDIUM;
                } else if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DETAILS_SHORT.equals(details)) {
                    style = style | SWT.SHORT;
                }
                String type = _rendererProps.getStringProperty(EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_TYPE);
                if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_TYPE_CALENDAR.equals(type)) {
                    style = style | SWT.CALENDAR;
                } else if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_TYPE_DATE.equals(type)) {
                    style = style | SWT.DATE;
                } else if (EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_TYPE_TIME.equals(type)) {
                    style = style | SWT.TIME;
                }
                if (_rendererProps.getBooleanProperty(EJRWTDateTimeItemRendererDefinitionProperties.PROPERTY_DROP_DOWN, false)) {
                    style = style | SWT.DROP_DOWN;
                }
                _textField = newTextField(parent, style);
                _textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_DATETIME);
                String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
                if (customCSSKey != null && customCSSKey.trim().length() > 0) {
                    _textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
                }
                _textField.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        valueChanged();
                    }
                });
                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(EJRWTDateTimeItemRenderer.this);
                label.addMouseListener(new MouseListener() {

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

                    @Override
                    public void mouseDown(MouseEvent arg0) {
                    }

                    @Override
                    public void mouseDoubleClick(MouseEvent arg0) {
                    }
                });
                return label;
            }
        };
        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);
        String[] keys = new String[] { "BACKSPACE" };
        _textField.setData(EJ_RWT.ACTIVE_KEYS, keys);
        if ((_textField.getStyle() & SWT.TIME) != 0)
            _textField.addKeyListener(new KeyListener() {

                @Override
                public void keyReleased(KeyEvent e) {
                    if (e.keyCode == SWT.BS) {
                        Date value = getValue();
                        if (value != null) {
                            _textField.setTime(0, 0, 0);
                            valueChanged();
                        }
                    }
                }

                @Override
                public void keyPressed(KeyEvent e) {
                // TODO Auto-generated method stub
                }
            });
        _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();
        setInitialValue(_baseValue);
    }
}
Also used : EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) EJRWTAbstractActionDateTime(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionDateTime) DateTime(org.eclipse.swt.widgets.DateTime) Date(java.util.Date) KeyEvent(org.eclipse.swt.events.KeyEvent) Control(org.eclipse.swt.widgets.Control) MouseListener(org.eclipse.swt.events.MouseListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) KeyListener(org.eclipse.swt.events.KeyListener) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext) EJRWTAbstractActionDateTime(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionDateTime)

Aggregations

Date (java.util.Date)1 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 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 DateTime (org.eclipse.swt.widgets.DateTime)1 Label (org.eclipse.swt.widgets.Label)1 EJRWTAbstractActionDateTime (org.entirej.applicationframework.rwt.application.components.EJRWTAbstractActionDateTime)1 EJRWTAbstractLabel (org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel)1 EJRWTItemRendererVisualContext (org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext)1