Project

General

Profile

1
package eu.dnetlib.repo.manager.client;
2

    
3
import com.google.gwt.user.client.ui.FlowPanel;
4

    
5
import java.util.HashMap;
6
import java.util.Map;
7

    
8
/**
9
 * Created by stefania on 12/16/15.
10
 */
11
public abstract class TokenController {
12

    
13
    protected Map<String, TokenController> subControllers = new HashMap<String, TokenController>();
14

    
15
    public void showWidget(FlowPanel contentPanel, String parent, String rest) {
16
        getSubController(rest).showWidget(contentPanel, parent + "/" + splitToken(rest)[0], splitToken(rest)[1]);
17
    }
18

    
19
    public TokenController getSubController(String rest) {
20
//        Window.alert("return sub controller for " + rest + " = " + splitToken(rest)[0]);
21

    
22
        return subControllers.get(splitToken(rest)[0]);
23
    }
24

    
25
    public void drawHeader(String rest) {
26
//        Window.alert("getting header for " + rest + " (" + this.getClass().getName() + ")");
27
        RepositoryManager.pageHeader.clear();
28

    
29
        getSubController(rest).drawHeader(splitToken(rest)[1]);
30
    }
31

    
32
    public String[] getMenuPath(String parent, String rest) {
33

    
34
//        Window.alert("returning path for " + parent + ", " + rest + "(" + this.getClass().getName() + ")");
35
        String[] rests = getSubController(rest).getMenuPath(splitToken(rest)[0], splitToken(rest)[1]);
36

    
37
        if (parent != null) {
38
            String[] ret = new String[rests.length + 1];
39

    
40
            ret[0] = parent;
41
            for (int i = 0; i < rests.length; i++)
42
                ret[i + 1] = rests[i];
43

    
44
            return ret;
45
        } else
46
            return rests;
47
    }
48

    
49
    protected final String[] splitToken(String token) {
50

    
51
        if (token.contains("/"))
52
            return new String[] {token.substring(0, token.indexOf('/')), token.substring(token.indexOf('/') + 1)};
53
        else
54
            return new String[] {token, null};
55
    }
56

    
57
    protected void redrawWidget(FlowPanel contentPanel, RepositoryManagerWidget widget, String parentToken, String rest) {
58

    
59
        contentPanel.clear();
60

    
61
        widget.setToken(parentToken, rest);
62
        widget.clear();
63
        widget.reload();
64

    
65
        contentPanel.add(widget.asWidget());
66

    
67
        widget.afterAdditionToRootPanel();
68
    }
69
}
70

    
(11-11/13)