General panel for conferences

Change-Id: I50457bfe41fbfea05e8bff12338cb7ea05bbd3f7
This commit is contained in:
joha-asc 2011-07-12 13:59:41 +02:00
parent 11f71a21f6
commit 5a387c3f94
2 changed files with 284 additions and 0 deletions
src/main/java/se/su/dsv/scipro/conference/panels

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
</head>
<body>
<wicket:panel>
<div class="margin rounded-border">
<form wicket:id="sendForm">
<textarea wicket:id="textArea"></textarea>
<div>
<button type="submit" wicket:id="ajaxButton">
<img src="css/blueprint/plugins/buttons/icons/tick.png" alt="" />Send
Message
</button>
</div>
</form>
</div>
<div wicket:id="container" class="margin clear">
<div wicket:id="boardMessageDataView" class="rounded-border">
<span wicket:id="messageUser" class="small"> </span>
<span wicket:id="messageDate" class="small"></span>
<span><a href="#"
wicket:id="delete" class="right-corner-resource"> <img class="icon-12"
src="images/icons/delete_16x16.png" alt="Delete" title="Delete" />
</a>
</span>
<div wicket:id="messageLabel" class="margin"></div>
<div>
<a href="#" wicket:id="showComments"><span
wicket:id="commentNumber"></span> </a>
</div>
<div wicket:id="commentContainer">
<div wicket:id="commentThread"></div>
</div>
</div>
<div wicket:id="pagingNavigator"></div>
</div>
</wicket:panel>
</body>
</html>

