use of org.csstudio.opibuilder.model.AbstractContainerModel 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.AbstractContainerModel 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.AbstractContainerModel in project yamcs-studio by yamcs.
the class NativeTextEditpart method registerPropertyChangeHandlers.
@Override
protected void registerPropertyChangeHandlers() {
super.registerPropertyChangeHandlers();
removeAllPropertyChangeHandlers(NativeTextModel.PROP_ALIGN_H);
PropertyChangeListener updatePropSheetListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
updatePropSheet();
}
};
getWidgetModel().getProperty(NativeTextModel.PROP_MULTILINE_INPUT).addPropertyChangeListener(updatePropSheetListener);
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
AbstractWidgetModel model = getWidgetModel();
AbstractContainerModel parent = model.getParent();
parent.removeChild(model);
parent.addChild(model);
parent.selectWidget(model, true);
return false;
}
};
setPropertyChangeHandler(NativeTextModel.PROP_SHOW_NATIVE_BORDER, handler);
setPropertyChangeHandler(NativeTextModel.PROP_MULTILINE_INPUT, handler);
setPropertyChangeHandler(NativeTextModel.PROP_WRAP_WORDS, handler);
setPropertyChangeHandler(NativeTextModel.PROP_SHOW_H_SCROLL, handler);
setPropertyChangeHandler(NativeTextModel.PROP_SHOW_V_SCROLL, handler);
setPropertyChangeHandler(NativeTextModel.PROP_PASSWORD_INPUT, handler);
setPropertyChangeHandler(NativeTextModel.PROP_ALIGN_H, handler);
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class NativeTextEditpartDelegate method registerPropertyChangeHandlers.
@Override
public void registerPropertyChangeHandlers() {
editpart.removeAllPropertyChangeHandlers(TextInputModel.PROP_ALIGN_H);
PropertyChangeListener updatePropSheetListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
updatePropSheet();
}
};
model.getProperty(TextInputModel.PROP_MULTILINE_INPUT).addPropertyChangeListener(updatePropSheetListener);
IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
@Override
public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
AbstractContainerModel parent = model.getParent();
parent.removeChild(model);
parent.addChild(model);
parent.selectWidget(model, true);
return false;
}
};
editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_NATIVE_BORDER, handler);
editpart.setPropertyChangeHandler(TextInputModel.PROP_MULTILINE_INPUT, handler);
editpart.setPropertyChangeHandler(TextInputModel.PROP_WRAP_WORDS, handler);
editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_H_SCROLL, handler);
editpart.setPropertyChangeHandler(TextInputModel.PROP_SHOW_V_SCROLL, handler);
editpart.setPropertyChangeHandler(TextInputModel.PROP_PASSWORD_INPUT, handler);
editpart.setPropertyChangeHandler(TextInputModel.PROP_ALIGN_H, handler);
}
use of org.csstudio.opibuilder.model.AbstractContainerModel in project yamcs-studio by yamcs.
the class CopyWidgetsAction method getSelectedWidgetModels.
/**
* Gets the widget models of all currently selected EditParts.
*
* @return a list with all widget models that are currently selected.
* The order of the selected widgets was kept.
*/
protected final List<AbstractWidgetModel> getSelectedWidgetModels() {
List<?> selection = getSelectedObjects();
List<AbstractWidgetModel> sameParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> differentParentModels = new ArrayList<AbstractWidgetModel>();
List<AbstractWidgetModel> result = new ArrayList<AbstractWidgetModel>();
AbstractContainerModel parent = null;
for (Object o : selection) {
if (o instanceof AbstractBaseEditPart && !(o instanceof DisplayEditpart)) {
AbstractWidgetModel widgetModel = (AbstractWidgetModel) ((EditPart) o).getModel();
if (parent == null)
parent = widgetModel.getParent();
if (widgetModel.getParent() == parent)
sameParentModels.add(widgetModel);
else
differentParentModels.add(widgetModel);
}
}
// sort widgets to its original order
if (sameParentModels.size() > 1) {
AbstractWidgetModel[] modelArray = sameParentModels.toArray(new AbstractWidgetModel[0]);
Arrays.sort(modelArray, new Comparator<AbstractWidgetModel>() {
@Override
public int compare(AbstractWidgetModel o1, AbstractWidgetModel o2) {
if (o1.getParent().getChildren().indexOf(o1) > o2.getParent().getChildren().indexOf(o2))
return 1;
else
return -1;
}
});
result.addAll(Arrays.asList(modelArray));
if (differentParentModels.size() > 0)
result.addAll(differentParentModels);
return result;
}
if (differentParentModels.size() > 0)
sameParentModels.addAll(differentParentModels);
return sameParentModels;
}
Aggregations