-
Notifications
You must be signed in to change notification settings - Fork 45
/
TreeItem.java
197 lines (149 loc) · 4.94 KB
/
TreeItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.trees;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import org.eclipse.sirius.components.annotations.Immutable;
/**
* An item of the tree.
*
* @author sbegaudeau
*/
@Immutable
public final class TreeItem {
public static final String SELECTED_TREE_ITEM = "selectedTreeItem";
private String id;
private String kind;
private String label;
private String imageURL;
private boolean editable;
private boolean deletable;
private boolean selectable;
private boolean hasChildren;
private boolean expanded;
private List<TreeItem> children;
private TreeItem() {
// Prevent instantiation
}
public String getId() {
return this.id;
}
public String getKind() {
return this.kind;
}
public String getLabel() {
return this.label;
}
public boolean isEditable() {
return this.editable;
}
public boolean isDeletable() {
return this.deletable;
}
public boolean isSelectable() {
return this.selectable;
}
public String getImageURL() {
return this.imageURL;
}
public boolean isHasChildren() {
return this.hasChildren;
}
public boolean isExpanded() {
return this.expanded;
}
public List<TreeItem> getChildren() {
return this.children;
}
public static Builder newTreeItem(String id) {
return new Builder(id);
}
@Override
public String toString() {
String pattern = "{0} '{'id: {1}, kind: {2}, label: {3}, editable: {4}, deletable: {5}, imageURL: {6}, hasChildren: {7}, expanded: {8}, childCount: {9}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.kind, this.label, this.editable, this.deletable, this.imageURL, this.hasChildren, this.expanded,
this.children.size());
}
/**
* The builder used to create the tree item.
*
* @author sbegaudeau
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {
private String id;
private String kind;
private String label;
private String imageURL;
private boolean editable;
private boolean deletable;
private boolean selectable;
private boolean hasChildren;
private boolean expanded;
private List<TreeItem> children;
private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
public Builder kind(String kind) {
this.kind = Objects.requireNonNull(kind);
return this;
}
public Builder label(String label) {
this.label = Objects.requireNonNull(label);
return this;
}
public Builder imageURL(String imageURL) {
this.imageURL = Objects.requireNonNull(imageURL);
return this;
}
public Builder editable(boolean editable) {
this.editable = editable;
return this;
}
public Builder deletable(boolean deletable) {
this.deletable = deletable;
return this;
}
public Builder selectable(boolean selectable) {
this.selectable = selectable;
return this;
}
public Builder hasChildren(boolean hasChildren) {
this.hasChildren = hasChildren;
return this;
}
public Builder expanded(boolean expanded) {
this.expanded = expanded;
return this;
}
public Builder children(List<TreeItem> children) {
this.children = Objects.requireNonNull(children);
return this;
}
public TreeItem build() {
TreeItem treeItem = new TreeItem();
treeItem.id = Objects.requireNonNull(this.id);
treeItem.kind = Objects.requireNonNull(this.kind);
treeItem.label = Objects.requireNonNull(this.label);
treeItem.imageURL = Objects.requireNonNull(this.imageURL);
treeItem.editable = this.editable;
treeItem.deletable = this.deletable;
treeItem.selectable = this.selectable;
treeItem.expanded = this.expanded;
treeItem.hasChildren = this.hasChildren;
treeItem.children = Objects.requireNonNull(this.children);
return treeItem;
}
}
}