Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Pragmatically resize a view
Pragmatically resize a view [message #1776032] Thu, 09 November 2017 13:48 Go to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 107
Registered: July 2009
Senior Member
Question from stackoverflow.com

I'm testing an non-e4 RCP application using SWTBot and I need to change the size of my view. (Move the sash-bar)

I unsuccessfully tried

  • Resize my view using SWTBot (no such api)
  • Resize my view using Eclipse 3 API (no supported)
  • Resize my view using underlying e4 model (resizing not working)

e4 model approach seams to be promising, but I'm missing something, so it doesn't work.

I can

  • Get MPart of my view:
    view = ePartService.findPart(ID)

  • Get MTrimmedWindow:
     window = (view as EObject).eContainer as MTrimmedWindow



I can't

  • locale correct MPartSashContainer
  • move sash-bar with setContainerData()


I would like to know:

  • How can I move from MPart to its direct parent (e.g. MPartStack)? (MPart.getParent() returns null for my view)
  • Why common EObject methods like eContainer() are not present on M... objects?


Thank you very much in advance!

[Updated on: Thu, 09 November 2017 13:56]

Report message to a moderator

Re: Pragmatically resize a view [message #1776079 is a reply to message #1776032] Fri, 10 November 2017 14:27 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 757
Registered: January 2012
Senior Member

Walk up your MPart's ancestry using getParent() until you reach the MPartSashContainer. It uses the values of its children's getContainerData() to serve as weights. You can adjust those values and the MPSC will resize the contents appropriately.

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Pragmatically resize a view [message #1776086 is a reply to message #1776079] Fri, 10 November 2017 14:47 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 107
Registered: July 2009
Senior Member
Hello,

thank you for the response! The problem is, that the getParent() method returns NULL :(

I tried even waiting for couple of second after showing the view, but the view.getParent() continues returning NULL.

Xtend-Code:
UIThreadRunnable.syncExec(bot.getDisplay(), new Result<VoidType>() {
  override VoidType run() {
    val window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    val page =  window.getActivePage()
    page.showView(MyView.ID, null, IWorkbenchPage.VIEW_ACTIVATE)
    null
  }
})

Thread.sleep(2000)

UIThreadRunnable.syncExec(bot.getDisplay(), new Result<VoidType>() {
  override VoidType run() {
    val eModelService = PlatformUI.getWorkbench().getService(EModelService)
    val ePartService = PlatformUI.getWorkbench().getService(EPartService)

    // Try 1
    val eView = ePartService.findPart(InterpreterView.ID)
    eView.parent // NULL

    // Try 2
    ePartService.parts.filter[ find my view  here  ].first.parent // NULL


    null
  }
})
Re: Pragmatically resize a view [message #1776087 is a reply to message #1776086] Fri, 10 November 2017 14:49 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 107
Registered: July 2009
Senior Member
May be I'm not including some important JARs in my RCP product?
Re: Pragmatically resize a view [message #1776092 is a reply to message #1776087] Fri, 10 November 2017 15:12 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 757
Registered: January 2012
Senior Member

Keep ahold of the IViewPart returned by IWindow#showView() and get its MPart with something like:
IViewPart view = workbenchPage.showView(MyView.ID, ...);
part = view.getSite().getService(MPart.class);


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Pragmatically resize a view [message #1776097 is a reply to message #1776092] Fri, 10 November 2017 15:45 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 107
Registered: July 2009
Senior Member
It's still NULL :(

Debugging getParent() I get to this method
public abstract class UIElementImpl extends ... {
  @SuppressWarnings("unchecked")
  public MElementContainer<MUIElement> getParent() {
    if (eContainerFeatureID() != UiPackageImpl.UI_ELEMENT__PARENT) return null;
    return (MElementContainer<MUIElement>)eInternalContainer();
  }
}

and

public class MinimalEObjectImpl extends ... {
  @Override
  public int eContainerFeatureID()
  {
    return eFlags >> 16;
  }
}


The first line returns NULL:


  • UiPackageImpl.UI_ELEMENT__PARENT = 10
  • eFlags = -2359292
  • eFlags >> 16 = -36
Re: Pragmatically resize a view [message #1776257 is a reply to message #1776097] Tue, 14 November 2017 14:14 Go to previous messageGo to next message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 107
Registered: July 2009
Senior Member
Updated Eclipse to Neon3. The issue is still there.

Any ideas?
Re: Pragmatically resize a view [message #1776525 is a reply to message #1776257] Fri, 17 November 2017 09:42 Go to previous message
Boris Brodski is currently offline Boris BrodskiFriend
Messages: 107
Registered: July 2009
Senior Member
Ok, I found a solution myself.

The thing is, that the view is not a part of the e4 UI-Tree. view.eContainer is directly the MWindow. To be placed at the right spot the view is connected to the MPlaceholder, that is a part of the e4 UI-Tree and has getParent() != null.

In order to resize a view the steps are:


  • Show view
  • Find MPlaceholder of the view
  • Find MPartStack and MPartSashContainer object
  • Set containerData
  • Redraw widget (yes, auto-update seam not to work in this case)


Example:
    EModelService modelService = PlatformUI.getWorkbench().getService(EModelService.class);
    EPartService  partService  = PlatformUI.getWorkbench().getService(EPartService.class);

    // Show view
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    page.showView(MyView.ID, null, IWorkbenchPage.VIEW_ACTIVATE);

    MPart view = partService.findPart(MyView.ID);
    // view.getParent() => null, because 'view' is not a part of the e4 UI-model!
    // It is connected to the Model using MPlaceholder

    // Let's find the placeholder
    MWindow window = (MWindow)(((EObject)eView).eContainer);
    MPlaceholder placeholder = modelService.findPlaceholderFor(window, view);

    MUIElement element = placeholder;
    MPartStack partStack = null;
	while (element != null) {
        // This may not suite your configuration of views/stacks/sashes
	    if (element instanceof MPartStack && ((Object)element.parent) instanceof MPartSashContainer) {
                partStack = (MPartStack)element;
                break;
            }
            element = element.parent;
	    }
    }
    if (partStack == null) { /* handle error */ }

    // Now let's change the width weights
    for (MUIElement element : partStack.getParent().getChildren()) {
        if (element == partStack) {
            element.setContainerData("50"); // Width for my view
        } else {
            element.setContainerData("25"); // Widths for other views & editors
        }
    }

    // Surprisingly I had to redraw tho UI manually
    // There is for sure a better way to do it. Here is my (quick & very dirty):
    partStack.toBeRendered = false
    partStack.toBeRendered = true


Please correct me, if there is a better solution.

What to give me +1? ;)) you can do it here: https://stackoverflow.com/questions/47202032/pragmatically-resize-a-view-in-eclipse/47347113#47347113

[Updated on: Fri, 17 November 2017 09:44]

Report message to a moderator

Previous Topic:Placeholders on Multi-Window
Next Topic:E4 + SWT renderer in FullScreen mode?
Goto Forum:
  


Current Time: Wed Jun 20 13:50:25 GMT 2018

Powered by FUDForum. Page generated in 0.01671 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top