OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
49 ilm 1
package org.openconcerto.modules.customerrelationship.call.ovh;
2
 
3
import java.awt.GridBagConstraints;
4
import java.awt.GridBagLayout;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
126 ilm 7
import java.net.URI;
8
import java.net.URISyntaxException;
49 ilm 9
 
10
import javax.swing.JButton;
11
import javax.swing.JFrame;
12
import javax.swing.JLabel;
13
import javax.swing.JOptionPane;
14
import javax.swing.JPasswordField;
15
import javax.swing.JTextField;
16
import javax.swing.SwingConstants;
17
 
18
import org.openconcerto.erp.preferences.DefaultLocalPreferencePanel;
19
 
20
import org.openconcerto.ui.DefaultGridBagConstraints;
21
import org.openconcerto.ui.JLabelBold;
22
import org.openconcerto.utils.JImage;
23
 
24
public class OvhPreferencePanel extends DefaultLocalPreferencePanel {
25
    public static final String OVH_PROPERTIES = "ovh.properties";
26
    final JTextField textAccountLogin = new JTextField();
27
    final JPasswordField textAccountPassword = new JPasswordField();
28
    final JTextField textNumber = new JTextField();
29
    final JTextField textLogin = new JTextField();
30
    final JPasswordField textPassword = new JPasswordField();
31
 
32
    public OvhPreferencePanel() {
33
        super("Téléphonie OVH", OVH_PROPERTIES);
34
 
35
        this.setLayout(new GridBagLayout());
36
        GridBagConstraints c = new DefaultGridBagConstraints();
37
        // Logo OVH.com
38
        c.gridwidth = 3;
39
        c.fill = GridBagConstraints.NONE;
40
        c.anchor = GridBagConstraints.WEST;
41
        final JImage img = new JImage(OvhPreferencePanel.class.getResource("ovh.png"));
126 ilm 42
        try {
43
            img.setHyperLink(new URI("http://www.ovh.com/fr/telephonie/"));
44
        } catch (URISyntaxException e2) {
45
            e2.printStackTrace();
46
        }
49 ilm 47
        this.add(img, c);
48
 
49
        // Account
50
        c.gridx = 0;
51
        c.gridy++;
52
        c.fill = GridBagConstraints.HORIZONTAL;
53
        c.gridwidth = 1;
54
        this.add(new JLabelBold("Compte OVH"), c);
55
        c.gridx = 0;
56
        c.gridy++;
57
        c.fill = GridBagConstraints.HORIZONTAL;
58
        c.gridwidth = 1;
59
        this.add(new JLabel("Identifiant OVH", SwingConstants.RIGHT), c);
60
        c.gridx++;
61
        c.weightx = 1;
62
        this.add(textAccountLogin, c);
63
        c.gridx++;
64
        c.weightx = 0;
65
        this.add(new JLabel("(NIC-handle, Domaine, Email)"), c);
66
 
67
        c.gridx = 0;
68
        c.gridy++;
69
        this.add(new JLabel("Mot de passe", SwingConstants.RIGHT), c);
70
        c.gridx++;
71
        this.add(textAccountPassword, c);
72
 
73
        // Telephony
74
        c.gridx = 0;
75
        c.gridy++;
76
        c.fill = GridBagConstraints.HORIZONTAL;
77
        c.gridwidth = 1;
78
        this.add(new JLabelBold("Téléphonie SIP"), c);
79
        c.gridx = 0;
80
        c.gridy++;
81
        c.fill = GridBagConstraints.HORIZONTAL;
82
        c.gridwidth = 1;
83
        this.add(new JLabel("N° de ligne", SwingConstants.RIGHT), c);
84
        c.gridx++;
85
        c.weightx = 1;
86
        this.add(textNumber, c);
87
        c.gridx++;
88
        c.weightx = 0;
89
        this.add(new JLabel("(ex: 0311442288)"), c);
90
 
91
        c.gridx = 0;
92
        c.gridy++;
93
        c.fill = GridBagConstraints.HORIZONTAL;
94
        c.gridwidth = 1;
95
        this.add(new JLabel("Identifiant Click2Call", SwingConstants.RIGHT), c);
96
        c.gridx++;
97
        c.weightx = 1;
98
        this.add(textLogin, c);
99
        c.gridx++;
100
        c.weightx = 0;
101
        this.add(new JLabel("(identifiant pour appel en 1 clic)"), c);
102
 
103
        c.gridx = 0;
104
        c.gridy++;
105
        this.add(new JLabel("Mot de passe", SwingConstants.RIGHT), c);
106
        c.gridx++;
107
        this.add(textPassword, c);
108
 
109
        final JButton bTest = new JButton("Appliquer et tester les paramètres");
110
        bTest.setOpaque(false);
111
        c.fill = GridBagConstraints.NONE;
112
        c.gridx = 0;
113
        c.gridy++;
114
        c.gridwidth = 2;
115
        c.weighty = 1;
116
        c.anchor = GridBagConstraints.NORTHEAST;
117
        this.add(bTest, c);
118
        bTest.addActionListener(new ActionListener() {
119
            @Override
120
            public void actionPerformed(ActionEvent e) {
121
                storeValues();
122
                try {
123
                    OVHApi.testOVHAccount();
124
                    JOptionPane.showMessageDialog(OvhPreferencePanel.this, "Connexion réussie au service OVH");
125
                } catch (Exception e1) {
126
                    JOptionPane.showMessageDialog(OvhPreferencePanel.this, e1.getMessage());
127
                }
128
            }
129
        });
130
        textAccountLogin.setText(properties.getProperty("account", ""));
131
        textAccountPassword.setText(properties.getProperty("accountpassword", ""));
132
        textNumber.setText(properties.getProperty("from", ""));
133
        textLogin.setText(properties.getProperty("login", ""));
134
        textPassword.setText(properties.getProperty("password", ""));
135
    }
136
 
137
    @Override
138
    public void storeValues() {
139
        properties.setProperty("account", textAccountLogin.getText());
140
        properties.setProperty("accountpassword", String.valueOf(textAccountPassword.getPassword()));
141
        properties.setProperty("from", textNumber.getText());
142
        properties.setProperty("login", textLogin.getText());
143
        properties.setProperty("password", String.valueOf(textPassword.getPassword()));
144
        super.storeValues();
145
    }
146
 
147
    @Override
148
    public void restoreToDefaults() {
149
        textAccountLogin.setText("");
150
        textAccountPassword.setText("");
151
        textNumber.setText("");
152
        textLogin.setText("");
153
        textPassword.setText("");
154
    }
155
 
156
    public static void main(String[] args) {
157
        JFrame f = new JFrame();
158
        f.setContentPane(new OvhPreferencePanel());
159
        f.pack();
160
        f.setVisible(true);
161
    }
162
}