BrightSide Workbench Full Report + Source Code
bserp-www/src/main/java/org/turro/erp/resource/logic/ResourceWrapper.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.erp.resource.logic;
19 
20 import org.turro.auth.Authentication;
21 import org.turro.command.Command;
22 import org.turro.command.Context;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.log.LogType;
25 import org.turro.elephant.util.ZkossUtils;
26 import org.turro.erp.aptitude.AptitudeDegreeCombobox;
27 import org.turro.erp.entity.AptitudeDegree;
28 import org.turro.erp.entity.Resource;
29 import org.turro.jpa.Dao;
30 import org.turro.jpa.entity.EntityCollectionUtil;
31 import org.turro.zkoss.dialog.InputDialog;
32 import org.turro.zkoss.dialog.InputField;
33 import org.turro.zul.frame.Framework;
34 import org.zkoss.zk.ui.HtmlBasedComponent;
35 
40 public class ResourceWrapper extends org.turro.erp.resource.ResourceWrapper {
41 
43  super(entity);
44  }
45 
46  @Override
47  public Resource save() {
48  super.save();
49  return entity;
50  }
51 
52  public void delete(final boolean close) {
53  // Check if possible and notify
54  if(canDelete()) {
55  ZkossUtils.confirmDeletion(null, new Command() {
56  @Override
57  public Object execute(Context context) {
58  if(ResourceWrapper.super.delete()) {
59  if(close) Framework.getCurrent().closeSelected();
60  }
61  return null;
62  }
63  });
64  }
65  }
66 
67  @Override
68  public boolean canDelete() {
69  if(entity.getId() == 0) return false;
70  Dao dao = getDao();
71 // Long count = (Long) dao.getSingleResult(
72 // "select count(*) from Document " +
73 // "where contract = ?",
74 // new Object[] { contract });
75 // if(count == 0) {
76 // count = (Long) dao.getSingleResult(
77 // "select count(*) from DocumentLine " +
78 // "where store = ?",
79 // new Object[] { contract });
80 // }
81 // return count == 0;
82  return true;
83  }
84 
85  public void addAptitude() {
87  Framework.getCurrent().getPage(),
88  Application.getString("lAptitudes"),
89  new InputField[] {
90  new InputField("lAptitude", null, null, 0) {
91  @Override
92  protected HtmlBasedComponent createEditor() {
93  return new AptitudeDegreeCombobox();
94  }
95  }
96  }, new Command() {
97  @Override
98  public Object execute(Context context) {
99  InputField[] fields = (InputField[]) context.get("fields");
100  if(fields.length > 0) {
101  for(InputField f : fields) {
102  if(f.getValue() != null && "lAptitude".equals(f.getLabel())) {
103  AptitudeDegree od = (AptitudeDegree) f.getValue();
104  entity.getAptitudeDegrees().add(od);
105  }
106  }
107  }
108  return null;
109  }
110  });
111  }
112 
113  public void deleteAptitude(AptitudeDegree aptitudeDegree) {
114  if(aptitudeDegree != null) {
115  EntityCollectionUtil.remove(entity.getAptitudeDegrees(), aptitudeDegree);
116  }
117  }
118 
119  @Override
120  protected void logEntity(LogType logType, String path, String action, String data) {
121  Authentication.log(logType, path, action, data);
122  }
123 
124 }
static String getString(String key)
static void getInput(Page page, String title, String label, Object value, String format, int scale, final Command onOk)
static Framework getCurrent()
Definition: Framework.java:203