18 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.finance.accounting.element;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
|
|
17 |
import org.openconcerto.erp.core.finance.accounting.model.AssociationAnalytiqueModel;
|
|
|
18 |
import org.openconcerto.erp.core.finance.accounting.ui.PlanComptableCellRenderer;
|
|
|
19 |
import org.openconcerto.erp.element.objet.ClasseCompte;
|
|
|
20 |
import org.openconcerto.sql.element.BaseSQLComponent;
|
|
|
21 |
import org.openconcerto.sql.element.SQLComponent;
|
|
|
22 |
import org.openconcerto.sql.model.SQLSelect;
|
|
|
23 |
import org.openconcerto.sql.model.SQLTable;
|
80 |
ilm |
24 |
import org.openconcerto.sql.model.SQLTableEvent;
|
|
|
25 |
import org.openconcerto.sql.model.SQLTableModifiedListener;
|
18 |
ilm |
26 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
27 |
|
|
|
28 |
import java.awt.GridBagConstraints;
|
|
|
29 |
import java.awt.GridBagLayout;
|
|
|
30 |
import java.util.ArrayList;
|
|
|
31 |
import java.util.List;
|
|
|
32 |
import java.util.Vector;
|
|
|
33 |
|
|
|
34 |
import javax.swing.DefaultCellEditor;
|
|
|
35 |
import javax.swing.JComboBox;
|
|
|
36 |
import javax.swing.JScrollPane;
|
|
|
37 |
import javax.swing.JTabbedPane;
|
|
|
38 |
import javax.swing.JTable;
|
|
|
39 |
|
|
|
40 |
import org.apache.commons.dbutils.handlers.ArrayListHandler;
|
|
|
41 |
|
|
|
42 |
public class AssociationCompteAnalytiqueSQLElement extends ComptaSQLConfElement {
|
|
|
43 |
|
|
|
44 |
private JTabbedPane tabbedClasse;
|
|
|
45 |
|
|
|
46 |
// private JTable compteRep;
|
|
|
47 |
|
|
|
48 |
public AssociationCompteAnalytiqueSQLElement() {
|
|
|
49 |
super("ASSOCIATION_COMPTE_ANALYTIQUE", "une association compte analytique", "associations comptes analytiques");
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
@Override
|
|
|
53 |
protected List<String> getListFields() {
|
|
|
54 |
final List<String> l = new ArrayList<String>();
|
|
|
55 |
l.add("ID_COMPTE_PCE");
|
|
|
56 |
l.add("ID_REPARTITION_ANALYTIQUE");
|
|
|
57 |
l.add("ID_AXE_ANALYTIQUE");
|
|
|
58 |
return l;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
protected List<String> getComboFields() {
|
|
|
62 |
final List<String> l = new ArrayList<String>();
|
|
|
63 |
l.add("ID_COMPTE_PCE");
|
|
|
64 |
l.add("ID_REPARTITION_ANALYTIQUE");
|
|
|
65 |
return l;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/*
|
|
|
69 |
* (non-Javadoc)
|
|
|
70 |
*
|
|
|
71 |
* @see org.openconcerto.devis.SQLElement#getComponent()
|
|
|
72 |
*/
|
|
|
73 |
public SQLComponent createComponent() {
|
|
|
74 |
return new BaseSQLComponent(this) {
|
|
|
75 |
public void addViews() {
|
|
|
76 |
this.setLayout(new GridBagLayout());
|
|
|
77 |
|
|
|
78 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
79 |
c.weightx = 1;
|
|
|
80 |
c.weighty = 1;
|
|
|
81 |
c.fill = GridBagConstraints.BOTH;
|
|
|
82 |
|
|
|
83 |
final List<ClasseCompte> classeComptes = new ArrayList<ClasseCompte>();
|
|
|
84 |
tabbedClasse = new JTabbedPane();
|
|
|
85 |
|
80 |
ilm |
86 |
final SQLTable classeCompteTable = getTable().getBase().getTable("CLASSE_COMPTE");
|
|
|
87 |
final SQLSelect selClasse = new SQLSelect();
|
18 |
ilm |
88 |
selClasse.addSelect(classeCompteTable.getField("ID"));
|
|
|
89 |
selClasse.addSelect(classeCompteTable.getField("NOM"));
|
|
|
90 |
selClasse.addSelect(classeCompteTable.getField("TYPE_NUMERO_COMPTE"));
|
|
|
91 |
selClasse.addRawOrder("TYPE_NUMERO_COMPTE");
|
|
|
92 |
|
|
|
93 |
String reqClasse = selClasse.asString();
|
|
|
94 |
Object obClasse = getTable().getBase().getDataSource().execute(reqClasse, new ArrayListHandler());
|
|
|
95 |
|
80 |
ilm |
96 |
List<Object[]> myListClasse = (List<Object[]>) obClasse;
|
|
|
97 |
for (Object[] objTmp : myListClasse) {
|
18 |
ilm |
98 |
ClasseCompte ccTmp = new ClasseCompte(Integer.parseInt(objTmp[0].toString()), objTmp[1].toString(), objTmp[2].toString());
|
|
|
99 |
classeComptes.add(ccTmp);
|
|
|
100 |
tabbedClasse.add(ccTmp.getNom(), new JScrollPane(creerJTable(ccTmp)));
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
this.add(tabbedClasse, c);
|
|
|
104 |
|
80 |
ilm |
105 |
final SQLTableModifiedListener tListener = new SQLTableModifiedListener() {
|
18 |
ilm |
106 |
|
80 |
ilm |
107 |
@Override
|
|
|
108 |
public void tableModified(SQLTableEvent evt) {
|
|
|
109 |
final int tabCount = tabbedClasse.getTabCount();
|
|
|
110 |
for (int i = 0; i < tabCount; i++) {
|
18 |
ilm |
111 |
tabbedClasse.setComponentAt(i, new JScrollPane(creerJTable(classeComptes.get(i))));
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
}
|
80 |
ilm |
115 |
};
|
18 |
ilm |
116 |
|
80 |
ilm |
117 |
final SQLTable tAxeAnalytique = getElement().getDirectory().getElement(AxeAnalytiqueSQLElement.class).getTable();
|
|
|
118 |
tAxeAnalytique.addTableModifiedListener(tListener);
|
18 |
ilm |
119 |
|
80 |
ilm |
120 |
final SQLTable tRepartitionAnalytique = getElement().getDirectory().getElement(RepartitionAnalytiqueSQLElement.class).getTable();
|
|
|
121 |
tRepartitionAnalytique.addTableModifiedListener(tListener);
|
18 |
ilm |
122 |
|
80 |
ilm |
123 |
final SQLTable tRepartitionAnalytiqueElement = getElement().getDirectory().getElement(RepartitionAnalytiqueElementSQLElement.class).getTable();
|
|
|
124 |
tRepartitionAnalytiqueElement.addTableModifiedListener(tListener);
|
18 |
ilm |
125 |
|
80 |
ilm |
126 |
final SQLTable tComptePCE = getElement().getDirectory().getElement(ComptePCESQLElement.class).getTable();
|
|
|
127 |
tComptePCE.addTableModifiedListener(tListener);
|
18 |
ilm |
128 |
|
|
|
129 |
}
|
|
|
130 |
};
|
|
|
131 |
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
public JTable creerJTable(ClasseCompte ccTmp) {
|
80 |
ilm |
135 |
final AssociationAnalytiqueModel model = new AssociationAnalytiqueModel(ccTmp);
|
|
|
136 |
final JTable table = new JTable(model);
|
|
|
137 |
final Vector vect = model.getRepartitionsAxe();
|
18 |
ilm |
138 |
table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0));
|
|
|
139 |
table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0));
|
|
|
140 |
|
|
|
141 |
for (int i = 0; i < vect.size(); i++) {
|
80 |
ilm |
142 |
final Vector rep = (Vector) vect.get(i);
|
18 |
ilm |
143 |
JComboBox combo = new JComboBox();
|
|
|
144 |
for (int j = 0; j < rep.size(); j++) {
|
|
|
145 |
combo.addItem(rep.get(j));
|
|
|
146 |
}
|
|
|
147 |
table.getColumnModel().getColumn(i + 2).setCellEditor(new DefaultCellEditor(combo));
|
|
|
148 |
table.getColumnModel().getColumn(i + 2).setCellRenderer(new PlanComptableCellRenderer(0));
|
|
|
149 |
}
|
|
|
150 |
table.getTableHeader().setReorderingAllowed(false);
|
|
|
151 |
return table;
|
|
|
152 |
}
|
57 |
ilm |
153 |
|
|
|
154 |
@Override
|
|
|
155 |
protected String createCode() {
|
156 |
ilm |
156 |
return createCodeOfPackage() + ".analytic.account.relation";
|
57 |
ilm |
157 |
}
|
18 |
ilm |
158 |
}
|