New function

git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@273 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
joha-asc 2011-03-02 10:39:49 +00:00
parent fdf6113510
commit 445675738e
4 changed files with 249 additions and 0 deletions

@ -0,0 +1,10 @@
<!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>
<div wicket:id="commentThreadPanel""></div>
</body>
</html>

@ -0,0 +1,29 @@
/**
*
*/
package se.su.dsv.scipro.commentthread.panel;
import org.apache.wicket.PageParameters;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.basepages.PublicPage;
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
import se.su.dsv.scipro.data.dataobjects.Project;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class CommentThreadPage extends PublicPage {
@SpringBean
ProjectDao projectDao;
public CommentThreadPage(PageParameters pp) {
super(pp);
Project project = projectDao.load(1L);
add(new CommentThreadPanel("commentThreadPanel", project.getClass().toString(), project.getId()));
}
}

@ -0,0 +1,42 @@
<!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 wicket:id="container">
<table wicket:id="comment">
<tr>
<hr/>
</tr>
<tr><strong>Comment</strong></tr>
<tr >
<td wicket:id="date"></td>
</tr>
<tr >
<td wicket:id="from"></td>
</tr>
<tr>
<td wicket:id="message"></td>
</tr>
<tr>
<td><a href="#" wicket:id="deleteComment">delete<p/></a></td>
</tr>
</table>
<div wicket:id="navigator"></div>
</div>
<h4>Comment</h4>
<form wicket:id="commentForm">
Message:
<br />
<textarea wicket:id="textMessage" ></textarea>
<div/>
<input type="submit" wicket:id="submitButton" />
</form>
</wicket:panel>
</body>
</html>

@ -0,0 +1,168 @@
/**
*
*/
package se.su.dsv.scipro.commentthread.panel;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
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.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import se.su.dsv.scipro.commentthread.model.CommentThreadModel;
import se.su.dsv.scipro.components.autocomplete.AutoCompletionChoicesProvider;
import se.su.dsv.scipro.components.autocomplete.MultiObjectAutoCompleteBuilder;
import se.su.dsv.scipro.components.autocomplete.MultiObjectAutoCompleteField;
import se.su.dsv.scipro.components.autocomplete.MultiObjectAutoCompleteObjectConverter;
import se.su.dsv.scipro.components.autocomplete.MultiObjectAutoCompleteRenderer;
import se.su.dsv.scipro.data.dao.interfaces.CommentDao;
import se.su.dsv.scipro.data.dao.interfaces.CommentThreadDao;
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
import se.su.dsv.scipro.data.dataobjects.BoardMessage;
import se.su.dsv.scipro.data.dataobjects.Comment;
import se.su.dsv.scipro.data.dataobjects.CommentThread;
import se.su.dsv.scipro.data.dataobjects.MessageBoard;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.dataobjects.Recipient;
import se.su.dsv.scipro.data.dataobjects.User;
import se.su.dsv.scipro.message.models.MessageModel;
import se.su.dsv.scipro.message.panels.CustomPagingNavigator;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
public class CommentThreadPanel extends Panel{
@SpringBean
private CommentThreadDao commentThreadDao;
@SpringBean
private UserDao userDao;
@SpringBean
private CommentDao commentDao;
private WebMarkupContainer webMarkupContainer;
private CommentThread commentThread;
private PageableListView<Comment> commentListView;
private CustomPagingNavigator customPagingNavigator;
public CommentThreadPanel(String id, String className, long classId) {
super(id);
commentThread = commentThreadDao.getCommentThreadByClassAndId(className, classId);
if(commentThread == null){
CommentThread ct = new CommentThread();
ct.setClassName(className);
ct.setClassId(classId);
commentThread = commentThreadDao.save(ct);
}
List<Comment> commentList = commentThread.getCommentList();
webMarkupContainer = new WebMarkupContainer("container");
webMarkupContainer.setOutputMarkupId(true);
generateCommentListView();
webMarkupContainer.add(commentListView);
add(webMarkupContainer);
webMarkupContainer.add(customPagingNavigator);
add(new CommentForm("commentForm"));
}
private void generateCommentListView(){
commentThread = commentThreadDao.reLoad(commentThread);
List<Comment> commentList = commentThread.getCommentList();
commentListView = new PageableListView<Comment>(
"comment", commentList, 5) {
@Override
protected void populateItem(final ListItem<Comment> item) {
final Comment c = item.getModelObject();
item.add(new Label("date", c.getDateCreated()
.toString()));
item.add(new Label("from", c.getUser()
.getFirstName() + " " + c.getUser().getLastName()));
item.add(new Label("message", c.getComment()));
item.add(new CommentDeleteLink("deleteComment", c));
};
};
customPagingNavigator = new CustomPagingNavigator("navigator", commentListView){
@Override
public boolean isVisible(){
return commentListView.size() > 0;
}
};
}
public class CommentForm extends Form<CommentThreadModel> {
public CommentForm(String name) {
super(name, new CompoundPropertyModel<CommentThreadModel>(
new CommentThreadModel()));
add(new TextArea<String>("textMessage"));
add(new AjaxButton("submitButton", new Model<String>(
"Send Comment")) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
List<Comment> commentList = commentThread.getCommentList();
Comment comment = new Comment();
comment.setComment(((CommentThreadModel) form.getModelObject()).getTextMessage());
comment.setUser(userDao.load(1L));
comment = commentDao.save(comment);
commentList.add(comment);
commentThread.setCommentList(commentList);
commentThread = commentThreadDao.save(commentThread);
webMarkupContainer.remove(commentListView);
webMarkupContainer.remove(customPagingNavigator);
generateCommentListView();
webMarkupContainer.add(commentListView);
webMarkupContainer.add(customPagingNavigator);
target.addComponent(webMarkupContainer);
}
});
}
}
private class CommentDeleteLink extends AjaxLink<Comment> {
private static final long serialVersionUID = 5900025667153930797L;
private Comment comment;
public CommentDeleteLink(String id, Comment comment) {
super(id);
this.comment = comment;
}
@Override
public void onClick(AjaxRequestTarget target) {
comment = commentDao.reLoad(comment);
commentDao.delete(comment);
webMarkupContainer.remove(commentListView);
webMarkupContainer.remove(customPagingNavigator);
generateCommentListView();
webMarkupContainer.add(commentListView);
webMarkupContainer.add(customPagingNavigator);
target.addComponent(webMarkupContainer);
}
}
}