Skip to content

Commit

Permalink
Merge branch 'ControlSystemStudio:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
katysaintin authored Aug 9, 2024
2 parents aaf1d8b + d6206dd commit 03a30be
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class ExecuteCommandAction extends ActionInfoBase {

public static final String EXECUTE_COMMAND = "command";
private static final Integer PRIORITY = 40;
private String command;
private ExecuteCommandActionController executeCommandActionController;

Expand All @@ -51,6 +52,10 @@ public Image getImage() {
return ImageCache.getImage(ActionsDialog.class, "/icons/execute_script.png");
}

@Override
public Integer getPriority() {
return PRIORITY;
}

@Override
public void readFromXML(ModelReader modelReader, Element actionXml) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class ExecuteScriptAction extends ActionInfoBase {
public static final String EXECUTE_PYTHONSCRIPT = "EXECUTE_PYTHONSCRIPT";
public static final String EXECUTE_JAVASCRIPT = "EXECUTE_JAVASCRIPT";

private static final Integer PRIORITY = 30;

private ScriptInfo scriptInfo;
private String text;
private String path;
Expand Down Expand Up @@ -186,4 +188,9 @@ public ActionInfo commit(){
description = executeScriptController.getDescription();
return this;
}

@Override
public Integer getPriority() {
return PRIORITY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class OpenDisplayAction extends ActionInfoBase {

public static final String OPEN_DISPLAY = "open_display";

private static final Integer PRIORITY = 10;

private OpenDisplayActionController openDisplayActionController;

private static final Logger logger = Logger.getLogger(OpenDisplayAction.class.getName());
Expand Down Expand Up @@ -259,6 +261,11 @@ public Image getImage() {
return ImageCache.getImage(ActionsDialog.class, "/icons/open_display.png");
}

@Override
public Integer getPriority() {
return PRIORITY;
}

@Override
public Node getEditor(Widget widget) {
if (editorUi != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class OpenFileAction extends ActionInfoBase {

public static final String OPEN_FILE = "open_file";
private static final Integer PRIORITY = 50;
private String file;

private OpenFileActionController openFileActionController;
Expand Down Expand Up @@ -77,6 +78,11 @@ public Image getImage() {
return ImageCache.getImage(ActionsDialog.class, "/icons/open_file.png");
}

@Override
public Integer getPriority() {
return PRIORITY;
}

public String getFile() {
return file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class OpenWebPageAction extends ActionInfoBase {

public static final String OPEN_WEBPAGE = "open_webpage";
private static final Integer PRIORITY = 60;
private String url;
private OpenWebPageActionController openWebPageController;

Expand Down Expand Up @@ -65,6 +66,11 @@ public Image getImage() {
return ImageCache.getImage(ActionsDialog.class, "/icons/web_browser.png");
}

@Override
public Integer getPriority() {
return PRIORITY;
}

public String getURL() {
return url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class WritePVAction extends ActionInfoBase {
private String value = "0";

public static final String WRITE_PV = "write_pv";
private static final Integer PRIORITY = 20;
private final Logger logger = Logger.getLogger(WritePVAction.class.getName());

private WritePVActionController writePVActionController;
Expand Down Expand Up @@ -86,6 +87,16 @@ public Image getImage() {
return ImageCache.getImage(ActionsDialog.class, "/icons/write_pv.png");
}

@Override
public Integer getPriority() {
return PRIORITY;
}

@Override
public boolean matchesAction(String actionId) {
return actionId.equalsIgnoreCase(WRITE_PV);
}

public String getPV() {
return pv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public String getType() {
return type;
}


protected MenuItem createMenuItem(final Widget widget, final String description) {
// Expand macros in action description
String desc;
Expand Down
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<Object, Object>) 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<Object, Object> names_and_values)
{
Macros macros = new Macros();
names_and_values.entrySet().forEach(e -> macros.add(String.valueOf(e.getKey()), String.valueOf(e.getValue())));
return macros;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ default boolean matchesAction(String actionId) {
*/
String getDescription();

/**
*
* @return
*/
default Integer getPriority() {
return 100;
}

/**
* @param description User-defined string, overriding the default.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,23 @@ public void initialize() {

ServiceLoader<ActionInfo> actionInfos = ServiceLoader.load(ActionInfo.class);

// Order actions, see ActionInfo#compareTo
List<ActionInfo> sortedActionInfos = actionInfos.stream().map(p -> p.get()).sorted().toList();

for (ActionInfo actionInfo : sortedActionInfos)
{
final ImageView icon = new ImageView(actionInfo.getImage());
final MenuItem item = new MenuItem(actionInfo.toString(), icon);
item.setOnAction(event ->
{
ActionsDialogActionItem actionsDialogActionItem =
new ActionsDialogActionItem(widget, actionInfo);
actionList.add(actionsDialogActionItem);
actionsListView.setItems(actionList);
detailsPane.getChildren().add(actionInfo.getEditor(widget));
actionsListView.getSelectionModel().select(actionsDialogActionItem);
});
addButton.getItems().add(item);
}
actionInfos.stream()
.sorted(Comparator.comparing(actionInfo -> actionInfo.get().getPriority()))
.forEach(actionInfoProvider -> {
ActionInfo actionInfo = actionInfoProvider.get();
final ImageView icon = new ImageView(actionInfo.getImage());
final MenuItem item = new MenuItem(actionInfo.toString(), icon);
item.setOnAction(event ->
{
ActionsDialogActionItem actionsDialogActionItem =
new ActionsDialogActionItem(widget, actionInfo);
actionList.add(actionsDialogActionItem);
actionsListView.setItems(actionList);
detailsPane.getChildren().add(actionInfo.getEditor(widget));
actionsListView.getSelectionModel().select(actionsDialogActionItem);
});
addButton.getItems().add(item);
});

actionsListView.setCellFactory(view -> new ActionInfoCell());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class OpenFilterAction extends ActionInfoBase {

public static final String OPEN_SAR_FILTER = "open_sar_filter";
private static final String FILTER_ID_TAG = "filter_id";
private static final Integer PRIORITY = 55;

private OpenFilterActionController openFilterActionController;

Expand All @@ -49,6 +50,11 @@ public Image getImage() {
return ImageCache.getImage(OpenFilterAction.class, "/icons/bookcase.png");
}

@Override
public Integer getPriority() {
return PRIORITY;
}

@Override
public void readFromXML(ModelReader modelReader, Element actionXml) throws Exception {
filterId = XMLUtil.getChildString(actionXml, FILTER_ID_TAG).orElse("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class OpenNodeAction extends ActionInfoBase {

public static final String OPEN_SAR_NODE = "open_sar_node";
private static final String NODE_ID_TAG = "node_id";
private static final Integer PRIORITY = 56;

private OpenNodeActionController openNodeActionController;

Expand All @@ -48,6 +49,11 @@ public Image getImage() {
return ImageCache.getImage(OpenNodeAction.class, "/icons/bookcase.png");
}

@Override
public Integer getPriority() {
return PRIORITY;
}

@Override
public void readFromXML(ModelReader modelReader, Element actionXml) {
nodeId = XMLUtil.getChildString(actionXml, NODE_ID_TAG).orElse("");
Expand Down

0 comments on commit 03a30be

Please sign in to comment.