Search in sources :

Example 1 with EJRWTAbstractLabel

use of org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel 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)

Example 2 with EJRWTAbstractLabel

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

the class EJRWTLabelItemRenderer method createComponent.

@Override
public void createComponent(Composite composite) {
    String alignmentProperty = _rendererProps.getStringProperty(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_ALIGNMENT);
    if (alignmentProperty == null) {
        alignmentProperty = _rendererProps.getStringProperty("ALLIGNMENT");
    }
    boolean textWrapProperty = _rendererProps.getBooleanProperty(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_TEXT_WRAP, false);
    String hint = _screenItemProperties.getHint();
    int style = SWT.NONE;
    style = getComponentStyle(alignmentProperty, style);
    if (textWrapProperty) {
        style = style + SWT.WRAP;
    }
    _displayAsHyperlink = _rendererProps.getBooleanProperty(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_DISPLAY_AS_HYPERLINK, false);
    final String label = _screenItemProperties.getLabel();
    if (!_displayAsHyperlink) {
        final int labelStyle = style;
        final EJRWTAbstractLabel labelField = new EJRWTAbstractLabel(composite) {

            @Override
            public Label createLabel(Composite parent) {
                return new Label(parent, labelStyle);
            }

            @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;
            }
        };
        labelField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_LABEL);
        labelField.getLabelControl().setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_LABEL);
        String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
        if (customCSSKey != null && customCSSKey.trim().length() > 0) {
            labelField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
            labelField.getLabelControl().setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
        }
        // labelField.setData(EJ_RWT.MARKUP_ENABLED, _rendererProps.getBooleanProperty(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_HTML_FORMAT, false));
        labelField.getLabelControl().setData(EJ_RWT.MARKUP_ENABLED, _rendererProps.getBooleanProperty(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_HTML_FORMAT, false));
        String pictureName = _rendererProps.getStringProperty(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_PICTURE);
        if (pictureName != null && pictureName.length() > 0) {
            if (pictureName != null && pictureName.trim().length() > 0) {
                labelField.getLabelControl().setImage(EJRWTImageRetriever.get(pictureName));
            }
        }
        labelField.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent e) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        _item.executeActionCommand();
                    }
                });
            }
        });
        _labelField = new SWTComponentAdapter() {

            @Override
            public void setText(String text) {
                if (controlState(labelField)) {
                    labelField.setText(text);
                }
            }

            public void setFont(Font font) {
                labelField.setFont(font);
            }

            @Override
            public Font getFont() {
                return labelField.getFont();
            }

            public void setForeground(Color color) {
                labelField.setForeground(color);
            }

            @Override
            public Color getForeground() {
                return labelField.getForeground();
            }

            @Override
            public String getText() {
                return labelField.getText();
            }

            @Override
            public Control getControl() {
                return labelField;
            }
        };
    } else {
        final Link linkField;
        final Control control;
        // use workaround to make sure link also provide alignment
        if (alignmentProperty != null && alignmentProperty.trim().length() > 0) {
            if (alignmentProperty.equals(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_ALIGNMENT_LEFT)) {
                control = linkField = new Link(composite, style);
            } else if (alignmentProperty.equals(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_ALIGNMENT_RIGHT)) {
                EJRWTEntireJGridPane sub = new EJRWTEntireJGridPane(composite, 3);
                control = sub;
                sub.cleanLayout();
                new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
                new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
                linkField = new Link(sub, style);
            } else if (alignmentProperty.equals(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_ALIGNMENT_CENTER)) {
                EJRWTEntireJGridPane sub = new EJRWTEntireJGridPane(composite, 3);
                control = sub;
                sub.cleanLayout();
                new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
                linkField = new Link(sub, style);
                new Label(sub, SWT.NONE).setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
            } else {
                control = linkField = new Link(composite, style);
            }
        } else {
            control = linkField = new Link(composite, style);
        }
        linkField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_LABEL);
        _labelField = new SWTComponentAdapter() {

            String value;

            @Override
            public void setText(String text) {
                if (controlState(linkField)) {
                    linkField.setText(String.format("<a>%s</a>", value = text));
                }
            }

            @Override
            public void setFont(Font font) {
                if (controlState(linkField)) {
                    linkField.setFont(font);
                }
            }

            @Override
            public Font getFont() {
                if (controlState(linkField)) {
                    return linkField.getFont();
                }
                return null;
            }

            @Override
            public void setForeground(Color color) {
                if (controlState(linkField)) {
                    linkField.setForeground(color);
                }
            }

            @Override
            public Color getForeground() {
                if (controlState(linkField)) {
                    return linkField.getForeground();
                }
                return null;
            }

            @Override
            public String getText() {
                return value;
            }

            @Override
            public Control getControl() {
                return control;
            }
        };
        linkField.setData(EJ_RWT.MARKUP_ENABLED, _rendererProps.getBooleanProperty(EJRWTLabelItemRendererDefinitionProperties.PROPERTY_HTML_FORMAT, false));
        linkField.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        _item.executeActionCommand();
                    }
                });
            }
        });
    }
    _labelField.setText(label != null ? label : "");
    _labelField.getControl().setToolTipText(hint != null ? hint : "");
    _labelField.getControl().setData(_item.getReferencedItemProperties().getName());
    _labelField.getControl().addFocusListener(this);
    _visualContext = new EJRWTItemRendererVisualContext(_labelField.getControl().getBackground(), _labelField.getForeground(), _labelField.getControl().getFont());
    _mandatoryDecoration = new ControlDecoration(_labelField.getControl(), SWT.TOP | SWT.LEFT);
    _errorDecoration = new ControlDecoration(_labelField.getControl(), 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()));
    _errorDecoration.hide();
    _mandatoryDecoration.hide();
    setMessage(message);
}
Also used : EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Font(org.eclipse.swt.graphics.Font) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) EJRWTItemRendererVisualContext(org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext) Link(org.eclipse.swt.widgets.Link) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)

