OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.ui.light;
15
 
16
import net.minidev.json.JSONObject;
17
 
142 ilm 18
public class LightUICheckBox extends LightUserControl {
94 ilm 19
 
156 ilm 20
    public LightUICheckBox() {
21
        // for serialization
22
    }
23
 
94 ilm 24
    public LightUICheckBox(final JSONObject json) {
132 ilm 25
        super(json);
94 ilm 26
    }
27
 
28
    public LightUICheckBox(final String id, final String label) {
132 ilm 29
        super(id);
94 ilm 30
        this.setType(TYPE_CHECKBOX);
132 ilm 31
 
94 ilm 32
        this.setLabel(label);
33
        this.setValueType(LightUIElement.VALUE_TYPE_BOOLEAN);
34
    }
35
 
132 ilm 36
    public LightUICheckBox(final LightUICheckBox button) {
37
        super(button);
38
    }
39
 
94 ilm 40
    public void setChecked(boolean checked) {
41
        if (checked) {
42
            this.setValue("true");
43
        } else {
44
            this.setValue("false");
45
        }
46
    }
47
 
48
    public boolean isChecked() {
49
        if (this.getValue() == null) {
50
            return false;
51
        }
52
        return this.getValue().equals("true");
53
    }
132 ilm 54
 
55
    @Override
142 ilm 56
    public Object getValueForContext() {
132 ilm 57
        return this.isChecked();
58
    }
59
 
60
    @Override
142 ilm 61
    public void _setValueFromContext(Object value) {
132 ilm 62
        boolean bValue = false;
63
        if (value != null) {
64
            if (value.equals("true")) {
65
                bValue = true;
66
            }
67
            if (value.equals(true)) {
68
                bValue = true;
69
            }
70
        }
71
        this.setChecked(bValue);
72
    }
94 ilm 73
}