BrightSide Workbench Full Report + Source Code
GroupedControl.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 java.util.Collection;
22 import org.turro.contacts.Grouped;
23 import org.turro.entities.Entities;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.Vlayout;
29 
34 public class GroupedControl extends Vlayout implements AfterCompose {
35 
36  private String entityPath;
37  private boolean allowNew = true, allowEdit = true;
38 
39  public boolean isAllowNew() {
40  return allowNew;
41  }
42 
43  public void setAllowNew(boolean allowNew) {
44  this.allowNew = allowNew;
45  }
46 
47  public boolean isAllowEdit() {
48  return allowEdit;
49  }
50 
51  public void setAllowEdit(boolean allowEdit) {
52  this.allowEdit = allowEdit;
53  }
54 
55  public String getEntityPath() {
56  return entityPath;
57  }
58 
59  public void setEntityPath(String entityPath) {
60  this.entityPath = entityPath;
61  }
62 
63  public void setEntity(Object entity) {
65  }
66 
67  @Override
68  public void afterCompose() {
69  showGroups();
70  addEventListener(Events.ON_CHANGE, new EventListener<Event>() {
71  @Override
72  public void onEvent(Event event) throws Exception {
73  showGroups();
74  }
75  });
76  }
77 
78  private void showGroups() {
79  getChildren().clear();
80  Collection<Grouped> groups = Grouped.groups(entityPath);
81  for(Grouped g : groups) {
82  GroupedLine gl = new GroupedLine(g, allowEdit);
83  appendChild(gl);
84  gl.afterCompose();
85  }
86  if(allowNew) {
87  Grouped g = new Grouped();
88  g.setPath(entityPath);
89  GroupedLine gl = new GroupedLine(g, true);
90  appendChild(gl);
91  gl.afterCompose();
92  }
93  }
94 
95 }
static IElephantEntity getController(String path)
Definition: Entities.java:78
void setEntityPath(String entityPath)
void setAllowEdit(boolean allowEdit)