2013-06-30 46 views
1

我想調用我的應用程序中的上下文菜單。如何調用swtboot中的上下文菜單

問題是我沒有在樹中的任何項目。

我活躍我的看法,然後我想打開上下文菜單。

SWTBotView view = bot.viewByTitle("Project Explorer"); 

view.bot.tree().contextMenu("New").click(); 

然後我得到錯誤信息

能否請你告訴我我怎麼能不樹中的任何項目打開contextMeny?

回答

0

由於沒有直接的方法來做到這一點。我假設你有一個打開你的上下文菜單的快捷方式。

bot.activeShell().pressShortcut(<your shortcut>); 

bot.waitUntil(new ContextMenuAppears(tree, 
       "New")); 
tree.contextMenu("New").click(); 

其中ContextMenuAppears是等待所需上下文菜單出現的ICondition。

public class ContextMenuAppears implements ICondition { 

private SWTBotTree swtBotTree; 
private String mMenuText; 
public TekstContextMenuAppears(SWTBotTree pSwtBotTree, String menuText) { 
    swtBotTree = pSwtBotTree; 
    mMenuText = menuText; 
} 

@Override 
public boolean test() throws Exception { 
    try {   
     return swtBotTree.contextMenu(mMenuText).isVisible(); 
    } catch (WidgetNotFoundException e) { 
     return false; 
    } 

} 

@Override 
public void init(SWTBot bot) { 
    // TODO Auto-generated method stub 

} 

@Override 
public String getFailureMessage() { 
    // TODO Auto-generated method stub 
    return null; 
} 

} 
0

根據您要達到的目標,您可以嘗試通過文件菜單而不是上下文菜單。 「新」應該這樣工作。

+0

我需要從上下文菜單 – user2444677