Search in sources :

Example 21 with Macros

use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.

the class ActionUtil method resolve.

private static String resolve(final Widget source_widget, final String path) throws Exception {
    // Path to resolve, after expanding macros
    final Macros macros = source_widget.getEffectiveMacros();
    final String expanded_path = MacroHandler.replace(macros, path);
    // Resolve file relative to the source widget model (not 'top'!)
    final DisplayModel widget_model = source_widget.getDisplayModel();
    final String parent_file = widget_model.getUserData(DisplayModel.USER_DATA_INPUT_FILE);
    return ModelResourceUtil.resolveResource(parent_file, expanded_path);
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) Macros(org.csstudio.display.builder.model.macros.Macros)

Example 22 with Macros

use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.

the class ScriptUtil method openDisplay.

// ====================
// open/close displays
/**
 * Open a new display
 *
 *  @param widget Widget in 'current' display, used to resolve relative paths
 *  @param file Path to the display
 *  @param target Where to show the display: "REPLACE", "TAB", "WINDOW", "STANDALONE"
 *  @param macros Macros, may be <code>null</code>
 */
public static void openDisplay(final Widget widget, final String file, final String target, final Map<String, String> macros) {
    OpenDisplayActionInfo.Target the_target;
    try {
        the_target = OpenDisplayActionInfo.Target.valueOf(target);
    } catch (Throwable ex) {
        the_target = OpenDisplayActionInfo.Target.TAB;
    }
    final Macros the_macros;
    if (macros == null || macros.isEmpty())
        the_macros = null;
    else {
        the_macros = new Macros();
        for (String name : macros.keySet()) the_macros.add(name, macros.get(name));
    }
    final OpenDisplayActionInfo open = new OpenDisplayActionInfo("Open from script", file, the_macros, the_target);
    ActionUtil.handleAction(widget, open);
}
Also used : Macros(org.csstudio.display.builder.model.macros.Macros) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)

Example 23 with Macros

use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.

the class WidgetInfoDialog method createMacros.

private Tab createMacros(Macros orig_macros) {
    final Macros macros = (orig_macros == null) ? new Macros() : orig_macros;
    // Use text field to allow copying the name and value
    // Table uses list of macro names as input
    // Name column just displays the macro name,..
    final TableColumn<String, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(TextFieldTableCell.forTableColumn());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));
    // .. value column fetches the macro value
    final TableColumn<String, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(TextFieldTableCell.forTableColumn());
    value.setCellValueFactory(param -> new ReadOnlyStringWrapper(macros.getValue(param.getValue())));
    final TableView<String> table = new TableView<>(FXCollections.observableArrayList(macros.getNames()));
    table.getColumns().add(name);
    table.getColumns().add(value);
    table.setEditable(true);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return new Tab(Messages.WidgetInfoDialog_TabMacros, table);
}
Also used : Tab(javafx.scene.control.Tab) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) Macros(org.csstudio.display.builder.model.macros.Macros) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Example 24 with Macros

use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.

the class DisplayInfoXMLUtil method readDisplayInfo.

/**
 * Read display info
 *  @param macros_xml
 *  @param resolve
 *  @throws Exception on error
 *  @return {@link DisplayInfo}
 */
public static DisplayInfo readDisplayInfo(final Element display, final boolean resolve) throws Exception {
    final String path = XMLUtil.getChildString(display, XMLTags.FILE).orElseThrow(() -> new Exception("Missing display path"));
    final String name = XMLUtil.getChildString(display, XMLTags.NAME).orElse(path);
    final Element macros_xml = XMLUtil.getChildElement(display, XMLTags.MACROS);
    final Macros macros = macros_xml == null ? new Macros() : MacroXMLUtil.readMacros(macros_xml);
    return new DisplayInfo(path, name, macros, resolve);
}
Also used : Element(org.w3c.dom.Element) Macros(org.csstudio.display.builder.model.macros.Macros)

Example 25 with Macros

use of org.csstudio.display.builder.model.macros.Macros in project org.csstudio.display.builder by kasemir.

the class ArrayWidget method defineProperties.

@Override
protected void defineProperties(final List<WidgetProperty<?>> properties) {
    super.defineProperties(properties);
    properties.add(macros = propMacros.createProperty(this, new Macros()));
    properties.add(children = new ArrayWidgetChildrenProperty(this));
    properties.add(foreground = propForegroundColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.TEXT)));
    properties.add(background = propBackgroundColor.createProperty(this, WidgetColorService.getColor(NamedWidgetColors.BACKGROUND)));
    properties.add(insets = runtimePropInsets.createProperty(this, new int[] { 0, 0 }));
}
Also used : CommonWidgetProperties.propMacros(org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMacros) 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