Pragmatically resize a view [message #1776032] |
Thu, 09 November 2017 13:48 |
Boris Brodski Messages: 112 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 |
Eclipse User |
|
|
|
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.
|
|
|
|
|
Re: Pragmatically resize a view [message #1776092 is a reply to message #1776087] |
Fri, 10 November 2017 15:12 |
Eclipse User |
|
|
|
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);
|
|
|
|
|
Re: Pragmatically resize a view [message #1776525 is a reply to message #1776257] |
Fri, 17 November 2017 09:42 |
Boris Brodski Messages: 112 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
|
|
|
Powered by
FUDForum. Page generated in 0.02110 seconds