Search in sources :

Example 1 with OPIView

use of org.csstudio.opibuilder.runmode.OPIView in project yamcs-studio by yamcs.

the class RunOPIAction method run.

@Override
public void run() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        IEditorPart activeEditor = page.getActiveEditor();
        if (activeEditor != null) {
            // TODO: Should perform the 'save' in background, then return to UI thread when done..
            if (PreferencesHelper.isAutoSaveBeforeRunning() && activeEditor.isDirty()) {
                activeEditor.doSave(null);
            }
        }
        if (runtime_page == null) {
            // (Re-)create runtime window
            runtime_page = createRuntimePage();
        } else {
            runtime_page.getWorkbenchWindow().getShell().setActive();
        }
        if (activeEditor instanceof OPIEditor) {
            // DisplayModel displayModel = ((OPIEditor) activeEditor).getDisplayModel();
            // Rectangle bounds = new Rectangle(displayModel.getLocation(), displayModel.getSize());
            IEditorInput input = activeEditor.getEditorInput();
            IPath path = ResourceUtil.getPathInEditor(input);
            RunnerInput new_input = new RunnerInput(path, null);
            // because RunModeService would only pop old content back to the front.
            for (IViewReference view_ref : runtime_page.getViewReferences()) {
                if (view_ref.getId().startsWith(OPIView.ID)) {
                    IViewPart view = view_ref.getView(true);
                    if (view instanceof OPIView) {
                        OPIView opi_view = (OPIView) view;
                        if (new_input.equals(opi_view.getOPIInput())) {
                            try {
                                opi_view.setOPIInput(new_input);
                            } catch (PartInitException ex) {
                                OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to update existing runtime for " + new_input.getName(), ex);
                            }
                            break;
                        }
                    }
                }
            }
            RunModeService.openDisplayInView(runtime_page, new_input, DisplayMode.NEW_TAB);
        }
    } catch (Exception ex) {
        ExceptionDetailsErrorDialog.openError(page.getWorkbenchWindow().getShell(), "Cannot launch display runtime", ex);
    }
}
Also used : OPIView(org.csstudio.opibuilder.runmode.OPIView) OPIEditor(org.csstudio.opibuilder.editor.OPIEditor) IViewPart(org.eclipse.ui.IViewPart) IPath(org.eclipse.core.runtime.IPath) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) RunnerInput(org.csstudio.opibuilder.runmode.RunnerInput) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

OPIEditor (org.csstudio.opibuilder.editor.OPIEditor)1 OPIView (org.csstudio.opibuilder.runmode.OPIView)1 RunnerInput (org.csstudio.opibuilder.runmode.RunnerInput)1 IPath (org.eclipse.core.runtime.IPath)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1 IViewReference (org.eclipse.ui.IViewReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 PartInitException (org.eclipse.ui.PartInitException)1