19 package org.turro.financials.contract;
21 import org.turro.string.Strings;
22 import org.turro.command.Command;
23 import org.turro.command.Context;
24 import org.turro.elephant.util.Messages;
25 import org.turro.financials.document.DocumentDefinitionListbox;
26 import org.turro.financials.entity.Contract;
27 import org.turro.financials.entity.ContractFlow;
28 import org.turro.financials.entity.DocumentDefinition;
29 import org.turro.i18n.I_;
30 import org.turro.jpa.entity.EntityCollections;
31 import org.turro.util.Chars;
32 import org.turro.zkoss.dialog.InputDialog;
33 import org.turro.zkoss.dialog.InputField;
34 import org.zkoss.zk.ui.HtmlBasedComponent;
35 import org.zkoss.zk.ui.event.Event;
36 import org.zkoss.zk.ui.event.EventListener;
37 import org.zkoss.zk.ui.event.Events;
38 import org.zkoss.zul.Tab;
39 import org.zkoss.zul.Tabbox;
40 import org.zkoss.zul.Tabpanel;
41 import org.zkoss.zul.Tabpanels;
42 import org.zkoss.zul.Tabs;
53 this.contract = contract;
62 new InputField(
"Document model", null, null, 0) {
64 protected HtmlBasedComponent createEditor() {
65 DocumentDefinitionListbox ddl = new DocumentDefinitionListbox(contract.getContractDefinition());
66 ddl.setMold(
"select");
67 if(contractFlow != null) {
68 ddl.setObjectValue(contractFlow.getDocumentDefinition());
76 public Object execute(Context context) {
78 if(fields.length > 0) {
79 String description =
null;
82 if(
"Description".equals(f.getLabel())) {
83 description = (String) f.getValue();
84 }
else if(
"Document model".equals(f.getLabel())) {
85 documentDefinition = (DocumentDefinition) f.getValue();
88 if(!Strings.isBlank(description) && documentDefinition !=
null) {
89 if(contractFlow ==
null) {
90 ContractFlow cf =
new ContractFlow();
91 cf.setDescription(description);
92 cf.setDocumentDefinition(documentDefinition);
93 cf.setContract(contract);
96 contractFlow.setDescription(description);
97 contractFlow.setDocumentDefinition(documentDefinition);
107 private void addTabs() {
108 getChildren().clear();
109 Tabs tabs =
new Tabs();
111 Tabpanels tabpanels =
new Tabpanels();
112 appendChild(tabpanels);
115 final Tab tab =
new Tab(cf.getDocumentDefinition().getName() + Chars.forward().spaced() + cf.getDescription());
116 tab.setClosable(
true);
117 tab.addEventListener(9000, Events.ON_CLOSE,
new EventListener<Event>() {
119 public void onEvent(Event event) throws Exception {
120 event.stopPropagation();
121 Messages.confirmDeletion().add(cf.getDescription()).show(() -> {
123 EntityCollections.entities(contract.getContractFlows()).remove(cf);
125 Events.postEvent(new Event(Events.ON_CHANGE, ContractFlowTabbox.this.getParent()));
129 tab.addEventListener(Events.ON_DOUBLE_CLICK,
new EventListener<Event>() {
131 public void onEvent(Event event) throws Exception {
135 tabs.appendChild(tab);
136 Tabpanel panel =
new Tabpanel();
137 ContractExpiriesGrid ceg =
new ContractExpiriesGrid(cf);
138 ceg.addEventListener(Events.ON_CHANGE,
new EventListener<Event>() {
140 public void onEvent(Event event) throws Exception {
141 Events.postEvent(new Event(Events.ON_CHANGE, ContractFlowTabbox.this.getParent()));
145 ceg.setReadOnly(
false);
146 ceg.setAllowDeletions(
true);
147 ceg.setAllowInsertions(
true);
148 panel.appendChild(ceg);
149 tabpanels.appendChild(panel);
152 Tab addFlow =
new Tab(
"+");
153 tabs.appendChild(addFlow);
154 addFlow.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
156 public void onEvent(Event event) throws Exception {
158 Events.postEvent(new Event(Events.ON_CHANGE, ContractFlowTabbox.this.getParent()));
void setContract(Contract contract)
void addFlow(final ContractFlow contractFlow)
Set< ContractFlow > getContractFlows()
static String get(String msg)