BrightSide Workbench Full Report + Source Code
EntityCombobox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 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.entities;
20 
21 import java.util.LinkedList;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.turro.collections.parser.ParserException;
25 import org.turro.string.Strings;
26 import org.turro.collections.KeyValueMap;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.zkoss.input.GenericCombobox;
29 import org.zkoss.zul.Comboitem;
30 
35 public class EntityCombobox extends GenericCombobox<Object> {
36 
37  private String root;
38  private KeyValueMap kvm;
39 
40  public void setRoot(String root) {
41  this.root = root;
42  }
43 
44  public void setParameters(KeyValueMap kvm) {
45  this.kvm = kvm;
46  }
47 
48  public void setParameters(String values) {
49  try {
50  this.kvm = new KeyValueMap(values);
51  } catch (ParserException ex) {
52  Logger.getLogger(EntityCombobox.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
53  }
54  }
55 
56  @Override
57  public void populateList(String value, LinkedList list, int nRows) {
58  if(!Strings.isBlank(root)) {
59  list.addAll(Entities.getEntities(root, value, nRows, kvm));
60  } else {
61  list.addAll(Entities.getEntities(value, nRows, kvm));
62  }
63  }
64 
65  @Override
66  public String getTextFromObject(Object value) {
67  return Entities.getController(value).getName();
68  }
69 
70  @Override
71  public void render(Comboitem item, Object data, int index) throws Exception {
72  super.render(item, data, index);
73  String img = Entities.getController(data).getImage();
74  if(!Strings.isBlank(img)) item.setImage(img);
75  }
76 
77  public String getEntityPath() {
79  return ee != null ? ee.getPath() : null;
80  }
81 
82  public void setEntityPath(String entityPath) {
83  IElephantEntity ee = Entities.getController(entityPath);
84  if(ee != null) {
86  }
87  }
88 
91  }
92 
93  public void setController(IElephantEntity entity) {
94  if(entity != null) {
95  setObjectValue(entity.getEntity());
96  }
97  }
98 
99  public Object getEntity() {
100  return getObjectValue();
101  }
102 
103  public void setEntity(Object entity) {
104  setObjectValue(entity);
105  }
106 
107 }
static IElephantEntity getController(String path)
Definition: Entities.java:78
static Collection< Object > getEntities(String search, int maxResults)
Definition: Entities.java:106
void populateList(String value, LinkedList list, int nRows)
String getTextFromObject(Object value)
void setController(IElephantEntity entity)
void setParameters(KeyValueMap kvm)
void render(Comboitem item, Object data, int index)
void setEntityPath(String entityPath)