1 |
|
package org.kuali.student.common.ui.client.mvc.breadcrumb; |
2 |
|
|
3 |
|
import java.util.ArrayList; |
4 |
|
import java.util.List; |
5 |
|
|
6 |
|
import org.kuali.student.common.ui.client.mvc.Controller; |
7 |
|
import org.kuali.student.common.ui.client.mvc.history.HistoryManager; |
8 |
|
import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel; |
9 |
|
|
10 |
|
import com.google.gwt.user.client.ui.ComplexPanel; |
11 |
|
import com.google.gwt.user.client.ui.Composite; |
12 |
|
import com.google.gwt.user.client.ui.Hyperlink; |
13 |
|
import com.google.gwt.user.client.ui.InlineLabel; |
14 |
|
import com.google.gwt.user.client.ui.Panel; |
15 |
|
import com.google.gwt.user.client.ui.Widget; |
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
@author |
21 |
|
|
22 |
|
|
|
|
| 0% |
Uncovered Elements: 90 (90) |
Complexity: 25 |
Complexity Density: 0.47 |
|
23 |
|
public class BreadcrumbManager extends Composite{ |
24 |
|
|
25 |
|
public static List<Hyperlink> links = new ArrayList<Hyperlink>(); |
26 |
|
|
27 |
|
private static List<String> names = new ArrayList<String>(); |
28 |
|
|
29 |
|
private static Controller root; |
30 |
|
private static ComplexPanel panel = new SpanPanel(); |
31 |
|
private static boolean panelEmpty = true; |
32 |
|
|
33 |
|
private static Panel parentPanel; |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.33 |
|
35 |
|
private static class BreadcrumbData{ |
36 |
|
private String name; |
37 |
|
private String path; |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
38 |
0
|
public BreadcrumbData(String name, String path) {... |
39 |
0
|
super(); |
40 |
0
|
this.name = name; |
41 |
0
|
this.path = path; |
42 |
|
} |
43 |
|
} |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@param |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
0
|
public static void bind(Controller controller){... |
51 |
0
|
root = controller; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 68 (68) |
Complexity: 18 |
Complexity Density: 0.45 |
|
60 |
0
|
public static void updateLinks(String historyStack){... |
61 |
0
|
if (root == null){ |
62 |
0
|
return; |
63 |
|
} |
64 |
|
|
65 |
0
|
links.clear(); |
66 |
0
|
panel.clear(); |
67 |
0
|
panelEmpty = true; |
68 |
0
|
names.clear(); |
69 |
0
|
root.collectBreadcrumbNames(names); |
70 |
|
|
71 |
0
|
String[] arr = HistoryManager.splitHistoryStack(historyStack); |
72 |
0
|
List<BreadcrumbData> breadcrumbs = new ArrayList<BreadcrumbData>(); |
73 |
|
|
74 |
0
|
if(arr.length == names.size()){ |
75 |
0
|
String path = ""; |
76 |
|
|
77 |
0
|
for(int i = 1; i < names.size(); i++){ |
78 |
0
|
path = path + "/" + arr[i]; |
79 |
0
|
String name = names.get(i); |
80 |
|
|
81 |
0
|
if(name != null && !name.isEmpty()){ |
82 |
0
|
breadcrumbs.add(new BreadcrumbData(name, path)); |
83 |
|
} |
84 |
|
} |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
0
|
else if(names.size() > arr.length){ |
89 |
0
|
String path = ""; |
90 |
0
|
int j = 1; |
91 |
|
|
92 |
0
|
for(int i = 1; i < names.size(); i++){ |
93 |
0
|
String name = names.get(i); |
94 |
0
|
if(name.contains("@")){ |
95 |
0
|
String[] split = name.split("@"); |
96 |
0
|
name = split[0]; |
97 |
0
|
if(name != null && !name.isEmpty()){ |
98 |
|
|
99 |
0
|
breadcrumbs.add(new BreadcrumbData(name, split[1])); |
100 |
|
} |
101 |
|
} |
102 |
|
else{ |
103 |
0
|
if(j == arr.length){ |
104 |
0
|
break; |
105 |
|
} |
106 |
0
|
path = path + "/" + arr[j]; |
107 |
0
|
j++; |
108 |
0
|
if(name != null && !name.isEmpty()){ |
109 |
0
|
breadcrumbs.add(new BreadcrumbData(name, path)); |
110 |
|
} |
111 |
|
} |
112 |
|
} |
113 |
|
} |
114 |
|
|
115 |
0
|
if(parentPanel != null){ |
116 |
0
|
if(breadcrumbs.size() == 1){ |
117 |
0
|
panel.getParent().setVisible(false); |
118 |
|
} |
119 |
|
else{ |
120 |
0
|
panel.getParent().setVisible(true); |
121 |
|
|
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
0
|
for(int i = 0; i < breadcrumbs.size(); i++){ |
126 |
0
|
if(i < breadcrumbs.size() - 1){ |
127 |
0
|
createLink(breadcrumbs.get(i).name, breadcrumbs.get(i).path); |
128 |
|
} |
129 |
|
else{ |
130 |
0
|
createLabel(breadcrumbs.get(i).name); |
131 |
|
|
132 |
|
} |
133 |
|
} |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0
|
private static void createLabel(String name){... |
137 |
0
|
addToPanel(new InlineLabel(name)); |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
140 |
0
|
private static void createLink(String name, final String viewPath){... |
141 |
0
|
Hyperlink link = new Hyperlink(name, viewPath); |
142 |
0
|
links.add(link); |
143 |
0
|
addToPanel(link); |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
146 |
0
|
private static void addToPanel(Widget w){... |
147 |
0
|
if(panelEmpty){ |
148 |
0
|
panel.add(w); |
149 |
0
|
panelEmpty = false; |
150 |
|
} |
151 |
|
else{ |
152 |
0
|
panel.add(new InlineLabel(" \u00BB ")); |
153 |
0
|
panel.add(w); |
154 |
|
} |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
@return |
159 |
|
|
160 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
0
|
public static ComplexPanel getBreadcrumbPanel(){... |
162 |
0
|
return panel; |
163 |
|
} |
164 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
165 |
0
|
public static void setParentPanel(Panel panel){... |
166 |
0
|
parentPanel = panel; |
167 |
0
|
parentPanel.setVisible(false); |
168 |
|
} |
169 |
|
|
170 |
|
} |