Skip to content

Commit e1e9f81

Browse files
authored
Merge branch 'master' into ux-analytics-plugin
2 parents 7e18679 + 6a6c5be commit e1e9f81

File tree

145 files changed

+1485
-1966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+1485
-1966
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
14-
- name: Set up JDK 17
15-
uses: actions/setup-java@v1
14+
- name: Setup Maven and Java Action
15+
uses: s4u/setup-maven-action@v1.13.0
1616
with:
1717
java-version: '17'
18+
maven-version: '3.9.6'
1819
- name: Build
19-
run: mvn --batch-mode install
20+
run: mvn --batch-mode install -DskipTests

.github/workflows/build_latest.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
steps:
1717
- uses: actions/checkout@v2
18-
- name: Set up JDK 17
19-
uses: actions/setup-java@v1
18+
- name: Setup Maven and Java Action
19+
uses: s4u/setup-maven-action@v1.13.0
2020
with:
2121
java-version: '17'
22+
maven-version: '3.9.6'
2223
- name: Build
2324
run: mvn --batch-mode install -DskipTests
2425

app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/AlarmURI.java

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
package org.phoebus.applications.alarm.ui;
99

1010
import java.net.URI;
11+
import java.util.HashMap;
12+
import java.util.Map;
1113

1214
/** Alarm URI helpers
1315
*
@@ -23,18 +25,32 @@ public class AlarmURI
2325
/** URI schema used to refer to an alarm config */
2426
public static final String SCHEMA = "alarm";
2527

28+
/** Nme to use for item as query parameter */
29+
public static final String QUERY_PARAMETER_ITEM_NAME = "itemName";
30+
2631
/** @param server Kafka server host:port
2732
* @param config_name Alarm configuration root
2833
* @return URI used to access that alarm configuration, "alarm://host:port/config_name"
2934
*/
30-
public static URI createURI(final String server, final String config_name)
31-
{
32-
return URI.create(SCHEMA + "://" + server + "/" + config_name);
35+
public static URI createURI(final String server, final String config_name) {
36+
return createURI(server, config_name, null);
37+
}
38+
39+
/** @param server Kafka server host:port
40+
* @param config_name Alarm configuration root
41+
* @param rawQuery raw query for URI
42+
* @return URI used to access that alarm configuration, "alarm://host:port/config_name?rawQuery"
43+
*/
44+
public static URI createURI(final String server, final String config_name, String rawQuery) {
45+
if (rawQuery != null && rawQuery.length() > 0)
46+
return URI.create(SCHEMA + "://" + server + "/" + config_name + "?" + rawQuery);
47+
else
48+
return URI.create(SCHEMA + "://" + server + "/" + config_name);
3349
}
3450

3551
/** Parse alarm configuration parameters from URI
36-
* @param resource "alarm://localhost:9092/Accelerator"
37-
* @return [ "localhost:9092", "Accelerator" ]
52+
* @param resource "alarm://localhost:9092/Accelerator" or "alarm://localhost:9092/Accelerator?param=value"
53+
* @return ["localhost:9092", "Accelerator", null] or ["localhost:9092", "Accelerator", "param=value"]
3854
* @throws Exception on error
3955
*/
4056
public static String[] parseAlarmURI(final URI resource) throws Exception
@@ -55,10 +71,35 @@ public static String[] parseAlarmURI(final URI resource) throws Exception
5571
if (port < 0)
5672
port = 9092;
5773
String config_name = resource.getPath();
74+
String rawQuery = resource.getRawQuery();
5875
if (config_name.startsWith("/"))
5976
config_name = config_name.substring(1);
6077
if (config_name.isEmpty())
6178
throw new Exception("Missing alarm config name in " + resource + ", expecting " + SCHEMA + "://{host}:{port}/{config_name}");
62-
return new String[] { resource.getHost() + ":" + port, config_name };
79+
return new String[] { resource.getHost() + ":" + port, config_name, rawQuery };
6380
}
81+
82+
/**
83+
* Return a map with parameter names and values as key-value pairs for raw query of given resource.
84+
* @param resource "alarm://localhost:9092/Accelerator" or "alarm://localhost:9092/Accelerator?param=value"
85+
* @return map with parameter names as keys and parameter values as values for raw query
86+
*/
87+
public static Map<String, String> getRawQueryParametersValues(URI resource) {
88+
Map<String, String> map = new HashMap<>();
89+
String[] queryParametersValues = resource.getRawQuery() != null ? resource.getRawQuery().split("&") : null;
90+
if (queryParametersValues != null) {
91+
for (String queryParameterValue : queryParametersValues) {
92+
String[] parameterValue = queryParameterValue.split("=");
93+
if (parameterValue != null) {
94+
if (parameterValue.length == 2) {
95+
map.put(parameterValue[0], parameterValue[1]);
96+
} else if (parameterValue.length == 1) {
97+
map.put(parameterValue[0], null);
98+
}
99+
}
100+
}
101+
}
102+
return map;
103+
}
104+
64105
}

