/** * 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, null); 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); } } } } }
/** * Responds to the setting of contexts of handlers in the application model and reacts * accordingly. * * @param event * The event which signals the setting of the context. */ @Inject public void handleContextEvent(@Optional @EventTopic(UIEvents.Context.TOPIC_CONTEXT) Event event) { if (event == null) return; Object origin = event.getProperty(UIEvents.EventTags.ELEMENT); Object context = event.getProperty(UIEvents.EventTags.NEW_VALUE); if ((origin instanceof MHandlerContainer) && (UIEvents.EventTypes.SET.equals(event.getProperty(UIEvents.EventTags.TYPE)) && context instanceof IEclipseContext)) { MHandlerContainer handlerContainer = (MHandlerContainer) origin; IEclipseContext castedContext = (IEclipseContext) context; for (MHandler mHandler : handlerContainer.getHandlers()) { processActiveHandler(mHandler, castedContext); } } }
dialogbutton.getStyleClass().add("dialog-opener"); //$NON-NLS-1$ String commandId = handlerContainer.getHandlers().stream().filter(h -> h.getContributionURI().endsWith("org.eclipse.fx.ui.workbench.fx.perspective.SwitchPerspectiveDialogHandler")) //$NON-NLS-1$ .findFirst().map(h -> h.getCommand().getElementId()).orElse(null);