Example 3 with EJRWTAbstractLabel

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

the class EJRWTSingleRecordBlockRenderer method createBlockItemGridData.

private GridData createBlockItemGridData(EJRWTAppItemRenderer itemRenderer, EJFrameworkExtensionProperties blockRequiredItemProperties, Control control) {
    boolean grabExcessVerticalSpace = blockRequiredItemProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_EXPAND_Y_PROPERTY, false);
    boolean grabExcessHorizontalSpace = blockRequiredItemProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_EXPAND_X_PROPERTY, false);
    GridData gridData;
    if (grabExcessVerticalSpace && grabExcessHorizontalSpace) {
        gridData = new GridData(GridData.FILL_BOTH);
    } else if (!grabExcessVerticalSpace && grabExcessHorizontalSpace) {
        gridData = new GridData(GridData.FILL_BOTH);
    } else if (grabExcessVerticalSpace && !grabExcessHorizontalSpace) {
        gridData = new GridData(GridData.FILL_VERTICAL);
    } else {
        gridData = new GridData(GridData.FILL_VERTICAL);
    }
    gridData.horizontalSpan = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_XSPAN_PROPERTY, 1);
    gridData.verticalSpan = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_YSPAN_PROPERTY, 1);
    gridData.grabExcessHorizontalSpace = grabExcessHorizontalSpace;
    gridData.grabExcessVerticalSpace = grabExcessVerticalSpace;
    if (!grabExcessVerticalSpace) {
        gridData.verticalAlignment = SWT.CENTER;
    }
    int displayedWidth = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.DISPLAYED_WIDTH_PROPERTY, 0);
    int displayedHeight = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.DISPLAYED_HEIGHT_PROPERTY, 0);
    if (displayedWidth > 0) {
        float avgCharWidth = control == null ? 1 : EJRWTImageRetriever.getGraphicsProvider().getAvgCharWidth(control.getFont());
        if (itemRenderer != null && itemRenderer.useFontDimensions() && avgCharWidth > 0) {
            // add padding
            gridData.widthHint = (int) ((displayedWidth + 1) * avgCharWidth);
        } else {
            gridData.widthHint = displayedWidth;
        }
    }
    if (displayedHeight > 0) {
        float avgCharHeight = control == null ? 1 : EJRWTImageRetriever.getGraphicsProvider().getCharHeight(control.getFont());
        if (itemRenderer != null && itemRenderer.useFontDimensions() && avgCharHeight > 0) {
            // add padding
            gridData.heightHint = (int) ((displayedHeight + 1) * avgCharHeight);
        } else {
            gridData.heightHint = displayedHeight;
        }
    } else if (control instanceof EJRWTAbstractLabel) {
        gridData.heightHint = 20;
    }
    return gridData;
}
Also used : EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) GridData(org.eclipse.swt.layout.GridData)

