OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 17 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17 Rev 25
Line 17... Line 17...
17
import org.openconcerto.sql.model.SQLRow;
17
import org.openconcerto.sql.model.SQLRow;
18
import org.openconcerto.sql.model.SQLRowListRSH;
18
import org.openconcerto.sql.model.SQLRowListRSH;
19
import org.openconcerto.sql.model.SQLRowValues;
19
import org.openconcerto.sql.model.SQLRowValues;
20
import org.openconcerto.sql.model.SQLSelect;
20
import org.openconcerto.sql.model.SQLSelect;
21
import org.openconcerto.sql.model.SQLTable;
21
import org.openconcerto.sql.model.SQLTable;
22
import org.openconcerto.sql.model.SQLTableListener;
22
import org.openconcerto.sql.model.SQLTableEvent;
-
 
23
import org.openconcerto.sql.model.SQLTableEvent.Mode;
-
 
24
import org.openconcerto.sql.model.SQLTableModifiedListener;
23
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.model.Where;
24
 
26
 
25
import java.sql.SQLException;
27
import java.sql.SQLException;
26
import java.util.ArrayList;
28
import java.util.ArrayList;
27
import java.util.Arrays;
29
import java.util.Arrays;
Line 53... Line 55...
53
        sel2.addSelect(this.tableRight.getKey());
55
        sel2.addSelect(this.tableRight.getKey());
54
        sel2.addFieldOrder(this.tableRight.getField("CODE"));
56
        sel2.addFieldOrder(this.tableRight.getField("CODE"));
55
        List<SQLRow> rowsRights = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel2.asString(), new SQLRowListRSH(this.tableRight, true));
57
        List<SQLRow> rowsRights = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel2.asString(), new SQLRowListRSH(this.tableRight, true));
56
        this.cache.addAll(rowsRights);
58
        this.cache.addAll(rowsRights);
57
 
59
 
58
        this.tableRight.addTableListener(new SQLTableListener() {
60
        this.tableRight.addTableModifiedListener(new SQLTableModifiedListener() {
59
            @Override
61
            @Override
60
            public void rowAdded(SQLTable table, int id) {
62
            public void tableModified(SQLTableEvent evt) {
61
 
-
 
62
                UserRightsManagerModel.this.cache.add(table.getRow(id));
63
                if (evt.getMode() == Mode.ROW_ADDED) {
63
            }
-
 
64
 
-
 
65
            @Override
-
 
66
            public void rowDeleted(SQLTable table, int id) {
64
                    UserRightsManagerModel.this.cache.add(evt.getRow());
67
 
-
 
68
            }
-
 
69
 
-
 
70
            @Override
65
                } else {
71
            public void rowModified(SQLTable table, int id) {
-
 
72
                SQLRow row = table.getRow(id);
66
                    final SQLRow row = evt.getRow();
73
 
-
 
74
                for (int i = 0; i < UserRightsManagerModel.this.cache.size(); i++) {
67
                    for (int i = 0; i < UserRightsManagerModel.this.cache.size(); i++) {
75
                    SQLRow row2 = UserRightsManagerModel.this.cache.get(i);
68
                        final SQLRow row2 = UserRightsManagerModel.this.cache.get(i);
76
                    if (row2.getID() == id) {
69
                        if (row2.getID() == row.getID()) {
77
                        if (row.isArchived()) {
70
                            if (!row.isValid()) {
78
                            UserRightsManagerModel.this.cache.remove(i);
71
                                UserRightsManagerModel.this.cache.remove(i);
79
                        } else {
72
                            } else {
80
                            UserRightsManagerModel.this.cache.set(i, row2);
73
                                UserRightsManagerModel.this.cache.set(i, row2);
81
                        }
74
                            }
82
                        break;
75
                            break;
83
                    }
76
                        }
84
                }
77
                    }
85
            }
78
                }
-
 
79
            }
86
        });
80
        });
87
 
81
 
