OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 156 Rev 182
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-2019 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 net.minidev.json.JSONObject;
16
import net.minidev.json.JSONObject;
17
 
17
 
18
public class LightUICheckBox extends LightUserControl {
18
public class LightUICheckBox extends LightUserControl {
19
 
19
 
20
    public LightUICheckBox() {
20
    public LightUICheckBox() {
21
        // for serialization
21
        // for serialization
22
    }
22
    }
23
 
23
 
24
    public LightUICheckBox(final JSONObject json) {
24
    public LightUICheckBox(final JSONObject json) {
25
        super(json);
25
        super(json);
26
    }
26
    }
27
 
27
 
28
    public LightUICheckBox(final String id, final String label) {
28
    public LightUICheckBox(final String id, final String label) {
29
        super(id);
29
        super(id);
30
        this.setType(TYPE_CHECKBOX);
30
        this.setType(TYPE_CHECKBOX);
31
 
31
 
32
        this.setLabel(label);
32
        this.setLabel(label);
33
        this.setValueType(LightUIElement.VALUE_TYPE_BOOLEAN);
33
        this.setValueType(LightUIElement.VALUE_TYPE_BOOLEAN);
34
    }
34
    }
35
 
35
 
36
    public LightUICheckBox(final LightUICheckBox button) {
36
    public LightUICheckBox(final LightUICheckBox button) {
37
        super(button);
37
        super(button);
38
    }
38
    }
39
 
39
 
40
    public void setChecked(boolean checked) {
40
    public void setChecked(boolean checked) {
41
        if (checked) {
41
        if (checked) {
42
            this.setValue("true");
42
            this.setValue("true");
43
        } else {
43
        } else {
44
            this.setValue("false");
44
            this.setValue("false");
45
        }
45
        }
46
    }
46
    }
47
 
47
 
48
    public boolean isChecked() {
48
    public boolean isChecked() {
49
        if (this.getValue() == null) {
49
        if (this.getValue() == null) {
50
            return false;
50
            return false;
51
        }
51
        }
52
        return this.getValue().equals("true");
52
        return this.getValue().equals("true");
53
    }
53
    }
54
 
54
 
55
    @Override
55
    @Override
56
    public Object getValueForContext() {
56
    public Object getValueForContext() {
57
        return this.isChecked();
57
        return this.isChecked();
58
    }
58
    }
59
 
59
 
60
    @Override
60
    @Override
61
    public void _setValueFromContext(Object value) {
61
    public void _setValueFromContext(Object value) {
62
        boolean bValue = false;
62
        boolean bValue = false;
63
        if (value != null) {
63
        if (value != null) {
64
            if (value.equals("true")) {
64
            if (value.equals("true")) {
65
                bValue = true;
65
                bValue = true;
66
            }
66
            }
67
            if (value.equals(true)) {
67
            if (value.equals(true)) {
68
                bValue = true;
68
                bValue = true;
69
            }
69
            }
70
        }
70
        }
71
        this.setChecked(bValue);
71
        this.setChecked(bValue);
72
    }
72
    }
73
}
73
}