various updates, opensocial support
[ical-aggregator.git] / src / main / java / net / bzzt / ical / aggregator / web / FeedSelection.java
blob524c6c3f429c5febf6a08f875db758df0626102a
1 package net.bzzt.ical.aggregator.web;
3 import java.util.Collection;
4 import java.util.List;
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>
38 /**
41 private static final long serialVersionUID = 1L;
43 @Override
44 public Object getDisplayValue(Feed object)
46 return object.name;
49 @Override
50 public String getIdValue(Feed object, int index)
52 return String.valueOf(index);
57 public class FeedSelectionForm extends Form<List<Feed>>
60 /**
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)
71 super(id, model);
73 IModel<Collection<Feed>> collectionModel = (IModel) model;
75 final CheckGroup<Feed> feeds = new CheckGroup<Feed>("feed", collectionModel);
76 add(feeds);
78 feeds.add(new PropertyListView<Feed>("feeds", feedService.getFeeds())
81 /**
84 private static final long serialVersionUID = 1L;
86 @Override
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);
92 item.add(check);
94 Label name = new Label("name");
95 name.add(new AttributeModifier("for", true, new Model<String>(feeds.getMarkupId() + "-" + check.getMarkupId())));
96 item.add(name);
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);
107 else
109 link.add(new AttributeModifier("href", true, new Model<String>(modelObject.link.toString())));
111 description.add(link);
114 WebMarkupContainer toggle = new WebMarkupContainer("toggle");
115 item.add(toggle);
117 if (StringUtils.isBlank(item.getModelObject().description))
119 toggle.setVisible(false);
121 else
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;
140 @Override
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;
158 @Override
159 protected void onUpdate(AjaxRequestTarget target)
161 if (showRecurring.getModelObject())
163 ((AggregatorSession) getSession()).setMaxRecurrence(null);
165 else
167 ((AggregatorSession) getSession()).setMaxRecurrence(5);
169 parent.refresh(target);
172 add(showRecurring);
175 @Override
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)
191 super(id);
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();