OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 120 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 120 Rev 181
Line 1... Line 1...
1
package org.openconcerto.modules.extensionbuilder.translation.menu;
1
package org.openconcerto.modules.extensionbuilder.translation.menu;
2
 
2
 
3
import java.awt.GridBagConstraints;
3
import java.awt.GridBagConstraints;
4
import java.awt.GridBagLayout;
4
import java.awt.GridBagLayout;
-
 
5
import java.awt.event.ActionEvent;
-
 
6
import java.awt.event.ActionListener;
5
import java.util.Locale;
7
import java.util.Locale;
6
 
8
 
7
import javax.swing.JLabel;
9
import javax.swing.JLabel;
8
import javax.swing.JPanel;
10
import javax.swing.JPanel;
9
import javax.swing.JSeparator;
11
import javax.swing.JSeparator;
Line 22... Line 24...
22
 
24
 
23
    final Extension extension;
25
    final Extension extension;
24
    private JTextField textId;
26
    private JTextField textId;
25
    private JTextField textTranslation1;
27
    private JTextField textTranslation1;
26
    private JTextField textTranslation2;
28
    private JTextField textTranslation2;
-
 
29
    final LocaleSelector comboLang1;
-
 
30
    final LocaleSelector comboLang2;
27
 
31
 
28
    public MenuTranslationItemEditor(final Item item, final Extension extension) {
32
    public MenuTranslationItemEditor(final Item item, final Extension extension) {
29
        this.extension = extension;
33
        this.extension = extension;
30
        this.setLayout(new GridBagLayout());
34
        this.setLayout(new GridBagLayout());
31
        GridBagConstraints c = new DefaultGridBagConstraints();
35
        GridBagConstraints c = new DefaultGridBagConstraints();
Line 35... Line 39...
35
        this.add(new JLabel("Identifiant", SwingConstants.RIGHT), c);
39
        this.add(new JLabel("Identifiant", SwingConstants.RIGHT), c);
36
        c.gridx++;
40
        c.gridx++;
37
        c.fill = GridBagConstraints.HORIZONTAL;
41
        c.fill = GridBagConstraints.HORIZONTAL;
38
        c.weightx = 1;
42
        c.weightx = 1;
39
        c.gridwidth = 3;
43
        c.gridwidth = 3;
40
        textId = new JTextField();
44
        this.textId = new JTextField();
41
        this.add(textId, c);
45
        this.add(this.textId, c);
42
 
46
 
43
        // Language selector
47
        // Language selector
44
        c.gridx = 0;
48
        c.gridx = 0;
45
        c.gridy++;
49
        c.gridy++;
46
        c.weightx = 0;
50
        c.weightx = 0;
Line 48... Line 52...
48
        c.fill = GridBagConstraints.HORIZONTAL;
52
        c.fill = GridBagConstraints.HORIZONTAL;
49
        this.add(new JLabel("Langue et pays", SwingConstants.RIGHT), c);
53
        this.add(new JLabel("Langue et pays", SwingConstants.RIGHT), c);
50
        final String[] isoLanguages = Locale.getISOLanguages();
54
        final String[] isoLanguages = Locale.getISOLanguages();
51
        System.out.println(isoLanguages.length);
55
        System.out.println(isoLanguages.length);
52
 
56
 
53
        final LocaleSelector comboLang1 = new LocaleSelector();
57
        comboLang1 = new LocaleSelector();
54
 
58
 
55
        c.weightx = 1;
59
        c.weightx = 1;
56
        c.gridx++;
60
        c.gridx++;
57
        c.fill = GridBagConstraints.NONE;
61
        c.fill = GridBagConstraints.NONE;
58
        this.add(comboLang1, c);
62
        this.add(comboLang1, c);
Line 65... Line 69...
65
 
69
 
66
        c.gridheight = 1;
70
        c.gridheight = 1;
67
        c.weightx = 1;
71
        c.weightx = 1;
68
        c.gridx++;
72
        c.gridx++;
69
        c.fill = GridBagConstraints.NONE;
73
        c.fill = GridBagConstraints.NONE;
70
        final LocaleSelector comboLang2 = new LocaleSelector();
74
        comboLang2 = new LocaleSelector();
71
 
75
 
72
        comboLang2.setLocale(Locale.ENGLISH);
76
        comboLang2.setLocale(Locale.ENGLISH);
73
        this.add(comboLang2, c);
77
        this.add(comboLang2, c);
74
        // Traduction
78
        // Traduction
75
        c.gridx = 0;
79
        c.gridx = 0;
Line 82... Line 86...
82
        this.add(new JLabel("Traduction", SwingConstants.RIGHT), c);
86
        this.add(new JLabel("Traduction", SwingConstants.RIGHT), c);
83
        c.gridx++;
87
        c.gridx++;
84
 
88
 
85
        c.weightx = 1;
89
        c.weightx = 1;
86
 
90
 
87
        textTranslation1 = new JTextField(20);
91
        this.textTranslation1 = new JTextField(20);
88
 
92
 
89
        this.add(textTranslation1, c);
93
        this.add(this.textTranslation1, c);
90
 
94
 
91
        c.gridx += 2;
95
        c.gridx += 2;
92
        c.fill = GridBagConstraints.HORIZONTAL;
96
        c.fill = GridBagConstraints.HORIZONTAL;
93
 
97
 
94
        c.weightx = 1;
98
        c.weightx = 1;
95
        textTranslation2 = new JTextField(20);
99
        this.textTranslation2 = new JTextField(20);
96
        this.add(textTranslation2, c);
100
        this.add(this.textTranslation2, c);
97
 
101
 
98
        c.gridy++;
102
        c.gridy++;
99
        c.weighty = 1;
103
        c.weighty = 1;
100
        this.add(new JPanel(), c);
104
        this.add(new JPanel(), c);
101
 
105
 
102
        initUIFrom(item);
106
        initUIFrom(item);
103
 
107
 
104
        textTranslation1.getDocument().addDocumentListener(new DocumentListener() {
108
        this.textTranslation1.getDocument().addDocumentListener(new DocumentListener() {
105
 
109
 
106
            @Override
110
            @Override
107
            public void removeUpdate(DocumentEvent e) {
111
            public void removeUpdate(DocumentEvent e) {
108
                changedUpdate(e);
112
                changedUpdate(e);
109
 
113
 
Line 114... Line 118...
114
                changedUpdate(e);
118
                changedUpdate(e);
115
            }
119
            }
116
 
120
 
117
            @Override
121
            @Override
118
            public void changedUpdate(DocumentEvent e) {
122
            public void changedUpdate(DocumentEvent e) {
119
                extension.setMenuTranslation(item.getId(), textTranslation1.getText(), comboLang1.getLocale());
123
                extension.setMenuTranslation(item.getId(), MenuTranslationItemEditor.this.textTranslation1.getText(), comboLang1.getLocale());
120
                extension.setChanged();
124
                extension.setChanged();
121
            }
125
            }
122
        });
126
        });
123
        textTranslation2.getDocument().addDocumentListener(new DocumentListener() {
127
        this.textTranslation2.getDocument().addDocumentListener(new DocumentListener() {
124
 
128
 
125
            @Override
129
            @Override
126
            public void removeUpdate(DocumentEvent e) {
130
            public void removeUpdate(DocumentEvent e) {
127
                changedUpdate(e);
131
                changedUpdate(e);
128
 
132
 
Line 133... Line 137...
133
                changedUpdate(e);
137
                changedUpdate(e);
134
            }
138
            }
135
 
139
 
136
            @Override
140
            @Override
137
            public void changedUpdate(DocumentEvent e) {
141
            public void changedUpdate(DocumentEvent e) {
138
                extension.setMenuTranslation(item.getId(), textTranslation2.getText(), comboLang2.getLocale());
142
                extension.setMenuTranslation(item.getId(), MenuTranslationItemEditor.this.textTranslation2.getText(), comboLang2.getLocale());
139
                extension.setChanged();
143
                extension.setChanged();
140
            }
144
            }
141
        });
145
        });
-
 
146
        comboLang1.addActionListener(new ActionListener() {
-
 
147
 
-
 
148
            @Override
-
 
149
            public void actionPerformed(ActionEvent e) {
-
 
150
                MenuTranslation t = extension.getMenuTranslation(textId.getText(), comboLang1.getLocale().toString());
-
 
151
                if (t != null) {
-
 
152
                    textTranslation1.setText(t.getLabel());
-
 
153
                } else {
-
 
154
                    textTranslation1.setText("");
-
 
155
                }
-
 
156
            }
-
 
157
        });
-
 
158
        comboLang2.addActionListener(new ActionListener() {
-
 
159
 
-
 
160
            @Override
-
 
161
            public void actionPerformed(ActionEvent e) {
-
 
162
                MenuTranslation t = extension.getMenuTranslation(textId.getText(), comboLang2.getLocale().toString());
-
 
163
                if (t != null) {
-
 
164
                    textTranslation2.setText(t.getLabel());
-
 
165
                } else {
-
 
166
                    textTranslation2.setText("");
-
 
167
                }
-
 
168
            }
-
 
169
        });
142
 
170
 
143
    }
171
    }
