OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 83 Rev 180
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.ui.group;
14
 package org.openconcerto.ui.group;
15
 
15
 
16
import java.util.Collection;
16
import java.util.Collection;
17
import java.util.Collections;
17
import java.util.Collections;
-
 
18
import java.util.LinkedList;
-
 
19
import java.util.List;
-
 
20
import java.util.concurrent.atomic.AtomicReference;
-
 
21
import java.util.function.Consumer;
18
 
22
 
19
import net.jcip.annotations.GuardedBy;
23
import net.jcip.annotations.GuardedBy;
20
 
24
 
21
public class Item {
25
public class Item {
22
 
26
 
Line 64... Line 68...
64
    protected final void checkFrozen(String op) {
68
    protected final void checkFrozen(String op) {
65
        if (this.isFrozen())
69
        if (this.isFrozen())
66
            throw new IllegalStateException("Frozen cannot " + op);
70
            throw new IllegalStateException("Frozen cannot " + op);
67
    }
71
    }
68
 
72
 
69
    public synchronized void freeze() {
73
    public synchronized final void freeze() {
-
 
74
        if (this.getParent() != null)
-
 
75
            throw new IllegalStateException("Can only freeze from the root down");
-
 
76
        this._freeze();
-
 
77
    }
-
 
78
 
-
 
79
    protected synchronized void _freeze() {
70
        this.frozen = true;
80
        this.frozen = true;
71
    }
81
    }
72
 
82
 
73
    public final Item getChildFromID(final String id) {
83
    public final Item getChildFromID(final String id) {
74
        return this.getDescFromID(id, 1);
84
        return this.getDescFromID(id, 1);
Line 111... Line 121...
111
    public void setLocalHint(final LayoutHints localHint) {
121
    public void setLocalHint(final LayoutHints localHint) {
112
        checkFrozen("setLocalHint");
122
        checkFrozen("setLocalHint");
113
        this.localHint = new LayoutHints(localHint == null ? LayoutHints.DEFAULT_FIELD_HINTS : localHint);
123
        this.localHint = new LayoutHints(localHint == null ? LayoutHints.DEFAULT_FIELD_HINTS : localHint);
114
    }
124
    }
115
 
125
 
116
    public final Group getRoot() {
126
    public final void applyUntilRoot(final Consumer<Item> cons) {
117
        Item current = this;
127
        Item current = this;
118
        while (current.getParent() != null) {
128
        while (current != null) {
-
 
129
            cons.accept(current);
119
            current = current.getParent();
130
            current = current.getParent();
120
        }
131
        }
-
 
132
    }
-
 
133
 
-
 
134
    public final List<String> getAbsolutePath() {
-
 
135
        final LinkedList<String> res = new LinkedList<>();
-
 
136
        this.applyUntilRoot((item) -> res.addFirst(item.getId()));
-
 
137
        return res;
-
 
138
    }
-
 
139
 
-
 
140
    public final Group getRoot() {
-
 
141
        final AtomicReference<Item> current = new AtomicReference<>();
-
 
142
        this.applyUntilRoot((item) -> current.set(item));
121
        return current instanceof Group ? (Group) current : null;
143
        return current.get() instanceof Group ? (Group) current.get() : null;
122
    }
144
    }
123
 
145
 
124
    protected void printTree(final StringBuilder builder, final int localOrder, final int level) {
146
    protected void printTree(final StringBuilder builder, final int localOrder, final int level) {
125
        for (int i = 0; i < level - 1; i++) {
147
        for (int i = 0; i < level - 1; i++) {
126
            builder.append("  ");
148
            builder.append("  ");