OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 74 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
153 ilm 16
import org.openconcerto.modules.extensionbuilder.list.ListDescriptor;
74 ilm 17
import org.openconcerto.sql.element.GroupSQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.model.DBRoot;
21
import org.openconcerto.sql.model.SQLTable;
153 ilm 22
import org.openconcerto.sql.request.ListSQLRequest;
23
import org.openconcerto.sql.request.RowItemDesc;
24
import org.openconcerto.sql.view.list.SQLTableModelSource;
25
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
74 ilm 26
 
27
public class TableDescritor {
28
    private String name;
29
    private List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>();
30
 
31
    public TableDescritor(String string) {
32
        this.name = string;
33
 
34
    }
35
 
36
    public void createElement(final Extension ext) {
37
        // Create elements
38
        ComptaPropsConfiguration conf = ComptaPropsConfiguration.getInstanceCompta();
39
        DBRoot root = conf.getRootSociete();
40
        if (conf.getDirectory().getElement(name) == null) {
41
            final SQLTable table = root.getTable(name);
42
            final SQLElement e = new SQLElement("ext." + name, "ext." + name, table) {
43
 
44
                @Override
45
                protected List<String> getListFields() {
46
                    return new ArrayList<String>(0);
47
                }
48
 
49
                @Override
153 ilm 50
                protected SQLTableModelSourceOnline instantiateTableSourceOnline(ListSQLRequest req) {
51
                    ListDescriptor listDesc = null;
52
                    for (ListDescriptor listDescriptor : ext.getCreateListList()) {
53
                        if (listDescriptor.getMainTable().equals(getTable().getName())) {
54
                            listDesc = listDescriptor;
55
                            break;
56
                        }
57
                    }
58
                    if (listDesc != null) {
59
                        return ext.createSource(this, req, listDesc);
60
                    } else {
61
                        return super.instantiateTableSourceOnline(req);
62
                    }
63
 
64
                }
65
 
66
                @Override
74 ilm 67
                protected SQLComponent createComponent() {
68
 
69
                    for (final ComponentDescritor cDescriptor : ext.getCreateComponentList()) {
70
                        if (cDescriptor.getTable().equals(table.getTable().getName())) {
153 ilm 71
                            return new ExtensionGroupSQLComponent(this, cDescriptor.getGroup());
74 ilm 72
                        }
73
                    }
74
                    JOptionPane.showMessageDialog(new JFrame(), "Unable to create default creation component for table " + name);
75
                    return null;
76
                }
77
            };
78
            conf.getDirectory().addSQLElement(e);
79
            Log.get().info("Autocreate element for table: " + table.getName());
80
        }
81
    }
82
 
83
    public String getName() {
84
        return name;
85
    }
86
 
87
    public void setName(String name) {
88
        this.name = name;
89
    }
90
 
91
    public List<FieldDescriptor> getFields() {
92
        return fields;
93
    }
94
 
95
    public void add(FieldDescriptor f) {
96
        fields.add(f);
97
 
98
    }
99
 
100
    public void remove(FieldDescriptor field) {
101
        fields.remove(field);
102
 
103
    }
104
 
105
    @Override
106
    public String toString() {
107
        return name;
108
    }
109
 
110
    public void sortFields() {
111
        Collections.sort(this.fields, new Comparator<FieldDescriptor>() {
112
 
113
            @Override
114
            public int compare(FieldDescriptor o1, FieldDescriptor o2) {
115
                return o1.getName().compareToIgnoreCase(o2.getName());
116
            }
117
        });
118
 
119
    }
120
 
121
}