BrightSide Workbench Full Report + Source Code
CustomerOrderShow.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.reference;
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.DateFormats;
25 import org.turro.elephant.util.DecimalFormats;
26 import org.turro.elephant.util.ZkossUtils;
27 import org.turro.elephant.zkoss.Modal;
28 import org.turro.erp.entity.CustomerOrder;
29 import org.turro.erp.entity.OrderReference;
30 import org.turro.zkoss.layout.GridLayout;
31 import org.zkoss.zk.ui.Component;
32 import org.zkoss.zk.ui.Executions;
33 import org.zkoss.zk.ui.event.Event;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zk.ui.util.GenericForwardComposer;
36 import org.zkoss.zul.Label;
37 import org.zkoss.zul.Toolbarbutton;
38 import org.zkoss.zul.Window;
39 
44 public class CustomerOrderShow extends GenericForwardComposer {
45 
46  private Toolbarbutton newOrder, editOrder, deleteOrder;
47  private GridLayout order;
48  private Label orderId, orderDate, custCode, controlDate, delivery, description, quantity, price;
49  private OrderReference orderReference;
50 
51  public void onClick$newOrder() {
52  editOrder();
53  Events.postEvent(new Event(Events.ON_CHANGE));
54  }
55 
56  public void onClick$editOrder() {
57  editOrder();
58  Events.postEvent(new Event(Events.ON_CHANGE));
59  }
60 
61  public void onClick$deleteOrder() {
62  ZkossUtils.confirmDeletion(null, new Command() {
63  @Override
64  public Object execute(Context context) {
65  orderReference.setCustomerOrder(null);
66  updateControls();
67  Events.postEvent(new Event(Events.ON_CHANGE));
68  return null;
69  }
70  });
71  }
72 
73  private void editOrder() {
74  Window w = (Window) Executions.createComponents("/WEB-INF/_zul/erp/workorder/editCustomerOrder.zul", null, null);
75  w.setMode(Window.MODAL);
76  Events.sendEvent(Events.ON_USER, w, orderReference);
77  Modal.doModal(w, new Command() {
78  @Override
79  public Object execute(Context context) {
80  updateControls();
81  return null;
82  }
83  });
84  }
85 
86  @Override
87  public void doAfterCompose(Component comp) throws Exception {
88  super.doAfterCompose(comp);
89  orderReference = (OrderReference) order.getData();
90  updateControls();
91 
92  }
93 
94  private void updateControls() {
95  CustomerOrder customerOrder = orderReference.getCustomerOrder();
96  newOrder.setVisible(customerOrder == null);
97  editOrder.setVisible(!newOrder.isVisible());
98  deleteOrder.setVisible(!newOrder.isVisible());
99  order.setVisible(!newOrder.isVisible());
100  if(order.isVisible()) {
101  orderId.setValue(customerOrder.getOrderId());
102  orderDate.setValue(DateFormats.formatNull(customerOrder.getOrderDate(), true));
103  custCode.setValue(customerOrder.getCustomerCode());
104  controlDate.setValue(DateFormats.formatNull(customerOrder.getControlDate(), true));
105  delivery.setValue(DateFormats.formatNull(customerOrder.getDelivery(), true));
106  description.setValue(customerOrder.getDescription());
107  quantity.setValue(DecimalFormats.format(customerOrder.getQuantity()));
108  price.setValue(DecimalFormats.format(customerOrder.getPrice()) +
109  (customerOrder.isWantBudget() ? (" [" + Application.getString("lBudget") + "]") : ""));
110  } else {
111  orderId.setValue(null);
112  orderDate.setValue(null);
113  custCode.setValue(null);
114  controlDate.setValue(null);
115  delivery.setValue(null);
116  description.setValue(null);
117  quantity.setValue(null);
118  price.setValue(null);
119  }
120  }
121 
122 
123 }
static String getString(String key)
static String formatNull(Date d, boolean dateOnly)
static String format(Number value, String pattern)
static int doModal(String file)
Definition: Modal.java:38
void setCustomerOrder(CustomerOrder customerOrder)