1
|
package eu.dnetlib.repo.manager.client;
|
2
|
|
3
|
import com.google.gwt.user.client.Window;
|
4
|
import com.google.gwt.user.client.ui.FlowPanel;
|
5
|
|
6
|
import java.util.HashMap;
|
7
|
import java.util.Map;
|
8
|
|
9
|
/**
|
10
|
* Created by stefania on 12/16/15.
|
11
|
*/
|
12
|
public abstract class TokenController {
|
13
|
|
14
|
protected Map<String, TokenController> subControllers = new HashMap<String, TokenController>();
|
15
|
|
16
|
public void showWidget(FlowPanel contentPanel, String parent, String rest) {
|
17
|
getSubController(rest).showWidget(contentPanel, parent + "/" + splitToken(rest)[0], splitToken(rest)[1]);
|
18
|
}
|
19
|
|
20
|
public TokenController getSubController(String rest) {
|
21
|
// Window.alert("return sub controller for " + rest + " = " + splitToken(rest)[0]);
|
22
|
|
23
|
return subControllers.get(splitToken(rest)[0]);
|
24
|
}
|
25
|
|
26
|
public String[] getMenuPath(String parent, String rest) {
|
27
|
|
28
|
// Window.alert("returning path for " + parent + ", " + rest + "(" + this.getClass().getName() + ")");
|
29
|
String[] rests = getSubController(rest).getMenuPath(splitToken(rest)[0], splitToken(rest)[1]);
|
30
|
|
31
|
if (parent != null) {
|
32
|
String[] ret = new String[rests.length + 1];
|
33
|
|
34
|
ret[0] = parent;
|
35
|
for (int i = 0; i < rests.length; i++)
|
36
|
ret[i + 1] = rests[i];
|
37
|
|
38
|
return ret;
|
39
|
} else
|
40
|
return rests;
|
41
|
}
|
42
|
|
43
|
protected final String[] splitToken(String token) {
|
44
|
|
45
|
if (token.contains("/"))
|
46
|
return new String[] {token.substring(0, token.indexOf('/')), token.substring(token.indexOf('/') + 1)};
|
47
|
else
|
48
|
return new String[] {token, null};
|
49
|
}
|
50
|
|
51
|
protected void redrawWidget(FlowPanel contentPanel, RepositoryManagerWidget widget, String parentToken, String rest) {
|
52
|
|
53
|
contentPanel.clear();
|
54
|
|
55
|
widget.setToken(parentToken, rest);
|
56
|
widget.clear();
|
57
|
widget.reload();
|
58
|
|
59
|
contentPanel.add(widget.asWidget());
|
60
|
|
61
|
Window.scrollTo(0, 0);
|
62
|
|
63
|
widget.afterAdditionToRootPanel();
|
64
|
}
|
65
|
}
|
66
|
|