0
我爲Eclipse編寫了一個插件,這是一個包含一些視圖的透視圖。在關閉Eclipse時,我在重置視角時遇到了問題。我已經到了可以釋放視圖中的所有內容並隱藏視圖的地步,但是當您再次啓動Eclipse時,我隱藏的視圖又回來了。如何在用戶關閉Eclipse時重置視角?Eclipse插件開發 - 關閉Eclipse透視圖重置
我爲Eclipse編寫了一個插件,這是一個包含一些視圖的透視圖。在關閉Eclipse時,我在重置視角時遇到了問題。我已經到了可以釋放視圖中的所有內容並隱藏視圖的地步,但是當您再次啓動Eclipse時,我隱藏的視圖又回來了。如何在用戶關閉Eclipse時重置視角?Eclipse插件開發 - 關閉Eclipse透視圖重置
我使用org.eclipse.ui.PerspectiveAdapter注意觀點。 每次打開透視圖時都會檢查某些內容,並且 會採取措施打開或關閉某些視圖。
我在激活器中註冊了PerspectiveAdapter。開始(BundleContext上下文) 事件調用方法。
我的breif激活碼如下。
/*
* (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();
}
}
}
我希望這會有所幫助。
爲什麼Eclipse關閉時需要重置視角?通常,透視設置應該在重新啓動時保持不變。 – 2011-02-25 16:17:36
我希望視角可以在第一次打開時回到佈局。我有隻顯示某些數據庫連接時顯示的視圖,當您關閉eclipse時,這些連接已關閉,因此當您再次啓動eclipse時,我不希望這些視圖。 – Pieter 2011-03-03 11:27:51