没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > majick-properties |
majick-properties
|
0 | 0 | 23 |
贡献者 | 讨论 | 代码提交 |
Wotsit ?majick-properties is a library providing interfaces and code for easier manipulation of bean properties.
public class Experience {
/**
* A simple unconstrainted name property should be easily understood by anybody
*/
private final ComparableProperty nameProperty = PropertyUtils.create(String.class, "name", support);
/**
* A constrained double property could allow external code to prevent it from having certain values (see in tests for examples)
*/
private final ComparableVetoableProperty valueProperty = PropertyUtils.create(Double.class, "value", support, vetoSupport);to generate ui components for them this way
UIProvider provider = new UIProvider();
Component editor = provider.getEditor(experience.getNameProperty());Notice in this case the editor component has its model connected by listeners to the name property, making allowed changes to be directly reflected in bean name.
Weaknesses of classical JavaBeansFor so long ago, I've found rather boring to work with JavaBeans. Especially, one thing made me crazy : each time I want to define a setter able to send events, I have to rewrite the same code block (which, actually, I put in an Eclipse code template) :
public void setValue(Object newValue) {
if((value==null && newValue!=null) || (value!=null && !value.equals(newValue)) {
Object old = value;
value = newValue;
support.firePropertyChange("value", old, newValue);
}
}Well, as soon as the bean gets larger than two or three fields, it is a nightmare to write, and an even more nightmarish work to evolve (as an example when setter has to do something besides setting the value (wich, as far as I know, is now firmly discouradged by ayatollahs of separation of concerns, ignoring that, sometimes, member fields of a same bean are tied by buisness rules)). So, as long as I'm concerned, classical Java beans are no more a good conceptual solution. In fact, it goes even farer when considering the uttermost failure that BeanInfo and other constructs are. They're absolutely unusable by hand, making fast bean binding impossible.
Existing solutions (in other languages)Meanwhile, other platforms have forged solid properties solutions :
C# properties are one of them Ruby attr_accessor are, to my mind, the most brilliant solution to this problem
Majick solution ?Well, here are some of the inspirations of majick-properties.
And here is the majick-properties mojo : make the use of properties as simple, straightforward, and intuitive as possible. In a ruby-like fashion, I'll try here to provide tooling and objects allowing easy use of properties in contexts I know.