BrightSide Workbench Full Report + Source Code
ContractNotesComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.financials.contract.logic;
20 
21 import org.turro.financials.contract.ContractDefinitionCombobox;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.ContractDefinition;
24 import org.turro.financials.entity.ContractDefinitionNotes;
25 import org.zkoss.zk.ui.Component;
26 import org.zkoss.zk.ui.util.GenericForwardComposer;
27 import org.zkoss.zul.Textbox;
28 import org.zkoss.zul.Toolbarbutton;
29 
34 public class ContractNotesComposer extends GenericForwardComposer<Component> {
35 
36  private ContractDefinitionCombobox definition;
37  private Toolbarbutton save;
38  private Textbox notes;
39 
40  public void onChange$notes() {
41  save.setDisabled(false);
42  }
43 
44  public void onSelect$definition() {
45  ContractDefinition ctcdef = definition.getObjectValue();
46  if(ctcdef != null) {
47  if(ctcdef.getNotes() == null) {
48  notes.setValue("");
49  } else {
50  notes.setValue(ctcdef.getNotes().getNotes());
51  }
52  notes.setDisabled(false);
53  } else {
54  notes.setValue("");
55  notes.setDisabled(true);
56  }
57  save.setDisabled(true);
58  }
59 
60  public void onClick$save() {
61  ContractDefinition ctcdef = definition.getObjectValue();
62  if(ctcdef != null) {
63  ContractDefinitionNotes cdn = ctcdef.getNotes();
64  if(ctcdef.getNotes() == null) {
65  cdn = new ContractDefinitionNotes();
66  cdn.setContractDefinition(ctcdef);
67  }
68  cdn.setNotes(notes.getValue());
69  new FinancialsPU().saveObject(cdn);
70  }
71  save.setDisabled(true);
72  }
73 
74  @Override
75  public void doAfterCompose(Component comp) throws Exception {
76  super.doAfterCompose(comp);
77  save.setDisabled(true);
78  }
79 
80 }
void setContractDefinition(ContractDefinition contractDefinition)