use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.
the class XMLUtil method fillLinkingContainerSub.
private static void fillLinkingContainerSub(final AbstractLinkingContainerModel container, List<IPath> trace, final MacrosInput macrosInput_) throws Exception {
if (container == null)
return;
if (container.getRootDisplayModel() != null && container.getRootDisplayModel().getOpiFilePath() != null) {
if (trace.contains(container.getRootDisplayModel().getOpiFilePath())) {
container.setOPIFilePath("");
throw new Exception("Opi link contains some loops.\n" + trace.toString());
} else {
trace.add(container.getRootDisplayModel().getOpiFilePath());
}
IPath path = container.getOPIFilePath();
if (path != null && !path.isEmpty()) {
final Map<String, String> macroMap = PreferencesHelper.getMacros();
if (macrosInput_ != null && macrosInput_.getMacrosMap() != null) {
macroMap.putAll(macrosInput_.getMacrosMap());
}
macroMap.putAll(buildMacroMap(container));
String resolvedPath = MacroUtil.replaceMacros(path.toString(), s -> macroMap.get(s));
path = ResourceUtil.getPathFromString(resolvedPath);
final DisplayModel inside = new DisplayModel(path);
inside.setDisplayID(container.getRootDisplayModel(false).getDisplayID());
inside.setParentDisplayModel(container.getRootDisplayModel());
try {
fillDisplayModelFromInputStreamSub(ResourceUtil.pathToInputStream(path), inside, Display.getCurrent(), trace, macrosInput_);
} catch (Exception ex) {
OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to load LinkingContainer opi_file " + path, ex);
}
// mark connection as it is loaded from linked opi
for (AbstractWidgetModel w : inside.getAllDescendants()) for (ConnectionModel conn : w.getSourceConnections()) conn.setLoadedFromLinkedOpi(true);
AbstractContainerModel loadTarget = inside;
if (!container.getGroupName().trim().equals("")) {
// $NON-NLS-1$
AbstractWidgetModel group = inside.getChildByName(container.getGroupName());
if (group != null && group instanceof AbstractContainerModel) {
loadTarget = (AbstractContainerModel) group;
}
}
// container.addChildren(loadTarget.getChildren(), true);
container.setDisplayModel(inside);
}
}
}
use of org.csstudio.opibuilder.model.DisplayModel 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();
}
}
});
}
use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.
the class PasteWidgetsAction method getAbsolutePosition.
/**
* @param widgetModel
* @return the absolute position of a widget relative to display.
*/
private Point getAbsolutePosition(AbstractWidgetModel widgetModel) {
if (widgetModel instanceof DisplayModel)
return new Point(0, 0);
Point result = widgetModel.getLocation();
AbstractContainerModel parent = widgetModel.getParent();
while (!(parent instanceof DisplayModel)) {
result.translate(parent.getLocation());
parent = parent.getParent();
}
return result;
}
use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.
the class NewOPIFileWizardPage method getInitialContents.
@Override
protected InputStream getInitialContents() {
DisplayModel displayModel = new DisplayModel();
SchemaService.getInstance().applySchema(displayModel);
String s = XMLUtil.widgetToXMLString(displayModel, true);
InputStream result = new ByteArrayInputStream(s.getBytes());
return result;
}
use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.
the class CreateGroupAction method run.
@Override
public void run(IAction action) {
List<AbstractWidgetModel> originalSelectedWidgets = getSelectedWidgetModels();
CompoundCommand compoundCommand = new CompoundCommand("Create Group");
List<AbstractWidgetModel> selectedWidgets = new ArrayList<AbstractWidgetModel>();
selectedWidgets.addAll(originalSelectedWidgets);
// remove the selected widgets which are children of another selected widget.
for (AbstractWidgetModel widget : originalSelectedWidgets) {
if (widget instanceof DisplayModel) {
selectedWidgets.remove(widget);
continue;
}
if (widget instanceof AbstractContainerModel) {
for (AbstractWidgetModel child : originalSelectedWidgets) {
if (((AbstractContainerModel) widget).getChildren().contains(child))
selectedWidgets.remove(child);
}
}
}
int minDepth = Integer.MAX_VALUE;
int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
AbstractWidgetModel minDepthWidget = selectedWidgets.get(0);
for (AbstractWidgetModel widget : selectedWidgets) {
int leftX = widget.getLocation().x;
int upY = widget.getLocation().y;
int rightX = widget.getLocation().x + widget.getSize().width;
int bottomY = widget.getLocation().y + widget.getSize().height;
int depth = widget.getNestedDepth();
if (leftX < minX)
minX = leftX;
if (upY < minY)
minY = upY;
if (rightX > maxX)
maxX = rightX;
if (bottomY > maxY)
maxY = bottomY;
if (minDepth > depth) {
minDepth = depth;
minDepthWidget = widget;
}
}
// Orphan order should be reversed so that undo operation has the correct order.
AbstractWidgetModel[] widgetsArray = selectedWidgets.toArray(new AbstractWidgetModel[selectedWidgets.size()]);
for (int i = widgetsArray.length - 1; i >= 0; i--) {
compoundCommand.add(new OrphanChildCommand(widgetsArray[i].getParent(), widgetsArray[i]));
}
GroupingContainerModel groupingContainerModel = new GroupingContainerModel();
SchemaService.getInstance().applySchema(groupingContainerModel);
// the parent should be the widget with minimum nested depth
AbstractContainerModel parent = minDepthWidget.getParent();
int borderWidth = 0;
if (groupingContainerModel.getBorderStyle() == BorderStyle.GROUP_BOX)
borderWidth = 30;
groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN, true);
groupingContainerModel.setPropertyValue(GroupingContainerModel.PROP_SHOW_SCROLLBAR, false);
compoundCommand.add(new WidgetCreateCommand(groupingContainerModel, parent, new Rectangle(minX, minY, maxX - minX + borderWidth, maxY - minY + borderWidth), false));
for (AbstractWidgetModel widget : selectedWidgets) {
compoundCommand.add(new AddWidgetCommand(groupingContainerModel, widget, new Rectangle(widget.getLocation().translate(-minX, -minY), widget.getSize())));
}
execute(compoundCommand);
}
Aggregations