Search in sources :

Example 1 with LinkingContainerEditpart

use of org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart in project yamcs-studio by yamcs.

the class EditEmbeddedOPIHandler method execute.

/**
 * Determine the widget that was the object of the mouse click.
 * If it can be established to be a LinkingContainerEditpart, extract
 * the path of the embedded opi and request opening an OPIEditor with this file.
 */
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IPath path = null;
    LinkingContainerEditpart linkingContainer = null;
    ISelection selection = HandlerUtil.getActiveMenuSelection(event);
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        Object o = structuredSelection.getFirstElement();
        if (o instanceof LinkingContainerEditpart) {
            linkingContainer = (LinkingContainerEditpart) o;
            path = linkingContainer.getWidgetModel().getOPIFilePath();
        }
    }
    if (path != null) {
        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null) {
            IWorkbenchPage page = window.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 ex) {
                    ErrorHandlerUtil.handleError("Failed to open embedded OPI in editor", ex);
                }
            }
        }
    }
    // required return value
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) LinkingContainerEditpart(org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart) IPath(org.eclipse.core.runtime.IPath) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with LinkingContainerEditpart

use of org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart in project yamcs-studio by yamcs.

the class EditableLinkingContainerPropertyTester method test.

/**
 * Establish if the receiver object is a LinkingContainer widget suitable
 * for editing in OPIEditor.
 *
 * If:
 * <ul>
 *  <li>OPIBuilder is in no-edit mode
 *  <li>the receiver is not a linking container
 *  <li>no path can be extracted from the widget
 *  <li>the embedding panel is served over HTTP
 *  <li>the embedded panel is served over HTTP
 * </ul>
 *  return false
 */
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    IPath displayPath = null;
    IPath embeddedPath = null;
    boolean editable = false;
    if (property.equals("isEditable")) {
        if (!PreferencesHelper.isNoEdit()) {
            if (receiver instanceof LinkingContainerEditpart) {
                LinkingContainerEditpart lc = (LinkingContainerEditpart) receiver;
                displayPath = lc.getWidgetModel().getDisplayModel().getOpiFilePath();
                embeddedPath = lc.getWidgetModel().getOPIFilePath();
            }
        }
        editable = (displayPath instanceof Path && embeddedPath instanceof Path);
    }
    return editable;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) LinkingContainerEditpart(org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart) IPath(org.eclipse.core.runtime.IPath)

Example 3 with LinkingContainerEditpart

use of org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart in project yamcs-studio by yamcs.

the class LinkingContainerModel method scaleChildren.

/**
 * Scale its children.
 */
@Override
public void scaleChildren() {
    if (isAutoFit())
        return;
    // The linking container model doesn't hold its children actually, so it
    // has to ask editpart to get its children.
    GraphicalViewer viewer = getRootDisplayModel().getViewer();
    if (viewer == null)
        return;
    LinkingContainerEditpart editpart = (LinkingContainerEditpart) viewer.getEditPartRegistry().get(this);
    Dimension size = getSize();
    double newWidthRatio = size.width / (double) getOriginSize().width;
    double newHeightRatio = size.height / (double) getOriginSize().height;
    boolean allowScale = true;
    if (getDisplayModel() != null) {
        allowScale = getDisplayModel().getDisplayScaleData().isAutoScaleWidgets();
        if (allowScale) {
            int minWidth = getDisplayModel().getDisplayScaleData().getMinimumWidth();
            if (minWidth < 0) {
                minWidth = getDisplayModel().getWidth();
            }
            int minHeight = getDisplayModel().getDisplayScaleData().getMinimumHeight();
            if (minHeight < 0) {
                minHeight = getDisplayModel().getHeight();
            }
            if (getWidth() * newWidthRatio < minWidth)
                newWidthRatio = minWidth / (double) getOriginSize().width;
            if (getHeight() * newHeightRatio < minHeight)
                newHeightRatio = minHeight / (double) getOriginSize().height;
        }
    }
    if (allowScale)
        for (Object child : editpart.getChildren()) ((AbstractBaseEditPart) child).getWidgetModel().scale(newWidthRatio, newHeightRatio);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) LinkingContainerEditpart(org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart) Dimension(org.eclipse.draw2d.geometry.Dimension)

Aggregations

LinkingContainerEditpart (org.csstudio.opibuilder.widgets.editparts.LinkingContainerEditpart)3 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 PartInitException (org.eclipse.ui.PartInitException)1