forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainer.java
More file actions
executable file
·104 lines (101 loc) · 2.71 KB
/
Copy pathContainer.java
File metadata and controls
executable file
·104 lines (101 loc) · 2.71 KB
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
package javaforce.webui;
/** Base class for components that can "contain" other components.
*
* @author pquiring
*/
import java.util.*;
public abstract class Container extends Component {
public void setClient(WebUIClient client) {
super.setClient(client);
int cnt = count();
for(int a=0;a<cnt;a++) {
get(a).setClient(client);
}
}
public void init() {
super.init();
int cnt = count();
for(int a=0;a<cnt;a++) {
get(a).init();
}
}
public Component getComponent(String name) {
if (this.name != null && this.name.equals(name)) {
return this;
}
int cnt = count();
for(int a=0;a<cnt;a++) {
Component child = get(a);
if (child instanceof Container) {
Container container = (Container)child;
child = container.getComponent(name);
if (child != null) return child;
} else {
if (child.name != null && child.name.equals(name)) {
return child;
}
}
}
return null;
}
private ArrayList<Component> components = new ArrayList<Component>();
public Component get(int idx) {
return components.get(idx);
}
public Component get(String name) {
int cnt = count();
for(int a=0;a<cnt;a++) {
Component comp = get(a);
if (comp.id.equals(name)) return comp;
if (comp instanceof Container) {
Container container = (Container)comp;
comp = container.get(name);
if (comp != null) return comp;
}
}
return null;
}
public void set(int idx, Component c) {
components.set(idx, c);
}
/** Add component to end of components. */
public void add(Component comp) {
comp.parent = this;
components.add(comp);
if (client != null) {
comp.setClient(client);
comp.init();
}
if (id != null) {
sendEvent("add", new String[] {"html=" + comp.html()});
}
}
/** Add component at index. */
public void add(int idx, Component comp) {
comp.parent = this;
Component before = (idx < 0 || idx >= count()) ? null : components.get(idx);
components.add(idx, comp);
if (client != null) {
comp.setClient(client);
comp.init();
}
if (id != null) {
if (before == null)
sendEvent("add", new String[] {"html=" + comp.html()});
else
sendEvent("addbefore", new String[] {"html=" + comp.html(), "beforeid=" + before.id});
}
}
public void remove(Component comp) {
components.remove(comp);
}
public void remove(int idx) {
components.remove(idx);
}
public void removeAll() {
components.clear();
}
public int count() {
return components.size();
}
}