OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
67 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.group;
15
 
16
import java.util.HashSet;
17
import java.util.Set;
18
 
19
public class Item {
20
    private String id;
21
    protected Group parent;
22
    protected LayoutHints localHint;
23
 
24
    public Item(String id) {
25
        this.id = id.trim();
26
        this.localHint = new LayoutHints(LayoutHints.DEFAULT_FIELD_HINTS);
27
    }
28
 
29
    public Item(String id, LayoutHints hint) {
30
        this.id = id.trim();
31
        this.localHint = new LayoutHints(hint);
32
    }
33
 
34
    public String getId() {
35
        return id;
36
    }
37
 
38
    public void setId(String id) {
39
        this.id = id;
40
    }
41
 
42
    public Group getParent() {
43
        return parent;
44
    }
45
 
46
    public LayoutHints getLocalHint() {
47
        return localHint;
48
    }
49
 
50
    public void setLocalHint(LayoutHints localHint) {
51
        this.localHint = localHint;
52
    }
53
 
54
    public Group getRoot() {
55
        final Set<String> roots = new HashSet<String>();
56
        Group root = parent;
57
        while (root != null) {
58
            if (roots.contains(root)) {
59
                throw new IllegalStateException("Loop detected in group hierarchy at " + root.getId() + " for " + roots);
60
            }
61
            roots.add(root.getId());
62
            root = root.getParent();
63
        }
64
        return root;
65
    }
66
 
67
    public void dumpOneColumn(StringBuilder builder, int localOrder, int level) {
68
        for (int i = 0; i < level - 1; i++) {
69
            builder.append("  ");
70
        }
71
 
72
        builder.append("+-- ");
73
        builder.append(localOrder + " " + this.getId() + " [" + localHint + "]\n");
74
    }
75
 
76
    public int dumpTwoColumn(StringBuilder builder, int x, int localOrder, int level) {
77
        if (localHint.largeWidth() && x > 0) {
78
            builder.append("\n");
79
            x = 0;
80
        }
81
        // print a leaf
82
        builder.append(" (" + x + ")");
83
        builder.append(localOrder + " " + this.getId() + "[" + localHint + "]");
84
 
85
        if (localHint.largeWidth()) {
86
            x += 2;
87
        } else {
88
            x++;
89
        }
90
 
91
        if (x > 1) {
92
            builder.append("\n");
93
            x = 0;
94
        }
95
        return x;
96
    }
97
 
98
    @Override
99
    public String toString() {
100
        return "Item:" + this.getId();
101
    }
102
}