2012-04-26 37 views
0

我的站點左邊有一個GWT樹。在中心是一個GWT-TabBar。GWT多個有一個令牌的活動/場所

這兩個部分都實現爲Views/Activities/Places。我有兩個標記器:樹「m」和標籤「t」。

如果我訪問一個地方(goTo())只有這個地方將被用來生成歷史記號。 但我想看到這個:<page>#m:sub/sub/sub;t:map

我其實認爲活動&的洞的想法的地方。當只有一個標記器可以一次提供一個標記時,我看不出有多個標記器。

回答

3

無法同時顯示兩個不同的標記#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; 
    } 

} 

這會給你看起來像的網址;

的index.html#概述:T = /樹/樹/葉; M = 2

你可能會遇到麻煩與前在令牌斜槓,不知道跑。如有必要,將它們改爲其他角色;

活動接收傳入的地方並將狀態注入視圖;

+0

嗯,我擔心這將是唯一的解決方案!在我發現GWT-「活動/地點」之前,我實施了一個意外(但有多個「地點」)的類似方法。 無論如何。現在我知道我沒有錯過文檔中的內容!謝謝。 – 2012-04-27 08:48:57

+0

重要的是,你不能一次在多個地方,只有多個顯示區域由個人活動管理。該地點確定哪些活動被激活。 – koma 2012-04-27 10:35:09