BrightSide Workbench Full Report + Source Code
ConstraintKeyBox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.publication.model;
20 
21 import org.turro.contacts.social.SocialGroupListbox;
22 import org.turro.entities.EntityCombobox;
23 import org.turro.string.Strings;
24 import org.zkoss.zk.ui.annotation.ComponentAnnotation;
25 import org.zkoss.zk.ui.event.Event;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zk.ui.event.InputEvent;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.Hlayout;
30 import org.zkoss.zul.Space;
31 import org.zkoss.zul.Toolbarbutton;
32 
37 @ComponentAnnotation({"value:@ZKBIND(ACCESS=both,SAVE_EVENT=onChange)"})
38 public class ConstraintKeyBox extends Hlayout implements AfterCompose {
39 
41 
42  public String getValue() {
43  if(mode == ConstraintKeyMode.ENTITY) {
44  EntityCombobox combo = (EntityCombobox) getChildren().get(0);
45  return combo.getEntityPath();
46  } else if(mode == ConstraintKeyMode.SOCIAL_GROUP) {
47  SocialGroupListbox list = (SocialGroupListbox) getChildren().get(0);
48  return list.getKeyString();
49  }
50  return null;
51  }
52 
53  public void setValue(String keyId) {
54  if(Strings.isBlank(keyId)) {
55  mode = ConstraintKeyMode.EMPTY;
56  } else if(keyId.startsWith("/")) {
58  } else {
60  }
61  updateControl(keyId);
62  }
63 
64  private void updateControl(String keyId) {
65  if(mode == ConstraintKeyMode.EMPTY) {
66  getChildren().remove(0);
67  getChildren().add(0, new Space());
68  } else if(mode == ConstraintKeyMode.ENTITY) {
69  getChildren().remove(0);
70  EntityCombobox combo = new EntityCombobox();
71  combo.setEntityPath(keyId);
72  combo.setWidth("400px");
73  combo.addEventListener(Events.ON_SELECT, (Event event) -> {
74  Events.postEvent(new InputEvent("onChange", this, combo.getEntityPath(), null));
75  });
76  getChildren().add(0, combo);
77  } else if(mode == ConstraintKeyMode.SOCIAL_GROUP) {
78  getChildren().remove(0);
79  SocialGroupListbox list = new SocialGroupListbox();
80  list.setMold("select");
81  list.setKeyString(keyId);
82  list.addEventListener(Events.ON_SELECT, (Event event) -> {
83  Events.postEvent(new InputEvent("onChange", this, list.getKeyString(), null));
84  });
85  getChildren().add(0, list);
86  }
87  }
88 
89  @Override
90  public void afterCompose() {
91  appendChild(new Space());
92  Toolbarbutton social = new Toolbarbutton();
93  social.setImage("/_zul/images/contact.png");
94  social.addEventListener(Events.ON_CLICK, (Event event) -> {
95  mode = ConstraintKeyMode.SOCIAL_GROUP;
96  updateControl(null);
97  });
98  appendChild(social);
99  Toolbarbutton entity = new Toolbarbutton();
100  entity.setImage("/_zul/images/entity.png");
101  entity.addEventListener(Events.ON_CLICK, (Event event) -> {
102  mode = ConstraintKeyMode.ENTITY;
103  updateControl(null);
104  });
105  appendChild(entity);
106  Toolbarbutton delete = new Toolbarbutton();
107  delete.setImage("/_zul/images/delete.png");
108  delete.addEventListener(Events.ON_CLICK, (Event event) -> {
109  mode = ConstraintKeyMode.EMPTY;
110  updateControl(null);
111  Events.postEvent(new InputEvent("onChange", this, "", null));
112  });
113  appendChild(delete);
114  }
115 
116 }