BrightSide Workbench Full Report + Source Code
LineTypePreferenceListbox.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.linetype;
19 
20 import org.turro.financials.entity.ContractPreference;
21 import org.turro.financials.entity.Document;
22 import org.turro.financials.entity.DocumentDefinition;
23 import org.turro.financials.entity.LineType;
24 import org.turro.financials.model.contract.ContractDefinitionWrapper;
25 import org.turro.financials.model.document.LineTypeSet;
26 import org.turro.zkoss.input.CollectionListbox;
27 
32 public class LineTypePreferenceListbox extends CollectionListbox<LineType> {
33 
35  }
36 
38  setCollection(document.getLineTypes());
39  }
40 
41  public LineTypePreferenceListbox(Document document, DocumentDefinition descendant) {
42  LineTypeSet result = new LineTypeSet();
43  if(document != null && descendant != null) {
45  document.getContract().getContractDefinition()).getLineTypesFor(
46  document.getDocumentDefinition(), descendant);
47  for(LineType lt : lts) {
48  if(lt.getName().contains("%n")) {
49  if(document.getContract().getContractPreferences().isEmpty()) {
50  LineType ltt = lt.clone();
52  result.add(ltt);
53  } else {
55  LineType ltt = lt.clone();
56  ltt.setContractPreference(cp);
57  result.add(ltt);
58  }
59  }
60  } else {
61  LineType ltt = lt.clone();
63  result.add(ltt);
64  }
65  }
66  }
67  setCollection(result);
68  }
69 
70  public void setDocument(Document document) {
71  updateCollection(document.getLineTypes());
72  }
73 
74  public void setRegexp(String regexp) {
75  setCollection(new LineTypeSet(regexp));
76  }
77 
78  @Override
79  protected String convertToString(LineType v) {
80  return v == null ? "" : v.getComposedName();
81  }
82 
83 }
ContractDefinition getContractDefinition()
Definition: Contract.java:125
Set< ContractPreference > getContractPreferences()
Definition: Contract.java:145
ContractPreference getDefaultContractPreference()
Definition: Document.java:429
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
Collection< LineType > getLineTypes()
Definition: Document.java:734
void setContractPreference(ContractPreference contractPreference)
Definition: LineType.java:81
LineTypePreferenceListbox(Document document, DocumentDefinition descendant)
void setCollection(Collection< V > collection)