}
@SuppressWarnings("serial")
private void addTemplatesRow()
{
final FieldsetPanel templatesRow = gridBuilder.newFieldset(getString("templates")).suppressLabelForWarning();
final String[] templateNames = userPrefDao.getPrefNames(UserPrefArea.TIMESHEET_TEMPLATE);
if (templateNames != null && templateNames.length > 0) {
// DropDownChoice templates
final String label = getString("userPref.template.select");
final LabelValueChoiceRenderer<String> templateNamesChoiceRenderer = new LabelValueChoiceRenderer<String>();
templateNamesChoiceRenderer.addValue("", label);
for (final String name : templateNames) {
templateNamesChoiceRenderer.addValue(name, name);
}
final DropDownChoice<String> templateNamesChoice = new DropDownChoice<String>(templatesRow.getDropDownChoiceId(),
new PropertyModel<String>(this, "templateName"), templateNamesChoiceRenderer.getValues(), templateNamesChoiceRenderer) {
@Override
protected boolean wantOnSelectionChangedNotifications()
{
return true;
}
/**
* @see org.apache.wicket.markup.html.form.AbstractSingleSelectChoice#getDefaultChoice(java.lang.String)
*/
@Override
protected CharSequence getDefaultChoice(final String selectedValue)
{
return "";
}
@Override
protected void onSelectionChanged(final String newSelection)
{
if (StringUtils.isNotEmpty(newSelection) == true) {
// Fill fields with selected template values:
final UserPrefDO userPref = userPrefDao.getUserPref(UserPrefArea.TIMESHEET_TEMPLATE, newSelection);
if (userPref != null) {
data.setKost2(null).setTask(null);
locationTextField.processInput(); // Update model.
descriptionArea.processInput(); // Update model.
if (recentUserPref != null) {
final String recentLocation = recentUserPref.getUserPrefEntryAsString("location");
if (StringUtils.equals(recentLocation, data.getLocation()) == true) {
// Previous value was filled by recent user pref so overwrite it:
data.setLocation(null);
}
final String recentDescription = recentUserPref.getUserPrefEntryAsString("description");
if (StringUtils.equals(recentDescription, data.getDescription()) == true) {
// Previous value was filled by recent user pref so overwrite it:
data.setDescription(null);
}
}
userPrefDao.fillFromUserPrefParameters(userPref, data, true);
recentUserPref = userPref;
locationTextField.modelChanged();
descriptionArea.modelChanged();
if (cost2ChoicePanel != null) {
cost2ChoicePanel.getDropDownChoice().modelChanged();
}
}
templateName = "";
refresh();
}
}
};
templateNamesChoice.setNullValid(true);
templatesRow.add(templateNamesChoice);
}
// Needed as submit link because the modal dialog reloads the page and otherwise any previous change will be lost.
final AjaxSubmitLink link = new AjaxSubmitLink(IconLinkPanel.LINK_ID) {
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form< ? > form)
{
recentSheetsModalDialog.open(target);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form< ? > form)
{
}
};
link.setDefaultFormProcessing(false);
templatesRow
.add(new IconLinkPanel(templatesRow.newChildId(), IconType.FOLDER_OPEN, new ResourceModel("timesheet.recent.select"), link));
recentSheetsModalDialog = new TimesheetEditSelectRecentDialogPanel(parentPage.newModalDialogId(), getString("timesheet.recent.select"),
parentPage, TimesheetEditForm.this, cost2Exists, timesheetDao, taskTree, userFormatter);
parentPage.add(recentSheetsModalDialog);
recentSheetsModalDialog.init();
}