BrightSide Workbench Full Report + Source Code
TextComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.newsletter;
20 
21 import org.turro.string.Strings;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.turro.composer.EntityPathComposer;
25 import org.turro.elephant.context.Application;
26 import org.turro.elephant.impl.util.Parser;
27 import org.turro.i18n.I_;
28 import org.turro.publication.db.PublicationPU;
29 import org.turro.publication.entity.NewsSection;
30 import org.turro.zkoss.dialog.SelectionDialog;
31 import org.turro.zkoss.text.WikiEditor;
32 import org.zkoss.zk.ui.Component;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.EventListener;
35 import org.zkoss.zk.ui.event.Events;
36 import org.zkoss.zk.ui.event.InputEvent;
37 import org.zkoss.zk.ui.select.annotation.Listen;
38 import org.zkoss.zk.ui.select.annotation.Wire;
39 
44 public class TextComposer extends EntityPathComposer<NewsSection> {
45 
46  @Wire("#wiki")
47  private WikiEditor wiki;
48 
49  @Listen("onChange = *; onSelect = *; onCheck = *")
50  public final void onChange(Event event) {
51  Events.postEvent(new Event(Events.ON_CHANGE));
52  }
53 
54  @Listen("onClick = #selBanner")
55  public void onSelectBanner() {
56  BannerComposer banner = new BannerComposer(entity.getBanner(), PublicationPU.getObjectPath(entity.getNewsletter()));
57  SelectionDialog.showComponent(getPage(), I_.get("Banner"), banner, "90%", "60%", new Command() {
58  @Override
59  public Object execute(Context context) {
60  String result = banner.getResult();
61  if(!Strings.isBlank(result)) {
62  entity.setBanner(result);
63  } else {
64  entity.setBanner(null);
65  }
66  Events.postEvent(new Event(Events.ON_CHANGE));
67  return null;
68  }
69  });
70  }
71 
72  @Listen("onClick = #delBanner")
73  public void onDeleteBanner() {
74  entity.setBanner(null);
75  Events.postEvent(new Event(Events.ON_CHANGE));
76  }
77 
78  @Override
79  public void doAfterCompose(Component comp) throws Exception {
80  super.doAfterCompose(comp);
81  initWiki();
82  }
83 
84  private void initWiki() {
85  wiki.setWidth("100%");
86  wiki.setHeight("100%");
87  wiki.setValue(entity.getWiki());
88  wiki.setImageFolder("/_internal/files" + PublicationPU.getObjectPath(entity.getNewsletter()));
89  wiki.setFileFolder("/_internal/files" + PublicationPU.getObjectPath(entity.getNewsletter()));
90  wiki.setReadonly(entity.getNewsletter().getId() == null);
91  wiki.addEventListener(Events.ON_CHANGE, new EventListener<InputEvent>() {
92  @Override
93  public void onEvent(InputEvent event) throws Exception {
94  wiki.setValue(event.getValue());
95  entity.setWiki(wiki.getValue());
96  entity.setBody(wiki.getHtml());
97  }
98  });
99  }
100 
101 }
static String get(String msg)
Definition: I_.java:41
void doAfterCompose(Component comp)
final void onChange(Event event)
static String getObjectPath(Object object)
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
void setReadonly(boolean value)
void setImageFolder(String folder)
void setValue(String value)
Definition: WikiEditor.java:98
void setFileFolder(String folder)