BrightSide Workbench Full Report + Source Code
ImageComposer.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 java.io.File;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.turro.composer.EntityPathComposer;
25 import org.turro.elephant.context.ElephantContext;
26 import org.turro.i18n.I_;
27 import org.turro.publication.db.PublicationPU;
28 import org.turro.publication.entity.NewsSection;
29 import org.turro.zkoss.dialog.SelectionDialog;
30 import org.turro.zkoss.text.RepositoryContent;
31 import org.turro.zkoss.text.RepositoryWalker;
32 import org.zkoss.zk.ui.Component;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zk.ui.select.annotation.Listen;
36 import org.zkoss.zk.ui.select.annotation.Wire;
37 import org.zkoss.zul.Html;
38 import org.zkoss.zul.Textbox;
39 
44 public class ImageComposer extends EntityPathComposer<NewsSection> {
45 
46  @Wire("#image")
47  private Html html;
48 
49  @Wire("#urlLink")
50  private Textbox urlLink;
51 
52  @Listen("onClick = #selImage")
53  public void onSelectImage() {
54  RepositoryWalker repositories = new RepositoryWalker(null);
55  repositories.selectFolder("/_internal/files" + PublicationPU.getObjectPath(entity.getNewsletter()));
57  repositories.setReadOnlyRepository(entity.getNewsletter().getId() == null);
58  repositories.setNoTreeRepository(false);
59  SelectionDialog.showComponent(getPage(), I_.get("Repository"), repositories, "90%", "90%", new Command() {
60  @Override
61  public Object execute(Context context) {
62  File result = repositories.getResult();
63  if(result != null) {
64  entity.setWiki("$no_wiki\n" + imageString(result));
65  entity.setBody(imageString(result));
66  html.setContent(entity.getBody());
67  Events.postEvent(new Event(Events.ON_CHANGE));
68  }
69  return null;
70  }
71  });
72  }
73 
74  @Listen("onChange = #urlLink")
75  public void onUrlLink() {
76  entity.setBanner(urlLink.getValue());
77  Events.postEvent(new Event(Events.ON_CHANGE));
78  }
79 
80  @Override
81  public void doAfterCompose(Component comp) throws Exception {
82  super.doAfterCompose(comp);
83  html.setContent(entity.getBody());
84  urlLink.setValue(entity.getBanner());
85  }
86 
87  private String imageString(File image) {
88  StringBuilder sb = new StringBuilder();
89  sb.append("<img border=\"0\" style=\"width:100%;\" src=\"")
91  .append(ElephantContext.getRelativePath(image.getAbsolutePath()))
92  .append("\"/>");
93  return sb.toString();
94  }
95 
96 }
static String get(String msg)
Definition: I_.java:41
void doAfterCompose(Component comp)
static String getObjectPath(Object object)
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
void setNoTreeRepository(boolean noTreeRepository)
void setReadOnlyRepository(boolean readOnlyRepository)