app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/area/AlarmAreaView.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import static org.phoebus.applications.alarm.AlarmSystem.logger;
1111

12+
import java.net.URLEncoder;
13+
import java.nio.charset.StandardCharsets;
1214
import java.util.LinkedHashSet;
1315
import java.util.List;
1416
import java.util.Set;
@@ -31,16 +33,15 @@
3133
import org.phoebus.applications.alarm.model.AlarmTreeItem;
3234
import org.phoebus.applications.alarm.model.SeverityLevel;
3335
import org.phoebus.applications.alarm.ui.AlarmUI;
36+
import org.phoebus.applications.alarm.ui.AlarmURI;
3437
import org.phoebus.ui.javafx.JFXUtil;
3538
import org.phoebus.ui.javafx.UpdateThrottle;
3639

3740
import javafx.application.Platform;
38-
import javafx.collections.ObservableList;
3941
import javafx.geometry.Insets;
4042
import javafx.geometry.Pos;
4143
import javafx.scene.control.ContextMenu;
4244
import javafx.scene.control.Label;
43-
import javafx.scene.control.MenuItem;
4445
import javafx.scene.paint.Color;
4546
import javafx.scene.shape.StrokeLineCap;
4647
import javafx.scene.shape.StrokeLineJoin;
@@ -104,8 +105,6 @@ public AlarmAreaView(final AlarmClient model)
104105

105106
areaFilter = new AreaFilter(AlarmSystem.alarm_area_level);
106107
model.addListener(this);
107-
108-
createContextMenu();
109108
}
110109

111110
// AlarmClientModelListener
@@ -205,6 +204,23 @@ private void recreateItems(final List<String> items)
205204
for (String item_name : items)
206205
{
207206
final Label view_item = newAreaLabel(item_name);
207+
208+
// context menu content for alarm model item instead of alarm area
209+
// link to item in tree view
210+
view_item.setOnContextMenuRequested(event -> {
211+
// need to clear and repopulate context menu since alarm area is recreated multiple times
212+
// (but number of times unknown)
213+
for (int i=menu.getItems().size()-1; i>0; i--) {
214+
if (menu.getItems().get(i).getClass().equals(OpenTreeViewAction.class)) {
215+
menu.getItems().remove(i);
216+
}
217+
}
218+
219+
OpenTreeViewAction otva = new OpenTreeViewAction(alarmConfigName, AlarmURI.QUERY_PARAMETER_ITEM_NAME + "=" + URLEncoder.encode(item_name, StandardCharsets.UTF_8));
220+
menu.getItems().add(otva);
221+
menu.show(this.getScene().getWindow(), event.getScreenX(), event.getScreenY());
222+
});
223+
208224
itemViewMap.put(item_name, view_item);
209225
updateItem(item_name);
210226
final int column = index % AlarmSystem.alarm_area_column_count;
@@ -241,19 +257,10 @@ private void updateItem(final String item_name)
241257
view_item.setStyle("-fx-alignment: center; -fx-border-color: black; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-insets: 1; -fx-background-radius: 10; -fx-text-fill: " + JFXUtil.webRGB(AlarmUI.getAlarmAreaPanelColor(severityLevel)) + "; -fx-background-color: " + JFXUtil.webRGB(AlarmUI.getAlarmAreaPanelBackgroundColor(severityLevel)));
242258
}
243259

244-
private void createContextMenu()
245-
{
246-
final ObservableList<MenuItem> menu_items = menu.getItems();
247-
248-
menu_items.add(new OpenTreeViewAction(alarmConfigName));
249-
this.setOnContextMenuRequested(event ->
250-
menu.show(this.getScene().getWindow(), event.getScreenX(), event.getScreenY())
251-
);
252-
}
253-
254260
/** @return Context menu */
255261
public ContextMenu getMenu()
256262
{
257263
return menu;
258264
}
265+
259266
}

app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/area/OpenTreeViewAction.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,24 @@
2020
* @author Evan Smith
2121
*/
2222
@SuppressWarnings("nls")
23-
public class OpenTreeViewAction extends MenuItem
24-
{
23+
public class OpenTreeViewAction extends MenuItem {
2524

2625
/**
2726
* Constructor
2827
* @param alarmConfigName The alarm configuration name
2928
*/
30-
public OpenTreeViewAction(String alarmConfigName)
31-
{
29+
public OpenTreeViewAction(String alarmConfigName) {
30+
this(alarmConfigName, null);
31+
}
32+
33+
/**
34+
* Constructor
35+
* @param alarmConfigName The alarm configuration name
36+
* @param alarmRawQuery raw query for alarm (null if no such information is available)
37+
*/
38+
public OpenTreeViewAction(String alarmConfigName, String alarmRawQuery) {
3239
final AlarmTreeMenuEntry entry = new AlarmTreeMenuEntry();
33-
entry.setResource(AlarmURI.createURI(AlarmSystem.server, alarmConfigName));
40+
entry.setResource(AlarmURI.createURI(AlarmSystem.server, alarmConfigName, alarmRawQuery));
3441
setText(entry.getName());
3542
setGraphic(new ImageView(entry.getIcon()));
3643
setOnAction(event ->
@@ -45,4 +52,5 @@ public OpenTreeViewAction(String alarmConfigName)
4552
}
4653
});
4754
}
55+
4856
}

