OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
Line 13... Line 13...
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
 
17
 
-
 
18
import java.io.IOException;
-
 
19
import java.io.ObjectInput;
-
 
20
import java.io.ObjectOutput;
18
import java.io.PrintStream;
21
import java.io.PrintStream;
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;
24
 
27
 
25
public class LightUIContainer extends LightUIElement {
28
public class LightUIContainer extends LightUIElement {
26
    private List<LightUIElement> children = new ArrayList<LightUIElement>(1);
29
    private List<LightUIElement> children = new ArrayList<LightUIElement>(1);
27
 
30
 
-
 
31
    public LightUIContainer() {
-
 
32
        // Serialization
-
 
33
    }
-
 
34
 
28
    public LightUIContainer(final String id) {
35
    public LightUIContainer(final String id) {
29
        super(id);
36
        super(id);
30
    }
37
    }
31
 
38
 
32
    public LightUIContainer(final JSONObject json) {
39
    public LightUIContainer(final JSONObject json) {
Line 89... Line 96...
89
 
96
 
90
    public int getChildrenCount() {
97
    public int getChildrenCount() {
91
        return this.children.size();
98
        return this.children.size();
92
    }
99
    }
93
 
100
 
-
 
101
    /**
-
 
102
     * Remove all the children from this container
-
 
103
     * 
-
 
104
     * Warning : it doesn't destroy the children
-
 
105
     */
94
    public void clear() {
106
    public void clear() {
95
        this.children.clear();
107
        this.children.clear();
96
    }
108
    }
97
 
109
 
98
    public boolean replaceChild(final LightUIElement pChild) {
110
    public boolean replaceChild(final LightUIElement pChild) {
Line 271... Line 283...
271
                final JSONObject jsonElement = JSONConverter.getObjectFromJSON(o, JSONObject.class);
283
                final JSONObject jsonElement = JSONConverter.getObjectFromJSON(o, JSONObject.class);
272
                if (jsonElement == null) {
284
                if (jsonElement == null) {
273
                    throw new IllegalArgumentException("null element in json parameter");
285
                    throw new IllegalArgumentException("null element in json parameter");
274
                }
286
                }
275
                final LightUIElement lightElement = JSONToLightUIConvertorManager.getInstance().createUIElementFromJSON(jsonElement);
287
                final LightUIElement lightElement = JSONToLightUIConvertorManager.getInstance().createUIElementFromJSON(jsonElement);
276
                this.children.add(lightElement);
288
                this.addChild(lightElement);
277
            }
289
            }
278
        }
290
        }
279
    }
291
    }
280
 
292
 
281
    @Override
293
    @Override
282
    public void destroy() {
294
    public void writeExternal(ObjectOutput out) throws IOException {
283
        super.destroy();
295
        super.writeExternal(out);
-
 
296
        out.writeInt(this.children.size());
284
        for (final LightUIElement child : this.children) {
297
        for (LightUIElement e : this.children) {
285
            child.destroy();
298
            out.writeObject(e);
286
        }
299
        }
287
    }
300
    }
288
 
301
 
289
    @Override
302
    @Override
-
 
303
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-
 
304
        super.readExternal(in);
290
    public JSONToLightUIConvertor getConvertor() {
305
        int n = in.readInt();
-
 
306
        this.children.clear();
291
        return new JSONToLightUIConvertor() {
307
        for (int i = 0; i < n; i++) {
-
 
308
            LightUIElement e = (LightUIElement) in.readObject();
-
 
309
            this.children.add(e);
-
 
310
        }
-
 
311
 
-
 
312
    }
-
 
313
 
292
            @Override
314
    @Override
-
 
315
    public void destroy() {
-
 
316
        super.destroy();
293
            public LightUIElement convert(JSONObject json) {
317
        for (final LightUIElement child : this.children) {
294
                return new LightUIContainer(json);
318
            child.destroy();
295
            }
319
        }
296
        };
-
 
297
    }
320
    }
-
 
321
 
298
}
322
}