use of org.csstudio.opibuilder.runmode.OPIShell in project yamcs-studio by yamcs.
the class EditOPIAction method run.
@Override
public void run() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
IOPIRuntime opiRuntime = OPIShell.getOPIShellForShell(shell);
if (opiRuntime == null) {
// if the selected object isn't an OPIShell so grab the
// OPIView or OPIRunner currently selected
IWorkbenchPart part = page.getActivePart();
if (part instanceof IOPIRuntime) {
opiRuntime = (IOPIRuntime) part;
}
}
IWorkbenchWindow targetWindow = null;
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
if (window.getActivePage().getPerspective().getId().equals(OPIEditorPerspective.ID)) {
targetWindow = window;
}
}
if (targetWindow == null) {
try {
targetWindow = PlatformUI.getWorkbench().openWorkbenchWindow(OPIEditorPerspective.ID, null);
} catch (WorkbenchException e) {
throw new RuntimeException(e);
}
}
targetWindow.getShell().setActive();
if (opiRuntime != null) {
IPath path = opiRuntime.getDisplayModel().getOpiFilePath();
page = targetWindow.getActivePage();
if (page != null) {
try {
IEditorInput editorInput = ResourceUtil.editorInputFromPath(path);
page.openEditor(editorInput, OPI_EDITOR_ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
} catch (PartInitException e) {
ErrorHandlerUtil.handleError("Failed to open current OPI in editor", e);
}
}
}
}
Aggregations