private void init() {
add(newModalWindow(MODAL_WINDOW_ID));
final Label label = new Label("label", newLabelModel()) {
@Override
public boolean isVisible() {
Reference ref = ReferenceEditorPanel.this.getModelObject();
return ref != null && !ref.isEmpty();
}
};
setOutputMarkupId(true);
add(label);
add(new AjaxLink<Void>("edit") {
@Override
public void onClick(AjaxRequestTarget target) {
getModalWindow().setModel(ReferenceEditorPanel.this.getModel());
getModalWindow().setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
public void onClose(AjaxRequestTarget target) {
target.addComponent(ReferenceEditorPanel.this);
ReferenceEditorPanel.this.onUpdate(target);
}
});
getModalWindow().show(target);
}
});
add(new AjaxLink<Void>("clear") {
@Override
public void onClick(AjaxRequestTarget target) {
Reference ref = ReferenceEditorPanel.this.getModelObject();
ref.makeEmpty();
// indicate that reference was changed (might be needed if the
// model is buffered)
ReferenceEditorPanel.this.setModelObject(ref);
target.addComponent(ReferenceEditorPanel.this);
ReferenceEditorPanel.this.onUpdate(target);
}
@Override
public boolean isEnabled() {
Reference ref = ReferenceEditorPanel.this.getModelObject();
return ref != null && !ref.isEmpty();
}
});
}