BrightSide Workbench Full Report + Source Code
WorksheetComposer.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.worksheet;
20 
21 import org.turro.auth.Authentication;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.turro.contacts.util.ContactControl;
25 import org.turro.dossier.db.DossierPU;
26 import org.turro.dossier.entity.Worksheet;
27 import org.turro.dossier.issue.IssueWrapper;
28 import org.turro.dossier.util.WorksheetUtil;
29 import org.turro.elephant.context.Application;
30 import org.turro.elephant.util.Messages;
31 import org.turro.i18n.I_;
32 import org.turro.jpa.Dao;
33 import org.turro.zkoss.dialog.SelectionDialog;
34 import org.turro.zkoss.input.CollectionListbox;
35 import org.turro.zul.frame.Framework;
36 import org.zkoss.zk.ui.Component;
37 import org.zkoss.zk.ui.select.SelectorComposer;
38 import org.zkoss.zk.ui.select.annotation.Listen;
39 import org.zkoss.zk.ui.select.annotation.Wire;
40 import org.zkoss.zul.Toolbarbutton;
41 
46 public class WorksheetComposer extends SelectorComposer<Component> {
47 
48  @Wire("#contact")
49  private ContactControl contact;
50 
51  @Wire("#save")
52  private Toolbarbutton save;
53 
54  @Wire("#worksheet")
55  private WorksheetGrid worksheet;
56 
57  @Listen("onChange = #contact")
58  public void onChangeValues() {
59  updateGrid();
60  }
61 
62  @Listen("onClick = #addIssue")
63  public void onAddIssue() {
65  @Override
66  protected String convertToString(IssueWrapper v) {
67  return v.getIssue().getFullDescription();
68  }
69  };
70  issues.setCheckmark(true);
71  issues.setMultiple(true);
72  issues.setSelectFirst(false);
73  issues.updateCollection(worksheet.getNotInGrid(contact.getIContact()));
75  Framework.getCurrent().getPage(),
76  I_.get("Issues"),
77  issues, "80%", "80%", new Command() {
78  @Override
79  public Object execute(Context context) {
80  if(issues != null) {
81  for(IssueWrapper iw : issues.getObjectValues()) {
82  worksheet.addValue(contact.getIContact(), iw);
83  }
84  save.setDisabled(!worksheet.isNeedSave());
85  }
86  return null;
87  }
88  });
89  }
90 
91  @Listen("onClick = #save")
92  public void onSave() {
93  if(contact.getIContact().isValid()) {
94  Dao dao = new DossierPU();
95  for(Worksheet ws : worksheet.getWorksheetModel()) {
96  ws.setIdContact(contact.getIContact().getId());
97  dao.saveObject(ws);
98  }
99  updateGrid();
100  }
101  }
102 
103  @Listen("onClick = #delete")
104  public void onDelete() {
105  if(contact.getIContact().isValid()) {
106  Messages.confirmDeletion().show(() -> {
108  updateGrid();
109  });
110  }
111  }
112 
113  @Listen("onChange = #worksheet")
114  public void onChangeGrid() {
115  save.setDisabled(!worksheet.isNeedSave());
116  }
117 
118  @Override
119  public void doFinally() throws Exception {
120  super.doFinally();
122  if(app.isInRole("worksheet:all")) {
123 
124  } else {
125  contact.setReadOnly(true);
126  }
128  updateGrid();
129  }
130 
131  private void updateGrid() {
132  worksheet.setValues(contact.getIContact());
133  save.setDisabled(!worksheet.isNeedSave());
134  }
135 
136 }
static void removeWorksheet(String idContact)
ListModelList< Worksheet > getWorksheetModel()
void addValue(IContact contact, IssueWrapper iw)
Collection< IssueWrapper > getNotInGrid(IContact contact)
static Messages confirmDeletion()
Definition: Messages.java:87
static String get(String msg)
Definition: I_.java:41
void setSelectFirst(boolean selectFirst)
static Framework getCurrent()
Definition: Framework.java:203