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.GridBagConstraints;
4
import java.awt.event.ActionEvent;
5
import java.util.ArrayList;
6
import java.util.Arrays;
7
import java.util.HashSet;
8
import java.util.List;
9
import java.util.Set;
10
 
11
import javax.swing.AbstractAction;
12
 
13
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
14
import org.openconcerto.erp.core.common.ui.PanelFrame;
165 ilm 15
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
147 ilm 16
import org.openconcerto.erp.modules.AbstractModule;
17
import org.openconcerto.erp.modules.ModuleElement;
18
import org.openconcerto.sql.element.GlobalMapper;
19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.element.SQLElement;
21
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.view.EditFrame;
23
import org.openconcerto.sql.view.EditPanel.EditMode;
24
import org.openconcerto.sql.view.IListFrame;
25
import org.openconcerto.sql.view.ListeAddPanel;
26
import org.openconcerto.sql.view.list.IListe;
27
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
28
import org.openconcerto.sql.view.list.RowAction;
29
import org.openconcerto.ui.DefaultGridBagConstraints;
30
import org.openconcerto.ui.FrameUtil;
31
import org.openconcerto.ui.group.Group;
32
import org.openconcerto.utils.ListMap;
33
 
34
public class CustomerSupportTicketSQLElement extends ModuleElement {
35
 
36
    public CustomerSupportTicketSQLElement(final AbstractModule module) {
37
        super(module, Module.TABLE_CUSTOMER_SUPPORT_TICKET);
38
 
39
        // Suivi
40
        final RowAction.PredicateRowAction addSuiviAction = new RowAction.PredicateRowAction(new AbstractAction("Suivi du ticket") {
41
 
42
            @Override
43
            public void actionPerformed(ActionEvent e) {
44
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
45
                SuiviTicketPanel panel = new SuiviTicketPanel(sRow);
46
                PanelFrame frame = new PanelFrame(panel, "Suivi ticket client");
47
                frame.setSize(800, 600);
48
                FrameUtil.show(frame);
49
            }
50
        }, true) {
51
        };
52
        addSuiviAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
53
        getRowActions().add(addSuiviAction);
54
 
55
        // Suivi
56
        final RowAction.PredicateRowAction detailsAction = new RowAction.PredicateRowAction(new AbstractAction("Détails client") {
57
 
58
            @Override
59
            public void actionPerformed(ActionEvent e) {
60
                SQLRow sRow = IListe.get(e).getSelectedRow().asRow();
61
                EditFrame frame = new EditFrame(getForeignElement("ID_CLIENT"), EditMode.READONLY);
62
                frame.selectionId(sRow.getForeignID("ID_CLIENT"));
63
                frame.pack();
64
                FrameUtil.show(frame);
65
            }
66
        }, true) {
67
        };
68
        detailsAction.setPredicate(IListeEvent.getSingleSelectionPredicate());
69
        getRowActions().add(detailsAction);
70
 
71
        // Histo
72
        final RowAction.PredicateRowAction addHistoriqueAction = new RowAction.PredicateRowAction(new AbstractAction("Historique des interventions sur tickets") {
73
 
74
            @Override
75
            public void actionPerformed(ActionEvent e) {
76
                final SQLElement elementHisto = getDirectory().getElement(Module.TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY);
77
                final ListeAddPanel panel = new ListeAddPanel(elementHisto);
78
                IListFrame frame = new IListFrame(panel);
79
 
80
                IListFilterDatePanel panelDate = new IListFilterDatePanel(panel.getListe(), elementHisto.getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
81
                GridBagConstraints c = new DefaultGridBagConstraints();
82
                c.gridy = 1;
83
                c.gridwidth = GridBagConstraints.REMAINDER;
84
                c.weightx = 1;
85
                c.weighty = 0;
86
                c.gridy++;
87
                panel.add(panelDate, c);
88
                FrameUtil.show(frame);
89
            }
90
        }, true) {
91
        };
92
        addHistoriqueAction.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
93
        getRowActions().add(addHistoriqueAction);
94
 
165 ilm 95
        MouseSheetXmlListeListener l = new MouseSheetXmlListeListener(CustomerSupportTicketSheetXML.class);
96
 
97
        getRowActions().addAll(l.getRowActions());
147 ilm 98
    }
99
 
100
    @Override
101
    public Set<String> getReadOnlyFields() {
102
        Set<String> s = new HashSet<String>();
103
        s.add("NUMBER");
104
        return s;
105
    }
106
 
107
    @Override
108
    protected String createCode() {
109
        return "customersupport.ticket";
110
    }
111
 
112
    @Override
113
    protected List<String> getListFields() {
114
        final List<String> l = new ArrayList<String>();
115
        l.add("NUMBER");
116
        l.add("DATE");
117
        l.add("LABEL");
118
        l.add("ID_CLIENT");
119
        l.add("STATUS");
120
        l.add("RATING");
121
        l.add("INFOS");
122
        l.add("CLOSED_AND_ARCHIVED");
123
        return l;
124
    }
125
 
126
    @Override
127
    protected List<String> getComboFields() {
128
        final List<String> l = new ArrayList<String>();
129
        l.add("NUMBER");
130
        l.add("DATE");
131
        l.add("ID_CLIENT");
132
        l.add("LABEL");
133
        return l;
134
    }
135
 
136
    @Override
137
    public ListMap<String, String> getShowAs() {
138
        ListMap<String, String> map = new ListMap<String, String>();
139
        map.put(null, Arrays.asList("NUMBER", "DATE", "ID_CLIENT", "LABEL", "RATING", "STATUS"));
140
        return map;
141
    }
142
 
143
    @Override
144
    public SQLComponent createComponent() {
145
        final String groupId = this.getCode() + ".default";
146
        final Group group = GlobalMapper.getInstance().getGroup(groupId);
147
        if (group == null) {
148
            throw new IllegalStateException("No group found for id " + groupId);
149
        }
150
        return createComponent(group);
151
    }
152
 
153
    protected SQLComponent createComponent(final Group group) {
154
        return new CustomerSupportTicketSQLComponent(this, group);
155
    }
156
}