OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 132 | 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 org.openconcerto.utils.io.JSONConverter;
132 ilm 17
 
94 ilm 18
import net.minidev.json.JSONObject;
19
 
132 ilm 20
public class LightUIButtonWithSelectionContext extends LightUIButton {
94 ilm 21
 
156 ilm 22
    private RowSelectionSpec tableSelection;
132 ilm 23
 
24
    public LightUIButtonWithSelectionContext(final JSONObject json) {
25
        super(json);
94 ilm 26
    }
132 ilm 27
 
28
    public LightUIButtonWithSelectionContext(final String id, final RowSelectionSpec tableSelection) {
29
        super(id, LightUIElement.TYPE_BUTTON_WITH_SELECTION_CONTEXT);
30
        this.tableSelection = tableSelection;
31
    }
32
 
33
    public LightUIButtonWithSelectionContext(final LightUIButtonWithSelectionContext button) {
34
        super(button);
35
    }
36
 
156 ilm 37
    @Override
38
    public void destroy() {
39
        super.destroy();
40
        this.tableSelection = null;
41
    }
42
 
132 ilm 43
    public RowSelectionSpec getTableSelection() {
44
        return this.tableSelection;
45
    }
46
 
47
    @Override
48
    protected void copy(final LightUIElement element) {
49
        super.copy(element);
50
 
51
        if (!(element instanceof LightUIButtonWithSelectionContext)) {
52
            throw new InvalidClassException(LightUIButtonWithSelectionContext.class.getName(), element.getClassName(), element.getId());
53
        }
54
        final LightUIButtonWithSelectionContext button = (LightUIButtonWithSelectionContext) element;
55
        this.tableSelection = button.tableSelection;
56
    }
57
 
58
    @Override
59
    public void fromJSON(final JSONObject json) {
94 ilm 60
        super.fromJSON(json);
156 ilm 61
        this.tableSelection = new RowSelectionSpec();
62
        final JSONObject o = (JSONObject) json.get("table-selection");
63
        this.tableSelection.fromJSON(o);
94 ilm 64
    }
132 ilm 65
 
66
    @Override
67
    public JSONObject toJSON() {
94 ilm 68
        final JSONObject json = super.toJSON();
132 ilm 69
        json.put("table-selection", this.tableSelection.toJSON());
94 ilm 70
        return json;
71
    }
72
}