BrightSide Workbench Full Report + Source Code
CommentPanel.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.issue.wizard;
20 
21 import org.turro.string.Strings;
22 import org.turro.elephant.context.Application;
23 import org.turro.i18n.I_;
24 import org.turro.jpa.input.EntityArrayListbox;
25 import org.turro.registry.ChangeCategory;
26 import org.turro.registry.DateTimeChange;
27 import org.turro.registry.NumberChange;
28 import org.turro.registry.UniqueNumber;
29 import org.turro.zkoss.input.ExpressionInput;
30 import org.turro.zkoss.label.LabelExtended;
31 import org.turro.zkoss.wizard.WizardPanelComposer;
32 import org.zkoss.zul.Datebox;
33 import org.zkoss.zul.Intbox;
34 import org.zkoss.zul.Textbox;
35 import org.zkoss.zul.Vlayout;
36 
41 public class CommentPanel extends WizardPanelComposer {
42 
43  private Textbox comment;
44  private Datebox control, delivery, startDate, commentDate;
45  private ExpressionInput inputexpenses, inputhours, inputprice;
46  private ExpressionInput expenses, hours, price;
47  private LabelExtended realexpenses, realhours, realprice,
48  leftexpenses, lefthours, leftprice;
49  private Vlayout arrayPanel;
50  private EntityArrayListbox array;
51  private Intbox count;
52 
53 
54  @Override
55  public boolean doEnter() {
58  commentDate.setValue(iw.date);
59  commentDate.setLenient(true);
60  commentDate.setFormat("short+short");
61  commentDate.setDisabled(!app.isInRole("issue:all"));
62  commentDate.setButtonVisible(!commentDate.isDisabled());
63  comment.setValue(iw.comment);
64  control.setValue(iw.issue.getControlDate());
65  control.setLenient(true);
66  control.setFormat("short+short");
67  delivery.setValue(iw.issue.getDelivery());
68  delivery.setLenient(true);
69  delivery.setFormat("short+short");
70  realexpenses.setDouble(iw.getIssue().getSumExpenses());
71  realhours.setDouble(iw.getIssue().getSumHours());
72  realprice.setDouble(iw.getIssue().getSumPrice());
73  inputexpenses.setValue(iw.expenses);
74  inputhours.setValue(iw.hours);
75  inputprice.setValue(iw.price);
76  startDate.setValue(iw.issue.getStartDate());
77  startDate.setLenient(true);
78  startDate.setFormat("short+short");
79  expenses.setValue(iw.issue.getExpenses());
80  hours.setValue(iw.issue.getHours());
81  price.setValue(iw.issue.getPrice());
82  updateWhatsLeft();
83  arrayPanel.setVisible(iw.issue.getId() == null || iw.issue.getId() == 0L);
84  onChange$startDate();
85  return true;
86  }
87 
88  @Override
89  public boolean doLeave(boolean forwards) {
90  ChangeCategory issueCat = new ChangeCategory(2, I_.get("Changes"));
91  ChangeCategory commentCat = new ChangeCategory(5, I_.get("Comment"));
93  if(commentDate.getValue() != null) iw.date = commentDate.getValue();
94  iw.comment = comment.getValue();
95  iw.changes.addChange(new DateTimeChange(issueCat, I_.get("Control"),
96  iw.issue.getControlDate(), control.getValue()));
97  iw.issue.setControlDate(control.getValue());
98  iw.changes.addChange(new DateTimeChange(issueCat, I_.get("Delivery"),
99  iw.issue.getDelivery(), delivery.getValue()));
100  iw.issue.setDelivery(delivery.getValue());
101  iw.expenses = inputexpenses.getDoubleValue();
102  iw.hours = inputhours.getDoubleValue();
103  iw.price = inputprice.getDoubleValue();
104  if(!Strings.isBlank(iw.comment)) {
105  iw.changes.addComment(commentCat, iw.comment);
106  }
107  if(iw.expenses != 0.0d) {
108  iw.changes.addChange(new UniqueNumber(issueCat, I_.get("Expenses"),
109  iw.expenses));
110  }
111  if(iw.hours != 0.0d) {
112  iw.changes.addChange(new UniqueNumber(issueCat, I_.get("Hours"),
113  iw.hours));
114  }
115  if(iw.price != 0.0d) {
116  iw.changes.addChange(new UniqueNumber(issueCat, I_.get("Price"),
117  iw.price));
118  }
119  iw.changes.addChange(new DateTimeChange(issueCat, I_.get("Start date"),
120  iw.issue.getStartDate(), startDate.getValue()));
121  iw.issue.setStartDate(startDate.getValue());
122  iw.changes.addChange(new NumberChange(issueCat, I_.get("Prevision") + "/" + I_.get("Expenses"),
123  iw.issue.getExpenses(), expenses.getDoubleValue()));
124  iw.issue.setExpenses(expenses.getDoubleValue());
125  iw.changes.addChange(new NumberChange(issueCat, I_.get("Prevision") + "/" + I_.get("Hours"),
126  iw.issue.getHours(), hours.getDoubleValue()));
127  iw.issue.setHours(hours.getDoubleValue());
128  iw.changes.addChange(new NumberChange(issueCat, I_.get("Prevision") + "/" + I_.get("Price"),
129  iw.issue.getPrice(), price.getDoubleValue()));
130  iw.issue.setPrice(price.getDoubleValue());
131  iw.repeat = array.getObjectValue();
132  iw.repeatCount = count.intValue();
133  return !forwards || ( true );
134  }
135 
136  public void onChange$inputexpenses() {
137  updateWhatsLeft();
138  }
139 
140  public void onChange$inputhours() {
141  updateWhatsLeft();
142  }
143 
144  public void onChange$inputprice() {
145  updateWhatsLeft();
146  }
147 
148  public void onChange$startDate() {
149  array.setDisabled(startDate.getValue() == null);
150  count.setDisabled(array.isDisabled());
151  }
152 
153  private void updateWhatsLeft() {
155  leftexpenses.setDouble(
156  expenses.getDoubleValue() -
157  iw.getIssue().getSumExpenses() -
158  inputexpenses.getDoubleValue()
159  );
160  lefthours.setDouble(
161  hours.getDoubleValue() -
162  iw.getIssue().getSumHours() -
163  inputhours.getDoubleValue()
164  );
165  leftprice.setDouble(
166  price.getDoubleValue() -
167  iw.getIssue().getSumPrice() -
168  inputprice.getDoubleValue()
169  );
170  }
171 
172 }
173 
void setControlDate(Date controlDate)
Definition: Issue.java:138
void setStartDate(Date startDate)
Definition: Issue.java:327
void setHours(double hours)
Definition: Issue.java:311
void setPrice(double price)
Definition: Issue.java:319
void setExpenses(double expenses)
Definition: Issue.java:303
void setDelivery(Date delivery)
Definition: Issue.java:146
static String get(String msg)
Definition: I_.java:41
boolean doLeave(boolean forwards)
LabelExtended setDouble(double value)