final String docOldName = docName.toString();
final String docOldPath = docPath.toString();
final FeedbackPanel feedback = new FeedbackPanel("feedback");
feedback.setOutputMarkupId(true);
add(feedback);
Form copyForm = new Form("copyForm")
{
@Override
protected void onValidate()
{
if (copyFlag)
{
if (docOldName.equals(getDocName())
&& docOldPath.equals(getDocPath()))
{
error(docType
+ " can't be copied with same name at same location");
}
} else
{
if (docOldName.equals(getDocName())
&& docOldPath.equals(getDocPath()))
{
error(docType
+ " can't be moved with same name at same location");
}
}
}
};
copyForm.setOutputMarkupId(true);
copyForm.add(new Label("docType-label", "Doc Type"));
TextField typeField = new TextField("docType", new PropertyModel(
this, "docType"));
typeField.setRequired(true);
copyForm.add(typeField);
copyForm.add(new Label("docName-label", "Document Name"));
TextField nameField = new TextField("docName", new PropertyModel(
this, "docName"));
nameField.setRequired(true);
copyForm.add(nameField);
AjaxCheckBox copyIdsChkBox = new AjaxCheckBox("copyIds", new PropertyModel(this, "copyIds"))
{
@Override
protected void onUpdate(AjaxRequestTarget target)
{
}
};
copyForm.add(copyIdsChkBox);
AjaxButton copyButton = new AjaxButton("copy",new ResourceModel("common.copy"),copyForm)
{
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
docAction(true, docOldName, getDocName(), docOldPath, getDocPath(), getCopyIds());
((ModalWindow) CopyMoveWindow.this.getParent()).close(target);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
target.addComponent(feedback);
}
};
AjaxButton moveButton = new AjaxButton("move",new ResourceModel("common.move"), copyForm)
{
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
docAction(false, docOldName, getDocName(), docOldPath, getDocPath(), getCopyIds());
((ModalWindow) CopyMoveWindow.this.getParent()).close(target);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
target.addComponent(feedback);
}
};
copyButton.setVisibilityAllowed(true);
moveButton.setVisibilityAllowed(true);
copyForm.add(copyButton);
copyForm.add(moveButton);
if (copyFlag)
{
copyButton.setVisible(true);
moveButton.setVisible(false);