-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathUserline.java
More file actions
128 lines (119 loc) · 4.52 KB
/
Userline.java
File metadata and controls
128 lines (119 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package example;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import example.models.Timeline;
import example.models.Tweet;
import org.apache.wicket.PageParameters;
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.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.protocol.http.WebSession;
import org.wyki.cassandra.pelops.UuidHelper;
/**
* This is the typical twitter page. A form for submitting a 140-character
* tweet, and all the tweets that user has made and tweets from everyone
* that he is following.
*/
public class Userline extends HomePage {
private String username;
private Long nextpage;
public Userline(final PageParameters parameters) {
super(parameters);
nextpage = parameters.getAsLong("nextpage");
username = ((TwissSession) WebSession.get()).getUname();
if (username == null) {
setRedirect(true);
setResponsePage(Publicline.class);
}
else {
setup();
}
}
private void setup() {
add(new TweetForm("poster"));
Timeline timeline = getTimeline(username, nextpage);
List<Tweet> tweets = timeline.getView();
if (tweets.size() > 0) {
add(new ListView<Tweet>("tweetlist", tweets) {
@Override
public void populateItem(final ListItem<Tweet> listitem) {
listitem.add(new Link("link") {
@Override
public void onClick() {
PageParameters p = new PageParameters();
p.put("username", listitem.getModel().getObject().getUname());
setResponsePage(Publicline.class, p);
}
}.add(new Label("tuname",listitem.getModel().getObject().getUname())));
listitem.add(new Label("tbody", ": " + listitem.getModel().getObject().getBody()));
}
}).setVersioned(false);
Long linktopaginate = timeline.getNextview();
if (linktopaginate != null) {
nextpage = linktopaginate;
WebMarkupContainer pagediv = new WebMarkupContainer("pagedown");
PageForm pager = new PageForm("pageform");
pagediv.add(pager);
add(pagediv);
}
else {
add(new WebMarkupContainer("pagedown") {
@Override
public boolean isVisible() {
return false;
}
});
}
}
else {
ArrayList<String> hack = new ArrayList<String>(1);
hack.add("There are no tweets yet. Post one!");
add(new ListView<String>("tweetlist", hack ) {
@Override
public void populateItem(final ListItem<String> listitem) {
listitem.add(new Link("link") {
@Override
public void onClick() {
}
}.add(new Label("tuname","")));
listitem.add(new Label("tbody", listitem.getModel().getObject()));
}
}).setVersioned(false);
add(new WebMarkupContainer("pagedown") {
@Override
public boolean isVisible() {
return false;
}
});
}
}
private class PageForm extends Form {
public PageForm(String id) {
super(id);
}
@Override
public void onSubmit() {
PageParameters p = new PageParameters();
p.put("nextpage", nextpage);
setResponsePage(getPage().getClass(), p);
}
}
private class TweetForm extends Form {
private String tweetbody;
public TweetForm(String id) {
super(id);
add(new TextArea("tweetbody", new PropertyModel(this,"tweetbody")));
}
@Override
public void onSubmit() {
saveTweet(new Tweet(UuidHelper.newTimeUuid().toString().getBytes(), username, tweetbody));
setResponsePage(getPage().getClass());
}
}
}