OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 142 Rev 156
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.ui.light;
14
 package org.openconcerto.ui.light;
15
 
15
 
16
import org.openconcerto.utils.io.JSONConverter;
16
import org.openconcerto.utils.io.JSONConverter;
17
import org.openconcerto.utils.io.Transferable;
17
import org.openconcerto.utils.io.Transferable;
18
 
18
 
-
 
19
import java.io.Externalizable;
-
 
20
import java.io.IOException;
-
 
21
import java.io.ObjectInput;
-
 
22
import java.io.ObjectOutput;
-
 
23
 
19
import net.minidev.json.JSONObject;
24
import net.minidev.json.JSONObject;
20
 
25
 
21
public class LightUIComboBoxElement implements Transferable {
26
public class LightUIComboBoxElement implements Transferable, Externalizable {
22
    /**
27
    /**
23
     * ID of row, must be unique for a LightUIComboBox. It's represent the SQLRow ID when the
28
     * ID of row, must be unique for a LightUIComboBox. It's represent the SQLRow ID when the
24
     * LightUICombo is attach to a field in database
29
     * LightUICombo is attach to a field in database
25
     */
30
     */
26
    private Integer id = null;
31
    private Integer id = null;
27
 
32
 
28
    private String value1 = null;
33
    private String value1 = null;
29
    private String value2 = null;
34
    private String value2 = null;
30
    private String icon = null;
35
    private String icon = null;
31
 
36
 
-
 
37
    public LightUIComboBoxElement() {
-
 
38
        // Serialization
-
 
39
    }
-
 
40
 
32
    public LightUIComboBoxElement(final JSONObject json) {
41
    public LightUIComboBoxElement(final JSONObject json) {
33
        this.fromJSON(json);
42
        this.fromJSON(json);
34
    }
43
    }
35
 
44
 
36
    public LightUIComboBoxElement(final int id) {
45
    public LightUIComboBoxElement(final int id) {
37
        this.id = id;
46
        this.id = id;
38
    }
47
    }
39
    
48
 
40
    public LightUIComboBoxElement(final int id, final String value1) {
49
    public LightUIComboBoxElement(final int id, final String value1) {
41
        this.id = id;
50
        this.id = id;
42
        this.value1 = value1;
51
        this.value1 = value1;
43
    }
52
    }
44
    
53
 
45
    public LightUIComboBoxElement(final int id, final String value1, final String value2) {
54
    public LightUIComboBoxElement(final int id, final String value1, final String value2) {
46
        this.id = id;
55
        this.id = id;
47
        this.value1 = value1;
56
        this.value1 = value1;
48
        this.value2 = value2;
57
        this.value2 = value2;
49
    }
58
    }
50
 
59
 
51
    public LightUIComboBoxElement(final LightUIComboBoxElement comboElement) {
60
    public LightUIComboBoxElement(final LightUIComboBoxElement comboElement) {
52
        this.id = comboElement.id;
61
        this.id = comboElement.id;
53
        this.value1 = comboElement.value1;
62
        this.value1 = comboElement.value1;
54
        this.value2 = comboElement.value2;
63
        this.value2 = comboElement.value2;
55
        this.icon = comboElement.icon;
64
        this.icon = comboElement.icon;
56
    }
65
    }
57
 
66
 
58
    public int getId() {
67
    public int getId() {
59
        return this.id;
68
        return this.id;
60
    }
69
    }
61
 
70
 
62
    public String getValue1() {
71
    public String getValue1() {
63
        return this.value1;
72
        return this.value1;
64
    }
73
    }
65
 
74
 
66
    public String getValue2() {
75
    public String getValue2() {
67
        return this.value2;
76
        return this.value2;
68
    }
77
    }
69
 
78
 
70
    public String getIcon() {
79
    public String getIcon() {
71
        return this.icon;
80
        return this.icon;
72
    }
81
    }
73
 
82
 
74
    public void setValue1(final String value1) {
83
    public void setValue1(final String value1) {
75
        this.value1 = value1;
84
        this.value1 = value1;
76
    }
85
    }
77
 
86
 
78
    public void setValue2(final String value2) {
87
    public void setValue2(final String value2) {
79
        this.value2 = value2;
88
        this.value2 = value2;
80
    }
89
    }
81
 
90
 
82
    public void setIcon(final String icon) {
91
    public void setIcon(final String icon) {
83
        this.icon = icon;
92
        this.icon = icon;
84
    }
93
    }
85
 
94
 
86
    @Override
95
    @Override
87
    public JSONObject toJSON() {
96
    public JSONObject toJSON() {
88
        final JSONObject json = new JSONObject();
97
        final JSONObject json = new JSONObject();
89
 
98
 
90
        if (this.id == null) {
99
        if (this.id == null) {
91
            throw new IllegalArgumentException("Attribute id must be not null before send to client");
100
            throw new IllegalArgumentException("Attribute id must be not null before send to client");
92
        }
101
        }
93
        json.put("id", this.id);
102
        json.put("id", this.id);
94
        json.put("class", "LightUIComboBoxElement");
103
        json.put("class", "LightUIComboBoxElement");
95
 
104
 
96
        if (this.value1 != null) {
105
        if (this.value1 != null) {
97
            json.put("value1", this.value1);
106
            json.put("value1", this.value1);
98
        }
107
        }
99
        if (this.value2 != null) {
108
        if (this.value2 != null) {
100
            json.put("value2", this.value2);
109
            json.put("value2", this.value2);
101
        }
110
        }
102
        if (this.icon != null) {
111
        if (this.icon != null) {
103
            json.put("icon", this.icon);
112
            json.put("icon", this.icon);
104
        }
113
        }
105
 
114
 
106
        return json;
115
        return json;
107
    }
116
    }
108
 
117
 
109
    @Override
118
    @Override
110
    public void fromJSON(final JSONObject json) {
119
    public void fromJSON(final JSONObject json) {
111
        this.id = (Integer) JSONConverter.getParameterFromJSON(json, "id", Integer.class);
120
        this.id = JSONConverter.getParameterFromJSON(json, "id", Integer.class);
112
        this.value1 = (String) JSONConverter.getParameterFromJSON(json, "value1", String.class);
121
        this.value1 = JSONConverter.getParameterFromJSON(json, "value1", String.class);
113
        this.value2 = (String) JSONConverter.getParameterFromJSON(json, "value2", String.class);
122
        this.value2 = JSONConverter.getParameterFromJSON(json, "value2", String.class);
114
        this.icon = (String) JSONConverter.getParameterFromJSON(json, "icon", String.class);
123
        this.icon = JSONConverter.getParameterFromJSON(json, "icon", String.class);
-
 
124
    }
-
 
125
 
-
 
126
    @Override
-
 
127
    public void writeExternal(ObjectOutput out) throws IOException {
-
 
128
        // TODO : value1,value2 et icon -> "" par défaut
-
 
129
        if (value1 == null)
-
 
130
            value1 = "";
-
 
131
        if (value2 == null)
-
 
132
            value2 = "";
-
 
133
        if (icon == null)
-
 
134
            icon = "";
-
 
135
        out.writeInt(id);
-
 
136
        out.writeUTF(value1);
-
 
137
        out.writeUTF(value2);
-
 
138
        out.writeUTF(icon);
-
 
139
    }
-
 
140
 
-
 
141
    @Override
-
 
142
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
143
        this.id = in.readInt();
-
 
144
        this.value1 = in.readUTF();
-
 
145
        this.value2 = in.readUTF();
-
 
146
        this.icon = in.readUTF();
-
 
147
 
-
 
148
    }
-
 
149
 
-
 
150
    @Override
-
 
151
    public String toString() {
-
 
152
        return id + ":" + value1 + ":" + value2;
115
    }
153
    }
116
}
154
}