2008-10-27 107 views

回答

1

找到一種方法來輕鬆地做到這一點:你必須創建一個ShellListenerShellAdapter,其中有當外殼圖標化,取消圖標,激活,停用並關閉時調用的方法。

創建後,它會與下面的行添加爲一個監聽器:

int i; 

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().addShellListener(yourListenerHere); 

如果你從外殼的聽衆列表中刪除,請確保工作臺,ActiveWorkbnchWindow和殼牌不爲空。

1

我可以建議一種方法:你可以爲它編寫一個插件。
例如,看到這個即興的「教程」,我做到了,嘗試了它在Ganymede上的作品。最終的Shell變量有點難看,但工作。如果你知道更好的解決方案只拍:) ((其實還有一種方法:延長自己ControlListener類,但需要更多的編碼:))

  1. 創建一個新的插件項目,它的名稱你想從名爲模板創建它:Hello World命令
  2. 打開SampleHandler類,然後用此代碼替換execute()函數。

    public Object execute(ExecutionEvent event) throws ExecutionException { 
         IWorkbenchWindow window = HandlerUtil 
           .getActiveWorkbenchWindowChecked(event); 
         final Shell s = window.getShell(); 
    
    
    window.getShell().addControlListener(new ControlListener() { 
    
         @Override 
         public void controlMoved(ControlEvent e) { 
          // TODO Auto-generated method stub 
    
         } 
    
         @Override 
         public void controlResized(ControlEvent e) { 
          MessageDialog.openInformation(s, 
            "WindowEventHandler Plug-in", "RESIZED: " 
              + e.toString() + "\nHello, Eclipse world"); 
         } 
    
        }); 
        MessageDialog.openInformation(window.getShell(), 
          "WindowEventHandler Plug-in", 
          "Hello, Eclipse world, resize will be taken care of."); 
    
        return null; 
    } 
    
  3. now。啓動項目(Run As-> Eclipse應用程序),然後在工具欄上選擇一個Eclipse按鈕。點擊它!它觸發了上述代碼的運行,其中的本質是window.getShell()與主窗口組件一起返回,因此您可以向其添加偵聽器。

如果你希望它自動運行,不僅僅是一個按鈕,你必須找到一個插件,其中入口點連接到應用程序的開始。

希望這會有所幫助。

b

相關問題