88
        this.tableUserRight.addTableListener(new SQLTableListener() {
82
        this.tableUserRight.addTableModifiedListener(new SQLTableModifiedListener() {
-
 
83
 
89
            @Override
84
            @Override
90
            public void rowAdded(SQLTable table, int id) {
85
            public void tableModified(SQLTableEvent evt) {
-
 
86
                if (evt.getMode() == Mode.ROW_ADDED) {
-
 
87
                    rowAdded(evt);
-
 
88
                } else {
-
 
89
                    rowModified(evt);
-
 
90
                }
-
 
91
            }
91
 
92
 
-
 
93
            public void rowAdded(SQLTableEvent evt) {
92
                SQLRow row = table.getRow(id);
94
                final SQLRow row = evt.getRow();
93
                if (row.getInt("ID_USER_COMMON") == UserRightsManagerModel.this.idUser) {
95
                if (row.getInt("ID_USER_COMMON") == UserRightsManagerModel.this.idUser) {
94
                    SQLRowValues rowVals = getSQLRowValuesForID(id);
96
                    SQLRowValues rowVals = getSQLRowValuesFor(row);
95
                    if (rowVals == null) {
97
                    if (rowVals == null) {
96
                        UserRightsManagerModel.this.listRowValues.add(row.createUpdateRow());
98
                        UserRightsManagerModel.this.listRowValues.add(row.createUpdateRow());
97
                        fireTableRowsInserted(UserRightsManagerModel.this.listRowValues.size() - 2, UserRightsManagerModel.this.listRowValues.size() - 1);
99
                        fireTableRowsInserted(UserRightsManagerModel.this.listRowValues.size() - 2, UserRightsManagerModel.this.listRowValues.size() - 1);
98
                    }
100
                    }
99
                }
101
                }
100
            }
102
            }
101
 
103
 
102
            @Override
-
 
103
            public void rowDeleted(SQLTable table, int id) {
-
 
104
            }
-
 
105
 
-
 
106
            @Override
-
 
107
            public void rowModified(SQLTable table, int id) {
104
            public void rowModified(SQLTableEvent evt) {
108
                SQLRow row = table.getRow(id);
105
                final SQLRow row = evt.getRow();
109
                if (row.getInt("ID_USER_COMMON") == UserRightsManagerModel.this.idUser) {
106
                if (row.getInt("ID_USER_COMMON") == UserRightsManagerModel.this.idUser) {
110
                    SQLRowValues rowVals = getSQLRowValuesForID(id);
107
                    SQLRowValues rowVals = getSQLRowValuesFor(row);
111
                    int index = UserRightsManagerModel.this.listRowValues.indexOf(rowVals);
108
                    int index = UserRightsManagerModel.this.listRowValues.indexOf(rowVals);
112
                    if (row.isArchived()) {
109
                    if (!row.isValid()) {
113
                        UserRightsManagerModel.this.listRowValues.removeElement(rowVals);
110
                        UserRightsManagerModel.this.listRowValues.removeElement(rowVals);
114
                        fireTableRowsDeleted(index - 1, index + 1);
111
                        fireTableRowsDeleted(index - 1, index + 1);
115
                    } else {
112
                    } else {
116
                        rowVals.loadAbsolutelyAll(row);
113
                        rowVals.loadAbsolutelyAll(row);
117
                        fireTableRowsUpdated(index - 1, index + 1);
114
                        fireTableRowsUpdated(index - 1, index + 1);
Line 119... Line 116...
119
                }
116
                }
120
            }
117
            }
121
        });
118
        });
122
    }
119
    }
123
 
120
 
124
    private SQLRowValues getSQLRowValuesForID(int id) {
121
    private SQLRowValues getSQLRowValuesFor(final SQLRow row) {
125
        SQLRow row = this.tableUserRight.getRow(id);
-
 
126
        final String string2 = row.getString("CODE");
122
        final String string2 = row.getString("CODE");
127
        for (SQLRowValues rowVals : this.listRowValues) {
123
        for (SQLRowValues rowVals : this.listRowValues) {
128
            final String string = rowVals.getString("CODE");
124
            final String string = rowVals.getString("CODE");
129
            if (rowVals.getID() == id || (string != null && string2 != null && string.equalsIgnoreCase(string2))) {
125
            if (rowVals.getID() == row.getID() || (string != null && string2 != null && string.equalsIgnoreCase(string2))) {
130
                return rowVals;
126
                return rowVals;
131
            }
127
            }
132
        }
128
        }
133
        return null;
129
        return null;
134
    }
130
    }