BrightSide Workbench Full Report + Source Code
ProductComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 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.product.logic;
20 
21 import org.turro.elephant.context.Application;
22 import org.turro.elephant.util.Messages;
23 import org.turro.fieldit.FieldItUtil;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.Product;
26 import org.turro.financials.menu.FinancialsMenu;
27 import org.turro.groupit.GroupItUtil;
28 import org.turro.jpa.composer.EntityComposer;
29 import org.turro.jpa.entity.DaoEntity;
30 import org.turro.zul.fieldit.ValueItGrid;
31 import org.turro.zul.frame.Framework;
32 import org.turro.zul.groupit.GroupedGrid;
33 import org.zkoss.zk.ui.Component;
34 import org.zkoss.zk.ui.select.annotation.Listen;
35 import org.zkoss.zk.ui.select.annotation.Wire;
36 
41 public class ProductComposer extends EntityComposer<Product, Long> {
42 
43  private boolean groupsChanged = false;
44 
45  @Wire("#groups")
46  private GroupedGrid groups;
47 
48  @Wire("#values")
49  private ValueItGrid values;
50 
51  @Listen("onChange = #groups")
52  public void onGroupsChange() {
53  groupsChanged = true;
54  }
55 
56  @Listen("onChange = #values")
57  public void onValuesChange() {
58  groupsChanged = true;
59  }
60 
61  @Override
62  protected String getAttributeName() {
63  return "product";
64  }
65 
66  @Override
67  protected Product getEntityInstance(Long id) {
68  if(id == null) {
69  entity = new Product();
70  } else {
71  entity = new FinancialsPU().find(Product.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 void afterSave() {
86  super.afterSave();
87  if(groups != null) {
90  }
91  if(entity != null) {
93  }
94  }
95 
96  @Override
97  protected void doOnDelete() {
98  Messages.confirmDeletion().show(() -> {
100  });
101  }
102 
103  @Override
104  protected boolean shouldBeSaved() {
105  return !entity.isEmpty() && (entity.getId() == 0) || super.shouldBeSaved() || groupsChanged;
106  }
107 
108  @Override
109  protected boolean inSaveRole() {
110  return Application.getApplication().isInRole("finan-product:edit");
111  }
112 
113  @Override
114  protected boolean inDeleteRole() {
115  return Application.getApplication().isInRole("finan-product:delete");
116  }
117 
118 }
static Messages confirmDeletion()
Definition: Messages.java:87
static void saveValues(Collection< ValueIt > values)
static void saveValues(Collection< Grouped > values)
Collection< ValueIt > getValues()
static Framework getCurrent()
Definition: Framework.java:203
void setSelectedLabel(String text)
Definition: Framework.java:103
void setSelectedTooltiptext(String text)
Definition: Framework.java:107