use of org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig.CheckBox 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;
}
}
use of org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig.CheckBox in project rap by entirej.
the class EJRWTStackedItemRenderer method buildStackUI.
protected void buildStackUI(EJRWTEntireJStackedPane stackedPane) {
// create stack UI for eash type
// EJStackedItemRendererType.LABEL;
{
final Label label = new Label(stackedPane, SWT.NONE);
label.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_LABEL);
label.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_LABEL);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
label.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
stackedPane.add(EJRWTStackedItemRendererType.LABEL.name(), new EJRWTEntireJStackedPane.StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.LABEL.name();
}
@Override
public Control getControl() {
return label;
}
});
label.setData(_item.getReferencedItemProperties().getName());
label.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(label.getBackground(), label.getForeground(), label.getFont()));
}
{
int style = SWT.NONE;
final Button _button = new Button(stackedPane, style = style | SWT.CHECK);
_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
Object old = null;
Object newVal = null;
EJRWTStackedItemRendererConfig.CheckBox config = (CheckBox) _baseValue.getConfig();
if (_button.getSelection()) {
old = config.getCheckBoxUnCheckedValue();
newVal = config.getCheckBoxCheckedValue();
} else {
old = config.getCheckBoxCheckedValue();
newVal = config.getCheckBoxUnCheckedValue();
}
_item.executeActionCommand();
_item.itemValueChaged(getRealValue());
}
});
}
});
_button.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_CHECKBOX);
_button.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_CHECKBOX);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
_button.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
stackedPane.add(EJRWTStackedItemRendererType.CHECKBOX.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.CHECKBOX.name();
}
@Override
public Control getControl() {
return _button;
}
});
_button.setData(_item.getReferencedItemProperties().getName());
_button.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(_button.getBackground(), _button.getForeground(), _button.getFont()));
}
{
int style = SWT.NONE;
final Button _button = new Button(stackedPane, style);
_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
_item.executeActionCommand();
}
});
}
});
_button.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_BUTTON);
_button.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_BUTTON);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
_button.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
stackedPane.add(EJRWTStackedItemRendererType.BUTTON.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.BUTTON.name();
}
@Override
public Control getControl() {
return _button;
}
});
_button.setData(_item.getReferencedItemProperties().getName());
_button.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(_button.getBackground(), _button.getForeground(), _button.getFont()));
}
{
int style = SWT.READ_ONLY;
final Combo _comboField = new Combo(stackedPane, style);
final ComboViewer _comboViewer = new ComboViewer(_comboField);
_comboField.setData(_item.getReferencedItemProperties().getName());
_comboField.addFocusListener(EJRWTStackedItemRenderer.this);
_comboViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof ComboBoxValue) {
ComboBoxValue value = (ComboBoxValue) element;
return value.getItemValueAsString();
}
return "";
}
});
_comboViewer.setContentProvider(new ArrayContentProvider());
_comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
private ComboBoxValue getComboBoxValue() {
if (controlState(_comboField)) {
IStructuredSelection selection = (IStructuredSelection) _comboViewer.getSelection();
return (ComboBoxValue) selection.getFirstElement();
}
return null;
}
@Override
public void selectionChanged(SelectionChangedEvent event) {
if (!_modifyListener.enable) {
return;
}
if (isValid()) {
Object old = _baseValue.getValue();
ComboBoxValue value = getComboBoxValue();
if (value != null) {
value.populateReturnItems(_item.getBlock().getBlockController(), _item.getScreenType());
}
_item.itemValueChaged(getRealValue());
setMandatoryBorder(_mandatory);
} else {
_isValid = true;
}
_item.executeActionCommand();
}
});
_comboField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_COMBOBOX);
_comboField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_COMBOBOX);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
_comboField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
stackedPane.add(EJRWTStackedItemRendererType.COMBO.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.COMBO.name();
}
@Override
public Control getControl() {
return _comboField;
}
});
_comboField.setData(_item.getReferencedItemProperties().getName());
_comboField.setData("VIEW", _comboViewer);
_comboField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(_comboField.getBackground(), _comboField.getForeground(), _comboField.getFont()));
}
// EJStackedItemRendererType.SPACER;
{
final Label label = new Label(stackedPane, SWT.NONE);
// label.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_LABEL);
// label.setData(EJ_RWT.CUSTOM_VARIANT+"_DEF",
// EJ_RWT.CSS_CV_ITEM_LABEL);
// String customCSSKey =
// _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
//
// if (customCSSKey != null && customCSSKey.trim().length() > 0)
// {
// label.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
// }
stackedPane.add(EJRWTStackedItemRendererType.SPACER.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.SPACER.name();
}
@Override
public Control getControl() {
return label;
}
});
label.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(label.getBackground(), label.getForeground(), label.getFont()));
}
// EJStackedItemRendererType.TEXT;
{
final Text textField = new Text(stackedPane, SWT.BORDER);
connectLOVAction(textField);
textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_TEXT);
textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_TEXT);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
textField.setData(_item.getReferencedItemProperties().getName());
textField.addFocusListener(this);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
textField.addModifyListener(_modifyListener);
stackedPane.add(EJRWTStackedItemRendererType.TEXT.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.TEXT.name();
}
@Override
public Control getControl() {
return textField;
}
});
textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
}
// EJStackedItemRendererType.TEXT;
{
final Text textField = new Text(stackedPane, SWT.BORDER | SWT.MULTI | SWT.WRAP);
connectLOVAction(textField);
textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_TEXTAREA);
textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_TEXTAREA);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
textField.setData(_item.getReferencedItemProperties().getName());
textField.addFocusListener(this);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
textField.addModifyListener(_modifyListener);
stackedPane.add(EJRWTStackedItemRendererType.TEXT_AREA.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.TEXT_AREA.name();
}
@Override
public Control getControl() {
return textField;
}
});
textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
}
// EJStackedItemRendererType.NUMBER;
{
final Text textField = new Text(stackedPane, SWT.BORDER | SWT.RIGHT);
textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_NUMBER);
textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_NUMBER);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
textField.setData(_item.getReferencedItemProperties().getName());
textField.addFocusListener(this);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
textField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
if (textField.getText().trim().length() > 0) {
try {
_decimalFormatter.parse(textField.getText());
_errorDecoration.hide();
} catch (ParseException e) {
_rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_FORMAT);
_errorDecoration.setDescriptionText(String.format("Invalid Number format. Should be %s ", _rendererProps.getStringProperty(EJRWTTextItemRendererDefinitionProperties.PROPERTY_FORMAT)));
_errorDecoration.show();
}
}
}
});
connectLOVAction(textField);
textField.addModifyListener(_modifyListener);
textField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0) {
try {
_modifyListener.enable = false;
Object value = getValue();
if (value != null && _baseValue.getValue() != null) {
textField.setText(_decimalFormatter.format(_baseValue.getValue()));
} else {
textField.setText("");
}
} finally {
_modifyListener.enable = true;
}
}
@Override
public void focusGained(FocusEvent arg0) {
}
});
stackedPane.add(EJRWTStackedItemRendererType.NUMBER.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.NUMBER.name();
}
@Override
public Control getControl() {
return textField;
}
});
textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
}
// EJStackedItemRendererType.DATE;
{
final Text textField = new Text(stackedPane, SWT.BORDER | SWT.RIGHT);
textField.setData(EJ_RWT.CUSTOM_VARIANT, EJ_RWT.CSS_CV_ITEM_DATE);
textField.setData(EJ_RWT.CUSTOM_VARIANT + "_DEF", EJ_RWT.CSS_CV_ITEM_DATE);
textField.setData(_item.getReferencedItemProperties().getName());
textField.addFocusListener(this);
String customCSSKey = _rendererProps.getStringProperty(EJRWTButtonItemRendererDefinitionProperties.PROPERTY_CSS_KEY);
connectLOVAction(textField);
if (customCSSKey != null && customCSSKey.trim().length() > 0) {
textField.setData(EJ_RWT.CUSTOM_VARIANT, customCSSKey);
}
textField.addModifyListener(_modifyListener);
textField.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
if (textField.getText().trim().length() > 0) {
try {
_dateFormat.parse(textField.getText());
_errorDecoration.hide();
} catch (ParseException e) {
String format = _dateFormat.toFormatString();
if (format == null || format.length() == 0) {
format = "eg: " + _dateFormat.format(new Date());
}
_errorDecoration.setDescriptionText(String.format("Invalid Date format. Should be %s ", format));
_errorDecoration.show();
}
}
}
});
textField.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent arg0) {
try {
_modifyListener.enable = false;
Object value = getValue();
if (value != null && _baseValue.getValue() != null) {
textField.setText(_dateFormat.format(_baseValue.getValue()));
} else {
textField.setText("");
}
} finally {
_modifyListener.enable = true;
}
}
@Override
public void focusGained(FocusEvent arg0) {
}
});
stackedPane.add(EJRWTStackedItemRendererType.DATE.name(), new StackedPage() {
@Override
public String getKey() {
return EJRWTStackedItemRendererType.DATE.name();
}
@Override
public Control getControl() {
return textField;
}
});
textField.setData("EJRWTItemRendererVisualContext", new EJRWTItemRendererVisualContext(textField.getBackground(), textField.getForeground(), textField.getFont()));
}
{
}
}
Aggregations