开发者

Default label value for org.eclipse.swt.widgets.Text control; prevent databinding from persisting value

Hy,

suppose a org.eclipse.swt.widgets.Text control connected via databinding to the model Person. The Text represents the surname of the person.

Now, everytime the model is changed, the value is updated, this is ok. Now I want the following:

If there is no value for surname in the model, i want the text-control to contain a hint label, s.a. "Insert surname" which is not supposed to be persisted!

I could create this behavior by adding a modifyListener to the textcontrol which sets the text if the length of setText is 0, I cannot prevent, however, the databinding then to per开发者_高级运维sist "Insert surname"!

I tried extending Text (to override getText), which is not allowed, and wrapping Text into a "LabeledText" requires me to modify the DataBinding!

Anyone aware of a solution for this?

Thx


org.eclipse.swt.widgets.Text.setMessage() is a method exactly performing the requested task.


I think it is quite hard to simulate such behavior with standard SWT widgets. So, probably, you need to create a custom widget, with validation simulation inside. Your validator should return you a validation status, which can be used afterwards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