1 package net
.bzzt
.ical
.aggregator
.web
;
3 import java
.util
.Collection
;
6 import net
.bzzt
.ical
.aggregator
.model
.Feed
;
7 import net
.bzzt
.ical
.aggregator
.service
.FeedService
;
9 import org
.apache
.commons
.lang
.StringUtils
;
10 import org
.apache
.wicket
.AttributeModifier
;
11 import org
.apache
.wicket
.Session
;
12 import org
.apache
.wicket
.ajax
.AjaxRequestTarget
;
13 import org
.apache
.wicket
.ajax
.form
.AjaxFormChoiceComponentUpdatingBehavior
;
14 import org
.apache
.wicket
.ajax
.form
.AjaxFormComponentUpdatingBehavior
;
15 import org
.apache
.wicket
.markup
.html
.WebMarkupContainer
;
16 import org
.apache
.wicket
.markup
.html
.basic
.Label
;
17 import org
.apache
.wicket
.markup
.html
.form
.Check
;
18 import org
.apache
.wicket
.markup
.html
.form
.CheckBox
;
19 import org
.apache
.wicket
.markup
.html
.form
.CheckGroup
;
20 import org
.apache
.wicket
.markup
.html
.form
.Form
;
21 import org
.apache
.wicket
.markup
.html
.form
.IChoiceRenderer
;
22 import org
.apache
.wicket
.markup
.html
.list
.ListItem
;
23 import org
.apache
.wicket
.markup
.html
.list
.PropertyListView
;
24 import org
.apache
.wicket
.markup
.html
.panel
.Panel
;
25 import org
.apache
.wicket
.model
.IModel
;
26 import org
.apache
.wicket
.model
.Model
;
27 import org
.apache
.wicket
.model
.PropertyModel
;
28 import org
.apache
.wicket
.spring
.injection
.annot
.SpringBean
;
30 public class FeedSelection
extends Panel
33 private final AggregatorLayoutPage parent
;
35 public class FeedRenderer
implements IChoiceRenderer
<Feed
>
41 private static final long serialVersionUID
= 1L;
44 public Object
getDisplayValue(Feed object
)
50 public String
getIdValue(Feed object
, int index
)
52 return String
.valueOf(index
);
57 public class FeedSelectionForm
extends Form
<List
<Feed
>>
63 private static final long serialVersionUID
= 1L;
65 @SpringBean(name
= "feedService")
66 private FeedService feedService
;
68 @SuppressWarnings("unchecked")
69 public FeedSelectionForm(String id
, IModel
<List
<Feed
>> model
)
73 IModel
<Collection
<Feed
>> collectionModel
= (IModel
) model
;
75 final CheckGroup
<Feed
> feeds
= new CheckGroup
<Feed
>("feed", collectionModel
);
78 feeds
.add(new PropertyListView
<Feed
>("feeds", feedService
.getFeeds())
84 private static final long serialVersionUID
= 1L;
87 protected void populateItem(ListItem
<Feed
> item
)
89 Feed modelObject
= item
.getModelObject();
90 Check
<Feed
> check
= new Check
<Feed
>("check", new Model
<Feed
>(modelObject
));
91 check
.setOutputMarkupId(true);
94 Label name
= new Label("name");
95 name
.add(new AttributeModifier("for", true, new Model
<String
>(feeds
.getMarkupId() + "-" + check
.getMarkupId())));
98 WebMarkupContainer description
= new WebMarkupContainer("descriptionContainer");
99 description
.setOutputMarkupId(true);
100 item
.add(description
);
101 description
.add(new Label("description"));
102 WebMarkupContainer link
= new WebMarkupContainer("link");
103 if (modelObject
.link
== null)
105 link
.setVisible(false);
109 link
.add(new AttributeModifier("href", true, new Model
<String
>(modelObject
.link
.toString())));
111 description
.add(link
);
114 WebMarkupContainer toggle
= new WebMarkupContainer("toggle");
117 if (StringUtils
.isBlank(item
.getModelObject().description
))
119 toggle
.setVisible(false);
123 Model
<String
> toggleDescription
= new Model
<String
>("if (document.getElementById('"
124 + description
.getMarkupId() + "').style.display == 'block') { document.getElementById('"
125 + description
.getMarkupId() + "').style.display = 'none'; } else { document.getElementById('"
126 + description
.getMarkupId() + "').style.display = 'block'; }");
127 toggle
.add(new AttributeModifier("onclick", true, toggleDescription
));
132 feeds
.add(new AjaxFormChoiceComponentUpdatingBehavior()
138 private static final long serialVersionUID
= 1L;
141 protected void onUpdate(AjaxRequestTarget target
)
143 ((AggregatorSession
) getSession()).setSelectedFeeds(getModelObject());
144 parent
.refresh(target
);
149 final CheckBox showRecurring
= new CheckBox("showRecurring", new Model
<Boolean
>(((AggregatorSession
) getSession()).getMaxRecurrence() == null));
150 showRecurring
.add(new AjaxFormComponentUpdatingBehavior("onchange")
156 private static final long serialVersionUID
= 1L;
159 protected void onUpdate(AjaxRequestTarget target
)
161 if (showRecurring
.getModelObject())
163 ((AggregatorSession
) getSession()).setMaxRecurrence(null);
167 ((AggregatorSession
) getSession()).setMaxRecurrence(5);
169 parent
.refresh(target
);
176 protected void onSubmit()
178 ((AggregatorSession
) getSession()).setSelectedFeeds(getModelObject());
179 setResponsePage(WicketApplication
.get().getHomePage());
187 private static final long serialVersionUID
= 1L;
189 public FeedSelection(String id
, AggregatorLayoutPage aggregatorLayoutPage
)
192 this.parent
= aggregatorLayoutPage
;
193 add(new FeedSelectionForm("form", new PropertyModel
<List
<Feed
>>(this, "selectedFeeds")));
196 public List
<Feed
> getSelectedFeeds()
198 return ((AggregatorSession
) Session
.get()).getSelectedFeeds();