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);
}
}
Aggregations