BrightSide Workbench Full Report + Source Code
WorkOrderComposer.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.erp.workorder.logic;
20 
21 import org.turro.command.Command;
22 import org.turro.command.Context;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.util.ZkossUtils;
25 import org.turro.erp.db.ErpPU;
26 import org.turro.erp.entity.OrderReference;
27 import org.turro.erp.entity.WorkOrder;
28 import org.turro.erp.menu.ErpMenu;
29 import org.turro.erp.reference.OrderReferenceGrid;
30 import org.turro.jpa.composer.EntityComposer;
31 import org.turro.jpa.entity.DaoEntity;
32 import org.turro.zul.frame.Framework;
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 import org.zkoss.zul.Tab;
37 
42 public class WorkOrderComposer extends EntityComposer<WorkOrder, Long> {
43 
44  @Wire("#tabtasks")
45  private Tab tabtasks;
46 
47  @Wire("#tabvaluation")
48  private Tab tabvaluation;
49 
50  @Wire("#tabbudgets")
51  private Tab tabbudgets;
52 
53  @Wire("#lines")
54  private OrderReferenceGrid lines;
55 
56  @Listen("onSelect = #tablines")
57  public void onSelectLines() {
58  lines.updateRows();
59  }
60 
61  @Override
62  protected String getAttributeName() {
63  return "workOrder";
64  }
65 
66  @Override
67  protected WorkOrder getEntityInstance(Long id) {
68  if(id == null) {
69  entity = new WorkOrder();
70  entity.setWorkOrderDate(new java.util.Date());
71  entity.setDescription("");
72  } else {
73  entity = new ErpPU().find(WorkOrder.class, id);
74  }
75  return entity;
76  }
77 
78  @Override
79  protected DaoEntity getWrapperInstance(Component comp) {
82  Framework.getCurrent().setSelectedTooltiptext(entity.getFullDescription());
83  return w;
84  }
85 
86  @Override
87  public void afterSave() {
88  if(entity != null) {
90  }
91  }
92 
93  @Override
94  protected void doOnChange() {
95  super.doOnChange();
96  tabtasks.setDisabled(!canViewTasks());
97  tabvaluation.setDisabled(tabtasks.isDisabled());
98  tabbudgets.setDisabled(tabtasks.isDisabled());
99  }
100 
101  @Override
102  protected void doOnDelete() {
103  ZkossUtils.confirmDeletion(null, new Command() {
104  @Override
105  public Object execute(Context context) {
106  WorkOrderComposer.super.onDelete();
107  return null;
108  }
109  });
110 
111  }
112 
113  @Override
114  protected boolean shouldBeSaved() {
115  return !entity.isEmpty() && (entity.getId() == 0) || super.shouldBeSaved();
116  }
117 
118  @Override
119  protected boolean inSaveRole() {
120  return Application.getApplication().isInRole("erp-workorder:edit");
121  }
122 
123  @Override
124  protected boolean inDeleteRole() {
125  return Application.getApplication().isInRole("erp-workorder:delete");
126  }
127 
128  private boolean canViewTasks() {
129  for(OrderReference or : entity.getOrderReferences()) {
130  if(!or.isEmpty() && or.getId() < 1) {
131  return false;
132  }
133  }
134  return true;
135  }
136 
137 }
static void showWorkOrder(WorkOrder workOrder)
Definition: ErpMenu.java:123
static Framework getCurrent()
Definition: Framework.java:203
void setSelectedLabel(String text)
Definition: Framework.java:103
void setSelectedTooltiptext(String text)
Definition: Framework.java:107