use of org.entirej.applicationframework.rwt.renderers.stack.EJRWTStackedItemRendererConfig 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;
}
}
Aggregations