use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidget method getEffectiveMacros.
/**
* Databrowser widget extends parent macros
*
* @return {@link Macros}
*/
@Override
public Macros getEffectiveMacros() {
final Macros base = super.getEffectiveMacros();
final Macros my_macros = propMacros().getValue();
return Macros.merge(base, my_macros);
}
use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class RuntimeViewPart method loadModel.
/**
* Load display model, schedule representation
* @param info Display to load
*/
private void loadModel(final DisplayInfo info) {
try {
final DisplayModel model = info.shouldResolve() ? ModelLoader.resolveAndLoadModel(null, info.getPath()) : ModelLoader.loadModel(info.getPath());
// This code is called
// 1) From OpenDisplayAction
// No macros in info.
// 2) On application restart with DisplayInfo from memento
// info contains snapshot of macros from last run
// Could simply use info's macros if they are non-empty,
// but merging macros with those loaded from model file
// allows for newly added macros in the display file.
final Macros macros = Macros.merge(model.propMacros().getValue(), info.getMacros());
model.propMacros().setValue(macros);
// For runtime, expand macros
if (!representation.isEditMode())
DisplayMacroExpander.expandDisplayMacros(model);
// Schedule representation on UI thread
representation.execute(() -> representModel(model));
} catch (Exception ex) {
final String message = "Cannot load " + info;
logger.log(Level.SEVERE, message, ex);
showMessage(message, ex);
}
}
use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class MacrosTable method getMacros.
/**
* @return {@link Macros} for data in table
*/
public Macros getMacros() {
final Macros macros = new Macros();
for (MacroItem item : data) {
final String name = item.getName().trim();
final String value = item.getValue().trim();
// Skip empty rows
if (!name.isEmpty() && !value.isEmpty())
macros.add(name, value);
}
return macros;
}
use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class DisplayInfoParserTest method testSerialization.
@Test
public void testSerialization() throws Exception {
final Macros macros = new Macros();
DisplayInfo display = new DisplayInfo("/a/path/file.opi", "Alias", macros);
String serialized = DisplayInfoXMLUtil.toXML(display);
System.out.println(serialized);
assertThat(serialized, not(containsString("<macros>")));
DisplayInfo copy = DisplayInfoXMLUtil.fromXML(serialized);
System.out.println(copy);
assertThat(copy, equalTo(display));
// Current implementation of DisplayInfo keeps reference to macros,
// so changing macros will result in updated DisplayInfo.
// This test does not depend on it and always creates a new DisplayInfo.
macros.add("S", "Test");
display = new DisplayInfo("/a/path/file.opi", "Alias", macros);
serialized = DisplayInfoXMLUtil.toXML(display);
System.out.println(serialized);
assertThat(serialized, containsString("<macros>"));
copy = DisplayInfoXMLUtil.fromXML(serialized);
System.out.println(copy);
assertThat(copy, equalTo(display));
}
use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.
the class OpenDisplayFile method openDisplay.
@Override
public void openDisplay(final String path, final String data) throws Exception {
final Macros macros = MacroXMLUtil.readMacros(data);
// 'resolve', i.e. use *.bob over *.opi if found
final DisplayInfo info = new DisplayInfo(path, "Display from command line", macros, true);
new OpenDisplayAction(info).run();
}
Aggregations