Pieter
Pieter

Reputation: 1

Eclipse plugin developement-closing Eclipse perspective reset

I wrote a plug-in for Eclipse which is a perspective with some views. I'm having problems resetting the perspective when closing Eclipse. I got to the point where I can release all the things on the views and hide the the views but when you start Eclipse again the views which I hid is back. How do I get the perspective to reset when the user closes Eclipse ?

Upvotes: 0

Views: 924

Answers (1)

Thirumal
Thirumal

Reputation: 11

I used org.eclipse.ui.PerspectiveAdapter to watchout for perspectives. Everytime the perspective is opened check for something and take action to open or close certain views.

I register the PerspectiveAdapter in the Activator. start(BundleContext context) event call method.

My breif Activator code is as follows.

/*
 * (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();
    }       
}

}

I hope that this will be of some help.

Upvotes: 1

Related Questions