});
gridBuilder.newGridPanel();
{
// Title
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.title"));
final RequiredMaxLengthTextField title = new RequiredMaxLengthTextField(InputPanel.WICKET_ID,
new PropertyModel<String>(data, "title"));
title.add(WicketUtils.setFocus());
fs.add(title);
}
{
// Authors
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.authors"));
final MaxLengthTextField authors = new MaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(data, "authors"));
fs.add(dependentFormComponents[0] = authors);
}
gridBuilder.newSplitPanel(GridSize.COL50);
{
// DropDownChoice bookType
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.type"));
final LabelValueChoiceRenderer<BookType> bookTypeChoiceRenderer = new LabelValueChoiceRenderer<BookType>(this, BookType.values());
final DropDownChoice<BookType> bookTypeChoice = new DropDownChoice<BookType>(fs.getDropDownChoiceId(),
new PropertyModel<BookType>(data, "type"), bookTypeChoiceRenderer.getValues(), bookTypeChoiceRenderer);
bookTypeChoice.setNullValid(false).setRequired(true);
fs.add(bookTypeChoice);
}
{
// Year of publishing
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.yearOfPublishing"));
final MaxLengthTextField yearOfPublishing = new MaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(data,
"yearOfPublishing"));
fs.add(dependentFormComponents[1] = yearOfPublishing);
}
{
// DropDownChoice bookStatus
final FieldsetPanel fs = gridBuilder.newFieldset(getString("status"));
final LabelValueChoiceRenderer<BookStatus> bookStatusChoiceRenderer = new LabelValueChoiceRenderer<BookStatus>(this,
BookStatus.values());
final DropDownChoice<BookStatus> bookStatusChoice = new DropDownChoice<BookStatus>(fs.getDropDownChoiceId(),
new PropertyModel<BookStatus>(data, "status"), bookStatusChoiceRenderer.getValues(), bookStatusChoiceRenderer);
bookStatusChoice.setNullValid(false).setRequired(true);
fs.add(bookStatusChoice);
}
{
// Signature
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.signature"));
final MaxLengthTextField signature = new MaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(data, "signature"));
signature.add(new AbstractValidator<String>() {
private static final long serialVersionUID = 6488923290863235755L;
@Override
protected void onValidate(final IValidatable<String> validatable)
{
data.setSignature(validatable.getValue());
if (bookDao.doesSignatureAlreadyExist(data) == true) {
validatable.error(new ValidationError().addMessageKey("book.error.signatureAlreadyExists"));
}
}
});
fs.add(dependentFormComponents[2] = signature);
}
gridBuilder.newSplitPanel(GridSize.COL50);
{
// ISBN
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.isbn"));
fs.add(new MaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(data, "isbn")));
}
{
// Keywords
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.keywords"));
fs.add(new MaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(data, "keywords")));
}
{
// Publisher
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.publisher"));
final MaxLengthTextField publisher = new MaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(data, "publisher"));
fs.add(dependentFormComponents[3] = publisher);
}
{
// Editor
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.editor"));
final MaxLengthTextField editor = new MaxLengthTextField(InputPanel.WICKET_ID, new PropertyModel<String>(data, "editor"));
fs.add(dependentFormComponents[4] = editor);
}
gridBuilder.newGridPanel();
{
// Abstract
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.abstract"));
fs.add(new MaxLengthTextArea(TextAreaPanel.WICKET_ID, new PropertyModel<String>(data, "abstractText")));
}
{
// Comment
final FieldsetPanel fs = gridBuilder.newFieldset(getString("comment"));
fs.add(new MaxLengthTextArea(TextAreaPanel.WICKET_ID, new PropertyModel<String>(data, "comment")));
}
if (isNew() == false) {
{
// Lend out
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.lending")).suppressLabelForWarning();
fs.add(new DivTextPanel(fs.newChildId(), new Model<String>() {
/**
* @see org.apache.wicket.model.Model#getObject()
*/
@Override
public String getObject()
{
if (data.getLendOutBy() == null) {
return "";
}
final StringBuffer buf = new StringBuffer();
// Show full user name:
buf.append(data.getLendOutBy().getFullname());
if (data.getLendOutDate() != null) {
buf.append(", ");
// Show lend out date:
buf.append(DateTimeFormatter.instance().getFormattedDate(data.getLendOutDate()));
}
return buf.toString();
}
}) {
/**
* @see org.apache.wicket.Component#isVisible()
*/
@Override
public boolean isVisible()
{
return data.getLendOutBy() != null;
}
});
fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<String>("lendout")) {
@Override
public final void onSubmit()
{
parentPage.lendOut();
}
}, getString("book.lendOut"), SingleButtonPanel.NORMAL));
fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<String>("returnBook")) {
@Override
public final void onSubmit()
{
parentPage.returnBook();
}
}, getString("book.returnBook"), SingleButtonPanel.DANGER) {
/**
* @see org.apache.wicket.Component#isVisible()
*/
@Override
public boolean isVisible()
{
return data.getLendOutBy() != null;
}
});
}
{
// Lend out comment
final FieldsetPanel fs = gridBuilder.newFieldset(getString("book.lendOutNote"));
fs.add(new MaxLengthTextArea(TextAreaPanel.WICKET_ID, new PropertyModel<String>(data, "lendOutComment")));
}
}
}