BrightSide Workbench Full Report + Source Code
CategoryComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.dossier.zul.dossier;
20 
21 import java.util.HashSet;
22 import org.turro.action.queue.ConstraintKeys;
23 import org.turro.attach.zul.control.AttachmentControl;
24 import org.turro.dossier.db.DossierPU;
25 import org.turro.dossier.dossier.CategoryCombobox;
26 import org.turro.dossier.dossier.CategoryWrapper;
27 import org.turro.dossier.entity.Category;
28 import org.turro.dossier.entity.CategoryParticipant;
29 import org.turro.dossier.entity.DescriptorDefinition;
30 import org.turro.dossier.entity.WorthDefinition;
31 import org.turro.dossier.search.CategoryResults;
32 import org.turro.elephant.util.Messages;
33 import org.turro.file.zul.control.FileControl;
34 import org.turro.mail.queue.QueueManager;
35 import org.zkoss.zk.ui.Component;
36 import org.zkoss.zk.ui.select.SelectorComposer;
37 import org.zkoss.zk.ui.select.annotation.Listen;
38 import org.zkoss.zk.ui.select.annotation.Wire;
39 import org.zkoss.zul.Checkbox;
40 import org.zkoss.zul.Include;
41 import org.zkoss.zul.Label;
42 import org.zkoss.zul.Textbox;
43 import org.zkoss.zul.Toolbarbutton;
44 
49 public class CategoryComposer extends SelectorComposer<Component> {
50 
51  private Category category;
52 
53  @Wire("#category")
54  private org.turro.dossier.dossier.CategoryTree categoryTree;
55 
56  @Wire("#identifier")
57  private Label identifier;
58 
59  @Wire("#description")
60  private Textbox description;
61 
62  @Wire("#parent")
63  private CategoryCombobox parent;
64 
65  @Wire("#kbase")
66  private Checkbox kbase;
67 
68  @Wire("#ownprj")
69  private Checkbox ownprj;
70 
71  @Wire("#participantGrid")
72  private CategoryParticipantGrid participantGrid;
73 
74  @Wire("#descriptorsGrid")
75  private DescriptorDefinitionGrid descriptorDefinitionGrid;
76 
77  @Wire("#worthsGrid")
78  private WorthDefinitionGrid worthDefinitionGrid;
79 
80  @Wire("#createCategory")
81  private Toolbarbutton createCategory;
82 
83  @Wire("#saveCategory")
84  private Toolbarbutton saveCategory;
85 
86  @Wire("#deleteCategory")
87  private Toolbarbutton deleteCategory;
88 
89  @Wire("#attachments")
90  private AttachmentControl attachments;
91 
92  @Wire("#files")
93  private FileControl files;
94 
95  @Wire("#webContent")
96  private Include webContent;
97 
98  @Listen("onSelect = #category")
99  public void onSelectCategory() {
100  category = categoryTree.getSelectedCategory();
101  if(category != null) {
102  identifier.setValue(category.getId() + "");
103  description.setValue(category.getDescription());
104  parent.setCategory(category.getParent());
105  kbase.setChecked(category.isKnowledgeBase());
106  ownprj.setChecked(category.isOwnsProjects());
107  participantGrid.setCategory(category);
108  descriptorDefinitionGrid.setCategory(category);
109  worthDefinitionGrid.setCategory(category);
110  attachments.setEntity(category);
111  attachments.setLabel(category.getDescription());
112  attachments.setPublicOnly(!(new CategoryWrapper(category).getCanShowAllAttachments()));
113  attachments.afterCompose();
114  files.setEntity(category);
115  files.setLabel(category.getDescription());
116  files.afterCompose();
117  webContent.setAttribute("entity", categoryTree.getSelectedCategory());
118  webContent.invalidate();
119  saveCategory.setDisabled(false);
120  deleteCategory.setDisabled(!(new CategoryWrapper(category).canDelete()));
121  } else {
122  identifier.setValue(null);
123  description.setValue(null);
124  parent.setCategory(null);
125  kbase.setChecked(false);
126  ownprj.setChecked(false);
127  participantGrid.setCategory(null);
128  descriptorDefinitionGrid.setCategory(null);
129  worthDefinitionGrid.setCategory(category);
130  attachments.setEntity(null);
131  attachments.setLabel("");
132  attachments.afterCompose();
133  files.setEntity(null);
134  files.setLabel("");
135  files.afterCompose();
136  webContent.setAttribute("entity", null);
137  webContent.invalidate();
138  saveCategory.setDisabled(true);
139  }
140  }
141 
142  @Listen("onClick = #createCategory")
143  public void onCreateCategory() {
144  category = new Category();
145  identifier.setValue("<auto>");
146  description.setValue(category.getDescription());
147  parent.setCategory(category.getParent());
148  kbase.setChecked(category.isKnowledgeBase());
149  ownprj.setChecked(category.isOwnsProjects());
150  participantGrid.setCategory(category);
151  descriptorDefinitionGrid.setCategory(category);
152  worthDefinitionGrid.setCategory(category);
153  attachments.setEntity(null);
154  attachments.setLabel("");
155  attachments.afterCompose();
156  files.setEntity(null);
157  files.setLabel("");
158  files.afterCompose();
159  webContent.setAttribute("entity", null);
160  webContent.invalidate();
161  saveCategory.setDisabled(false);
162  deleteCategory.setDisabled(true);
163  }
164 
165  @Listen("onClick = #saveCategory")
166  public void onSaveCategory() {
167  category.setDescription(description.getValue());
168  category.setParent(parent.getCategory());
169  category.setKnowledgeBase(kbase.isChecked());
170  category.setOwnsProjects(ownprj.isChecked());
171  category.setParticipants(new HashSet<CategoryParticipant>(participantGrid.getValues()));
172  category.setDescriptors(new HashSet<DescriptorDefinition>(descriptorDefinitionGrid.getValues()));
173  category.setWorths(new HashSet<WorthDefinition>(worthDefinitionGrid.getValues()));
174  if(!category.isEmpty()) {
175  for(CategoryParticipant p : category.getParticipants()) {
176  p.setRole(p.getRole()); //ensure properties for owner
177  }
178  CategoryResults.saveCategory(category);
179  for(CategoryParticipant p : category.getParticipants()) {
180  new QueueManager().subscribeDefaults(ConstraintKeys.from(p.getIContact()));
181  }
182  categoryTree.reloadContents();
183  parent.refreshModel();
185  }
186  }
187 
188  @Listen("onClick = #deleteCategory")
189  public void onDeleteCategory() {
190  final Category cat = categoryTree.getSelectedCategory();
191  if(cat != null) {
193  new CategoryWrapper(cat).delete();
194  categoryTree.reloadContents();
196  });
197  }
198  }
199 
200  @Override
201  public void doFinally() throws Exception {
202  super.doFinally();
203  saveCategory.setDisabled(true);
204  deleteCategory.setDisabled(true);
206  }
207 
208 }
static ConstraintKeys from(IContact contact)
Set< CategoryParticipant > getParticipants()
Definition: Category.java:116
void setParticipants(Set< CategoryParticipant > participants)
Definition: Category.java:124
void setOwnsProjects(boolean ownsProjects)
Definition: Category.java:156
void setDescription(String description)
Definition: Category.java:96
void setParent(Category parent)
Definition: Category.java:112
void setWorths(Set< WorthDefinition > worths)
Definition: Category.java:172
void setKnowledgeBase(boolean knowledgeBase)
Definition: Category.java:148
void setDescriptors(Set< DescriptorDefinition > descriptors)
Definition: Category.java:164
static void saveCategory(Category category)
static Messages confirmDeletion()
Definition: Messages.java:87
Messages add(String word)
Definition: Messages.java:50
void subscribeDefaults(ConstraintKeys keys)