eclipse-platform / eclipse.platform.ui

Eclipse Platform
https://projects.eclipse.org/projects/eclipse.platform
Eclipse Public License 2.0
77 stars 162 forks source link

Maximize/Minimize does not work when views are not inside a folder #666

Open MLausberg opened 1 year ago

MLausberg commented 1 year ago

Background of upcoming code: Adding Views outside a Folder, because in this case the view title is not shown, see Bug 5684 - [RCP] [ViewMgmt] Ability to show/hide view title programmatically

To Reproduce With older versions of Eclipse 4.X the maximize/Minimize did work.

Within Eclipse 3.X (and Version before 4.25) I was able to add views like

public class MyPerspectiveLayout implements ICustomPerspectiveLayout {

 @Override
    public void createLayout(IPageLayout pLayout) {

...
        String editorArea = pLayout.getEditorArea();
        pLayout.setEditorAreaVisible(false);

        pLayout.addStandaloneView(SCREENMANAGER_VIEW_ID, false, IPageLayout.TOP, 0.5f, editorArea);
        // Set the screen manager view to not closable.
        IViewLayout screenView = pLayout.getViewLayout(SCREENMANAGER_VIEW_ID);
        screenView.setCloseable(false);
        screenView.setMoveable(false);

        //Show System Navigation View as a stand alone view and not a fast view
        pLayout.addStandaloneViewPlaceholder(SYSTEMNAVIGATION_VIEW_ID, IPageLayout.BOTTOM, 0.95f, editorArea, false);

        // Set the navigation view to not closable.
        IViewLayout navigationView = pLayout.getViewLayout(SYSTEMNAVIGATION_VIEW_ID);
        navigationView.setCloseable(false);
        navigationView.setMoveable(false);
    }
...
}

For MAXIMIZE/MINIMIZE I used the following command whcih is marked as DEPRECATED today.

                    IViewReference tViewReference = activePage.findViewReference(pViewName);
                    IViewPart part = null;
                    if (tViewReference != null) {
                        // [20131029] lm #46981
                        // Do create a new view if the view is not present
                        part = tViewReference.getView(true);

                    } else {
                        try {
                            part = activePage.showView(pViewName);
                        } catch (PartInitException e) {
                            LOGGER.error("Not able to show view: " + pViewName, e); //$NON-NLS-1$
                        }
                    }
                    if (part == null) {
                        return;
                    }

                    if (!forceMaximize) {
                        if (tViewReference != null && IWorkbenchPage.STATE_MAXIMIZED == part.getSite().getPage().getPartState(tViewReference)) {
                            return;
                        }
                    }

                    pWindow.getActivePage().activate(part);
                    ActionFactory.IWorkbenchAction maximizeAction = ActionFactory.MAXIMIZE.create(pWindow);
                    if (maximizeAction.isEnabled()) {
                        maximizeAction.run();
                    }

Expected behavior Problem:

The "placeholder" is an instance of PlaceholderImpl and "parent" will be of instance "PartSashContainerImpl". Because of this the instanceof command will fail

        case EModelService.OUTSIDE_PERSPECTIVE:
            MUIElement parent = placeholder == null ? model.getParent() : placeholder.getParent();
            if (parent instanceof MPartStack) {
                element = parent;
            }
            break;
WorkbenchPage.getActiveElement(IWorkbenchPartReference) line: 4273  
WorkbenchPage.toggleZoom(IWorkbenchPartReference) line: 4344    
MaximizePartHandler.execute(ExecutionEvent) line: 39    
HandlerProxy.execute(ExecutionEvent) line: 283  
E4HandlerProxy.execute(IEclipseContext, Map, Event, IEvaluationContext) line: 97    
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 62  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 43  
Method.invoke(Object, Object...) line: 566  
MethodRequestor.execute() line: 58  
InjectorImpl.invokeUsingClass(Object, Class<?>, Class<Annotation>, Object, PrimaryObjectSupplier, PrimaryObjectSupplier, boolean, boolean, boolean) line: 317   
InjectorImpl.invoke(Object, Class<Annotation>, Object, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 251  
ContextInjectionFactory.invoke(Object, Class<Annotation>, IEclipseContext, IEclipseContext, Object) line: 173   
WorkbenchHandlerServiceHandler(HandlerServiceHandler).execute(ExecutionEvent) line: 156 
Command.executeWithChecks(ExecutionEvent) line: 488 
ParameterizedCommand.executeWithChecks(Object, Object) line: 485    

When i add the view like

public class MyPerspectiveLayout implements ICustomPerspectiveLayout {

 @Override
    public void createLayout(IPageLayout pLayout) {

...
        ModeledFolderLayout left = (ModeledFolderLayout)pLayout.createFolder("left", IPageLayout.TOP, (float)0.95, editorArea);
        left.addPlaceholder(SYSTEMNAVIGATION_VIEW_ID);
         left.addPlaceholder(SCREENMANAGER_VIEW_ID);

The MAXIMIZE/MINIMIZE is working BUT now I do see the View title in the UI

Screenshots When using my original code

        pLayout.addStandaloneView(SCREENMANAGER_VIEW_ID, false, IPageLayout.TOP, 0.5f, editorArea);
        pLayout.addStandaloneViewPlaceholder(SYSTEMNAVIGATION_VIEW_ID, IPageLayout.BOTTOM, 0.95f, editorArea, false);

it currently looks like image

When creating the folder and adding the views into it it looks like image

Environment: I do use Version: 2022-09 (4.25.0) as Target Platform on Windows 10

  1. JRE/JDK version JDK-11.0.16+8
jukzi commented 1 year ago

@MLausberg can you contribute a fix?