BrightSide Workbench Full Report + Source Code
ActionTypeBox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.crm.zul.sale;
20 
21 import java.util.Collection;
22 import java.util.HashSet;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import org.turro.command.Command;
26 import org.turro.command.Context;
27 import org.turro.crm.db.CrmPU;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.util.Images;
30 import org.turro.zkoss.input.MultiLabelBox;
31 
36 public class ActionTypeBox extends MultiLabelBox<String> {
37 
38  private HashSet<String> types;
39 
40  public void setTypes(HashSet<String> types) {
41  this.types = types;
42  }
43 
44  public Collection<String> getTypes() {
45  return types;
46  }
47 
48  @Override
49  protected boolean checkVisible() {
50  return true;
51  }
52 
53  @Override
54  protected boolean checkNew() {
55  return true;
56  }
57 
58  @Override
59  protected boolean checkEditable() {
60  return true;
61  }
62 
63  @Override
64  protected boolean checkDelete() {
65  return true;
66  }
67 
68  @Override
69  protected String getNewImage() {
70  return Images.getImage("list-add");
71  }
72 
73  @Override
74  protected Collection<String> getCollection() {
75  return types;
76  }
77 
78  @Override
79  protected String convertToString(String label) {
80  return label;
81  }
82 
83  @Override
84  protected Collection<String> getLabelChoices() {
85  return new CrmPU().getResultList("select distinct sat from SaleAction sa join sa.actionType sat");
86  }
87 
88  @Override
89  protected void addChoice(String choice, Command command) {
90  if(types == null) {
91  types = new HashSet<>();
92  }
93  if(types.add(choice)) {
94  if(command != null) try {
95  command.execute(null);
96  } catch (Exception ex) {
97  Logger.getLogger(ActionTypeBox.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
98  }
99  }
100  }
101 
102  @Override
103  protected void changeChoice(final String oldChoice, String choice, final Command command) {
104  addChoice(choice, new Command() {
105  @Override
106  public Object execute(Context context) {
107  deleteChoice(oldChoice, new Command() {
108  @Override
109  public Object execute(Context context) {
110  if(command != null) try {
111  command.execute(null);
112  } catch (Exception ex) {
113  Logger.getLogger(ActionTypeBox.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
114  }
115  return true;
116  }
117  });
118  return true;
119  }
120  });
121  }
122 
123  @Override
124  protected void deleteChoice(String oldChoice, Command command) {
125  if(types.remove(oldChoice)) {
126  if(command != null) try {
127  command.execute(null);
128  } catch (Exception ex) {
129  Logger.getLogger(ActionTypeBox.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
130  }
131  }
132  }
133 
134 }
void changeChoice(final String oldChoice, String choice, final Command command)
void addChoice(String choice, Command command)
void setTypes(HashSet< String > types)
Collection< String > getLabelChoices()
Collection< String > getCollection()
void deleteChoice(String oldChoice, Command command)
static String getImage(String image)
Definition: Images.java:36