19 package org.turro.newsletter;
21 import java.util.TreeSet;
22 import org.turro.string.Strings;
23 import org.turro.elephant.util.Images;
24 import org.turro.i18n.I_;
25 import org.turro.jpa.entity.EntityCollections;
26 import org.turro.publication.entity.NewsSection;
27 import org.turro.publication.entity.NewsSectionType;
28 import org.turro.publication.entity.Newsletter;
29 import org.turro.zkoss.label.LabelTypes;
30 import org.turro.zkoss.layout.GroupboxArrow;
31 import org.zkoss.zk.ui.HtmlBasedComponent;
32 import org.zkoss.zk.ui.event.Event;
33 import org.zkoss.zk.ui.event.EventListener;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zul.Button;
36 import org.zkoss.zul.Hlayout;
37 import org.zkoss.zul.Html;
38 import org.zkoss.zul.Image;
39 import org.zkoss.zul.Include;
40 import org.zkoss.zul.Label;
41 import org.zkoss.zul.Vlayout;
52 this.newsletter = newsletter;
56 private void addRows() {
57 getChildren().clear();
60 newsSection.setNewsOrder(idx++);
63 protected void doFillContent() {
64 Include sectionBand =
new Include(
"/WEB-INF/_zul/publication/sectionBand.zul");
65 sectionBand.setDynamicProperty(
"entity", newsSection);
66 sectionBand.setDynamicProperty(
"grid",
SectionsGrid.this);
67 appendChild(sectionBand);
69 Include textBand =
new Include(
"/WEB-INF/_zul/publication/textBand.zul");
70 textBand.setDynamicProperty(
"entity", newsSection);
71 appendChild(textBand);
72 }
else if(NewsSectionType.NEWS_SECTION_IMAGE.equals(newsSection.getType())) {
73 Include imageBand =
new Include(
"/WEB-INF/_zul/publication/imageBand.zul");
74 imageBand.setDynamicProperty(
"entity", newsSection);
75 appendChild(imageBand);
76 }
else if(NewsSectionType.NEWS_SECTION_EXTERNAL.equals(newsSection.getType())) {
77 Include externalBand =
new Include(
"/WEB-INF/_zul/publication/externalBand.zul");
78 externalBand.setDynamicProperty(
"entity", newsSection);
79 appendChild(externalBand);
83 Hlayout hbox =
new Hlayout();
85 hbox.setSclass(
"z-valign-middle");
86 hbox.setValign(
"middle");
87 hbox.appendChild(
new Image(Images.getImage(newsSection.isNewColumn() ?
"table_column" :
"table_row")));
88 hbox.appendChild(LabelTypes.getSoftLabel(I_.byKey(newsSection.getType().toString())));
89 hbox.appendChild(getLabel(newsSection));
93 Hlayout buttonBox =
new Hlayout();
94 buttonBox.setSpacing(
"20px");
95 buttonBox.setStyle(
"margin:20px;");
96 Button addImage =
new Button(I_.get(
"Add") +
" " + I_.get(
"Image section"));
97 addImage.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
99 public void onEvent(Event event) throws Exception {
100 createSection(NewsSectionType.NEWS_SECTION_IMAGE);
103 buttonBox.appendChild(addImage);
104 Button addText =
new Button(I_.get(
"Add") +
" " + I_.get(
"Text section"));
105 addText.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
107 public void onEvent(Event event) throws Exception {
108 createSection(NewsSectionType.NEWS_SECTION_TEXT);
111 buttonBox.appendChild(addText);
112 Button addExternal =
new Button(I_.get(
"Add") +
" " + I_.get(
"External section"));
113 addExternal.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
115 public void onEvent(Event event) throws Exception {
116 createSection(NewsSectionType.NEWS_SECTION_EXTERNAL);
119 buttonBox.appendChild(addExternal);
120 appendChild(buttonBox);
126 setNewsletter(newsletter);
131 if(ns.getNewsOrder() == newsSection.
getNewsOrder() - 1) {
134 setNewsletter(newsletter);
142 if(ns.getNewsOrder() == newsSection.
getNewsOrder() + 1) {
145 setNewsletter(newsletter);
157 setNewsletter(newsletter);
160 private HtmlBasedComponent getLabel(NewsSection newsSection) {
161 if(newsSection.isEmpty()) {
162 return new Label(I_.get(
"Empty"));
164 if(NewsSectionType.NEWS_SECTION_TEXT.equals(newsSection.getType())) {
165 return new Label(Strings.truncateAndWarn(newsSection.getWiki(), 100));
166 }
else if(NewsSectionType.NEWS_SECTION_IMAGE.equals(newsSection.getType())) {
167 return new Html(
"<div style='max-width:23px;max-height:23px;'>" + newsSection.getBody() +
"</div>");
168 }
else if(NewsSectionType.NEWS_SECTION_EXTERNAL.equals(newsSection.getType())) {
169 return new Label(Strings.truncateAndWarn(newsSection.getBody(), 100));
171 return new Label(I_.get(
"Empty"));
static EntityCollections entities(Collection values)
boolean remove(IDaoEntity entity)
void moveDown(NewsSection newsSection)
void moveUp(NewsSection newsSection)
void setNewsletter(Newsletter newsletter)
void deleteSection(NewsSection newsSection)
void setNewsOrder(int newsOrder)
void setNewsletter(Newsletter newsletter)
void setType(NewsSectionType type)
Set< NewsSection > getNewsSections()
void setCaption(Component comp)
void setOpen(boolean open)