BrightSide Workbench Full Report + Source Code
RelatedControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.related;
20 
21 import org.turro.elephant.entities.db.Related;
22 import org.turro.entities.Entities;
23 import org.zkoss.zk.ui.HtmlBasedComponent;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.Events;
26 import org.zkoss.zk.ui.ext.AfterCompose;
27 import org.zkoss.zul.Vlayout;
28 
33 public class RelatedControl extends Vlayout implements AfterCompose {
34 
35  private String entityPath;
36  private boolean allowMultiple = false, atRight = true;
37  private IAddRelated newControl = null;
38 
39  public String getEntityPath() {
40  return entityPath;
41  }
42 
43  public void setEntityPath(String entityPath) {
44  this.entityPath = entityPath;
45  }
46 
47  public void setEntity(Object entity) {
49  }
50 
51  public void setNewControl(IAddRelated newControl) {
52  this.newControl = newControl;
53  }
54 
55  public void setAllowMultiple(boolean allowMultiple) {
56  this.allowMultiple = allowMultiple;
57  }
58 
59  @Override
60  public void afterCompose() {
61  showRelations();
62  addEventListener(Events.ON_CHANGE, (Event event) -> {
63  showRelations();
64  });
65  }
66 
67  private void showRelations() {
68  getChildren().clear();
69  HtmlBasedComponent tmpCtrl = (newControl != null ? newControl.getControl(this) : null);
70  for(Related rp : Relateds.from(entityPath).destinations()) {
71  if(!allowMultiple) tmpCtrl = null;
72  appendChild(new RelatedLine(rp, true, (atRight ? tmpCtrl : null)));
73  tmpCtrl = null;
74  }
75  for(Related rp : Relateds.from(entityPath).origins()) {
76  if(!allowMultiple) tmpCtrl = null;
77  appendChild(new RelatedLine(rp, false, (atRight ? tmpCtrl : null)));
78  tmpCtrl = null;
79  }
80  if(tmpCtrl != null) {
81  appendChild(tmpCtrl);
82  if(tmpCtrl instanceof AfterCompose) {
83  ((AfterCompose) tmpCtrl).afterCompose();
84  }
85  }
86  }
87 
88 }
static IElephantEntity getController(String path)
Definition: Entities.java:78
void setAllowMultiple(boolean allowMultiple)
void setEntityPath(String entityPath)
void setNewControl(IAddRelated newControl)
static Relateds from(String entityPath)
Definition: Relateds.java:145
List< Related > destinations()
Definition: Relateds.java:68
HtmlBasedComponent getControl(HtmlBasedComponent base)