BrightSide Workbench Full Report + Source Code
PortfolioStatusDetailRow.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.financials.portfolio;
19 
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.turro.elephant.db.WhereClause;
23 import org.turro.financials.model.contract.PortfolioStatus;
24 import org.turro.i18n.I_;
25 import org.turro.plugin.filter.IFilterValue;
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.Detail;
30 
35 public class PortfolioStatusDetailRow extends Detail {
36 
37  private PortfolioStatus portfolioStatus;
38 
39  public PortfolioStatusDetailRow(PortfolioStatus portfolioStatus) {
40  this.portfolioStatus = portfolioStatus;
41  addEventListener(Events.ON_OPEN, new EventListener() {
42  @Override
43  public void onEvent(Event event) throws Exception {
44  fillDetail();
45  }
46  });
47  }
48 
49  private void fillDetail() {
50  if(getChildren().isEmpty()) {
51  IFilterValue fv = new IFilterValue() {
52  @Override
53  public void addConstraint(WhereClause wc) {
54  wc.addClause("and doc.contract = :contract");
55  wc.addNamedValue("contract", portfolioStatus.getContract());
56  }
57  @Override
58  public String getLabel() {
59  return I_.get("Contract");
60  }
61  @Override
62  public boolean hasValue() {
63  return true;
64  }
65  };
66  List<IFilterValue> l = new ArrayList<IFilterValue>();
67  l.add(fv);
68  PortfolioGrid pg = new PortfolioGrid();
69  pg.getFilter().load(RelationMode.RELATE_BOTH, l);
70  pg.setDefaultBehavior(false);
71  appendChild(pg);
72  pg.afterCompose();
73  pg.reload();
74  PortfolioDisagreementsGrid pdg = new PortfolioDisagreementsGrid(portfolioStatus.getContract());
75  if(!pdg.getCollection().isEmpty()) {
76  pdg.setDefaultBehavior(false);
77  appendChild(pdg);
78  pdg.afterCompose();
79  }
80  }
81  }
82 }
void addNamedValue(String name, Object value)