Example 4 with EJRWTAbstractLabel

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

the class EJRWTAbstractScreenRenderer method createBlockItemGridData.

private GridData createBlockItemGridData(EJRWTAppItemRenderer itemRenderer, EJFrameworkExtensionProperties blockRequiredItemProperties, Control control) {
    boolean grabExcessVerticalSpace = blockRequiredItemProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_EXPAND_Y_PROPERTY, false);
    boolean grabExcessHorizontalSpace = blockRequiredItemProperties.getBooleanProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_EXPAND_X_PROPERTY, false);
    GridData gridData;
    if (grabExcessVerticalSpace && grabExcessHorizontalSpace) {
        gridData = new GridData(GridData.FILL_BOTH);
    } else if (!grabExcessVerticalSpace && grabExcessHorizontalSpace) {
        gridData = new GridData(GridData.FILL_BOTH);
    } else if (grabExcessVerticalSpace && !grabExcessHorizontalSpace) {
        gridData = new GridData(GridData.FILL_VERTICAL);
    } else {
        gridData = new GridData(GridData.FILL_VERTICAL);
    }
    gridData.horizontalSpan = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_XSPAN_PROPERTY, 1);
    gridData.verticalSpan = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.MAIN_YSPAN_PROPERTY, 1);
    gridData.grabExcessHorizontalSpace = grabExcessHorizontalSpace;
    gridData.grabExcessVerticalSpace = grabExcessVerticalSpace;
    if (!grabExcessVerticalSpace) {
        gridData.verticalAlignment = SWT.CENTER;
    }
    int displayedWidth = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.DISPLAYED_WIDTH_PROPERTY, 0);
    int displayedHeight = blockRequiredItemProperties.getIntProperty(EJRWTSingleRecordBlockDefinitionProperties.DISPLAYED_HEIGHT_PROPERTY, 0);
    if (displayedWidth > 0) {
        float avgCharWidth = control == null ? 1 : EJRWTImageRetriever.getGraphicsProvider().getAvgCharWidth(control.getFont());
        if (itemRenderer != null && itemRenderer.useFontDimensions() && avgCharWidth > 0) {
            // add padding
            gridData.widthHint = (int) ((displayedWidth + 1) * avgCharWidth);
        } else {
            gridData.widthHint = displayedWidth;
        }
    }
    if (displayedHeight > 0) {
        float avgCharHeight = control == null ? 1 : EJRWTImageRetriever.getGraphicsProvider().getCharHeight(control.getFont());
        if (itemRenderer != null && itemRenderer.useFontDimensions() && avgCharHeight > 0) {
            // add padding
            gridData.heightHint = (int) ((displayedHeight + 1) * avgCharHeight);
        } else {
            gridData.heightHint = displayedHeight;
        }
    } else if (control instanceof EJRWTAbstractLabel) {
        gridData.heightHint = 20;
    }
    return gridData;
}
Also used : EJRWTAbstractLabel(org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel) GridData(org.eclipse.swt.layout.GridData)

Example 5 with EJRWTAbstractLabel

use of org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel 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

EJRWTAbstractLabel (org.entirej.applicationframework.rwt.application.components.EJRWTAbstractLabel)5 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3 GridData (org.eclipse.swt.layout.GridData)3 Composite (org.eclipse.swt.widgets.Composite)3 Control (org.eclipse.swt.widgets.Control)3 Label (org.eclipse.swt.widgets.Label)3 EJRWTItemRendererVisualContext (org.entirej.applicationframework.rwt.utils.EJRWTItemRendererVisualContext)3 KeyEvent (org.eclipse.swt.events.KeyEvent)2 KeyListener (org.eclipse.swt.events.KeyListener)2 MouseListener (org.eclipse.swt.events.MouseListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Date (java.util.Date)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 VerifyEvent (org.eclipse.swt.events.VerifyEvent)1 VerifyListener (org.eclipse.swt.events.VerifyListener)1 Color (org.eclipse.swt.graphics.Color)1 Font (org.eclipse.swt.graphics.Font)1 DateTime (org.eclipse.swt.widgets.DateTime)1