@Override
protected void onConfigure() {
super.onConfigure();
setVisible(MavenArtifactNotifierSession.get().hasRoleAdmin());
}
}.add(new AuthenticatedOnlyBehavior()));
}
};
add(artifactListView);
add(new WebMarkupContainer("emptyList") {
private static final long serialVersionUID = 6700720373087584498L;
@Override
public void onConfigure() {
super.onConfigure();
setVisible(artifactListView.size() <= 0);
}
});
// Add artifact form
IModel<Artifact> emptyArtifactModel = new GenericEntityModel<Long, Artifact>(null);
final ArtifactDropDownChoice artifactDropDown = new ArtifactDropDownChoice("artifact", emptyArtifactModel,
new ProjectArtifactSelect2AjaxAdapter(ArtifactDropDownChoice.CHOICE_RENDERER));
artifactDropDown.setWidth(DropDownChoiceWidth.NORMAL);
artifactDropDown.setRequired(true);
artifactDropDown.setLabel(new ResourceModel("project.description.artifacts.chooseOne"));
artifactDropDown.add(new LabelPlaceholderBehavior());
artifactDropDown.add(new AuthenticatedOnlyBehavior());
final Form<Artifact> addArtifactForm = new StatelessForm<Artifact>("addArtifactForm", emptyArtifactModel) {
private static final long serialVersionUID = 1L;
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(MavenArtifactNotifierSession.get().hasRoleAdmin());
}
};
addArtifactForm.add(artifactDropDown);
addArtifactForm.add(new AjaxSubmitLink("addArtifactLink", addArtifactForm) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
Project project = ProjectArtifactsPanel.this.getModelObject();
Artifact selectedArtifact = artifactDropDown.getModelObject();
if (selectedArtifact != null) {
if (selectedArtifact.getProject() == null) {
try {
projectService.addArtifact(project, selectedArtifact);
getSession().success(getString("project.description.artifacts.add.success"));
} catch (Exception e) {
LOGGER.error("Unknown error occured while adding an artifact to a project", e);
getSession().error(getString("project.description.artifacts.add.error"));
}
} else {
LOGGER.error("Artifact already added to a project");
getSession().warn(getString("project.description.artifacts.add.alreadyHasProject"));
}
}
artifactDropDown.setModelObject(null);
target.add(getPage());
FeedbackUtils.refreshFeedback(target, getPage());
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
FeedbackUtils.refreshFeedback(target, getPage());
}
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(MavenArtifactNotifierSession.get().hasRoleAdmin());
}
});
addArtifactForm.add(new AuthenticatedOnlyBehavior());
add(addArtifactForm);
}