use of org.eclipse.e4.ui.model.application.ui.MContext in project eclipse.platform.ui by eclipse-platform.
the class PartServiceImpl method getParentWithContext.
private MContext getParentWithContext(MUIElement part) {
MElementContainer<MUIElement> parent = part.getParent();
MUIElement intermediate = parent;
if (intermediate == null) {
intermediate = part;
} else {
while (parent != null) {
if (parent instanceof MContext) {
if (((MContext) parent).getContext() != null)
return (MContext) parent;
}
intermediate = parent;
parent = parent.getParent();
}
}
MPlaceholder placeholder = modelService.findPlaceholderFor(getWindow(), intermediate);
parent = placeholder.getParent();
while (parent != null) {
if (parent instanceof MContext) {
if (((MContext) parent).getContext() != null)
return (MContext) parent;
}
parent = parent.getParent();
}
return null;
}
use of org.eclipse.e4.ui.model.application.ui.MContext in project eclipse.platform.ui by eclipse-platform.
the class HandlerProcessingAddon method handleHandlerEvent.
/**
* Responds to the coming and goings of handlers in the application model by activating and
* deactivating them accordingly.
*
* @param event
* The event thrown in the event bus
*/
@Inject
@Optional
public void handleHandlerEvent(@EventTopic(UIEvents.HandlerContainer.TOPIC_HANDLERS) Event event) {
if ((event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MHandlerContainer) && (event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MContext)) {
MHandlerContainer handlerContainer = (MHandlerContainer) event.getProperty(UIEvents.EventTags.ELEMENT);
if (UIEvents.EventTypes.ADD.equals(event.getProperty(UIEvents.EventTags.TYPE))) {
if (event.getProperty(UIEvents.EventTags.NEW_VALUE) instanceof MHandler) {
MHandler handler = (MHandler) event.getProperty(UIEvents.EventTags.NEW_VALUE);
MContext mContext = (MContext) handlerContainer;
IEclipseContext context = mContext.getContext();
if (context != null) {
processActiveHandler(handler, context);
}
}
} else if (UIEvents.EventTypes.REMOVE.equals(event.getProperty(UIEvents.EventTags.TYPE))) {
if (event.getProperty(UIEvents.EventTags.OLD_VALUE) instanceof MHandler) {
MHandler handler = (MHandler) event.getProperty(UIEvents.EventTags.OLD_VALUE);
MContext mContext = (MContext) handlerContainer;
IEclipseContext context = mContext.getContext();
if (context != null) {
MCommand command = handler.getCommand();
if (command != null) {
String commandId = command.getElementId();
EHandlerService handlerService = context.get(EHandlerService.class);
handlerService.deactivateHandler(commandId, handler.getObject());
}
}
}
}
}
}
use of org.eclipse.e4.ui.model.application.ui.MContext in project eclipse.platform.ui by eclipse-platform.
the class HandlerProcessingAddon method postConstruct.
/**
* Do initial check of handlers and their context upon creation
*
* @param application
* @param modelService
*/
@PostConstruct
public void postConstruct(MApplication application, EModelService modelService) {
List<MHandlerContainer> findElements = modelService.findElements(application, null, MHandlerContainer.class);
for (MHandlerContainer mHandlerContainer : findElements) {
if (mHandlerContainer instanceof MContext) {
MContext mContext = (MContext) mHandlerContainer;
IEclipseContext context = mContext.getContext();
if (context != null) {
for (MHandler mHandler : mHandlerContainer.getHandlers()) {
processActiveHandler(mHandler, context);
}
}
}
}
}
use of org.eclipse.e4.ui.model.application.ui.MContext in project eclipse.platform.ui by eclipse-platform.
the class ElementReferenceRenderer method disposeWidget.
@Override
public void disposeWidget(MUIElement element) {
MPlaceholder ph = (MPlaceholder) element;
MUIElement refElement = ph.getRef();
Control refCtrl = (Control) refElement.getWidget();
// Remove the element ref from the rendered list
Set<MPlaceholder> refs = renderedMap.get(refElement);
refs.remove(ph);
IEclipseContext curContext = modelService.getContainingContext(ph);
if (refs.isEmpty()) {
// part. See bug 347471 for details
if (refElement instanceof MPart) {
MPart thePart = (MPart) refElement;
String imageURI = thePart.getIconURI();
thePart.setIconURI(null);
thePart.setIconURI(imageURI);
}
renderingEngine.removeGui(refElement);
renderedMap.remove(refElement);
} else // to dispose the 'real' part
if (refCtrl != null && !refCtrl.isDisposed()) {
MPlaceholder currentRef = refElement.getCurSharedRef();
if (currentRef == ph) {
// Find another *rendered* ref to pass the part on to
for (MPlaceholder aPH : refs) {
Composite phComp = (Composite) aPH.getWidget();
if (phComp == null || phComp.isDisposed())
continue;
// Reparent the context(s) (if any)
IEclipseContext newParentContext = modelService.getContainingContext(aPH);
List<MContext> allContexts = modelService.findElements(refElement, null, MContext.class);
for (MContext ctxtElement : allContexts) {
IEclipseContext theContext = ctxtElement.getContext();
// this may be null if it hasn't been rendered yet
if (theContext != null) {
if (theContext.getParent() == curContext) {
// deactivate ourselves first
if (curContext.getActiveChild() == theContext) {
theContext.deactivate();
}
theContext.setParent(newParentContext);
}
}
}
// reset the 'cur' ref
refElement.setCurSharedRef(aPH);
// Reparent the widget
refCtrl.setParent(phComp);
break;
}
} else if (currentRef != null) {
Composite phComp = (Composite) currentRef.getWidget();
if (phComp == null || phComp.isDisposed()) {
super.disposeWidget(element);
return;
}
// Reparent the context(s) (if any)
IEclipseContext newParentContext = modelService.getContainingContext(currentRef);
List<MContext> allContexts = modelService.findElements(refElement, null, MContext.class);
for (MContext ctxtElement : allContexts) {
IEclipseContext theContext = ctxtElement.getContext();
// this may be null if it hasn't been rendered yet
if (theContext != null && theContext.getParent() == curContext) {
// ourselves first
if (curContext.getActiveChild() == theContext) {
theContext.deactivate();
}
theContext.setParent(newParentContext);
}
}
}
}
super.disposeWidget(element);
}
use of org.eclipse.e4.ui.model.application.ui.MContext in project eclipse.platform.ui by eclipse-platform.
the class ElementReferenceRenderer method createWidget.
@Override
public Object createWidget(final MUIElement element, Object parent) {
MPlaceholder ph = (MPlaceholder) element;
final MUIElement ref = ph.getRef();
ref.setCurSharedRef(ph);
Set<MPlaceholder> renderedRefs = renderedMap.get(ref);
if (renderedRefs == null) {
renderedRefs = new HashSet<>();
renderedMap.put(ref, renderedRefs);
}
if (!renderedRefs.contains(ph))
renderedRefs.add(ph);
Composite newComp = new Composite((Composite) parent, SWT.NONE);
newComp.setLayout(new FillLayout());
// if the placeholder is *not* in the currently active perspective
// then don't re-parent the current view
int phLoc = modelService.getElementLocation(ph);
if (phLoc == EModelService.IN_ACTIVE_PERSPECTIVE || phLoc == EModelService.IN_SHARED_AREA || phLoc == EModelService.OUTSIDE_PERSPECTIVE) {
Control refWidget = (Control) ref.getWidget();
if (refWidget == null) {
ref.setToBeRendered(true);
refWidget = (Control) renderingEngine.createGui(ref, newComp, getContextForParent(ref));
} else if (refWidget.getParent() != newComp) {
refWidget.setParent(newComp);
}
if (ref instanceof MContext) {
IEclipseContext context = ((MContext) ref).getContext();
IEclipseContext newParentContext = getContext(ph);
if (context.getParent() != newParentContext) {
context.setParent(newParentContext);
}
}
}
return newComp;
}
Aggregations