OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 147 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
147 ilm 1
package org.openconcerto.modules.customersupport;
2
 
3
import java.awt.Color;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
6
import java.awt.Insets;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.text.DateFormat;
10
import java.text.SimpleDateFormat;
11
import java.util.ArrayList;
12
import java.util.Collections;
13
import java.util.Comparator;
14
import java.util.Date;
15
import java.util.List;
16
 
17
import javax.swing.JButton;
18
import javax.swing.JFrame;
19
import javax.swing.JLabel;
20
import javax.swing.JPanel;
21
import javax.swing.JScrollPane;
22
import javax.swing.SwingUtilities;
23
 
24
import org.openconcerto.sql.Configuration;
25
import org.openconcerto.sql.element.SQLElement;
26
import org.openconcerto.sql.model.SQLRow;
27
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLRowListRSH;
29
import org.openconcerto.sql.model.SQLRowValues;
30
import org.openconcerto.sql.model.SQLSelect;
31
import org.openconcerto.sql.model.SQLSelect.LockStrength;
32
import org.openconcerto.sql.model.Where;
33
import org.openconcerto.sql.view.EditFrame;
34
import org.openconcerto.sql.view.EditPanel.EditMode;
35
import org.openconcerto.sql.view.EditPanelListener;
36
import org.openconcerto.ui.DefaultGridBagConstraints;
37
import org.openconcerto.ui.FrameUtil;
38
import org.openconcerto.ui.JLabelBold;
39
import org.openconcerto.ui.component.ITextArea;
40
 
