use of org.csstudio.opibuilder.model.AbstractWidgetModel 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.AbstractWidgetModel 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.AbstractWidgetModel in project yamcs-studio by yamcs.
the class ChangeOrderAction method fillWidgetMap.
/**
* @param widgetMap
*/
private void fillWidgetMap(Map<AbstractContainerModel, List<IndexedWidget>> widgetMap) {
for (Object selection : getSelectedObjects()) {
if (selection instanceof AbstractBaseEditPart) {
AbstractBaseEditPart widgetEditpart = (AbstractBaseEditPart) selection;
AbstractWidgetModel widgetModel = (AbstractWidgetModel) widgetEditpart.getModel();
if (widgetEditpart.getParent() != null && widgetModel.getParent() != null) {
AbstractContainerModel containerModel = (AbstractContainerModel) widgetEditpart.getParent().getModel();
if (!widgetMap.containsKey(containerModel)) {
widgetMap.put(containerModel, new LinkedList<IndexedWidget>());
}
widgetMap.get(containerModel).add(new IndexedWidget(containerModel.getIndexOf(widgetModel), widgetModel));
}
}
}
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class DistributeWidgetsAction method getSortedModelArray.
private AbstractWidgetModel[] getSortedModelArray(final boolean byHorizontal) {
AbstractWidgetModel[] modelArray = new AbstractWidgetModel[getSelectedWidgetModels().size()];
int i = 0;
for (AbstractWidgetModel model : getSelectedWidgetModels()) {
modelArray[i++] = model;
}
Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {
@Override
public int compare(AbstractWidgetModel o1, AbstractWidgetModel o2) {
int o1loc, o2loc;
if (byHorizontal) {
o1loc = o1.getLocation().x;
o2loc = o2.getLocation().x;
} else {
o1loc = o1.getLocation().y;
o2loc = o2.getLocation().y;
}
if (o1loc < o2loc)
return -1;
else if (o1loc > o2loc)
return 1;
else
return 0;
}
});
return modelArray;
}
use of org.csstudio.opibuilder.model.AbstractWidgetModel in project yamcs-studio by yamcs.
the class OPIWidgetsTransfer method nativeToJava.
@Override
public Object nativeToJava(TransferData transferData) {
if (!isSupportedType(transferData))
return null;
byte[] bytes = (byte[]) super.nativeToJava(transferData);
if (bytes == null)
return null;
try {
DisplayModel displayModel = // $NON-NLS-1$
(DisplayModel) XMLUtil.fillWidgetsFromXMLString(new String(bytes, "UTF-8"), null);
List<AbstractWidgetModel> widgets = displayModel.getChildren();
return widgets;
} catch (Exception e) {
OPIBuilderPlugin.getLogger().log(Level.WARNING, "Failed to transfer XML to widget", e);
}
return null;
}
Aggregations