BrightSide Workbench Full Report + Source Code
InTouchControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.zul.intouch;
20 
21 import org.turro.string.Strings;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.turro.contacts.Contact;
25 import org.turro.contacts.InTouch;
26 import org.turro.contacts.zul.label.AddressInfo;
27 import org.turro.contacts.zul.label.ContactInfo;
28 import org.turro.elephant.util.Images;
29 import org.turro.elephant.util.Messages;
30 import org.turro.elephant.zkoss.Modal;
31 import org.turro.entities.Entities;
32 import org.turro.intouch.InTouchUtil;
33 import org.turro.zkoss.label.LabelExtended;
34 import org.turro.zkoss.label.LabelTypes;
35 import org.turro.zkoss.layout.GridLayout;
36 import org.zkoss.zk.ui.HtmlBasedComponent;
37 import org.zkoss.zk.ui.event.Event;
38 import org.zkoss.zk.ui.event.EventListener;
39 import org.zkoss.zk.ui.event.Events;
40 import org.zkoss.zk.ui.ext.AfterCompose;
41 import org.zkoss.zul.A;
42 import org.zkoss.zul.Space;
43 import org.zkoss.zul.Vlayout;
44 import org.zkoss.zul.Window;
45 
50 public class InTouchControl extends GridLayout implements AfterCompose {
51 
52  private String entityPath;
53  private Contact provider;
54 
55  public Contact getProvider() {
56  return provider;
57  }
58 
59  public void setProvider(Contact provider) {
60  this.provider = provider;
61  }
62 
63  public String getEntityPath() {
64  return entityPath;
65  }
66 
67  public void setEntityPath(String entityPath) {
68  this.entityPath = entityPath;
69  }
70 
71  public void setEntity(Object entity) {
73  }
74 
75  @Override
76  public void afterCompose() {
77  if(provider == null || entityPath.endsWith("/0") || Strings.isBlank(entityPath)) {
78  return;
79  }
80  setColumns("3,3,3,1,min,min");
81  showInTouchs();
82  addEventListener(Events.ON_CHANGE, new EventListener<Event>() {
83  @Override
84  public void onEvent(Event event) throws Exception {
85  showInTouchs();
86  }
87  });
88  }
89 
90  private void showInTouchs() {
91  clearRows();
92  for(InTouch inTouch : InTouchUtil.inTouch(entityPath)) {
93  Vlayout vbox = new Vlayout();
94  vbox.appendChild(LabelTypes.getCaptionLabel(inTouch.getName()));
95  vbox.appendChild(LabelTypes.getSoftLabel(inTouch.getDescription()));
96  addComponent(vbox);
97  addComponent(new ContactInfo(inTouch.getContact()));
98  addComponent(new AddressInfo(inTouch.getAddress(), provider));
99  addComponent(new LabelExtended().setDate(inTouch.getControl()));
100  addComponent(getEditButton(inTouch));
101  addComponent(getDeleteButton(inTouch));
102  getCurrentRow().setSclass("z-valign-middle");
103  addRow();
104  }
105  addComponent(new Space());
106  addComponent(new Space());
107  addComponent(new Space());
108  addComponent(new Space());
109  InTouch inTouch = new InTouch();
110  inTouch.setPath(entityPath);
111  addComponent(getEditButton(inTouch));
112  addComponent(new Space());
113  }
114 
115  private HtmlBasedComponent getEditButton(final InTouch inTouch) {
116  A edit = new A(null, Images.getImage(Strings.isBlank(inTouch.getId()) ? "list-add" : "edit"));
117  edit.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
118  @Override
119  public void onEvent(Event event) throws Exception {
120  InTouchEdit edit = new InTouchEdit(provider, inTouch);
121  edit.setMode(Window.MODAL);
122  Modal.doModal(edit, new Command() {
123  @Override
124  public Object execute(Context context) {
125  showInTouchs();
126  return true;
127  }
128  });
129  }
130  });
131  return edit;
132  }
133 
134  private HtmlBasedComponent getDeleteButton(final InTouch inTouch) {
135  A delete = new A(null, Images.getImage("list-remove"));
136  delete.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
137  @Override
138  public void onEvent(Event event) throws Exception {
139  Messages.confirmDeletion().add(inTouch.getName()).show(() -> {
140  InTouchUtil.removeInTouch(inTouch);
141  showInTouchs();
142  });
143  }
144  });
145  return delete;
146  }
147 
148 }
static IElephantEntity getController(String path)
Definition: Entities.java:78
void setEntityPath(String entityPath)