| 787 | ==== Depending on a non-final property inside a "create()" method of a ResourceProperty ==== |
| 788 | * Using an non-final property inside a the create method will eventually work if that property is not null or is already initialized. Changing that property however will not affect the value of the resource property since its create method is invoked only once... |
| 789 | {{{ |
| 790 | public RwProp<Icon> icon() { |
| 791 | return getBean().makeValueProp("icon", Icon.class); |
| 792 | } |
| 793 | |
| 794 | public RwProp<String> toolTip() { |
| 795 | return getBean().makeValueProp("toolTip", String.class); |
| 796 | } |
| 797 | |
| 798 | public Prop<JButton> button() { |
| 799 | class button extends ResourceProperty<JButton> { |
| 800 | |
| 801 | @Override |
| 802 | protected JButton create() { |
| 803 | JButton res = new JButton(); |
| 804 | res.setIcon(icon().get()); |
| 805 | return res; |
| 806 | } |
| 807 | |
| 808 | @Override |
| 809 | protected void destroy(JButton res) { |
| 810 | //nothing. |
| 811 | } |
| 812 | |
| 813 | @Override |
| 814 | protected void setup(JButton res) { |
| 815 | res.setToolTipText(toolTip().get()); |
| 816 | } |
| 817 | } |
| 818 | return getBean().makeProp(button.class); |
| 819 | } |
| 820 | }}} |
| 821 | |
| 822 | * In this case the icon will be set (if initialized by the time the create method is invoked). Besides, the tool-tip will be set, no matter what because the setUp method will be invoked after the initialization of the toolTip()'s property. If we change the tool-tip the setUp method will be re-setUp-ed. '''However if we change the icon property, the icon of the button will not be set to the new one.''' Be careful about such scenarios, because it will probably remain silent. |
| 823 | |
| 824 | |