Search code examples
eclipseeclipse-rcp

How do I know that a view is on fast-view state, programmatically?


We develop an Eclipse RCP Application that is built on Eclipse 3.8. We're trying to build it on Eclipse 4.8 and some of our code was broken, given the removal of some classes.

On Eclipse 3.8, we know a view is on fast-view state when this line returns null:

( (PartSite)viewPart.getSite() ).getPane().getContainer();

But both PartSite and the method getContainer() are not available anymore on Eclipse 4.8.

How can we check if a view is on fast-view state?


Solution

  • There are no fast views in Eclipse 4, just minimized parts.

    You will need to use some of the e4 APIs to determine if the part or its container is minimized. Something like:

    EPartService partService = getSite().getService(EPartService.class);
    
    MUIElement part = partService.findPart(getSite().getId());
    
    MElementContainer<?> parent = part.getParent();
    
    if (parent == null) {
       part = part.getCurSharedRef();
    
       parent = part.getParent();
    }
    
    boolean minimized = isMinimized(part) || isMinimized(parent);
    
    
    private boolean isMinimized(MUIElement element) {
       List<String> tags = element.getTags();
       return tags.contains(IPresentationEngine.MINIMIZED) && !tags.contains(IPresentationEngine.ACTIVE);
    }
    

    You can track the changes in minimized tags like this:

    IEventBroker broker = getSite().getService(IEventBroker.class);
    
    broker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, event -> {
       Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
       Object newValue = event.getProperty(UIEvents.EventTags.NEW_VALUE);
       Object oldValue = event.getProperty(UIEvents.EventTags.OLD_VALUE);
    
       if (IPresentationEngine.MINIMIZED.equals(newValue))
         System.out.println("min added " + element);
       if (IPresentationEngine.MINIMIZED.equals(oldValue))
         System.out.println("min removed " + element);
     });