001 package net.databinder.components;
002
003 import net.databinder.models.BindingModel;
004
005 import org.apache.wicket.Component;
006 import org.apache.wicket.markup.html.link.Link;
007
008 /**
009 * Unbinds the target persistent model. This will generally revert the object
010 * to a "blank" state, such as when creating a new object with a form instead of
011 * updating one.
012 * @see BindingModel
013 */
014 public class UnbindLink extends Link {
015 private Component target;
016
017 /**
018 * @param id this component id
019 * @param target component to be notified when unbinding model
020 * @param model
021 */
022 public UnbindLink(String id, Component target, BindingModel model) {
023 super(id, model);
024 this.target = target;
025 }
026 /** unbinds model */
027 @Override
028 public void onClick() {
029 target.modelChanging();
030 ((BindingModel)getModel()).unbind();
031 target.modelChanged();
032 }
033 /** @return true if model is bound */
034 @Override
035 public boolean isEnabled() {
036 return ((BindingModel)getModel()).isBound();
037 }
038 }