BrightSide Workbench Full Report + Source Code
SkillsChosenbox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.skills;
20 
21 import java.util.Collection;
22 import java.util.Set;
23 import org.turro.elephant.entities.db.SkillType;
24 import org.zkoss.zk.ui.ext.AfterCompose;
25 import org.zkoss.zkmax.zul.Chosenbox;
26 import org.zkoss.zul.ListModelList;
27 
32 public class SkillsChosenbox extends Chosenbox implements AfterCompose {
33 
34  private String rootFilter, entityPath;
35  private SkillType types[];
36  private boolean populated;
37  private Collection<SkillRoot> internalValues;
38 
39  public void setRootFilter(String rootFilter) {
40  this.rootFilter = rootFilter;
41  }
42 
43  public void setEntityPath(String entityPath) {
44  this.entityPath = entityPath;
45  setObjectValues(Skills.getSkillsAsRootFrom(entityPath, types));
46  }
47 
48  public void setTypes(SkillType[] types) {
49  this.types = types;
50  }
51 
52  public void setTypes(String[] types) {
53  this.types = new SkillType[types.length];
54  for(int i = 0; i < types.length; i++) {
55  this.types[0] = SkillType.valueOf(types[0]);
56  }
57  }
58 
59  public void setTypes(String types) {
60  setTypes(types.split("\\s*,\\s*"));
61  }
62 
63  public String getEntityPath() {
64  return entityPath;
65  }
66 
67  public SkillType[] getTypes() {
68  return types;
69  }
70 
71  public Set<SkillRoot> getObjectValues() {
72  return getSelectedObjects();
73  }
74 
75  public void setObjectValues(Collection<SkillRoot> internalValues) {
76  if(internalValues != null) setSelectedObjects(internalValues);
77  }
78 
79  public void addToModel(SkillRoot value) {
80  ((ListModelList) getModel()).add(value);
81  Set set = getSelectedObjects();
82  set.add(value);
83  setSelectedObjects(set);
84  }
85 
86  @Override
87  public void afterCompose() {
88  if(!populated) {
89  populateList();
90  populated = true;
91  if (internalValues != null) {
92  setObjectValues(internalValues);
93  internalValues = null;
94  } else {
95  setObjectValues(null);
96  }
97  }
98  }
99 
100  private void populateList() {
101  setModel(new ListModelList<>(Skills.getAvailables(rootFilter, types)));
102  }
103 
104 }
void setRootFilter(String rootFilter)
void addToModel(SkillRoot value)
void setTypes(SkillType[] types)
void setEntityPath(String entityPath)
void setObjectValues(Collection< SkillRoot > internalValues)
static List< SkillRoot > getSkillsAsRootFrom(String entityPath, SkillType... types)
Definition: Skills.java:44
static List< SkillRoot > getAvailables(String rootFilter, SkillType... types)
Definition: Skills.java:60