use of org.eclipse.e4.ui.model.application.MContribution in project eclipse.platform.ui by eclipse-platform.
the class HeadlessContextPresentationEngine method createGui.
@Override
public Object createGui(MUIElement element, Object parentWidget, IEclipseContext parentContext) {
MUIElement current = element;
while (current != null) {
if (!current.isToBeRendered()) {
return null;
}
if (current.getCurSharedRef() != null) {
current = current.getCurSharedRef();
} else {
current = current.getParent();
}
}
MUIElement parent = element.getParent();
if (element.getCurSharedRef() != null) {
parent = element.getCurSharedRef().getParent();
}
if (!(parent instanceof MApplication)) {
// if the element is not under the application, it should have a
// parent widget
Assert.isNotNull(parentWidget);
}
if (element.getWidget() != null) {
if (element instanceof MContext) {
IEclipseContext context = ((MContext) element).getContext();
if (context.getParent() != parentContext) {
context.setParent(parentContext);
}
}
return element.getWidget();
}
element.setRenderer(this);
Object widget = new Object();
element.setWidget(widget);
if (element instanceof MContext) {
MContext mcontext = (MContext) element;
IEclipseContext createdContext = mcontext.getContext();
if (createdContext == null) {
String contextName = element.getClass().getInterfaces()[0].getName() + // $NON-NLS-1$
" eclipse context";
createdContext = (parentContext != null) ? parentContext.createChild(contextName) : EclipseContextFactory.create(contextName);
populateModelInterfaces(mcontext, createdContext, element.getClass().getInterfaces());
for (String variable : mcontext.getVariables()) {
createdContext.declareModifiable(variable);
}
mcontext.setContext(createdContext);
if (element instanceof MContribution && createContributions) {
MContribution contribution = (MContribution) element;
String uri = contribution.getContributionURI();
if (uri != null) {
Object clientObject = contributionFactory.create(uri, createdContext);
contribution.setObject(clientObject);
}
}
if (parentContext != null && parentContext.getActiveChild() == null) {
createdContext.activate();
}
} else if (createdContext.getParent() != parentContext) {
createdContext.setParent(parentContext);
}
}
if (element instanceof MGenericStack) {
MGenericStack<?> container = (MGenericStack<?>) element;
MUIElement active = container.getSelectedElement();
if (active != null) {
createGui(active, container, getParentContext(active));
} else {
List<?> children = container.getChildren();
if (!children.isEmpty()) {
((MElementContainer) element).setSelectedElement((MUIElement) children.get(0));
}
}
} else if (element instanceof MElementContainer<?>) {
for (Object child : ((MElementContainer<?>) element).getChildren()) {
if (child instanceof MUIElement) {
createGui((MUIElement) child, element, getParentContext((MUIElement) child));
if (child instanceof MContext) {
IEclipseContext childContext = ((MContext) child).getContext();
IEclipseContext pContext = getParentContext((MUIElement) child);
if (childContext != null && pContext.getActiveChild() == null) {
childContext.activate();
}
}
}
}
if (element instanceof MWindow) {
MWindow window = (MWindow) element;
for (MWindow childWindow : window.getWindows()) {
createGui(childWindow, element, window.getContext());
}
}
if (element instanceof MPerspective) {
MPerspective perspective = (MPerspective) element;
for (MWindow childWindow : perspective.getWindows()) {
createGui(childWindow, element, perspective.getContext());
}
}
} else if (element instanceof MPlaceholder) {
MPlaceholder placeholder = (MPlaceholder) element;
MUIElement ref = placeholder.getRef();
if (ref != null) {
ref.setCurSharedRef(placeholder);
ref.setToBeRendered(true);
createGui(ref);
List<MPlaceholder> placeholders = renderedPlaceholders.get(ref);
if (placeholders == null) {
placeholders = new ArrayList<>();
renderedPlaceholders.put(ref, placeholders);
} else if (placeholders.contains(placeholder)) {
return null;
}
placeholders.add(placeholder);
}
}
return widget;
}
Aggregations