BrightSide Workbench Full Report + Source Code
GenericFilterListbox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.zkoss.filter;
20 
21 import java.util.Collection;
22 import org.turro.command.Command;
23 import org.turro.elephant.util.Images;
24 import org.turro.i18n.I_;
25 import org.turro.zkoss.dialog.SelectionDialog;
26 import org.turro.zkoss.input.CollectionListbox;
27 import org.turro.zul.frame.Framework;
28 import org.zkoss.zk.ui.event.Event;
29 import org.zkoss.zk.ui.event.EventListener;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.Button;
33 import org.zkoss.zul.Hbox;
34 import org.zkoss.zul.Vlayout;
35 
40 public class GenericFilterListbox<E> extends Vlayout implements AfterCompose {
41 
42  private Filter<E> filter;
43  private FilterGrid filterGrid;
44  private CollectionListbox<E> entities;
45  private boolean multiple = true, checkmark = true, selectFirst = false;
46 
47  public GenericFilterListbox(Filter<E> filter, FilterGrid filterGrid, CollectionListbox<E> entities) {
48  this.filter = filter;
49  this.filterGrid = filterGrid;
50  this.entities = entities;
51  }
52 
53  public void setMultiple(boolean multiple) {
54  this.multiple = multiple;
55  }
56 
57  public void setCheckmark(boolean checkmark) {
58  this.checkmark = checkmark;
59  }
60 
61  public void setSelectFirst(boolean selectFirst) {
62  this.selectFirst = selectFirst;
63  }
64 
65  @Override
66  public void afterCompose() {
67  entities.setMultiple(multiple);
68  entities.setCheckmark(checkmark);
69  entities.setSelectFirst(selectFirst);
70  entities.setVflex(true);
71  Button search = new Button(I_.get("Search"), Images.getImage("search"));
72  search.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
73  @Override
74  public void onEvent(Event event) throws Exception {
75  if(filterGrid.hasValues()) {
76  entities.updateCollection(filter.getObjectValues(filterGrid.getValues()));
77  }
78  }
79  });
80  appendChild(filterGrid);
81  filterGrid.afterCompose();
82  Hbox hbox = new Hbox();
83  hbox.setHflex("true");
84  hbox.setPack("end");
85  hbox.setStyle("padding:10px");
86  hbox.setSpacing("15px");
87  hbox.appendChild(search);
88  appendChild(hbox);
89  appendChild(entities);
90  entities.afterCompose();
91  }
92 
93  public Collection<E> getObjectValues() {
94  return entities.getObjectValues();
95  }
96 
97  public E getObjectValue() {
98  return entities.getObjectValue();
99  }
100 
101  public void show(String title, String width, String height, Command command) {
103  Framework.getCurrent().getPage(),
104  title, this, width, height, command);
105  }
106 }
static String getImage(String image)
Definition: Images.java:36
static String get(String msg)
Definition: I_.java:41
void show(String title, String width, String height, Command command)
GenericFilterListbox(Filter< E > filter, FilterGrid filterGrid, CollectionListbox< E > entities)
void setSelectFirst(boolean selectFirst)
static Framework getCurrent()
Definition: Framework.java:203