我为Eclipse编写了一个插件,它是一个带有一些视图的透视图。关闭Eclipse时,我在重置透视图时遇到问题。我已经到了可以在视图上释放所有内容并隐藏视图的点,但是当你再次启动Eclipse时,我隐藏的视图又回来了。当用户关闭Eclipse时如何获得重置的透视图?
答案 0 :(得分:1)
我使用org.eclipse.ui.PerspectiveAdapter来提醒观点。 每次打开透视图时都要检查某些内容 采取行动打开或关闭某些观点。
我在Activator中注册了PerspectiveAdapter。 start(BundleContext上下文) 事件调用方法。
我的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();
}
}
}
我希望这会有所帮助。