1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.contrib.inspector; |
16 |
| |
17 |
| import java.util.ArrayList; |
18 |
| import java.util.Collections; |
19 |
| import java.util.HashSet; |
20 |
| import java.util.List; |
21 |
| import java.util.Set; |
22 |
| |
23 |
| import org.apache.tapestry.BaseComponent; |
24 |
| import org.apache.tapestry.IComponent; |
25 |
| import org.apache.tapestry.INamespace; |
26 |
| import org.apache.tapestry.IRequestCycle; |
27 |
| import org.apache.tapestry.engine.ISpecificationSource; |
28 |
| import org.apache.tapestry.form.IPropertySelectionModel; |
29 |
| import org.apache.tapestry.form.StringPropertySelectionModel; |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| public abstract class Selector extends BaseComponent |
40 |
| { |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
0
| public void formSubmit(IRequestCycle cycle)
|
49 |
| { |
50 |
0
| Inspector inspector = (Inspector) getPage();
|
51 |
| |
52 |
0
| inspector.selectComponent((String) null);
|
53 |
| } |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
0
| public IPropertySelectionModel getPageModel()
|
62 |
| { |
63 |
0
| return new StringPropertySelectionModel(getPageNames());
|
64 |
| } |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
0
| public List getCrumbTrail()
|
73 |
| { |
74 |
0
| List result = null;
|
75 |
| |
76 |
0
| Inspector inspector = (Inspector) getPage();
|
77 |
0
| IComponent component = inspector.getInspectedComponent();
|
78 |
0
| IComponent container = null;
|
79 |
| |
80 |
0
| while (true)
|
81 |
| { |
82 |
0
| container = component.getContainer();
|
83 |
0
| if (container == null)
|
84 |
0
| break;
|
85 |
| |
86 |
0
| if (result == null)
|
87 |
0
| result = new ArrayList();
|
88 |
| |
89 |
0
| result.add(component);
|
90 |
| |
91 |
0
| component = container;
|
92 |
| } |
93 |
| |
94 |
0
| if (result == null)
|
95 |
0
| return null;
|
96 |
| |
97 |
| |
98 |
| |
99 |
| |
100 |
0
| Collections.reverse(result);
|
101 |
| |
102 |
0
| return result;
|
103 |
| } |
104 |
| |
105 |
0
| private String[] getPageNames()
|
106 |
| { |
107 |
0
| Set names = new HashSet();
|
108 |
| |
109 |
0
| ISpecificationSource source = getPage().getEngine().getSpecificationSource();
|
110 |
| |
111 |
0
| addPageNames(names, source.getFrameworkNamespace());
|
112 |
0
| addPageNames(names, source.getApplicationNamespace());
|
113 |
| |
114 |
0
| List l = new ArrayList(names);
|
115 |
0
| Collections.sort(l);
|
116 |
| |
117 |
0
| return (String[]) l.toArray(new String[l.size()]);
|
118 |
| } |
119 |
| |
120 |
0
| private void addPageNames(Set names, INamespace namespace)
|
121 |
| { |
122 |
0
| String idPrefix = namespace.getExtendedId();
|
123 |
| |
124 |
0
| List pageNames = namespace.getPageNames();
|
125 |
0
| int count = pageNames.size();
|
126 |
| |
127 |
0
| for (int i = 0; i < count; i++)
|
128 |
| { |
129 |
0
| String name = (String) pageNames.get(i);
|
130 |
| |
131 |
0
| if (idPrefix == null)
|
132 |
0
| names.add(name);
|
133 |
| else |
134 |
0
| names.add(idPrefix + ":" + name);
|
135 |
| } |
136 |
| |
137 |
0
| List ids = namespace.getChildIds();
|
138 |
0
| count = ids.size();
|
139 |
| |
140 |
0
| for (int i = 0; i < count; i++)
|
141 |
| { |
142 |
0
| String id = (String) ids.get(i);
|
143 |
| |
144 |
0
| addPageNames(names, namespace.getChildNamespace(id));
|
145 |
| } |
146 |
| } |
147 |
| |
148 |
| } |