OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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