app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeInstance.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import static org.phoebus.applications.alarm.AlarmSystem.logger;
1111

1212
import java.net.URI;
13+
import java.net.URLDecoder;
14+
import java.nio.charset.StandardCharsets;
1315
import java.util.concurrent.CompletableFuture;
1416
import java.util.logging.Level;
1517

@@ -46,7 +48,14 @@ public AlarmTreeInstance(final AlarmTreeApplication app, final URI input) throws
4648
{
4749
this.app = app;
4850

49-
tab = new DockItemWithInput(this, create(input), input, null, null);
51+
// split input with/without (raw) query
52+
// When the URI specifies multiple host / port pairs getHost() will not
53+
// work, so we use getAuthority() instead.
54+
final URI resource = new URI(input.getScheme(), input.getAuthority(), input.getPath(), null, null);
55+
String itemName = AlarmURI.getRawQueryParametersValues(input).get(AlarmURI.QUERY_PARAMETER_ITEM_NAME);
56+
itemName = itemName != null ? URLDecoder.decode(itemName, StandardCharsets.UTF_8) : null;
57+
58+
tab = new DockItemWithInput(this, create(resource, itemName), resource, null, null);
5059
Platform.runLater(() -> tab.setLabel(config_name + " " + app.getDisplayName()));
5160
tab.addCloseCheck(() ->
5261
{
@@ -65,10 +74,11 @@ public AppDescriptor getAppDescriptor()
6574
/** Create UI for input, starts alarm client
6675
*
6776
* @param input Alarm URI, will be parsed into `server` and `config_name`
77+
* @param itemName item name that may be expanded or given focus
6878
* @return Alarm UI
6979
* @throws Exception
7080
*/
71-
private Node create(final URI input) throws Exception
81+
private Node create(final URI input, String itemName) throws Exception
7282
{
7383
final String[] parsed = AlarmURI.parseAlarmURI(input);
7484
server = parsed[0];
@@ -77,7 +87,7 @@ private Node create(final URI input) throws Exception
7787
try
7888
{
7989
client = new AlarmClient(server, config_name, AlarmSystem.kafka_properties);
80-
final AlarmTreeView tree_view = new AlarmTreeView(client);
90+
final AlarmTreeView tree_view = new AlarmTreeView(client, itemName);
8191
client.start();
8292

8393
if (AlarmSystem.config_names.length > 0)
@@ -104,7 +114,8 @@ private void changeConfig(final String new_config_name)
104114
{
105115
// Use same server name, but new config_name
106116
final URI new_input = AlarmURI.createURI(server, new_config_name);
107-
tab.setContent(create(new_input));
117+
// no need for initial item name
118+
tab.setContent(create(new_input, null));
108119
tab.setInput(new_input);
109120
Platform.runLater(() -> tab.setLabel(config_name + " " + app.getDisplayName()));
110121
}

app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AlarmTreeView.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener
8888

8989
/** Model with current alarm tree, sends updates */
9090
private final AlarmClient model;
91+
private final String itemName;
9192

9293
/** Latch for initially pausing model listeners
9394
*
@@ -150,7 +151,15 @@ public class AlarmTreeView extends BorderPane implements AlarmClientListener
150151
// constant performance?
151152

152153
/** @param model Model to represent. Must <u>not</u> be running, yet */
153-
public AlarmTreeView(final AlarmClient model)
154+
public AlarmTreeView(final AlarmClient model) {
155+
this(model, null);
156+
}
157+
158+
/**
159+
* @param model Model to represent. Must <u>not</u> be running, yet
160+
* @param itemName item name that may be expanded or given focus
161+
*/
162+
public AlarmTreeView(final AlarmClient model, String itemName)
154163
{
155164
if (model.isRunning())
156165
throw new IllegalStateException();
@@ -159,6 +168,7 @@ public AlarmTreeView(final AlarmClient model)
159168
changing.setBackground(new Background(new BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY)));
160169

161170
this.model = model;
171+
this.itemName = itemName;
162172

163173
tree_view.setShowRoot(false);
164174
tree_view.setCellFactory(view -> new AlarmTreeViewCell());
@@ -203,6 +213,16 @@ private void startup()
203213
// Represent model that should by now be fairly complete
204214
tree_view.setRoot(createViewItem(model.getRoot()));
205215

216+
// expand tree item if is matches item name
217+
if (tree_view.getRoot() != null && itemName != null) {
218+
for (TreeItem treeItem : tree_view.getRoot().getChildren()) {
219+
if (((AlarmTreeItem) treeItem.getValue()).getName().equals(itemName)) {
220+
expandAlarms(treeItem);
221+
break;
222+
}
223+
}
224+
}
225+
206226
// Set change indicator so that it clears when there are no more changes
207227
indicateChange();
208228
showServerState(model.isServerAlive());

0 commit comments

Comments
 (0)