Skip to content

Commit

Permalink
expanding support for types of values set-able on macro properties #3108
Browse files Browse the repository at this point in the history
  • Loading branch information
shroffk committed Aug 8, 2024
1 parent 153d9e9 commit 4f3922f
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.phoebus.framework.macros.Macros;
import org.w3c.dom.Element;

import java.util.Map;

/** Widget property that describes macros.
*
* @author Kay Kasemir
Expand Down Expand Up @@ -48,9 +50,34 @@ public MacrosWidgetProperty(
public void setValueFromObject(final Object value) throws Exception
{
if (value instanceof Macros)
{
setValue((Macros) value);
}
else if (value instanceof Map)
{
setValue(fromMap((Map<String, String>) value));
}
else if (value instanceof String)
{
setValue(Macros.fromSimpleSpec((String) value));
}
else
{
throw new Exception("Need Macros, got " + value);
}
}

/**
* Parse Macro information from a {@link Map}
* Note: since Maps do not preserve order, this helper is for limited backward compatibility
* @param names_and_values a map of macro names( keys ) and their values
* @return a {@link Macros} initialized using the names and values from the map
*/
private static Macros fromMap(Map<String, String> names_and_values)
{
Macros macros = new Macros();
names_and_values.entrySet().forEach(e -> macros.add(e.getKey(), e.getValue()));
return macros;
}

@Override
Expand Down

0 comments on commit 4f3922f

Please sign in to comment.