Search in sources :

Example 1 with VariablesChartDialog

use of edu.uah.rsesc.aadlsimulator.ui.dialogs.VariablesChartDialog in project AGREE by loonwerks.

the class OpenVariablesChartHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        final SimulationUIService simulationUIService = (SimulationUIService) Objects.requireNonNull(PlatformUI.getWorkbench().getService(SimulationUIService.class), "unable to get simulation UI service");
        // Open Value Visualization Chart
        simulationUIService.getCurrentState().getSimulationEngine().queueNotification(new NotificationHandler() {

            @Override
            public void handleNotification(final SimulationEngineNotification notification) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (simulationUIService.getCurrentState().getEngineState().getNumberOfFrames() != 0) {
                            simulationUIService.lockUserInterface();
                            final Shell shell = new Shell(Display.getDefault().getActiveShell(), SWT.SHELL_TRIM & ~SWT.MIN);
                            // Listening for cancellation
                            final SimulatorStateListener simCanceledListener = new SimulatorStateListener() {

                                @Override
                                public void onSimulatorStateChanged(SimulatorState simulatorState) {
                                    if (simulationUIService.getCurrentState().getEngineState() == null) {
                                        if (shell != null && !shell.isDisposed()) {
                                            // Close view on cancel
                                            shell.close();
                                        }
                                    }
                                }
                            };
                            simulationUIService.addStateChangeListener(simCanceledListener);
                            try {
                                new VariablesChartDialog(shell, simulationUIService);
                            } finally {
                                simulationUIService.removeStateChangeListener(simCanceledListener);
                                simulationUIService.unlockUserInterface();
                            }
                        }
                    }
                });
            }
        });
    } catch (final Exception ex) {
        final Status status = new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Error", ex);
        StatusManager.getManager().handle(status, StatusManager.SHOW | StatusManager.LOG);
    }
    return null;
}
Also used : SimulationUIService(edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) VariablesChartDialog(edu.uah.rsesc.aadlsimulator.ui.dialogs.VariablesChartDialog) SimulatorStateListener(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener) NotificationHandler(edu.uah.rsesc.aadlsimulator.NotificationHandler) SimulatorState(edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState) SimulationEngineNotification(edu.uah.rsesc.aadlsimulator.SimulationEngineNotification) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

NotificationHandler (edu.uah.rsesc.aadlsimulator.NotificationHandler)1 SimulationEngineNotification (edu.uah.rsesc.aadlsimulator.SimulationEngineNotification)1 VariablesChartDialog (edu.uah.rsesc.aadlsimulator.ui.dialogs.VariablesChartDialog)1 SimulationUIService (edu.uah.rsesc.aadlsimulator.ui.services.SimulationUIService)1 SimulatorState (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorState)1 SimulatorStateListener (edu.uah.rsesc.aadlsimulator.ui.services.SimulatorStateListener)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Shell (org.eclipse.swt.widgets.Shell)1