OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 94 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 83
Line 20... Line 20...
20
import org.openconcerto.sql.model.SQLTableEvent;
20
import org.openconcerto.sql.model.SQLTableEvent;
21
import org.openconcerto.sql.model.SQLTableEvent.Mode;
21
import org.openconcerto.sql.model.SQLTableEvent.Mode;
22
import org.openconcerto.sql.model.SQLTableModifiedListener;
22
import org.openconcerto.sql.model.SQLTableModifiedListener;
23
import org.openconcerto.sql.sqlobject.IComboSelectionItem;
23
import org.openconcerto.sql.sqlobject.IComboSelectionItem;
24
 
24
 
-
 
25
import java.awt.Component;
25
import java.util.HashMap;
26
import java.util.HashMap;
26
import java.util.List;
27
import java.util.List;
27
import java.util.Map;
28
import java.util.Map;
28
 
29
 
-
 
30
import javax.swing.JTable;
-
 
31
import javax.swing.SwingUtilities;
29
import javax.swing.table.DefaultTableCellRenderer;
32
import javax.swing.table.DefaultTableCellRenderer;
30
 
33
 
31
public class KeyTableCellRenderer extends DefaultTableCellRenderer {
34
public class KeyTableCellRenderer extends DefaultTableCellRenderer {
32
 
35
 
33
    private String lastStringValue;
36
    private String lastStringValue;
34
    private Object toSelect;
37
    private Object toSelect;
35
    private boolean isLoading = false;
38
    private boolean isLoading = false;
36
    private final SQLElement el;
39
    private final SQLElement el;
-
 
40
    private JTable t;
37
    static private final Map<SQLElement, Map<Integer, IComboSelectionItem>> cacheMap = new HashMap<SQLElement, Map<Integer, IComboSelectionItem>>();
41
    static private final Map<SQLElement, Map<Integer, IComboSelectionItem>> cacheMap = new HashMap<SQLElement, Map<Integer, IComboSelectionItem>>();
38
 
42
 
39
    public KeyTableCellRenderer(final SQLElement el) {
43
    public KeyTableCellRenderer(final SQLElement el) {
40
        super();
44
        super();
41
        this.el = el;
45
        this.el = el;
Line 43... Line 47...
43
        if (cacheMap.get(this.el) == null) {
47
        if (cacheMap.get(this.el) == null) {
44
            loadCacheAsynchronous();
48
            loadCacheAsynchronous();
45
        }
49
        }
46
    }
50
    }
47
 
51
 
-
 
52
    @Override
-
 
53
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
-
 
54
        this.t = table;
-
 
55
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
-
 
56
    }
-
 
57
 
48
    public void setValue(Object value) {
58
    public void setValue(Object value) {
49
 
59
 
50
        if (this.isLoading) {
60
        if (this.isLoading) {
51
            this.toSelect = value;
61
            this.toSelect = value;
52
            setText("Chargement ...");
62
            setText("Chargement ...");
Line 78... Line 88...
78
        } catch (NumberFormatException e) {
88
        } catch (NumberFormatException e) {
79
            e.printStackTrace();
89
            e.printStackTrace();
80
 
90
 
81
        }
91
        }
82
 
92
 
83
        if (!newValue.equals(this.lastStringValue)) {
-
 
84
 
-
 
85
            this.lastStringValue = newValue;
93
        this.lastStringValue = newValue;
86
            setText(newValue);
94
        setText(newValue);
87
 
-
 
88
        }
-
 
89
    }
95
    }
90
 
96
 
91
    private void loadCacheAsynchronous() {
97
    private void loadCacheAsynchronous() {
92
        this.isLoading = true;
98
        this.isLoading = true;
93
        Configuration.getInstance().getNonInteractiveSQLExecutor().execute(new Runnable() {
99
        Configuration.getInstance().getNonInteractiveSQLExecutor().execute(new Runnable() {
94
            public void run() {
100
            public void run() {
-
 
101
 
95
                List<IComboSelectionItem> items = KeyTableCellRenderer.this.el.getComboRequest().getComboItems();
102
                List<IComboSelectionItem> items = KeyTableCellRenderer.this.el.getComboRequest().getComboItems();
96
                final Map<Integer, IComboSelectionItem> m = new HashMap<Integer, IComboSelectionItem>();
103
                final Map<Integer, IComboSelectionItem> m = new HashMap<Integer, IComboSelectionItem>();
97
                for (IComboSelectionItem comboSelectionItem : items) {
104
                for (IComboSelectionItem comboSelectionItem : items) {
98
                    m.put(comboSelectionItem.getId(), comboSelectionItem);
105
                    m.put(comboSelectionItem.getId(), comboSelectionItem);
99
                }
106
                }
Line 108... Line 115...
108
                            m.put(id, KeyTableCellRenderer.this.el.getComboRequest().getComboItem(id));
115
                            m.put(id, KeyTableCellRenderer.this.el.getComboRequest().getComboItem(id));
109
                    }
116
                    }
110
                }, true));
117
                }, true));
111
 
118
 
112
                KeyTableCellRenderer.this.isLoading = false;
119
                KeyTableCellRenderer.this.isLoading = false;
-
 
120
                SwingUtilities.invokeLater(new Runnable() {
113
 
121
 
-
 
122
                    @Override
-
 
123
                    public void run() {
114
                setValue(KeyTableCellRenderer.this.toSelect);
124
                        setValue(KeyTableCellRenderer.this.toSelect);
-
 
125
                        if (t != null)
-
 
126
                            t.repaint();
-
 
127
                    }
-
 
128
                });
115
 
129
 
116
            }
130
            }
117
        });
131
        });
118
 
132
 
119
    }
133
    }