OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 Rev 156
Line 14... Line 14...
14
 package org.openconcerto.ui.light;
14
 package org.openconcerto.ui.light;
15
 
15
 
16
import org.openconcerto.utils.i18n.TranslationManager;
16
import org.openconcerto.utils.i18n.TranslationManager;
17
import org.openconcerto.utils.io.JSONConverter;
17
import org.openconcerto.utils.io.JSONConverter;
18
 
18
 
-
 
19
import java.io.IOException;
-
 
20
import java.io.ObjectInput;
-
 
21
import java.io.ObjectOutput;
19
import java.util.ArrayList;
22
import java.util.ArrayList;
20
import java.util.List;
23
import java.util.List;
21
 
24
 
22
import net.minidev.json.JSONArray;
25
import net.minidev.json.JSONArray;
23
import net.minidev.json.JSONObject;
26
import net.minidev.json.JSONObject;
Line 31... Line 34...
31
    private boolean alreadyFilled = false;
34
    private boolean alreadyFilled = false;
32
    private boolean hasNotSpecifedLine = false;
35
    private boolean hasNotSpecifedLine = false;
33
 
36
 
34
    private LightUIComboBoxElement selectedValue = null;
37
    private LightUIComboBoxElement selectedValue = null;
35
 
38
 
36
    private List<LightUIComboBoxElement> values = new ArrayList<LightUIComboBoxElement>();
39
    private List<LightUIComboBoxElement> values = new ArrayList<>();
-
 
40
 
-
 
41
    public LightUIComboBox() {
-
 
42
        // Serialization
-
 
43
    }
37
 
44
 
38
    // Init from json constructor
45
    // Init from json constructor
39
    public LightUIComboBox(final JSONObject json) {
46
    public LightUIComboBox(final JSONObject json) {
40
        super(json);
47
        super(json);
41
    }
48
    }
Line 136... Line 143...
136
        this.values = combo.values;
143
        this.values = combo.values;
137
        this.selectedValue = combo.selectedValue;
144
        this.selectedValue = combo.selectedValue;
138
    }
145
    }
139
 
146
 
140
    @Override
147
    @Override
141
    public JSONToLightUIConvertor getConvertor() {
-
 
142
        return new JSONToLightUIConvertor() {
-
 
143
            @Override
-
 
144
            public LightUIElement convert(final JSONObject json) {
-
 
145
                return new LightUIComboBox(json);
-
 
146
            }
-
 
147
        };
-
 
148
    }
-
 
149
 
-
 
150
    @Override
-
 
151
    public JSONObject toJSON() {
148
    public JSONObject toJSON() {
152
        final JSONObject json = super.toJSON();
149
        final JSONObject json = super.toJSON();
153
 
150
 
154
        if (this.values != null && !this.values.isEmpty()) {
151
        if (this.values != null && !this.values.isEmpty()) {
155
            final JSONArray jsonValues = new JSONArray();
152
            final JSONArray jsonValues = new JSONArray();
Line 213... Line 210...
213
    }
210
    }
214
 
211
 
215
    @Override
212
    @Override
216
    public void destroy() {
213
    public void destroy() {
217
        super.destroy();
214
        super.destroy();
-
 
215
        this.selectedValue = null;
-
 
216
        this.values = null;
-
 
217
    }
-
 
218
 
-
 
219
    @Override
-
 
220
    public void writeExternal(ObjectOutput out) throws IOException {
-
 
221
        super.writeExternal(out);
-
 
222
        out.writeBoolean(this.alreadyFilled);
-
 
223
        out.writeBoolean(this.hasNotSpecifedLine);
-
 
224
 
-
 
225
        if (this.selectedValue != null) {
-
 
226
            out.writeBoolean(true);
-
 
227
            this.selectedValue.writeExternal(out);
-
 
228
        } else {
-
 
229
            out.writeBoolean(false);
-
 
230
        }
-
 
231
        out.writeInt(this.values.size());
-
 
232
        for (LightUIComboBoxElement e : this.values) {
-
 
233
            e.writeExternal(out);
-
 
234
        }
-
 
235
 
-
 
236
    }
-
 
237
 
-
 
238
    @Override
-
 
239
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
240
        super.readExternal(in);
-
 
241
        this.alreadyFilled = in.readBoolean();
-
 
242
        this.hasNotSpecifedLine = in.readBoolean();
-
 
243
        if (in.readBoolean()) {
-
 
244
            this.selectedValue = new LightUIComboBoxElement();
-
 
245
            this.selectedValue.readExternal(in);
-
 
246
        }
-
 
247
        int size = in.readInt();
218
        this.clearValues();
248
        this.values.clear();
-
 
249
        for (int i = 0; i < size; i++) {
-
 
250
            LightUIComboBoxElement e = new LightUIComboBoxElement();
-
 
251
            e.readExternal(in);
-
 
252
            this.values.add(e);
-
 
253
        }
-
 
254
 
219
    }
255
    }
220
}
256
}