use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class DisplayModel method defineProperties.
@Override
protected void defineProperties(final List<WidgetProperty<?>> properties) {
super.defineProperties(properties);
properties.add(macros = propMacros.createProperty(this, new Macros()));
properties.add(background = propBackgroundColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.BACKGROUND)));
properties.add(gridVisible = propGridVisible.createProperty(this, true));
properties.add(gridColor = propGridColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.GRID)));
properties.add(gridStepX = propGridStepX.createProperty(this, 10));
properties.add(gridStepY = propGridStepY.createProperty(this, 10));
properties.add(children = new ChildrenProperty(this));
}
use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class DisplayModel method getEffectiveMacros.
/**
* Display model provides macros for all its widgets.
* @return {@link Macros}
*/
@Override
public Macros getEffectiveMacros() {
// 1) Lowest priority are either
// 1.a) .. global macros from preferences
// 1.b) .. macros from embedding widget,
// which may in turn be embedded elsewhere,
// ultimately fetching the macros from preferences.
final Widget embedder = getUserData(DisplayModel.USER_DATA_EMBEDDING_WIDGET);
Macros result = (embedder == null) ? preference_macros : embedder.getEffectiveMacros();
// 2) This display may provide added macros or replacement values
result = Macros.merge(result, propMacros().getValue());
return result;
}
use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class ActionsWidgetProperty method readFromXML.
@Override
public void readFromXML(final ModelReader model_reader, final Element property_xml) throws Exception {
final boolean execute_as_one = Boolean.parseBoolean(property_xml.getAttribute(XMLTags.EXECUTE_AS_ONE)) || // Legacy files
Boolean.parseBoolean(property_xml.getAttribute("hook_all"));
final List<ActionInfo> actions = new ArrayList<>();
for (final Element action_xml : XMLUtil.getChildElements(property_xml, XMLTags.ACTION)) {
String type = action_xml.getAttribute(XMLTags.TYPE);
if ("OPEN_OPI_IN_VIEW".equals(type)) {
// No longer supporting open-in-view with <Position>
// to select left, right, ... part stack.
// Change into 'open display' for new tab
type = OPEN_DISPLAY;
final Document doc = action_xml.getOwnerDocument();
final Element target = doc.createElement(XMLTags.TARGET);
target.appendChild(doc.createTextNode(OpenDisplayActionInfo.Target.TAB.name()));
action_xml.appendChild(target);
}
final String description = XMLUtil.getChildString(action_xml, XMLTags.DESCRIPTION).orElse("");
if (// legacy used uppercase type name
OPEN_DISPLAY.equalsIgnoreCase(type)) {
// Use <file>, falling back to legacy <path>
final String file = XMLUtil.getChildString(action_xml, XMLTags.FILE).orElse(XMLUtil.getChildString(action_xml, XMLTags.PATH).orElse(""));
OpenDisplayActionInfo.Target target = OpenDisplayActionInfo.Target.REPLACE;
// Legacy used <replace> with value 0/1/2 for TAB/REPLACE/WINDOW
final Optional<String> replace = XMLUtil.getChildString(action_xml, "replace");
// later it switched to <mode> with many more options
final Optional<String> mode = XMLUtil.getChildString(action_xml, "mode");
if (replace.isPresent()) {
if ("0".equals(replace.get()))
target = OpenDisplayActionInfo.Target.TAB;
else if ("2".equals(replace.get()))
target = OpenDisplayActionInfo.Target.WINDOW;
} else if (mode.isPresent())
target = modeToTargetConvert(Integer.valueOf(mode.get()));
else
target = OpenDisplayActionInfo.Target.valueOf(XMLUtil.getChildString(action_xml, XMLTags.TARGET).orElse(OpenDisplayActionInfo.Target.REPLACE.name()).toUpperCase());
final Macros macros;
final Element macro_xml = XMLUtil.getChildElement(action_xml, XMLTags.MACROS);
if (macro_xml != null)
macros = MacroXMLUtil.readMacros(macro_xml);
else
macros = new Macros();
actions.add(new OpenDisplayActionInfo(description, file, macros, target));
} else if (// legacy used uppercase type name
WRITE_PV.equalsIgnoreCase(type)) {
// Compare legacy XML:
// <action type="WRITE_PV">
// <pv_name>$(M).TWR</pv_name>
// <value>1</value>
// <timeout>10</timeout>
// <confirm_message/>
// <description>-</description>
// </action>
// PV Name should be set.
final String pv_name = XMLUtil.getChildString(action_xml, XMLTags.PV_NAME).orElse("");
if (pv_name.isEmpty())
logger.log(Level.WARNING, "Ignoring <action type='" + WRITE_PV + "'> with empty <pv_name> on " + getWidget());
// PV may be empty to write "".
// In contrast to legacy opibuilder the value is _not_ trimmed,
// so it's possible to write " " (which opibuilder wrote as "")
final String value = XMLUtil.getChildString(action_xml, XMLTags.VALUE).orElse("");
actions.add(new WritePVActionInfo(description, pv_name, value));
} else if (EXECUTE_SCRIPT.equals(type)) {
// <script file="EmbeddedPy">
// <text> the embedded text </text>
// </script>
final Element el = XMLUtil.getChildElement(action_xml, XMLTags.SCRIPT);
if (el == null)
throw new Exception("Missing <script..>");
else {
final String path = el.getAttribute(XMLTags.FILE);
final String text = XMLUtil.getChildString(el, XMLTags.TEXT).orElse(null);
final ScriptInfo info = new ScriptInfo(path, text, false, Collections.emptyList());
actions.add(new ExecuteScriptActionInfo(description, info));
}
} else if ("EXECUTE_PYTHONSCRIPT".equalsIgnoreCase(type) || "EXECUTE_JAVASCRIPT".equalsIgnoreCase(type)) {
// Legacy XML:
// <action type="EXECUTE_PYTHONSCRIPT"> .. or "EXECUTE_JAVASCRIPT"
// <path>script.py</path>
// <scriptText><![CDATA[ /* The script */ ]]></scriptText>
// <embedded>false</embedded>
// <description>A script</description>
// </action>
final boolean embed = Boolean.parseBoolean(XMLUtil.getChildString(action_xml, "embedded").orElse("false"));
final String path = XMLUtil.getChildString(action_xml, XMLTags.PATH).orElse("");
final String text = XMLUtil.getChildString(action_xml, "scriptText").orElse("");
final ScriptInfo info;
if (embed) {
final String dialect = type.contains("PYTHON") ? ScriptInfo.EMBEDDED_PYTHON : ScriptInfo.EMBEDDED_JAVASCRIPT;
info = new ScriptInfo(dialect, text, false, Collections.emptyList());
} else
info = new ScriptInfo(path, null, false, Collections.emptyList());
actions.add(new ExecuteScriptActionInfo(description, info));
} else if (// legacy used uppercase type name
OPEN_FILE.equalsIgnoreCase(type)) {
// Use <file>, falling back to legacy <path>
final String file = XMLUtil.getChildString(action_xml, XMLTags.FILE).orElse(XMLUtil.getChildString(action_xml, XMLTags.PATH).orElse(""));
actions.add(new OpenFileActionInfo(description, file));
} else if (// legacy used uppercase type name
OPEN_WEBPAGE.equalsIgnoreCase(type)) {
// Use <url>, falling back to legacy <hyperlink>
final String url = XMLUtil.getChildString(action_xml, XMLTags.URL).orElse(XMLUtil.getChildString(action_xml, "hyperlink").orElse(""));
actions.add(new OpenWebpageActionInfo(description, url));
} else if (EXECUTE_COMMAND.equalsIgnoreCase(type) || "EXECUTE_CMD".equalsIgnoreCase(type)) {
// Legacy:
// <action type="EXECUTE_CMD">
// <command>echo Hello</command>
// <command_directory>$(user.home)</command_directory>
// <wait_time>10</wait_time>
// <description>Hello</description>
// </action>
//
// New:
// <action type="command">
// <command>echo Hello</command>
// <description>Hello</description>
// </action>
String command = XMLUtil.getChildString(action_xml, XMLTags.COMMAND).orElse("");
String directory = XMLUtil.getChildString(action_xml, "command_directory").orElse(null);
// Commands are now by default resolved relative to the display file.
if ("$(opi.dir)".equals(directory))
directory = null;
// Commands are now executed with their location as cwd.
if ("$(user.home)".equals(directory))
directory = null;
// If a legacy directory was provided, locate command there
if (directory != null && !directory.isEmpty())
command = directory + "/" + command;
actions.add(new ExecuteCommandActionInfo(description, command));
} else
logger.log(Level.WARNING, "Ignoring action of unknown type '" + type + "'");
}
setValue(new ActionInfos(actions, execute_as_one));
}
Aggregations