BrightSide Workbench Full Report + Source Code
ResourcesGrid.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.valuation;
20 
21 import org.turro.elephant.util.DecimalFormats;
22 import org.turro.i18n.I_;
23 import org.turro.zkoss.grid.PagingGrid;
24 import org.turro.zkoss.input.ExpressionInput;
25 import org.turro.zkoss.label.LabelTip;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.EventListener;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zul.*;
30 
35 public class ResourcesGrid extends PagingGrid {
36 
37  protected ValuationModel model;
38  protected String currencyFormat = "#0.00",
39  unitFormat = "#0.000";
40 
41  public void setValuationModel(ValuationModel model) {
42  this.model = model;
43  addColumns();
44  addRows();
45  }
46 
47  protected void addRows() {
48  Rows rows = getRows(true);
49  rows.getChildren().clear();
50 
51  for(ResourceRef resRef : model.getResources()) {
52  processResource(resRef);
53  }
54 
55  setRowCount(rows.getChildren().size());
56  }
57 
58  private void processResource(final ResourceRef resRef) {
59  Row row = new Row();
60  row.setValue(resRef);
61 
62  row.setSclass(resRef.getType() + "-res-row");
63 
64  Hlayout hbox = new Hlayout();
65  hbox.appendChild(new Image("/_zul/images/" + resRef.getType() + ".png"));
66  hbox.appendChild(new LabelTip(resRef.getName()));
67  row.appendChild(hbox);
68 
69  row.appendChild(new Label(DecimalFormats.format(resRef.getEstimatedUnits(), unitFormat)));
70  row.appendChild(new Label(DecimalFormats.format(resRef.getRealUnits(), unitFormat)));
71  row.appendChild(new Label(DecimalFormats.format(resRef.getUnitPrice(), currencyFormat)));
72 
73  final ExpressionInput finalPrice = new ExpressionInput();
74  finalPrice.setInplace(true);
75  finalPrice.setValue(resRef.getFinalPrice());
76  finalPrice.setCols(12);
77  finalPrice.addEventListener(Events.ON_CHANGE, new EventListener() {
78  @Override
79  public void onEvent(Event event) throws Exception {
80  resRef.setFinalPrice(((Number) finalPrice.getNumber()).doubleValue());
81  Events.postEvent(new Event(Events.ON_CHANGE, ResourcesGrid.this));
82  }
83  });
84  row.appendChild(finalPrice);
85 
86  getRows().appendChild(row);
87  }
88 
89  protected void addColumns() {
90  Auxhead ah = new Auxhead();
91  appendChild(ah);
92 
93  Auxheader ahr = new Auxheader();
94  ah.appendChild(ahr);
95 
96  ahr = new Auxheader(I_.get("Units"));
97  ahr.setAlign("center");
98  ahr.setColspan(2);
99  ah.appendChild(ahr);
100 
101  ahr = new Auxheader(I_.get("Price"));
102  ahr.setAlign("center");
103  ahr.setColspan(2);
104  ah.appendChild(ahr);
105 
106  Columns cols = new Columns();
107  cols.setSizable(true);
108  appendChild(cols);
109 
110  Column col = new Column();
111  col.setLabel(I_.get("Resource"));
112  col.setHflex("1");
113  cols.appendChild(col);
114 
115  col = new Column();
116  col.setLabel(I_.get("Estimated"));
117  col.setHflex("min");
118  cols.appendChild(col);
119 
120  col = new Column();
121  col.setLabel(I_.get("Real"));
122  col.setHflex("min");
123  cols.appendChild(col);
124 
125  col = new Column();
126  col.setLabel(I_.get("Market"));
127  col.setHflex("min");
128  cols.appendChild(col);
129 
130  col = new Column();
131  col.setLabel(I_.get("Final"));
132  col.setHflex("min");
133  cols.appendChild(col);
134  }
135 
136 }
static String format(Number value, String pattern)
static String get(String msg)
Definition: I_.java:41
void setValuationModel(ValuationModel model)
Rows getRows(boolean create)