Search in sources :

Example 1 with OPIEditor

use of org.csstudio.opibuilder.editor.OPIEditor in project yamcs-studio by yamcs.

the class CopyWidgetsAction method run.

@Override
public void run() {
    DisplayModel tempModel = new DisplayModel();
    List<AbstractWidgetModel> widgetModels = getSelectedWidgetModels();
    for (AbstractWidgetModel widget : widgetModels) {
        tempModel.addChild(widget, false);
    }
    String xml = XMLUtil.widgetToXMLString(tempModel, false);
    ((OPIEditor) getWorkbenchPart()).getClipboard().setContents(new Object[] { xml }, new Transfer[] { OPIWidgetsTransfer.getInstance() });
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            IAction pasteAction = ((ActionRegistry) ((OPIEditor) getWorkbenchPart()).getAdapter(ActionRegistry.class)).getAction(ActionFactory.PASTE.getId());
            if (pasteAction != null) {
                ((PasteWidgetsAction) pasteAction).refreshEnable();
            }
        }
    });
}
Also used : OPIEditor(org.csstudio.opibuilder.editor.OPIEditor) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) IAction(org.eclipse.jface.action.IAction) DisplayModel(org.csstudio.opibuilder.model.DisplayModel)

Example 2 with OPIEditor

use of org.csstudio.opibuilder.editor.OPIEditor in project yamcs-studio by yamcs.

the class LayoutWidgetsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart activeEditor = page.getActiveEditor();
    if (activeEditor instanceof OPIEditor) {
        ISelection currentSelection = ((GraphicalViewer) ((OPIEditor) activeEditor).getAdapter(GraphicalViewer.class)).getSelection();
        if (currentSelection instanceof IStructuredSelection) {
            Object element = ((IStructuredSelection) currentSelection).getFirstElement();
            if (element instanceof AbstractLayoutEditpart) {
                CommandStack commandStack = (CommandStack) ((OPIEditor) activeEditor).getAdapter(CommandStack.class);
                if (commandStack != null)
                    LayoutWidgetsImp.run((AbstractLayoutEditpart) element, commandStack);
            }
        }
    } else {
        return null;
    }
    return null;
}
Also used : OPIEditor(org.csstudio.opibuilder.editor.OPIEditor) CommandStack(org.eclipse.gef.commands.CommandStack) GraphicalViewer(org.eclipse.gef.GraphicalViewer) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractLayoutEditpart(org.csstudio.opibuilder.editparts.AbstractLayoutEditpart)

Example 3 with OPIEditor

use of org.csstudio.opibuilder.editor.OPIEditor 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)3 IEditorPart (org.eclipse.ui.IEditorPart)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 AbstractLayoutEditpart (org.csstudio.opibuilder.editparts.AbstractLayoutEditpart)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 DisplayModel (org.csstudio.opibuilder.model.DisplayModel)1 OPIView (org.csstudio.opibuilder.runmode.OPIView)1 RunnerInput (org.csstudio.opibuilder.runmode.RunnerInput)1 IPath (org.eclipse.core.runtime.IPath)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1 CommandStack (org.eclipse.gef.commands.CommandStack)1 IAction (org.eclipse.jface.action.IAction)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IViewPart (org.eclipse.ui.IViewPart)1 IViewReference (org.eclipse.ui.IViewReference)1 PartInitException (org.eclipse.ui.PartInitException)1