use of org.csstudio.opibuilder.model.DisplayModel in project yamcs-studio by yamcs.
the class WidgetTreeEditpart method getImage.
@Override
protected Image getImage() {
if (getWidgetModel() instanceof DisplayModel)
return super.getImage();
String typeID = getWidgetModel().getTypeID();
WidgetDescriptor widgetDescriptor = WidgetsService.getInstance().getWidgetDescriptor(typeID);
Image image = CustomMediaFactory.getInstance().getImageFromPlugin(widgetDescriptor.getPluginId(), widgetDescriptor.getIconPath());
return image;
}
use of org.csstudio.opibuilder.model.DisplayModel 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.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;
}
Aggregations