144
 
172
 
145
    private void initUIFrom(Item item) {
173
    private void initUIFrom(Item item) {
146
 
174
 
147
        final LayoutHints localHint = item.getLocalHint();
175
        final LayoutHints localHint = item.getLocalHint();
148
        System.out.println("ItemEditor.initUIFrom:" + item + " " + localHint);
176
        System.out.println("ItemEditor.initUIFrom:" + item + " " + localHint);
149
        textId.setEnabled(false);
177
        this.textId.setEnabled(false);
150
        if (textId != null) {
178
        if (this.textId != null) {
151
            textId.setText(item.getId());
179
            this.textId.setText(item.getId());
-
 
180
        }
-
 
181
        MenuTranslation t = extension.getMenuTranslation(textId.getText(), comboLang1.getLocale().toString());
-
 
182
        if (t != null) {
-
 
183
            textTranslation1.setText(t.getLabel());
-
 
184
        } else {
-
 
185
            textTranslation1.setText("");
-
 
186
        }
-
 
187
        t = extension.getMenuTranslation(textId.getText(), comboLang2.getLocale().toString());
-
 
188
        if (t != null) {
-
 
189
            textTranslation2.setText(t.getLabel());
-
 
190
        } else {
-
 
191
            textTranslation2.setText("");
152
        }
192
        }
153
 
-
 
154
    }
193
    }
155
}
194
}