BrightSide Workbench Full Report + Source Code
TagsChosenbox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.tags;
20 
21 import java.util.Collection;
22 import java.util.Set;
23 import org.zkoss.zk.ui.ext.AfterCompose;
24 import org.zkoss.zkmax.zul.Chosenbox;
25 import org.zkoss.zul.ListModelList;
26 
31 public class TagsChosenbox extends Chosenbox implements AfterCompose {
32 
33  private String rootFilter, entityPath;
34  private boolean populated;
35  private TagSet internalValues;
36 
37  public void setRootFilter(String rootFilter) {
38  this.rootFilter = rootFilter;
39  }
40 
41  public void setEntityPath(String entityPath) {
42  this.entityPath = entityPath;
43  setObjectValues(Tags.getTags(entityPath));
44  }
45 
46  public String getEntityPath() {
47  return entityPath;
48  }
49 
50  public Set<TagItem> getObjectValues() {
51  return getSelectedObjects();
52  }
53 
54  public void setObjectValues(Collection<TagItem> internalValues) {
55  if(internalValues != null) setSelectedObjects(internalValues);
56  }
57 
58  public void addToModel(TagItem value) {
59  ((ListModelList) getModel()).add(value);
60  Set set = getSelectedObjects();
61  set.add(value);
62  setSelectedObjects(set);
63  }
64 
65  @Override
66  public void afterCompose() {
67  if(!populated) {
68  populateList();
69  populated = true;
70  if (internalValues != null) {
71  setObjectValues(internalValues);
72  internalValues = null;
73  } else {
74  setObjectValues(null);
75  }
76  }
77  }
78 
79  private void populateList() {
80  setModel(new ListModelList<>(Tags.getAvailables(rootFilter)));
81  }
82 
83 }
void addToModel(TagItem value)
Set< TagItem > getObjectValues()
void setRootFilter(String rootFilter)
void setObjectValues(Collection< TagItem > internalValues)
void setEntityPath(String entityPath)
static TagSet getTags(Object entity)
Definition: Tags.java:351
static TagSet getAvailables()
Definition: Tags.java:65