19 package org.turro.valuation;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.EnumSet;
24 import org.turro.elephant.util.DecimalFormats;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.turro.zkoss.input.ExpressionInput;
28 import org.turro.zkoss.label.AbstractLabel;
29 import org.turro.zkoss.label.LabelTip;
30 import org.turro.zul.frame.Framework;
31 import org.zkoss.zk.ui.Component;
32 import org.zkoss.zk.ui.event.Event;
33 import org.zkoss.zk.ui.event.EventListener;
34 import org.zkoss.zk.ui.event.Events;
35 import org.zkoss.zul.*;
36 import org.zkoss.zul.impl.XulElement;
46 unitFormat =
"#0.000";
48 protected ArrayList<XulElement>
unitHeads =
new ArrayList<XulElement>();
54 public void setModes(Collection<MarginOverCostMode> marginModes, Collection<PropossedPriceMode> priceModes) {
55 model.setMarginModes(marginModes);
56 model.setPriceModes(priceModes);
69 rows.getChildren().clear();
71 for(Value value :
model.getRootValues()) {
80 private void processValue(Value value) {
86 if(value.getChildren() !=
null) {
87 for(Value child : value.getChildren()) {
92 if(value.getResources() !=
null) {
93 for(Resource res : value.getResources()) {
94 Row rowRes =
new Row();
102 for(Object row :
getRows().getChildren()) {
103 if(row instanceof Row) {
104 if(((Row) row).getValue() instanceof ValuationItem) {
105 refreshValue((Row) row, (ValuationItem) ((Row) row).getValue());
113 row.getChildren().clear();
115 final EnumSet<ResourceStatus> status = value.getStatus();
118 row.setSclass(value.getType() +
"-row");
120 Hlayout hbox =
new Hlayout();
121 Space s =
new Space();
122 s.setWidth(value.getLevel() * 15 +
"px");
125 if(value instanceof Value) {
126 Toolbarbutton breakdown =
new Toolbarbutton();
128 breakdown.addEventListener(Events.ON_CLICK,
new EventListener() {
130 public void onEvent(Event event)
throws Exception {
135 hbox.appendChild(breakdown);
137 hbox.appendChild(
new Image(
"/_zul/images/" + value.getType() +
".png"));
138 hbox.appendChild(
new LabelTip(value.getName()));
139 if(value.getUsage() !=
null) {
140 hbox.appendChild(
new Space());
141 hbox.appendChild(
new Image(
"/_zul/images/" + value.getUsage().getType() +
".png"));
142 hbox.appendChild(
new LabelTip(value.getUsage().getName()));
144 row.appendChild(hbox);
146 if(value instanceof Value) {
147 if(((Value) value).getExpressedUnits() == 0.0d) {
148 row.appendChild(
new Space());
150 row.appendChild(
new Label(
DecimalFormats.
format(((Value) value).getExpressedUnits(), unitFormat)));
153 row.appendChild(
new Space());
162 protected void doSomething() {
163 if(status.contains(ResourceStatus.RESOURCE_NO_ESTIMATED_COST)) {
164 setSclass(
"warnLabel");
165 final Component comp =
this;
166 addEventListener(Events.ON_CLICK,
new EventListener() {
168 public void onEvent(Event event)
throws Exception {
169 showTooltip(comp, value);
178 protected void doSomething() {
179 if(status.contains(ResourceStatus.RESOURCE_NO_COST)) {
180 setSclass(
"warnLabel");
181 final Component comp =
this;
182 addEventListener(Events.ON_CLICK,
new EventListener() {
184 public void onEvent(Event event)
throws Exception {
185 showTooltip(comp, value);
196 row.appendChild(getFinalPriceCell(value, status));
200 protected void doSomething() {
201 if(status.contains(ResourceStatus.RESOURCE_UNDER_MARGIN)) {
202 setSclass(
"warnLabel");
203 final Component comp =
this;
204 addEventListener(Events.ON_CLICK,
new EventListener() {
206 public void onEvent(Event event)
throws Exception {
207 showTooltip(comp, value);
218 foot.setSclass(
"valuation-foot-row");
232 Auxhead ah =
new Auxhead();
235 Auxheader ahr =
new Auxheader();
238 ahr =
new Auxheader(
I_.
get(
"Units"));
239 ahr.setAlign(
"center");
244 ahr =
new Auxheader(
I_.
get(
"Cost"));
245 ahr.setAlign(
"center");
249 ahr =
new Auxheader(
I_.
get(
"Price"));
250 ahr.setAlign(
"center");
254 Columns cols =
new Columns();
255 cols.setSizable(
true);
258 Column col =
new Column();
260 cols.appendChild(col);
263 col.setLabel(
I_.
get(
"Expressed"));
264 col.setAlign(
"right");
265 col.setWidth(
"100px");
266 cols.appendChild(col);
270 col.setLabel(
I_.
get(
"Estimated"));
271 col.setAlign(
"right");
272 col.setWidth(
"100px");
273 cols.appendChild(col);
277 col.setLabel(
I_.
get(
"Real"));
278 col.setAlign(
"right");
279 col.setWidth(
"100px");
280 cols.appendChild(col);
284 col.setLabel(
I_.
get(
"Estimated"));
285 col.setAlign(
"right");
286 col.setWidth(
"100px");
287 cols.appendChild(col);
290 col.setLabel(
I_.
get(
"Real"));
291 col.setAlign(
"right");
292 col.setWidth(
"100px");
293 cols.appendChild(col);
296 col.setLabel(
I_.
get(
"Estimated"));
297 col.setAlign(
"right");
298 col.setWidth(
"100px");
299 cols.appendChild(col);
302 col.setLabel(
I_.
get(
"Real"));
303 col.setAlign(
"right");
304 col.setWidth(
"100px");
305 cols.appendChild(col);
308 col.setLabel(
I_.
get(
"Final"));
310 col.setWidth(
"140px");
311 cols.appendChild(col);
314 col.setLabel(
I_.
get(
"Profit margin"));
315 col.setAlign(
"right");
316 col.setWidth(
"100px");
317 cols.appendChild(col);
320 col.setLabel(
I_.
get(
"Market"));
321 col.setAlign(
"right");
322 col.setWidth(
"100px");
323 cols.appendChild(col);
327 Footer footer =
new Footer();
328 foot.appendChild(footer);
330 footer =
new Footer();
331 footer.setAlign(
"right");
332 foot.appendChild(footer);
335 footer =
new Footer();
336 footer.setAlign(
"right");
337 foot.appendChild(footer);
340 footer =
new Footer();
341 footer.setAlign(
"right");
342 foot.appendChild(footer);
345 footer =
new Footer();
346 footer.setAlign(
"right");
347 foot.appendChild(footer);
349 footer =
new Footer();
350 footer.setAlign(
"right");
351 foot.appendChild(footer);
353 footer =
new Footer();
354 footer.setAlign(
"right");
355 foot.appendChild(footer);
357 footer =
new Footer();
358 footer.setAlign(
"right");
359 foot.appendChild(footer);
361 footer =
new Footer();
362 footer.setAlign(
"right");
363 foot.appendChild(footer);
365 footer =
new Footer();
366 footer.setAlign(
"right");
367 foot.appendChild(footer);
369 footer =
new Footer();
370 footer.setAlign(
"right");
371 foot.appendChild(footer);
378 return "/_zul/images/breakdown-open.png";
380 return "/_zul/images/breakdown-closed.png";
385 if(value.getData() instanceof
NodeData) {
386 ((
NodeData) value.getData()).changeState();
391 if(value.getData() instanceof
NodeData) {
392 return ((
NodeData) value.getData()).showBreakdown;
398 Value tmp = value.getParent();
400 if(tmp.getData() instanceof
NodeData) {
401 if(!((
NodeData) tmp.getData()).showBreakdown) {
405 tmp = tmp.getParent();
410 private void showTooltip(Component comp, ValuationItem value) {
412 Include include =
new Include(
"/WEB-INF/_zul/erp/workorder/valuationStatus.zul");
413 include.setDynamicProperty(
"value", value);
414 popup.appendChild(include);
415 popup.open(comp,
"after_end");
418 private Hlayout getFinalPriceCell(
final ValuationItem value, EnumSet<ResourceStatus> status) {
419 Hlayout hbox =
new Hlayout();
420 final ExpressionInput finalPrice =
new ExpressionInput();
422 finalPrice.setValue(value.getAsModePrice());
423 finalPrice.setInplace(
true);
424 finalPrice.setHflex(
"true");
425 finalPrice.addEventListener(Events.ON_CHANGE,
new EventListener() {
427 public void onEvent(Event event)
throws Exception {
428 value.setFinalPrice(((Number) finalPrice.getNumber()).doubleValue());
429 Events.postEvent(
new Event(Events.ON_CHANGE, ValuesGrid.this));
433 hbox.appendChild(finalPrice);
434 Vlayout vbox =
new Vlayout();
435 vbox.setWidth(
"14px");
436 vbox.setSpacing(
"0px");
437 hbox.appendChild(vbox);
438 String type = ResourceStatus.getType(status);
440 final Image img =
new Image(
"/_zul/images/12/" + type +
".png");
441 img.setStyle(
"cursor:pointer");
442 img.addEventListener(Events.ON_CLICK,
new EventListener() {
444 public void onEvent(Event event)
throws Exception {
445 showTooltip(img, value);
448 vbox.appendChild(img);
450 if(status.contains(ResourceStatus.RESOURCE_UNDER_COST)) {
451 final Image img =
new Image(
"/_zul/images/12/warn.png");
452 img.setStyle(
"cursor:pointer");
453 img.addEventListener(Events.ON_CLICK,
new EventListener() {
455 public void onEvent(Event event)
throws Exception {
456 showTooltip(img, value);
459 vbox.appendChild(img);
static String get(String msg)
ValuationModel getValuationModel()
ArrayList< XulElement > unitHeads
boolean isShowBreakdown(ValuationItem value)
void refreshFoot(Foot foot)
void refreshValue(Row row, final ValuationItem value)
void setShowUnits(boolean showUnits)
boolean isVisible(ValuationItem value)
void changeBreakdownState(ValuationItem value)
void setModes(Collection< MarginOverCostMode > marginModes, Collection< PropossedPriceMode > priceModes)
String getBreakdownImage(ValuationItem value)
Foot getFoot(boolean create)
Rows getRows(boolean create)
void setRowCount(int rows)
static Framework getCurrent()