Programming/Eclipse RCP

특정 뷰에 Context Menu 추가하기

Lawmin 2012. 1. 9. 13:11
[View]
public static final String ID = "com.lawmin.view";

...
 
MenuManager menuManager = new MenuManager();
Menu menu = menuManager.createContextMenu(tbRows);
// Set the MenuManager
tbRows.setMenu(menu);
menu.setData(tbvRows); // 이건... 이벤트 발생시 source 추적하기 위해... 
getSite().registerContextMenu(menuManager, tbvRows);
// Make the selection available
getSite().setSelectionProvider(tbvRows);

...

[Handler]
public class LawminHandler extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
Event ev = (Event)event.getTrigger();
MenuItem item = (MenuItem)ev.widget;
System.out.println(item.getParent().getData()); // 아까 저장한 source 정보
...

[plugin.xml]
<menuContribution allPopups="false" locationURI="popup:com.lawmin.view">
         <command commandId="com.lawmin.command" label="메뉴1" style="push"></command>
</menuContribution> 

<command id=" com.lawmin.command " name="File Export"></command> 

<handler class="핸들러클래스" commandId="com.lawmin.command"></handler>