BrightSide Workbench Full Report + Source Code
ContractComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.elephant.context.Application;
22 import org.turro.elephant.util.Messages;
23 import org.turro.financials.account.logic.BankAccounts;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.Contract;
26 import org.turro.financials.handshake.HandshakeControl;
27 import org.turro.i18n.I_;
28 import org.turro.jpa.composer.EntityComposer;
29 import org.turro.jpa.entity.DaoEntity;
30 import org.turro.zul.acceptance.AcceptanceButton;
31 import org.turro.zul.frame.Framework;
32 import org.zkoss.zk.ui.Component;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zk.ui.select.annotation.Listen;
36 import org.zkoss.zk.ui.select.annotation.Wire;
37 import org.zkoss.zk.ui.util.Clients;
38 import org.zkoss.zul.Toolbarbutton;
39 
44 public class ContractComposer extends EntityComposer<Contract, Long> {
45 
46  @Wire("#handshake")
47  private HandshakeControl handshake;
48 
49  @Wire("#acceptance")
50  private AcceptanceButton acceptance;
51 
52  @Wire("#importBank")
53  private Toolbarbutton importBank;
54 
55  @Listen("onClick = #importBank")
56  public void onImportBank() {
58  Events.postEvent(new Event(Events.ON_CHANGE));
59  }
60 
61  @Override
62  protected String getAttributeName() {
63  return "contract";
64  }
65 
66  @Override
67  protected Contract getEntityInstance(Long id) {
68  if(id == null) {
69  entity = new Contract();
70  } else {
71  entity = new FinancialsPU().find(Contract.class, id);
72  }
73  return entity;
74  }
75 
76  @Override
77  protected DaoEntity getWrapperInstance(Component comp) {
81  return w;
82  }
83 
84 // @Override
85 // protected boolean beforeDelete() {
86 // ContractWrapper w = (ContractWrapper) getWrapper();
87 // return super.beforeSave() && !acceptance.isBlocked();
88 // }
89 
90  @Override
91  protected boolean beforeSave() {
92  if(entity.getContractPreferences().isEmpty() &&
93  !(entity.getContractDefinition().getDefaultContractPreference().getName().contentEquals("#"))) {
94  Messages.info(I_.get("Preferences")).add(I_.get("No value")).show();
95  return false;
96  }
97 // if(entity.getNotes() != null && (entity.getNotes().contains("IVA:#") || entity.getNotes().contains("IRPF:#"))) {
98 // ZkossUtils.showMessage(I_.get("Notes"), I_.get("Notes") + ": IVA/IRPF " + I_.get("No value"));
99 // return false;
100 // }
101 // ContractWrapper w = (ContractWrapper) getWrapper();
102 // return super.beforeSave() && (acceptance == null || !acceptance.isBlocked());
103  return super.beforeSave();
104  }
105 
106  @Override
107  protected void doOnDelete() {
108  Messages.confirmDeletion().show(() -> {
110  });
111  }
112 
113  @Override
114  public void doFinally() throws Exception {
115  super.doFinally();
116  if(entity.getId() == 0) {
117  acceptance.setVisible(false);
118  importBank.setVisible(false);
119  }
120  if(entity.getContractDefinition() == null ||
121  !entity.getContractDefinition().isCash()) {
122  importBank.setDisabled(true);
123  }
124  }
125 
126  @Override
127  protected boolean shouldBeSaved() {
128  return !entity.isEmpty() && (entity.getId() == 0) || super.shouldBeSaved();
129  }
130 
131  @Override
132  protected boolean inSaveRole() {
133  return Application.getApplication().isInRole("finan-contract:edit");
134  }
135 
136  @Override
137  protected boolean inDeleteRole() {
138  return Application.getApplication().isInRole("finan-contract:delete");
139  }
140 
141  @Override
142  protected boolean canClose() {
143  if(handshake.isMustSave()) {
144  Clients.showNotification(I_.get("Save before continue"));
145  return false;
146  } else {
147  return super.canClose();
148  }
149  }
150 
151 
152 }
static Messages confirmDeletion()
Definition: Messages.java:87
Messages add(String word)
Definition: Messages.java:50
static void importN43(final Contract contract)
static String get(String msg)
Definition: I_.java:41
static Framework getCurrent()
Definition: Framework.java:203
void setSelectedLabel(String text)
Definition: Framework.java:103
void setSelectedTooltiptext(String text)
Definition: Framework.java:107