74 |
ilm |
1 |
package org.openconcerto.modules.extensionbuilder.table;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.Collections;
|
|
|
5 |
import java.util.Comparator;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
|
|
|
8 |
import javax.swing.JFrame;
|
|
|
9 |
import javax.swing.JOptionPane;
|
|
|
10 |
|
|
|
11 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
12 |
import org.openconcerto.erp.config.Log;
|
|
|
13 |
import org.openconcerto.modules.extensionbuilder.Extension;
|
153 |
ilm |
14 |
import org.openconcerto.modules.extensionbuilder.ExtensionGroupSQLComponent;
|
74 |
ilm |
15 |
import org.openconcerto.modules.extensionbuilder.component.ComponentDescritor;
|
162 |
ilm |
16 |
import org.openconcerto.modules.extensionbuilder.list.ColumnDescriptor;
|
153 |
ilm |
17 |
import org.openconcerto.modules.extensionbuilder.list.ListDescriptor;
|
74 |
ilm |
18 |
import org.openconcerto.sql.element.SQLComponent;
|
|
|
19 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
20 |
import org.openconcerto.sql.model.DBRoot;
|
162 |
ilm |
21 |
import org.openconcerto.sql.model.SQLField;
|
74 |
ilm |
22 |
import org.openconcerto.sql.model.SQLTable;
|
153 |
ilm |
23 |
import org.openconcerto.sql.request.ListSQLRequest;
|
|
|
24 |
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
|
74 |
ilm |
25 |
|
|
|
26 |
public class TableDescritor {
|
|
|
27 |
private String name;
|
|
|
28 |
private List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>();
|
|
|
29 |
|
|
|
30 |
public TableDescritor(String string) {
|
|
|
31 |
this.name = string;
|
|
|
32 |
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public void createElement(final Extension ext) {
|
|
|
36 |
// Create elements
|
|
|
37 |
ComptaPropsConfiguration conf = ComptaPropsConfiguration.getInstanceCompta();
|
|
|
38 |
DBRoot root = conf.getRootSociete();
|
|
|
39 |
if (conf.getDirectory().getElement(name) == null) {
|
|
|
40 |
final SQLTable table = root.getTable(name);
|
|
|
41 |
final SQLElement e = new SQLElement("ext." + name, "ext." + name, table) {
|
|
|
42 |
|
|
|
43 |
@Override
|
|
|
44 |
protected List<String> getListFields() {
|
|
|
45 |
return new ArrayList<String>(0);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
@Override
|
162 |
ilm |
49 |
protected List<String> getComboFields() {
|
|
|
50 |
List<String> l = new ArrayList<String>();
|
|
|
51 |
int matchCodeNom = 0;
|
|
|
52 |
for (SQLField field : getTable().getContentFields()) {
|
|
|
53 |
l.add(field.getName());
|
|
|
54 |
if (field.getName().equalsIgnoreCase("CODE") || field.getName().equalsIgnoreCase("NOM")) {
|
|
|
55 |
matchCodeNom++;
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
if (matchCodeNom == 2) {
|
|
|
59 |
l.add("CODE");
|
|
|
60 |
l.add("NOM");
|
|
|
61 |
} else {
|
|
|
62 |
ListDescriptor listDesc = null;
|
|
|
63 |
for (ListDescriptor listDescriptor : ext.getCreateListList()) {
|
|
|
64 |
if (listDescriptor.getMainTable().equals(getTable().getName())) {
|
|
|
65 |
listDesc = listDescriptor;
|
|
|
66 |
break;
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
for (ColumnDescriptor string : listDesc.getColumns()) {
|
|
|
70 |
if (!string.getFieldsPaths().contains(".")) {
|
|
|
71 |
l.add(string.getFieldsPaths());
|
|
|
72 |
break;
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
return l;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
@Override
|
153 |
ilm |
80 |
protected SQLTableModelSourceOnline instantiateTableSourceOnline(ListSQLRequest req) {
|
|
|
81 |
ListDescriptor listDesc = null;
|
|
|
82 |
for (ListDescriptor listDescriptor : ext.getCreateListList()) {
|
|
|
83 |
if (listDescriptor.getMainTable().equals(getTable().getName())) {
|
|
|
84 |
listDesc = listDescriptor;
|
|
|
85 |
break;
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
if (listDesc != null) {
|
|
|
89 |
return ext.createSource(this, req, listDesc);
|
|
|
90 |
} else {
|
|
|
91 |
return super.instantiateTableSourceOnline(req);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
@Override
|
74 |
ilm |
97 |
protected SQLComponent createComponent() {
|
|
|
98 |
|
|
|
99 |
for (final ComponentDescritor cDescriptor : ext.getCreateComponentList()) {
|
|
|
100 |
if (cDescriptor.getTable().equals(table.getTable().getName())) {
|
153 |
ilm |
101 |
return new ExtensionGroupSQLComponent(this, cDescriptor.getGroup());
|
74 |
ilm |
102 |
}
|
|
|
103 |
}
|
|
|
104 |
JOptionPane.showMessageDialog(new JFrame(), "Unable to create default creation component for table " + name);
|
|
|
105 |
return null;
|
|
|
106 |
}
|
|
|
107 |
};
|
|
|
108 |
conf.getDirectory().addSQLElement(e);
|
|
|
109 |
Log.get().info("Autocreate element for table: " + table.getName());
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
public String getName() {
|
|
|
114 |
return name;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
public void setName(String name) {
|
|
|
118 |
this.name = name;
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
public List<FieldDescriptor> getFields() {
|
|
|
122 |
return fields;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
public void add(FieldDescriptor f) {
|
|
|
126 |
fields.add(f);
|
|
|
127 |
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
public void remove(FieldDescriptor field) {
|
|
|
131 |
fields.remove(field);
|
|
|
132 |
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
@Override
|
|
|
136 |
public String toString() {
|
|
|
137 |
return name;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
public void sortFields() {
|
|
|
141 |
Collections.sort(this.fields, new Comparator<FieldDescriptor>() {
|
|
|
142 |
|
|
|
143 |
@Override
|
|
|
144 |
public int compare(FieldDescriptor o1, FieldDescriptor o2) {
|
|
|
145 |
return o1.getName().compareToIgnoreCase(o2.getName());
|
|
|
146 |
}
|
|
|
147 |
});
|
|
|
148 |
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
}
|