BrightSide Workbench Full Report + Source Code
ActionWithEntity.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.HashMap;
22 import org.turro.elephant.context.Application;
23 import org.turro.elephant.util.Images;
24 import org.turro.i18n.I_;
25 import org.zkoss.zk.ui.Executions;
26 import org.zkoss.zk.ui.IdSpace;
27 import org.zkoss.zk.ui.event.Event;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zk.ui.ext.AfterCompose;
30 import org.zkoss.zk.ui.select.Selectors;
31 import org.zkoss.zk.ui.select.annotation.Wire;
32 import org.zkoss.zul.Div;
33 import org.zkoss.zul.Popup;
34 import org.zkoss.zul.Toolbarbutton;
35 
40 public class ActionWithEntity extends Div implements IdSpace, AfterCompose {
41 
42  @Wire private Toolbarbutton actionButton;
43  @Wire private Toolbarbutton entityButton;
44  @Wire private EntityCombobox entitybox;
45  @Wire private Popup entityPopup;
46 
47  public ActionWithEntity() {
48  HashMap args = new HashMap();
49  args.put("el_label", Application.getStringMap());
50  args.put("i_", I_.api());
51  args.put("i", I_.map());
52  args.put("k", I_.byKeyMap());
53  Executions.createComponents("/WEB-INF/_zul/bs/comps/entity/actionWithEntity.zul", this, args);
54  Selectors.wireComponents(this, this, false);
55  Selectors.wireEventListeners(this, this);
56  }
57 
58  public void setEntity(Object entity) {
59  entitybox.setObjectValue(entity);
60  checkEmptyness();
61  }
62 
63  public Object getEntity() {
64  checkEmptyness();
65  return entitybox.getObjectValue();
66  }
67 
68  public void setRoot(String entityRoot) {
69  entitybox.setRoot(entityRoot);
70  entityButton.setPopupAttributes(entityPopup, "after_start", null, null, null);
71  }
72 
73  public void setLabel(String label) {
74  actionButton.setLabel(label);
75  }
76 
77  public void setImage(String image) {
78  actionButton.setImage(image);
79  }
80 
81  @Override
82  public void afterCompose() {
83  initControls();
84  }
85 
86  private void initControls() {
87  entityButton.setLabel(null);
88  entityButton.setImage(Images.get12Image("caret-down"));
89  entitybox.addEventListener(Events.ON_CLICK, (Event e) -> {
90  e.stopPropagation();
91  });
92  actionButton.addEventListener(Events.ON_CLICK, (Event e) -> {
93  Events.postEvent(new Event(Events.ON_CLICK, ActionWithEntity.this));
94  });
95  }
96 
97  private void checkEmptyness() {
98  if(entitybox.getObjectValue() == null) {
99  entityButton.setImage(Images.get12Image("caret-red-down"));
100  } else {
101  entityButton.setImage(Images.get12Image("caret-down"));
102  }
103  }
104 
105 }
static String get12Image(String image)
Definition: Images.java:40
static I18nByKey byKeyMap()
Definition: I_.java:91
static I18nApiWrapper api()
Definition: I_.java:65
static I18nMapWrapper map()
Definition: I_.java:69