簡體   English   中英

Eclipse插件開發-關閉Eclipse透視圖重置

[英]Eclipse plugin developement-closing Eclipse perspective reset

我為Eclipse編寫了一個插件,該插件帶有一些視圖。 關閉Eclipse時,無法重置透視圖。 我到達了可以釋放視圖上所有內容並隱藏視圖的地步,但是當您再次啟動Eclipse時,隱藏的視圖又回來了。 當用戶關閉Eclipse時,如何重新設置透視圖?

我使用org.eclipse.ui.PerspectiveAdapter來監視視角。 每次打開透視圖時,請檢查是否有東西,並采取措施打開或關閉某些視圖。

我在激活器中注冊了PerspectiveAdapter。 start(BundleContext context)事件調用方法。

我的breif Activator代碼如下。

/*
 * (non-Javadoc)
 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
 */
public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
    .......
    ll = new fomomentumplugin.perspectives.LicenseListener();
    IWorkbench wbench = PlatformUI.getWorkbench();
     IWorkbenchWindow window =  wbench.getActiveWorkbenchWindow() ;
     window.addPerspectiveListener(ll);
     ...........
}


and 

public class LicenseListener extends PerspectiveAdapter {

public  void perspectiveOpened(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
    String componentName = "FOMomentum";
    if(perspective.getId().equals("org.softools.FOMomentumPLugin.FO")){
        if(Activator.checkLicense == null || !Activator.checkLicense.isValidLicense(componentName)){
            System.out.println("org.softools.FOMomentumPLugin.FO perspective Activated with no license found message !");
        //page.resetPerspective();
            hideViews(page);
        }
        else showViews(page);
    }
}

public  void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
    String componentName = "FOMomentum";
    if(perspective.getId().equals("org.softools.FOMomentumPLugin.FO")){
        if(Activator.checkLicense == null || !Activator.checkLicense.isValidLicense(componentName)){
            System.out.println("org.softools.FOMomentumPLugin.FO perspective Activated with no license found message !");
        //page.resetPerspective();
            hideViews(page);
        }
        else showViews(page);
    }

}

private void hideViews(IWorkbenchPage page){
    IViewPart momentum = page.findView("fomomentumplugin.views.FOMomentumView") ;
        if(momentum != null){
            ((fomomentumplugin.views.FOMomentumView)momentum).removeCalendarCombo();
            page.hideView(momentum);
        }

    IViewPart momentumDetail = page.findView("fomomentumplugin.views.FOMomentumDetailView") ;
    page.hideView(momentumDetail);
    IViewPart movingAverageview = page.findView("FOCallCandlebarView") ;
    page.hideView(movingAverageview);
    IViewPart priceVolumeView = page.findView("FOMomentumPLugin.FOPutCandlebarView") ;
    page.hideView(priceVolumeView);
}

private void showViews(IWorkbenchPage page){
    try {
        page.showView("fomomentumplugin.views.FOMomentumView");
        page.showView("fomomentumplugin.views.FOMomentumDetailView");
        page.showView("FOCallCandlebarView");
        page.showView("FOMomentumPLugin.FOPutCandlebarView");
    } catch (PartInitException e) {
        e.printStackTrace();
    }       
}

}

我希望這會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM