Search in sources :

Example 26 with Macros

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);
}
Also used : CommonWidgetProperties.propMacros(org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMacros) Macros(org.csstudio.display.builder.model.macros.Macros)

Example 27 with 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);
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) Macros(org.csstudio.display.builder.model.macros.Macros) WorkbenchException(org.eclipse.ui.WorkbenchException) PartInitException(org.eclipse.ui.PartInitException)

Example 28 with Macros

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;
}
Also used : Macros(org.csstudio.display.builder.model.macros.Macros)

Example 29 with 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));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Macros(org.csstudio.display.builder.model.macros.Macros) Test(org.junit.Test)

Example 30 with Macros

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();
}
Also used : IOpenDisplayAction(org.csstudio.openfile.IOpenDisplayAction) Macros(org.csstudio.display.builder.model.macros.Macros)

Aggregations

Macros (org.csstudio.display.builder.model.macros.Macros)33 CommonWidgetProperties.propMacros (org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMacros)12 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)4 Test (org.junit.Test)4 DisplayModel (org.csstudio.display.builder.model.DisplayModel)3 ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Widget (org.csstudio.display.builder.model.Widget)2 ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)2 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)2 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)2 WritePVActionInfo (org.csstudio.display.builder.model.properties.WritePVActionInfo)2 Element (org.w3c.dom.Element)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1