[
https://issues.apache.org/jira/browse/WICKET-3776?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13045716#comment-13045716
]
Igor Vaynberg commented on WICKET-3776:
---------------------------------------
so you have replaced one anonymous class with another. where is the advantage?
i can see this helping only if you do not control the actual instantiation of
the ddc, which from your code looks like you do not. but, even if you do not
control the instantiation a simple approach is to let the parent of the ddc
override onconfigure and inside there call setvisible(foo) on the child ddc -
just like the parent is creating the predicate.
the reason we do not prefer this approach is the same reason we do not have
click listeners - it ends up being a lot more state to serialize/keep in memory.
that said, who are we to stop you?
public abstract class visibilitypredicate<t extends component> extends
abstractbehavior implements icomponentconfigurationbehavior {
protected abstract boolean evaluate(t c);
public final onConfigure(Component c) { c.setVisible(evaluate((t)c);
}
that gets you more than 90% of where you want to be.
> Implement default onConfigure() using optional Predicate
> --------------------------------------------------------
>
> Key: WICKET-3776
> URL: https://issues.apache.org/jira/browse/WICKET-3776
> Project: Wicket
> Issue Type: Improvement
> Components: wicket-core
> Affects Versions: 1.4.17
> Reporter: Russell Morrisey
> Labels: ConfigurationPredicate, Predicate, component,
> onConfigure, setEnabled, setVisible
>
> I would really like to see methods on Component to configure visible and
> enabled state using a predicate pattern. Ex:
> interface ConfigurationPredicate<T extends Component> extends IDetachable {
> boolean evaluate(T component);
> }
> ...
> DropDownChoice ddc = createDDC(); //my convenience method which sets standard
> properties, creates a label for the component, and other stuff
> ddc.setVisibility(new ConfigurationPredicate<DropDownChoice>() {
> public boolean evaluate(DropDownChoice component) {
> myOtherComponent.configure();
> return (myOtherComponent.isVisibleInHierarchy());
> }
> public void detach() {
> myOtherComponent.detach();
> }
> });
> Please consider creating an optional field on Component which can hold a
> visibility predicate and an enabled state predicate. You can see the
> advantage clearly in the code above: I don't have to inline my convenience
> method. I would like composition to be used, instead of inheritance, so I
> don't have to subclass DropDownChoice just to control the visibility.
> Thanks, guys!
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira