Search in sources :

Example 1 with IBeanListener

use of org.eclipse.scanning.api.event.bean.IBeanListener in project gda-core by openGDA.

the class ApplicationActionBarAdvisor method buildScanStatus.

private StatusLineContributionItem buildScanStatus() {
    StatusLineContributionItem scanStatus = new StatusLineContributionItem("GDA-ScanStatus", true, 55);
    IEventService service = ServiceHolder.getEventService();
    try {
        ISubscriber<IBeanListener<StatusBean>> statusTopicSubscriber = service.createSubscriber(getActiveMqUri(), EventConstants.STATUS_TOPIC);
        statusTopicSubscriber.addListener(event -> {
            if (event.getBean() instanceof ScanBean) {
                updateScanDetails(scanStatus, (ScanBean) event.getBean());
            }
        });
        ApplicationWorkbenchAdvisor.addCleanupWork(() -> {
            try {
                statusTopicSubscriber.removeAllListeners();
                statusTopicSubscriber.close();
            } catch (EventException e1) {
                logger.error("Error removing listener from STATUS_TOPIC", e1);
            }
        });
    } catch (NullPointerException e) {
        // Handling for non-StatusQueueView/Mapping beamlines, prevent stack trace being printed to console
        if (service == null) {
            logger.warn("EventService null when adding listener to STATUS_TOPIC, ScanBean status bar progress disabled. If this beamline uses the Queue, this will cause errors elsewhere");
        } else {
            throw e;
        }
    } catch (Exception e2) {
        logger.error("Error adding listener to STATUS_TOPIC", e2);
    }
    return scanStatus;
}
Also used : StatusLineContributionItem(org.eclipse.ui.texteditor.StatusLineContributionItem) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) EventException(org.eclipse.scanning.api.event.EventException) IEventService(org.eclipse.scanning.api.event.IEventService) IBeanListener(org.eclipse.scanning.api.event.bean.IBeanListener) URISyntaxException(java.net.URISyntaxException) EventException(org.eclipse.scanning.api.event.EventException)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 EventException (org.eclipse.scanning.api.event.EventException)1 IEventService (org.eclipse.scanning.api.event.IEventService)1 IBeanListener (org.eclipse.scanning.api.event.bean.IBeanListener)1 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)1 StatusLineContributionItem (org.eclipse.ui.texteditor.StatusLineContributionItem)1