BrightSide Workbench Full Report + Source Code
AssistantsVM.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.assistant.model;
20 
21 import org.turro.ws.service.ServerAdapter;
22 import java.util.HashSet;
23 import java.util.List;
24 import java.util.Set;
25 import org.turro.assistant.Assistant;
26 import org.turro.assistant.AssistantConstants;
27 import org.turro.assistant.AssistantSet;
28 import org.turro.assistant.Assistants;
29 import org.turro.string.Strings;
30 import org.zkoss.bind.annotation.BindingParam;
31 import org.zkoss.bind.annotation.Command;
32 import org.zkoss.bind.annotation.ExecutionArgParam;
33 import org.zkoss.bind.annotation.Init;
34 import org.zkoss.bind.annotation.NotifyChange;
35 
40 public class AssistantsVM {
41 
42  @Init
43  public void init(@ExecutionArgParam("as") AssistantSet assistants,
44  @ExecutionArgParam("servers") List<ServerAdapter> servers) {
45  this.assistants = assistants;
46  this.servers = servers;
47  }
48 
49  @NotifyChange("assistants")
50  @Command("add")
51  public void add() {
52  Assistants.addAssistantsFromEntity(entity, false, assistants, Strings.listToCvs(modifiers));
53  }
54 
55  @NotifyChange("assistants")
56  @Command("addDeep")
57  public void addDeep() {
58  Assistants.addAssistantsFromEntity(entity, true, assistants, Strings.listToCvs(modifiers));
59  }
60 
61  @NotifyChange("assistants")
62  @Command("delete")
63  public void delete(@BindingParam("assistant") Assistant assistant) {
64  assistants.remove(assistant);
65  }
66 
67  public boolean isWithServers() {
68  return !servers.isEmpty();
69  }
70 
71  /* Modifiers */
72 
73  private final Set<String> modifiers = new HashSet<>();
74 
75  public boolean getFromComments() {
76  return modifiers.contains(AssistantConstants.FROM_COMMENTS);
77  }
78 
79  public void setFromComments(boolean value) {
80  if(value) {
81  modifiers.add(AssistantConstants.FROM_COMMENTS);
82  } else {
83  modifiers.remove(AssistantConstants.FROM_COMMENTS);
84  }
85  }
86 
87  public boolean getFromVotes() {
88  return modifiers.contains(AssistantConstants.FROM_VOTES);
89  }
90 
91  public void setFromVotes(boolean value) {
92  if(value) {
93  modifiers.add(AssistantConstants.FROM_VOTES);
94  } else {
95  modifiers.remove(AssistantConstants.FROM_VOTES);
96  }
97  }
98 
99  public boolean getFromSubscriptions() {
100  return modifiers.contains(AssistantConstants.FROM_SUBSCRIPTIONS);
101  }
102 
103  public void setFromSubscriptions(boolean value) {
104  if(value) {
105  modifiers.add(AssistantConstants.FROM_SUBSCRIPTIONS);
106  } else {
107  modifiers.remove(AssistantConstants.FROM_SUBSCRIPTIONS);
108  }
109  }
110 
111  public boolean getFromStudents() {
112  return modifiers.contains(AssistantConstants.FROM_STUDENTS);
113  }
114 
115  public void setFromStudents(boolean value) {
116  if(value) {
117  modifiers.add(AssistantConstants.FROM_STUDENTS);
118  } else {
119  modifiers.remove(AssistantConstants.FROM_STUDENTS);
120  }
121  }
122 
123  public boolean getFromForum() {
124  return modifiers.contains(AssistantConstants.FROM_FORUM);
125  }
126 
127  public void setFromForum(boolean value) {
128  if(value) {
129  modifiers.add(AssistantConstants.FROM_FORUM);
130  } else {
131  modifiers.remove(AssistantConstants.FROM_FORUM);
132  }
133  }
134 
135  /* Entity */
136 
137  private Object entity;
138 
139  public Object getEntity() {
140  return entity;
141  }
142 
143  public void setEntity(Object entity) {
144  this.entity = entity;
145  }
146 
147  /* Models */
148 
149  private List<ServerAdapter> servers;
150 
151  public List<ServerAdapter> getServers() {
152  return servers;
153  }
154 
155  /* Assistants */
156 
157  private AssistantSet assistants;
158 
160  return assistants;
161  }
162 
163 }
static void addAssistantsFromEntity(Object entity, boolean deep, AssistantSet list, Object data)
Definition: Assistants.java:52
void init(@ExecutionArgParam("as") AssistantSet assistants, @ExecutionArgParam("servers") List< ServerAdapter > servers)
void delete(@BindingParam("assistant") Assistant assistant)