score:1

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

Related Query

More Query from same tag