BrightSide Workbench Full Report + Source Code
JpaLabelCombobox.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.jpa.input;
20 
21 import java.util.LinkedList;
22 import java.util.List;
23 import org.turro.string.Strings;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.Dao;
27 
32 public abstract class JpaLabelCombobox<V> extends JpaCombobox<V> {
33 
34  private Object[] parameters;
35  private List<String> defaultValues;
36 
37  public JpaLabelCombobox(Dao dao, WhereClause wc, List<String> defaultValues) {
38  super(dao, wc);
39  this.defaultValues = defaultValues;
40  }
41 
42  public void setParameters(Object[] parameters) {
43  this.parameters = parameters;
44  }
45 
46  public void setDefaultValues(List<String> defaultValues) {
47  this.defaultValues = defaultValues;
48  }
49 
50  @Override
51  public void populateList(String value, LinkedList list, int nRows) {
52  if(Strings.isBlank(value)) value = "";
53  addValues(list, defaultValues, value);
54  LinkedList tmp = new LinkedList();
55  super.populateList(value, tmp, nRows);
56  addValues(list, tmp, value);
57  }
58 
59  @Override
60  public String getTextFromObject(V value) {
61  if(parameters != null) {
62  return I_.format((String) value, parameters);
63  } else {
64  return I_.get((String) value);
65  }
66  }
67 
68  private void addValues(LinkedList list, List values, String search) {
69  if(values == null) return;
70  for(Object obj : values) {
71  String s = (String) obj;
72  if(!list.contains(s) && Strings.findsIgnoreCase(s, search)) {
73  list.add(s);
74  }
75  }
76  }
77 
78 }
static String format(String msg, Object... arguments)
Definition: I_.java:49
static String get(String msg)
Definition: I_.java:41
JpaLabelCombobox(Dao dao, WhereClause wc, List< String > defaultValues)
void setParameters(Object[] parameters)
void setDefaultValues(List< String > defaultValues)
void populateList(String value, LinkedList list, int nRows)