@ -0,0 +1,240 @@
/**
*
*/
package se.su.dsv.scipro.conference.panels;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.List;
import java.util.SortedSet;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.SciProSession;
import se.su.dsv.scipro.commentthread.panels.CommentThreadPanel;
import se.su.dsv.scipro.data.dao.interfaces.BoardMessageDao;
import se.su.dsv.scipro.data.dao.interfaces.CommentThreadDao;
import se.su.dsv.scipro.data.dao.interfaces.MessageBoardDao;
import se.su.dsv.scipro.data.dao.interfaces.NotificationDao;
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
import se.su.dsv.scipro.data.dao.interfaces.UserSettingsDao;
import se.su.dsv.scipro.data.dataobjects.BoardMessage;
import se.su.dsv.scipro.data.dataobjects.CommentThread;
import se.su.dsv.scipro.data.dataobjects.MessageBoard;
import se.su.dsv.scipro.data.dataobjects.Notification;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.data.dataobjects.UserSettings;
import se.su.dsv.scipro.data.dataobjects.interfaces.Commentable;
import se.su.dsv.scipro.dataproviders.BoardMessageDataProvider;
import se.su.dsv.scipro.security.auth.roles.Roles;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class ConferencePanel extends Panel {
private static final long serialVersionUID = 1L;
@SpringBean
private BoardMessageDao boardMessageDao;
@SpringBean
private MessageBoardDao messageBoardDao;
@SpringBean
private CommentThreadDao commentThreadDao;
@SpringBean
private NotificationDao notificationDao;
private MessageBoard messageBoard;
private DataView<BoardMessage> dataView;
private WebMarkupContainer webMarkupContainer;
private IModel<MessageBoard> messageBoardModel;
private List<User> userList;
public ConferencePanel(final String id, final Commentable keyObject, final List<User> userList,
final String title) {
super(id);
this.userList = userList;
SendWallMessageForm sendWallMessageForm;
add(sendWallMessageForm = new SendWallMessageForm("sendForm"));
messageBoard = messageBoardDao.getMessageBoard(keyObject);
if (keyObject == null) {
// TODO rewrite so thread is only created on demand, ie when
// someone's posted
messageBoard = new MessageBoard();
messageBoard.setTitle(title);
messageBoard = messageBoardDao.save(messageBoard);
}
webMarkupContainer = new WebMarkupContainer("container");
messageBoardModel = new LoadableDetachableModel<MessageBoard>() {
private static final long serialVersionUID = 1L;
@Override
protected MessageBoard load() {
return messageBoardDao.reLoad(messageBoard);
}
};
loadUserDataView(new BoardMessageDataProvider(messageBoardModel));
webMarkupContainer.add(dataView);
webMarkupContainer.setOutputMarkupId(true);
webMarkupContainer.add(new PagingNavigator("pagingNavigator", dataView));
add(webMarkupContainer);
}
public void loadUserDataView(IDataProvider<BoardMessage> boardMessageDataProvider) {
dataView = new DataView<BoardMessage>("boardMessageDataView", boardMessageDataProvider, 10) {
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(Item<BoardMessage> item) {
final BoardMessage bm = item.getModelObject();
item.add(new Label("messageLabel", bm.getMessage()));
item.add(new Label("messageUser", bm.getFromUser().getFirstName() + " "
+ bm.getFromUser().getLastName()));
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
item.add(new Label("messageDate", simpleDateFormat.format(bm.getDateCreated())));
item.add(new AjaxLink<Void>("delete") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
BoardMessage boardMessageTemp = boardMessageDao.reLoad(bm);
boardMessageDao.delete(boardMessageTemp);
webMarkupContainer.removeAll();
loadUserDataView(new BoardMessageDataProvider(messageBoardModel));
webMarkupContainer.add(dataView);
webMarkupContainer.add(new PagingNavigator("pagingNavigator", dataView));
target.addComponent(webMarkupContainer);
}
@Override
public boolean isVisible() {
SciProSession session = SciProSession.get();
if (session.authorizedForRole(Roles.ADMIN))
return true;
if (session.getUser().equals(bm.getFromUser()))
return true;
return false;
}
});
int commentSize = commentThreadDao.getCommentThreadSize(bm);
String comments = " Comments";
if (commentSize == 1) {
comments = " Comment";
}
final Label comment = new Label("commentNumber", commentSize + comments);
comment.setOutputMarkupId(true);
final WebMarkupContainer webMarkupContainer = new WebMarkupContainer(
"commentContainer");
webMarkupContainer.setOutputMarkupPlaceholderTag(true);
item.add(webMarkupContainer);
CommentThreadPanel ctp = new CommentThreadPanel("commentThread", bm, 5);
ctp.setOutputMarkupPlaceholderTag(true);
webMarkupContainer.add(ctp);
webMarkupContainer.setVisible(false);
item.add(new AjaxLink<String>("showComments", new Model<String>("Show Comments")) {
private static final long serialVersionUID = 1L;
private boolean clicked = false;
@Override
public void onClick(AjaxRequestTarget target) {
clicked = !clicked;
if (clicked) {
comment.setDefaultModelObject("Hide comments");
} else {
int commentSize = commentThreadDao.getCommentThreadSize(bm);
String comments = " Comments";
if (commentSize == 1) {
comments = " Comment";
}
comment.setDefaultModelObject(commentSize + comments);
}
webMarkupContainer.removeAll();
webMarkupContainer.add(new CommentThreadPanel("commentThread",
boardMessageDao.reLoad(bm), 5));
webMarkupContainer.setVisible(clicked);
target.addComponent(webMarkupContainer);
target.addComponent(comment);
}
}.add(comment));
}
};
}
private class SendWallMessageForm extends Form<String> {
private static final long serialVersionUID = 1L;
private String message;
public SendWallMessageForm(String id) {
super(id);
final TextArea<String> messageTextArea = new TextArea<String>("textArea",
new PropertyModel<String>(this, "message"));
add(messageTextArea);
AjaxButton button = new AjaxButton("ajaxButton") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
BoardMessage bm = new BoardMessage();
bm.setMessage(message);
bm.setMessageBoard(messageBoardDao.reLoad(messageBoard));
bm.setFromUser(SciProSession.get().getUser());
bm = boardMessageDao.save(bm);
Notification notification = new Notification();
notification.setInfoText(SciProSession.get().getUser()
+ " wrote on conference "
+ messageBoardDao.reLoad(messageBoard).getTitle());
notification.setSubscribers(new HashSet<User>(userList));
notificationDao.save(notification);
webMarkupContainer.removeAll();
loadUserDataView(new BoardMessageDataProvider(messageBoardModel));
webMarkupContainer.add(dataView);
webMarkupContainer.add(new PagingNavigator("pagingNavigator", dataView));
target.addComponent(webMarkupContainer);
}
};
add(button);
}
}
}