41
public class SuiviTicketPanel extends JPanel {
42
 
43
    private final SQLRowAccessor rowTicket;
44
    private JPanel panelHistory = new JPanel(new GridBagLayout());
45
    private DateFormat format = new SimpleDateFormat("dd/MM/yy HH:mm");
46
 
47
    public SuiviTicketPanel(SQLRowAccessor rowTicket) {
48
        super(new GridBagLayout());
49
        this.rowTicket = rowTicket;
50
        initUI();
51
    }
52
 
53
    public void initUI() {
54
        GridBagConstraints c = new DefaultGridBagConstraints();
55
 
56
        c.gridwidth = GridBagConstraints.REMAINDER;
57
 
58
        JLabel label1 = new JLabel(
59
                "Ticket N°" + this.rowTicket.getString("NUMBER") + " du " + format.format(this.rowTicket.getDate("DATE").getTime()) + " - Statut : " + this.rowTicket.getString("STATUS"));
60
        JLabel label2 = new JLabel("Client : " + this.rowTicket.getForeign("ID_CLIENT").getString("NOM"));
61
        String type = this.rowTicket.getString("TYPE");
62
        if (type == null || type.trim().isEmpty()) {
63
            type = "non renseigné";
64
        }
65
        JLabel label3 = new JLabel("Type : " + type + " - Intitulé : " + this.rowTicket.getString("LABEL"));
66
        c.gridwidth = GridBagConstraints.REMAINDER;
67
        this.add(label1, c);
68
        c.gridy++;
69
        this.add(label2, c);
70
        c.gridy++;
71
        this.add(label3, c);
72
 
73
        final ITextArea textInfos = new ITextArea();
74
        textInfos.setEditable(false);
75
        textInfos.setEnabled(false);
76
        textInfos.setBorder(null);
77
        textInfos.setDisabledTextColor(Color.BLACK);
78
        textInfos.setBackground(this.getBackground());
79
        textInfos.setText(this.rowTicket.getString("INFOS"));
80
        c.gridy++;
81
        c.weightx = 1;
82
        c.weighty = 0;
83
        c.fill = GridBagConstraints.HORIZONTAL;
84
        final JScrollPane comp = new JScrollPane(textInfos);
85
        comp.setBorder(null);
86
        DefaultGridBagConstraints.lockMinimumSize(comp);
87
        this.add(comp, c);
88
 
89
        final JLabelBold intSep = new JLabelBold("Liste des interventions");
90
        c.gridwidth = GridBagConstraints.REMAINDER;
91
        c.gridy++;
92
        c.gridx = 0;
93
        c.weightx = 1;
94
        this.add(intSep, c);
95
 
96
        c.gridy++;
97
        c.weightx = 0;
98
        c.weighty = 0;
99
        c.fill = GridBagConstraints.NONE;
100
        final JButton addSuivi = new JButton("Ajouter une intervention");
101
        this.add(addSuivi, c);
102
        addSuivi.addActionListener(new ActionListener() {
103
 
104
            @Override
105
            public void actionPerformed(ActionEvent e) {
106
                final SQLElement element = Configuration.getInstance().getDirectory().getElement(Module.TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY);
107
                EditFrame frame = new EditFrame(element, EditMode.CREATION);
108
                SQLRowValues rowVals = new SQLRowValues(element.getTable());
109
                rowVals.put("DATE", new Date());
110
                rowVals.put("ID_" + Module.TABLE_CUSTOMER_SUPPORT_TICKET, rowTicket.getID());
111
                frame.getSQLComponent().select(rowVals);
112
                FrameUtil.showPacked(frame);
113
 
114
                frame.addEditPanelListener(new EditPanelListener() {
115
 
116
                    @Override
117
                    public void modified() {
118
                    }
119
 
120
                    @Override
121
                    public void inserted(int id) {
122
                        fillPanelHistory();
123
                    }
124
 
125
                    @Override
126
                    public void deleted() {
127
                    }
128
 
129
                    @Override
130
                    public void cancelled() {
131
                    }
132
                });
133
            }
134
        });
135
 
136
        // Historique
137
 
138
        JScrollPane scrollPane = new JScrollPane(this.panelHistory);
139
        scrollPane.setBorder(null);
140
        fillPanelHistory();
141
        c.gridy++;
142
        c.fill = GridBagConstraints.BOTH;
143
        c.weightx = 1;
144
        c.weighty = 1;
145
        this.add(scrollPane, c);
146
 
147
        JButton buttonClose = new JButton("Fermer");
148
        c.gridy++;
149
        c.fill = GridBagConstraints.NONE;
150
        c.weightx = 0;
151
        c.weighty = 0;
152
        c.gridwidth = GridBagConstraints.REMAINDER;
153
        c.anchor = GridBagConstraints.EAST;
154
        this.add(buttonClose, c);
155
        buttonClose.addActionListener(new ActionListener() {
156
 
157
            @Override
158
            public void actionPerformed(ActionEvent e) {
159
                JFrame frame = (JFrame) SwingUtilities.getRoot(SuiviTicketPanel.this);
160
                frame.dispose();
161
            }
162
        });
163
    }
164
 
165
    public void fillPanelHistory() {
166
 
167
        this.panelHistory.removeAll();
168
 
169
        GridBagConstraints cHistory = new DefaultGridBagConstraints();
170
        cHistory.anchor = GridBagConstraints.NORTHWEST;
171
        cHistory.insets = new Insets(4, 1, 4, 1);
172
        final SQLSelect sel = new SQLSelect();
173
        sel.addSelectStar(this.rowTicket.getTable().getTable(Module.TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY));
174
        sel.setWhere(new Where(this.rowTicket.getTable().getTable(Module.TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY).getField("ID_" + Module.TABLE_CUSTOMER_SUPPORT_TICKET), "=", this.rowTicket.getID()));
175
        sel.setLockStrength(LockStrength.UPDATE);
176
        List<SQLRow> histoRows = SQLRowListRSH.execute(sel, false, false);
177
        List<SQLRowAccessor> histoRowsOrder = new ArrayList<SQLRowAccessor>();
178
        histoRowsOrder.addAll(histoRows);
179
        Collections.sort(histoRowsOrder, new Comparator<SQLRowAccessor>() {
180
            @Override
181
            public int compare(SQLRowAccessor o1, SQLRowAccessor o2) {
183 ilm 182
                if (o1.getObject("DATE") == null) {
183
                    return -1;
184
                }
185
                if (o2.getObject("DATE") == null) {
186
                    return 1;
187
                }
147 ilm 188
                return o2.getDate("DATE").compareTo(o1.getDate("DATE"));
189
            }
190
        });
191
 
192
        for (SQLRowAccessor sqlRowAccessor : histoRowsOrder) {
193
            HistoryPanel p = new HistoryPanel(sqlRowAccessor, this);
194
            cHistory.gridy++;
195
            cHistory.weightx = 1;
196
            cHistory.weighty = 0;
197
            cHistory.fill = GridBagConstraints.BOTH;
198
            panelHistory.add(p, cHistory);
199
        }
200
        cHistory.gridy++;
201
        cHistory.weightx = 1;
202
        cHistory.weighty = 1;
203
        JPanel spacer = new JPanel();
204
        spacer.setOpaque(false);
205
        panelHistory.add(spacer, cHistory);
206
        this.panelHistory.updateUI();
207
        this.panelHistory.revalidate();
208
        this.panelHistory.repaint();
209
    }
210
 
211
}