use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.
the class XMLUtil method widgetToXMLElement.
/**
* Flatten a widget to XML element.
*
* @param widgetModel
* model of the widget
* @return the XML element
*/
public static Element widgetToXMLElement(AbstractWidgetModel widgetModel) {
Element result = new Element((widgetModel instanceof DisplayModel) ? XMLTAG_DISPLAY : (widgetModel instanceof ConnectionModel) ? XMLTAG_CONNECTION : XMLTAG_WIDGET);
result.setAttribute(XMLATTR_TYPEID, widgetModel.getTypeID());
result.setAttribute(XMLATTR_VERSION, widgetModel.getVersion().toString());
List<String> propIds = new ArrayList<>(widgetModel.getAllPropertyIDs());
Collections.sort(propIds);
for (String propId : propIds) {
if (widgetModel.getProperty(propId).isSavable()) {
Element propElement = new Element(propId);
widgetModel.getProperty(propId).writeToXML(propElement);
result.addContent(propElement);
}
}
if (widgetModel instanceof AbstractContainerModel && !(widgetModel instanceof AbstractLinkingContainerModel)) {
AbstractContainerModel containerModel = (AbstractContainerModel) widgetModel;
for (AbstractWidgetModel child : containerModel.getChildren()) {
result.addContent(widgetToXMLElement(child));
}
}
// convert connections on this displayModel to xml element
if (widgetModel instanceof DisplayModel && ((DisplayModel) widgetModel).getConnectionList() != null) {
for (ConnectionModel connectionModel : ((DisplayModel) widgetModel).getConnectionList()) {
if (!connectionModel.isLoadedFromLinkedOpi()) {
Element connElement = widgetToXMLElement(connectionModel);
result.addContent(connElement);
}
}
}
return result;
}
use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.
the class XMLUtil method fillConnections.
@SuppressWarnings("rawtypes")
private static void fillConnections(Element element, DisplayModel displayModel) throws Exception {
if (element.getName().equals(XMLTAG_CONNECTION)) {
ConnectionModel result = new ConnectionModel(displayModel);
setPropertiesFromXML(element, result);
} else if (element.getName().equals(XMLTAG_DISPLAY)) {
List children = element.getChildren();
Iterator iterator = children.iterator();
while (iterator.hasNext()) {
Element subElement = (Element) iterator.next();
if (subElement.getName().equals(XMLTAG_CONNECTION)) {
fillConnections(subElement, displayModel);
}
}
}
}
use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.
the class ReplaceWidgetCommand method getAllConnections.
private List<ConnectionModel> getAllConnections(AbstractWidgetModel widget, boolean source) {
List<ConnectionModel> result = new ArrayList<ConnectionModel>();
result.addAll(source ? widget.getSourceConnections() : widget.getTargetConnections());
if (widget instanceof AbstractContainerModel) {
for (AbstractWidgetModel child : ((AbstractContainerModel) widget).getAllDescendants()) {
result.addAll(source ? child.getSourceConnections() : child.getTargetConnections());
}
}
return result;
}
use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.
the class ReplaceWidgetCommand method undo.
@Override
public void undo() {
container.removeChild(targetWidget);
container.addChild(index, srcWidget);
for (ConnectionModel conn : sourceConnections) {
if (conn.getSource() == targetWidget)
conn.setSource(srcWidget);
}
for (ConnectionModel conn : targetConnections) {
if (conn.getTarget() == targetWidget)
conn.setTarget(srcWidget);
}
removeConnections(sourceConnections);
removeConnections(targetConnections);
addConnections(sourceConnections);
addConnections(targetConnections);
}
use of org.csstudio.opibuilder.model.ConnectionModel in project yamcs-studio by yamcs.
the class AbstractPolyEditPart method registerPropertyChangeHandlers.
/**
* {@inheritDoc}
*/
@Override
protected void registerPropertyChangeHandlers() {
super.registerPropertyChangeHandlers();
// points
IWidgetPropertyChangeHandler pointsHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
Polyline polyline = (Polyline) refreshableFigure;
PointList points = (PointList) newValue;
if (points.size() != polyline.getPoints().size()) {
anchorMap = null;
// delete connections on deleted points
if (points.size() < polyline.getPoints().size()) {
for (ConnectionModel conn : getWidgetModel().getSourceConnections()) {
if (Integer.parseInt(conn.getSourceTerminal()) >= points.size()) {
conn.disconnect();
}
}
for (ConnectionModel conn : getWidgetModel().getTargetConnections()) {
if (Integer.parseInt(conn.getTargetTerminal()) >= points.size()) {
conn.disconnect();
}
}
}
}
// deselect the widget (this refreshes the polypoint drag
// handles)
int selectionState = getSelected();
setSelected(EditPart.SELECTED_NONE);
polyline.setPoints(points);
doRefreshVisuals(polyline);
// restore the selection state
setSelected(selectionState);
return false;
}
};
setPropertyChangeHandler(AbstractPolyModel.PROP_POINTS, pointsHandler);
IWidgetPropertyChangeHandler rotationHandler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
getWidgetModel().setPoints(PointsUtil.rotatePoints(getWidgetModel().getOriginalPoints().getCopy(), (Double) newValue), false);
return false;
}
};
setPropertyChangeHandler(AbstractPolyModel.PROP_ROTATION, rotationHandler);
}
Aggregations