2013-02-15 78 views
0

我正在嘗試爲我的GWT App創建一個CellTree,並在初始化Showcase [ie onModuleLoad] 我得到以下錯誤。我所要做的就是複製GWT Showcase應用程序並從頭開始構建。GWT CellTree創建問題

17:47:04.519 [ERROR] [ChannelView] Failed to create an instance of 
'com.app.capture.client.ClientFactory' via deferred binding 
java.lang.IllegalStateException: TreeNode no longer exists. 
at com.google.gwt.user.cellview.client.CellTreeNodeView$TreeNodeImpl.assertNotDestroyed(CellTreeNodeView.java:653) 
at com.google.gwt.user.cellview.client.CellTreeNodeView$TreeNodeImpl.setChildOpen(CellTreeNodeView.java:642) 
at com.google.gwt.user.cellview.client.CellTreeNodeView$TreeNodeImpl.setChildOpen(CellTreeNodeView.java:637) 
at com.app.capture.client.ui.MainMenuViewImpl.<init>(MainMenuViewImpl.java:35) 
at com.app.capture.client.ClientFactory.<clinit>(ClientFactory.java:13) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Class.java:264) 
at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:665) 
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:468) 
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49) 
at com.google.gwt.core.shared.GWT.create(GWT.java:57) 
at com.google.gwt.core.client.GWT.create(GWT.java:85) 
at com.app.capture.client.ChannelViewEntryPoint.onModuleLoad(ChannelViewEntryPoint.java:59) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:601) 
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406) 
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200) 
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526) 
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364) 
at java.lang.Thread.run(Thread.java:722) 

UI由兩個並排垂直放置的面板組成。左側是我想要添加細胞樹的導航面板。

的celltree視圖模型類是

package com.app.capture.client.ui.model; 
import java.util.ArrayList; 
import java.util.List; 
import com.google.gwt.cell.client.AbstractCell; 
import com.google.gwt.cell.client.Cell; 
import com.google.gwt.cell.client.TextCell; 
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; 
import com.google.gwt.view.client.ListDataProvider; 
import com.google.gwt.view.client.SingleSelectionModel; 
import com.google.gwt.view.client.TreeViewModel; 

public class MainMenuViewModel implements TreeViewModel { 

private static class Category { 
    private final String  name; 
    private final List<String> items = new ArrayList<String>(); 

    public Category(final String name) { 
     this.name = name; 
    } 

    public List<String> getItems() { 
     return this.items; 
    } 

    public String getName() { 
     return this.name; 
    } 

    public void addCategoryItem(String item) { 
     items.add(item); 
    } 
} 

private final List<Category>    categories; 
private final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>(); 

public MainMenuViewModel() { 
    categories = new ArrayList<Category>(); 

    Category apg = new Category("A"); 
    apg.addCategoryItem("11"); 
    apg.addCategoryItem("22"); 

    Category channel = new Category("B"); 
    channel.addCategoryItem("33"); 
    channel.addCategoryItem("44"); 
    channel.addCategoryItem("55"); 

    categories.add(apg); 
    categories.add(channel); 
} 

@Override 
public <T> NodeInfo<?> getNodeInfo(T value) { 
    if (value == null) { 
     // Root Level 
     ListDataProvider<Category> dataProvider = new ListDataProvider<Category>(categories); 
     Cell<Category> cell = new AbstractCell<Category>() { 
      @Override 
      public void render(com.google.gwt.cell.client.Cell.Context context, Category value, SafeHtmlBuilder sb) { 
       if (value != null) { 
        sb.appendEscaped(value.getName()); 
       } 
      } 
     }; 
     return new DefaultNodeInfo<Category>(dataProvider, cell); 
    } else if (value instanceof Category) { 
     ListDataProvider<String> dataProvider = new ListDataProvider<String>(((Category) value).getItems());    
     return new DefaultNodeInfo<String>(dataProvider, new TextCell(), selectionModel, null); 
    } 
    return null; 
} 

@Override 
public boolean isLeaf(Object value) { 
    if (value instanceof String) { 
     return true; 
    } 
    return false; 
} 

}

的主功能表視圖我的類定義是

public class MainMenuViewImpl extends Composite implements MainMenuView { 

interface MainMenuViewImplUiBinder extends UiBinder<Widget, MainMenuViewImpl> { 
} 

private static MainMenuViewImplUiBinder uiBinder = GWT.create(MainMenuViewImplUiBinder.class); 

private Presenter      presenter; 

@UiField(provided = true) 
CellTree        mainMenu; 

private MainMenuViewModel mainMenuModel; 

public MainMenuViewImpl() { 
    mainMenuModel = new MainMenuViewModel(); 
    mainMenu = new CellTree(mainMenuModel, null); 
    mainMenu.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); 
    TreeNode treeNode = mainMenu.getRootTreeNode(); 
    // This is where the exception is throw. If i remove the following line, no menu is displayed 
    treeNode.setChildOpen(0, true); 
    initWidget(uiBinder.createAndBindUi(this)); 

} 

@Override 
public void setPresenter(Presenter presenter) { 
    this.presenter = presenter; 
} 

}

我對MainMenu的UI粘結劑定義

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" 
xmlns:g="urn:import:com.google.gwt.user.client.ui" 
xmlns:c="urn:import:com.google.gwt.user.cellview.client"> 
<ui:style> 
    .mainMenu { 
     background-color: #d7dde8; 
     border: 1px solid #c3c3c3; 
    } 
</ui:style> 

<g:VerticalPanel styleName="{style.mainMenu}"> 
    <c:CellTree ui:field="mainMenu" />  
</g:VerticalPanel> 
</ui:UiBinder> 

我正在使用GWT 2.5.0。

任何幫助/指針來調試這個問題將不勝感激。

+0

你能移動這條線 「treeNode.setChildOpen(0,TRUE);」到某個位置「發佈」樹的渲染。 – SSR 2013-02-15 06:16:52

+0

@SSR。你的意思是在調用uibinder的initWidget()api之後調用api嗎?該樹提供了= true,所以我的理解是,它被渲染而不是附加到父項。 – 2013-02-15 17:07:04

回答

0

對於任何人來說,在代碼中沒有問題。 我認爲這個問題與Eclipse有關。

今天(發佈這個問題後的一天),我執行了以下步驟。

    項目
  1. 運行項目
  2. 重啓Eclipse
  3. GWT編譯。

這解決了我的問題。

0

你必須把「initWidget」方法

initWidget(uiBinder.createAndBindUi(this)); 

在視圖構造函數的第一線。
你的構造可能是這樣的:

public MainMenuViewImpl() 
{ 
    initWidget(uiBinder.createAndBindUi(this)); 
    mainMenuModel = new MainMenuViewModel(); 
    mainMenu = new CellTree(mainMenuModel, null); 
    mainMenu.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); 
    TreeNode treeNode = mainMenu.getRootTreeNode(); 
    // This is where the exception is throw. If i remove the following line, no menu is displayed 
    treeNode.setChildOpen(0, true); 
} 

;)