Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class OpenDisplayAction extends ActionInfoBase {

private String file;

private Boolean inheritParentMacros;

public static final String OPEN_DISPLAY = "open_display";

private static final Integer PRIORITY = 10;
Expand Down Expand Up @@ -85,6 +87,7 @@ public String toString() {
public OpenDisplayAction() {
this.description = Messages.ActionOpenDisplay;
this.type = OPEN_DISPLAY;
this.inheritParentMacros = true;
}

/**
Expand All @@ -94,7 +97,7 @@ public OpenDisplayAction() {
* @param target Where to show the display
*/
public OpenDisplayAction(final String description, final String file, final Macros macros, final OpenDisplayAction.Target target) {
this(description, file, macros, target, "");
this(description, file, macros, target, "", true);
}

/**
Expand All @@ -103,14 +106,16 @@ public OpenDisplayAction(final String description, final String file, final Macr
* @param macros Macros
* @param target Where to show the display
* @param pane Pane in which to open (for target==TAB)
* @param inheritParentMacros Should opened screen use parent screen macros
*/
public OpenDisplayAction(final String description, final String file, final Macros macros, final OpenDisplayAction.Target target, final String pane) {
public OpenDisplayAction(final String description, final String file, final Macros macros, final OpenDisplayAction.Target target, final String pane, final Boolean inheritParentMacros) {
this.description = description;
this.file = Objects.requireNonNull(file);
this.macros = macros;
this.target = target;
this.pane = pane;
this.type = OPEN_DISPLAY;
this.inheritParentMacros = inheritParentMacros;
}

public Target getTarget() {
Expand All @@ -129,6 +134,10 @@ public String getFile() {
return file;
}

public Boolean getInheritParentMacros() {
return inheritParentMacros;
}


@Override
public boolean matchesAction(String actionId) {
Expand Down Expand Up @@ -166,6 +175,14 @@ public void readFromXML(ModelReader modelReader, Element actionXml) {
macros = new Macros();
}

Optional<String> inheritParentMacrosXml = XMLUtil.getChildString(actionXml, XMLTags.INHERIT_PARENT_MACROS);
if (inheritParentMacrosXml.isPresent()) {
inheritParentMacros = Boolean.valueOf(inheritParentMacrosXml.get());
} else {
// Maintain previous behaviour
inheritParentMacros = true;
}

pane = XMLUtil.getChildString(actionXml, XMLTags.NAME).orElse("");
}

Expand All @@ -190,6 +207,9 @@ public void writeToXML(ModelWriter modelWriter, XMLStreamWriter writer) throws E
writer.writeCharacters(pane);
writer.writeEndElement();
}
writer.writeStartElement(XMLTags.INHERIT_PARENT_MACROS);
writer.writeCharacters(inheritParentMacros.toString());
writer.writeEndElement();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

package org.csstudio.display.actions;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
Expand Down Expand Up @@ -46,12 +49,16 @@ public class OpenDisplayActionController extends ActionControllerBase {
private TextField pane;
@SuppressWarnings("unused")
@FXML
private CheckBox inheritParentMacros;
@SuppressWarnings("unused")
@FXML
private VBox macrosTablePlaceholder;

private final MacrosTable macrosTable;

private final StringProperty paneProperty = new SimpleStringProperty();
private final StringProperty displayPathProperty = new SimpleStringProperty();
private final BooleanProperty useParentMacros = new SimpleBooleanProperty();

private OpenDisplayAction.Target target;
private final Widget widget;
Expand All @@ -69,6 +76,7 @@ public OpenDisplayActionController(Widget widget, OpenDisplayAction openDisplayA
target = openDisplayAction.getTarget();
paneProperty.set(openDisplayAction.getPane());
displayPathProperty.setValue(openDisplayAction.getFile());
useParentMacros.setValue(openDisplayAction.getInheritParentMacros());
macrosTable = new MacrosTable(openDisplayAction.getMacros());
}

Expand Down Expand Up @@ -98,6 +106,8 @@ public void initialize() {

displayPath.textProperty().bindBidirectional(displayPathProperty);

inheritParentMacros.selectedProperty().bindBidirectional(useParentMacros);

macrosTablePlaceholder.getChildren().add(macrosTable.getNode());
GridPane.setHgrow(macrosTable.getNode(), Priority.ALWAYS);
VBox.setVgrow(macrosTable.getNode(), Priority.ALWAYS);
Expand Down Expand Up @@ -125,6 +135,7 @@ public ActionInfo getActionInfo() {
displayPathProperty.get(),
macrosTable.getMacros(),
target,
paneProperty.get());
paneProperty.get(),
useParentMacros.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
</HBox>
<Label text="Pane:" GridPane.rowIndex="3" />
<TextField fx:id="pane" disable="true" GridPane.columnIndex="1" GridPane.columnSpan="2" GridPane.hgrow="ALWAYS" GridPane.rowIndex="3" />
<VBox fx:id="macrosTablePlaceholder" maxHeight="1.7976931348623157E308" GridPane.columnIndex="0" GridPane.columnSpan="3" GridPane.hgrow="ALWAYS" GridPane.rowIndex="4" GridPane.vgrow="ALWAYS" />
<CheckBox fx:id="inheritParentMacros" mnemonicParsing="false" text="Inherit Parent Macros" GridPane.rowIndex="4" GridPane.vgrow="NEVER" />
<VBox fx:id="macrosTablePlaceholder" maxHeight="1.7976931348623157E308" GridPane.columnIndex="0" GridPane.columnSpan="3" GridPane.hgrow="ALWAYS" GridPane.rowIndex="5" GridPane.vgrow="ALWAYS" />
</GridPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package org.csstudio.display.actions;

import org.csstudio.display.builder.model.DisplayModel;
import org.csstudio.display.builder.model.Widget;
import org.csstudio.display.builder.model.persist.ModelReader;
import org.csstudio.display.builder.model.persist.ModelWriter;
import org.csstudio.display.builder.model.properties.ActionInfos;
import org.csstudio.display.builder.model.spi.ActionInfo;
import org.csstudio.display.builder.model.widgets.ActionButtonWidget;
import org.junit.jupiter.api.Test;
import org.phoebus.framework.macros.Macros;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.Charset;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Test the Open Display action
*
* @author Becky Auger-Williams
*/
public class OpenDisplayTest {
@Test
public void missing_inherit_parent_macro_in_xml() {
String xml =
"<display version=\"2.0.0\">" +
" <widget type=\"action_button\" version=\"3.0.0\">" +
" <name>Action Button</name>" +
" <actions>" +
" <action type=\"open_display\">" +
" <description>Open Display</description>" +
" <file>test.bob</file>" +
" <target>window</target>" +
" </action>" +
" </actions>" +
" <text>Open window</text>" +
" <x>0</x>" +
" <y>0</y>" +
" <width>100</width>" +
" <tooltip>$(actions)</tooltip>" +
" </widget>" +
"</display>";

InputStream stream = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
assertDoesNotThrow(() -> {
ModelReader reader = new ModelReader(stream);
DisplayModel model = reader.readModel();
assertTrue(model.isClean());

// Check ActionButton widget
final List<Widget> widgets = model.getChildren();
assertEquals(1, widgets.size());
assertInstanceOf(ActionButtonWidget.class, widgets.getFirst());
ActionButtonWidget actionButton = (ActionButtonWidget) widgets.getFirst();

// Check actions
List<ActionInfo> actions = actionButton.propActions().getValue().getActions();
assertEquals(1, actions.size());
assertInstanceOf(OpenDisplayAction.class, actions.getFirst());

// Check inherit parent macros prop
OpenDisplayAction openDisplayAction = (OpenDisplayAction) actions.getFirst();
assertTrue(openDisplayAction.getInheritParentMacros());
});
}

@Test
public void inherit_parent_macros_false_xml() {
String xml =
"<display version=\"2.0.0\">" +
" <widget type=\"action_button\" version=\"3.0.0\">" +
" <name>Action Button</name>" +
" <actions>" +
" <action type=\"open_display\">" +
" <description>Open Display</description>" +
" <file>test.bob</file>" +
" <target>window</target>" +
" <inherit_parent_macros>false</inherit_parent_macros>" +
" </action>" +
" </actions>" +
" <text>Open window</text>" +
" <x>0</x>" +
" <y>0</y>" +
" <width>100</width>" +
" <tooltip>$(actions)</tooltip>" +
" </widget>"+
"</display>";

InputStream stream = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
assertDoesNotThrow(() -> {
ModelReader reader = new ModelReader(stream);
DisplayModel model = reader.readModel();
assertTrue(model.isClean());

// Check ActionButton widget
final List<Widget> widgets = model.getChildren();
assertEquals(1, widgets.size());
assertInstanceOf(ActionButtonWidget.class, widgets.getFirst());
ActionButtonWidget actionButton = (ActionButtonWidget) widgets.getFirst();

// Check actions on widget
List<ActionInfo> actions = actionButton.propActions().getValue().getActions();
assertEquals(1, actions.size());
assertInstanceOf(OpenDisplayAction.class, actions.getFirst());

// Check inherit parent macros prop
OpenDisplayAction openDisplayAction = (OpenDisplayAction) actions.getFirst();
assertFalse(openDisplayAction.getInheritParentMacros());
});
}

@Test
public void write_inherit_parent_macros_to_xml() {
ActionButtonWidget button = new ActionButtonWidget();
Macros macros = new Macros();
OpenDisplayAction openDisplayAction = new OpenDisplayAction(
"Open Display",
"test.bob",
macros,
OpenDisplayAction.Target.WINDOW,
null,
false);

ActionInfos actionInfos = new ActionInfos(List.of(openDisplayAction), false);
button.propActions().setValue(actionInfos);
assertDoesNotThrow(() -> {
final String xml = ModelWriter.getXML(List.of(button));
assertTrue(xml.contains("<inherit_parent_macros>false</inherit_parent_macros>"));
});
}

@Test
public void default_open_display_action_constructors() {
OpenDisplayAction openDisplayActionConstruct1 = new OpenDisplayAction();

assertTrue(openDisplayActionConstruct1.getInheritParentMacros());
assertSame(OpenDisplayAction.Target.REPLACE, openDisplayActionConstruct1.getTarget());

OpenDisplayAction openDisplayActionConstruct2 = new OpenDisplayAction(
"Open Display",
"test.bob",
new Macros(),
OpenDisplayAction.Target.WINDOW);

assertTrue(openDisplayActionConstruct2.getInheritParentMacros());
assertSame(OpenDisplayAction.Target.WINDOW, openDisplayActionConstruct2.getTarget());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface XMLTags
FONT = "font",
GREEN = "green",
HEIGHT = "height",
INHERIT_PARENT_MACROS="inherit_parent_macros",
MACROS = "macros",
NAME = "name",
PATH = "path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public void handleAction(Widget sourceWidget, ActionInfo actionInfo){
{
// Path to resolve, after expanding macros of action in environment of source widget
//final Macros macros = action.getMacros(); // Not copying, just using action's macros
openDisplayActionInfo.getMacros().expandValues(sourceWidget.getEffectiveMacros());
if (openDisplayActionInfo.getInheritParentMacros())
openDisplayActionInfo.getMacros().expandValues(sourceWidget.getEffectiveMacros());

// For display path, use the combined macros...
expanded_path = MacroHandler.replace(new MacroOrSystemProvider(openDisplayActionInfo.getMacros()), openDisplayActionInfo.getFile());
Expand Down
Loading