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;
}
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;
}
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);
}
Aggregations