BrightSide Workbench Full Report + Source Code
EditSkillsControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.skills;
20 
21 import java.util.stream.Collectors;
22 import org.turro.string.Strings;
23 import org.turro.action.Actions;
24 import org.turro.collections.KeyValueMap;
25 import org.turro.elephant.TemplateControl;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.entities.db.Skill;
28 import org.turro.elephant.entities.db.SkillType;
29 import org.zkoss.zk.ui.event.InputEvent;
30 import org.zkoss.zk.ui.select.annotation.Listen;
31 import org.zkoss.zk.ui.select.annotation.Wire;
32 
37 public class EditSkillsControl extends TemplateControl {
38 
39  private String path, entityPath;
40 
41  @Wire("#knowledge") private SkillsChosenbox knowledge;
42  @Wire("#functional") private SkillsChosenbox functional;
43  @Wire("#attitude") private SkillsChosenbox attitude;
44 
45  @Listen("onSelect=#knowledge")
46  public void onKnowledge() {
47  Skills.setSkillsFor(entityPath, knowledge.getObjectValues()
48  .stream().map(s -> s.getFor(entityPath)).collect(Collectors.toSet()),
50  }
51 
52  @Listen("onSelect=#functional")
53  public void onFunctional() {
54  Skills.setSkillsFor(entityPath, functional.getObjectValues()
55  .stream().map(s -> s.getFor(entityPath)).collect(Collectors.toSet()),
57  }
58 
59  @Listen("onSelect=#attitude")
60  public void onAttitude() {
61  Skills.setSkillsFor(entityPath, attitude.getObjectValues()
62  .stream().map(s -> s.getFor(entityPath)).collect(Collectors.toSet()),
64  }
65 
66  @Listen("onSearch=#knowledge")
67  public void onNewKnowledge(InputEvent event) {
68  String value = event.getValue();
69  if(!Strings.isBlank(value)) {
70  Skill skill = new Skill();
71  skill.setSkill(value);
72  skill.setEntityPath(entityPath);
74  Skills.addSkillFor(entityPath, skill);
75  knowledge.addToModel(new SkillRoot(skill));
76  }
77  }
78 
79  @Listen("onSearch=#functional")
80  public void onNewFunctional(InputEvent event) {
81  String value = event.getValue();
82  if(!Strings.isBlank(value)) {
83  Skill skill = new Skill();
84  skill.setSkill(value);
85  skill.setEntityPath(entityPath);
87  Skills.addSkillFor(entityPath, skill);
88  functional.addToModel(new SkillRoot(skill));
89  }
90  }
91 
92  @Listen("onSearch=#attitude")
93  public void onNewAttitude(InputEvent event) {
94  String value = event.getValue();
95  if(!Strings.isBlank(value)) {
96  Skill skill = new Skill();
97  skill.setSkill(value);
98  skill.setEntityPath(entityPath);
100  Skills.addSkillFor(entityPath, skill);
101  attitude.addToModel(new SkillRoot(skill));
102  }
103  }
104 
105  @Listen("onClick=#cancel")
106  public void onCancel() {
108  }
109 
110  public String getPath() {
111  return path;
112  }
113 
114  public void setPath(String path) {
115  this.path = path;
116  }
117 
118  public String getEntityPath() {
119  return entityPath;
120  }
121 
122  public void setEntityPath(String entityPath) {
123  this.entityPath = entityPath;
124  }
125 
126  @Override
127  protected void doFinally() {
128  super.doFinally();
130  if(kvm != null && kvm.containsKey("entityPath")) {
131  entityPath = kvm.get("entityPath");
132  }
133  initComponents();
134  }
135 
136  private void initComponents() {
137  if(!Strings.isBlank(entityPath)) {
141  } else {
142  Application.getApplication().sendRedirect(path);
143  }
144  }
145 
146 }
147 
148 
static KeyValueMap getRightNowAction(IConstructor constructor)
Definition: Actions.java:341
abstract void sendRedirect(String uri)
void setSkill(String skill)
Definition: Skill.java:47
void setType(SkillType type)
Definition: Skill.java:63
void setEntityPath(String entityPath)
Definition: Skill.java:55
void onNewFunctional(InputEvent event)
void addToModel(SkillRoot value)
void setObjectValues(Collection< SkillRoot > internalValues)
static List< SkillRoot > getSkillsAsRootFrom(String entityPath, SkillType... types)
Definition: Skills.java:44
static void setSkillsFor(String entityPath, Set< Skill > skills, SkillType... types)
Definition: Skills.java:91
static void addSkillFor(String entityPath, Skill skill)
Definition: Skills.java:85