GWT多个活动/地点与一个令牌



我的网站左侧有一个GWT树。中间是一个GWT-TabBar。

这两个部分都实现为视图/活动/地点。我有两个分词器:"m"代表树,"t"代表标签。

如果我访问一个地方(goTo()),只有这个地方将用于生成历史令牌。但我希望看到这个:<page>#m:sub/sub/sub;t:map

我实际上认为活动和场所的洞的想法。我不认为拥有多个分词器有什么意义,因为只有一个分词器可以同时提供令牌。

不能同时显示两个不同的标记 #m:和 #t:,因为不能同时在两个位置。

因此,如果选项卡和树同时显示,则必须同时将两者的状态存储在同一个位置。

这或多或少是您需要的。

public class ExamplePlace extends Place {
    public String treePosition = "/";
    public int tabIndex = 0;
    public ExamplePlace() {
        super();
    }
    public ExamplePlace(String treePosition, int tabIndex) {
        this.treePosition = treePosition;
        this.tabIndex = tabIndex;
    }
    @Prefix("overview")
    public static class Tokenizer implements PlaceTokenizer<ExamplePlace> {

        /**
         * parse token to get state
         * 
         */
        @Override
        public ExamplePlace getPlace(String token) {
            String treePosition = "";
            int tabIndex = 0;
            String[] states = token.split(";");
            for (String state : states) {
                String[] mapping = state.split("=");
                if (mapping.length == 2) {
                    if ("t".equals(mapping[0])) {
                        treePosition = mapping[1];
                    }
                    if ("m".equals(mapping[0])) {
                        try {
                            tabIndex = Integer.valueOf(mapping[1]);
                        } catch (Throwable e) {
                        }
                    }
                }
            }
            return new ExamplePlace(treePosition, tabIndex);
        }

        /**
         * store state in token
         * 
         */
        @Override
        public String getToken(ExamplePlace place) {
            StringBuffer sb = new StringBuffer();
            if (place.getTreePosition()!=null) {
                sb.append("t").append("=").append(place.getTreePosition());
               sb.append(";");
            }
            sb.append("m=").append(place.getTabIndex());
            return sb.toString();
        }
    }
    public String getTreePosition() {
        return treePosition;
    }
    public void setTreePosition(String treePosition) {
        this.treePosition = treePosition;
    }
    public int getTabIndex() {
        return tabIndex;
    }
    public void setTabIndex(int tabIndex) {
        this.tabIndex = tabIndex;
    }
}

这将为您提供看起来像 ;

索引.html#概述:t=/子树/子树/叶;m=2

不确定令牌中的正斜杠可能会遇到麻烦。如有必要,将它们更改为其他字符;

活动接收传入的位置并将状态注入到视图中;

最新更新