BrightSide Workbench Full Report + Source Code
GroupedLine.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2014 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.groupit;
20 
21 import org.turro.contacts.Grouped;
22 import org.turro.contacts.db.ContactsPU;
23 import org.turro.elephant.util.Images;
24 import org.zkoss.lang.Strings;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.EventListener;
27 import org.zkoss.zk.ui.event.Events;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Button;
30 import org.zkoss.zul.Hlayout;
31 
36 public class GroupedLine extends Hlayout implements AfterCompose {
37 
38  private Grouped grouped;
39  private final boolean allowEdit;
40 
41  public GroupedLine(Grouped grouped, boolean allowEdit) {
42  this.grouped = grouped;
43  this.allowEdit = allowEdit;
44  setSclass("z-valign-middle");
45  setValign("middle");
46 
47  }
48 
49  @Override
50  public void afterCompose() {
51  final CategoryCombobox category = new CategoryCombobox();
52  category.setCols(50);
53  if(grouped != null && grouped.getParent() != null) {
54  category.setObjectValue(grouped.getParent().getCategory());
55  }
56  category.setDisabled(!allowEdit);
57  appendChild(category);
58  final GroupItBandbox group = new GroupItBandbox();
59  group.afterCompose();
60  group.setCols(70);
61  if(grouped != null) {
62  group.setCategory(category.getObjectValue());
63  group.setObjectValue(grouped.getParent());
64  }
65  group.setDisabled(!allowEdit);
66  appendChild(group);
67  if(allowEdit) {
68  Button save = new Button(null, Images.getImage("save"));
69  appendChild(save);
70  save.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
71  @Override
72  public void onEvent(Event event) throws Exception {
73  grouped.setParent(group.getObjectValue());
74  boolean isNew = Strings.isBlank(grouped.getId());
75  grouped = new ContactsPU().saveObject(grouped);
76  if(isNew) {
77  Events.postEvent(new Event(Events.ON_CHANGE, GroupedLine.this.getParent()));
78  }
79  }
80  });
81  if(!Strings.isBlank(grouped.getId())) {
82  Button delete = new Button(null, Images.getImage("delete"));
83  appendChild(delete);
84  delete.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
85  @Override
86  public void onEvent(Event event) throws Exception {
87  new ContactsPU().deleteObject(grouped);
88  GroupedLine.this.detach();
89  }
90  });
91  }
92  }
93  category.addEventListener(Events.ON_SELECT, new EventListener<Event>() {
94  @Override
95  public void onEvent(Event event) throws Exception {
96  group.setCategory(category.getObjectValue());
97  }
98  });
99  }
100 
101 }
static String getImage(String image)
Definition: Images.java:36
GroupedLine(Grouped grouped, boolean allowEdit)