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 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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