Skip to content

Commit aa21840

Browse files
committed
Finalize web socket messages related to filters
1 parent 6bcade6 commit aa21840

14 files changed

+60
-184
lines changed

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/FilterViewInstance.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public FilterViewInstance(AppDescriptor appDescriptor) {
5454
return CompletableFuture.completedFuture(true);
5555
});
5656

57+
dockItem.setOnCloseRequest(e -> searchResultTableViewController.handleTabClosed());
58+
5759
DockPane.getActiveDockPane().addTab(dockItem);
5860
}
5961

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/FilterChangeListener.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ private void renameNode() {
751751
if (result.isPresent()) {
752752
node.getValue().setName(result.get());
753753
try {
754-
saveAndRestoreService.updateNode(node.getValue());
754+
saveAndRestoreService.updateNode(node.getValue(), false);
755755
} catch (Exception e) {
756756
Alert alert = new Alert(AlertType.ERROR);
757757
alert.setTitle(Messages.errorActionFailed);
@@ -1422,8 +1422,8 @@ private void openNode(String nodeId) {
14221422
return;
14231423
}
14241424
Stack<Node> copiedStack = new Stack<>();
1425-
DirectoryUtilities.CreateLocationStringAndNodeStack(node, false).getValue().forEach(copiedStack::push);
14261425
Platform.runLater(() -> {
1426+
DirectoryUtilities.CreateLocationStringAndNodeStack(node, false).getValue().forEach(copiedStack::push);
14271427
locateNode(copiedStack);
14281428
nodeDoubleClicked(node);
14291429
});
@@ -1491,7 +1491,7 @@ private void addOptionalLoggingMenuItem() {
14911491
}
14921492

14931493
@Override
1494-
public void handleWebSocketMessage(SaveAndRestoreWebSocketMessage saveAndRestoreWebSocketMessage){
1494+
public void handleWebSocketMessage(SaveAndRestoreWebSocketMessage<?> saveAndRestoreWebSocketMessage){
14951495
switch (saveAndRestoreWebSocketMessage.messageType()){
14961496
case NODE_ADDED -> nodeAdded((String)saveAndRestoreWebSocketMessage.payload());
14971497
case NODE_REMOVED -> nodeRemoved((String)saveAndRestoreWebSocketMessage.payload());

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreService.java

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public class SaveAndRestoreService {
7171

7272
private final ExecutorService executor;
7373

74-
private final List<DataChangeListener> dataChangeListeners = Collections.synchronizedList(new ArrayList<>());
7574
private final List<WebSocketMessageHandler> webSocketMessageHandlers = Collections.synchronizedList(new ArrayList<>());
7675
private static final Logger LOG = Logger.getLogger(SaveAndRestoreService.class.getName());
7776

@@ -138,10 +137,6 @@ public List<Node> getChildNodes(Node node) {
138137
return null;
139138
}
140139

141-
public Node updateNode(Node nodeToUpdate) throws Exception {
142-
return updateNode(nodeToUpdate, false);
143-
}
144-
145140
public Node updateNode(Node nodeToUpdate, boolean customTimeForMigration) throws Exception {
146141
Future<Node> future = executor.submit(() -> saveAndRestoreClient.updateNode(nodeToUpdate, customTimeForMigration));
147142
return future.get();
@@ -166,32 +161,18 @@ public Node getParentNode(String uniqueNodeId) throws Exception {
166161

167162
public Configuration createConfiguration(final Node parentNode, final Configuration configuration) throws Exception {
168163
Future<Configuration> future = executor.submit(() -> saveAndRestoreClient.createConfiguration(parentNode.getUniqueId(), configuration));
169-
Configuration newConfiguration = future.get();
170-
dataChangeListeners.forEach(l -> l.nodeAddedOrRemoved(parentNode.getUniqueId()));
171-
return newConfiguration;
164+
return future.get();
172165
}
173166

174167
public Configuration updateConfiguration(Configuration configuration) throws Exception {
175168
Future<Configuration> future = executor.submit(() -> saveAndRestoreClient.updateConfiguration(configuration));
176-
Configuration updatedConfiguration = future.get();
177-
// Associated configuration Node may have a new name
178-
dataChangeListeners.forEach(l -> l.nodeChanged(updatedConfiguration.getConfigurationNode()));
179-
return updatedConfiguration;
169+
return future.get();
180170
}
181171

182172
public List<Tag> getAllTags() throws Exception {
183173
Future<List<Tag>> future = executor.submit(saveAndRestoreClient::getAllTags);
184174
return future.get();
185175
}
186-
187-
public void addDataChangeListener(DataChangeListener dataChangeListener){
188-
dataChangeListeners.add(dataChangeListener);
189-
}
190-
191-
public void removeDataChangeListener(DataChangeListener dataChangeListener){
192-
dataChangeListeners.remove(dataChangeListener);
193-
}
194-
195176
/**
196177
* Moves the <code>sourceNode</code> to the <code>targetNode</code>. The target {@link Node} may not contain
197178
* any {@link Node} of same name and type as the source {@link Node}.
@@ -256,10 +237,7 @@ public Snapshot saveSnapshot(Node configurationNode, Snapshot snapshot) throws E
256237
return saveAndRestoreClient.updateSnapshot(snapshot);
257238
}
258239
});
259-
Snapshot updatedSnapshot = future.get();
260-
// Notify listeners as the configuration node has a new child node.
261-
dataChangeListeners.forEach(l -> l.nodeChanged(configurationNode));
262-
return updatedSnapshot;
240+
return future.get();
263241
}
264242

265243
public List<Node> getCompositeSnapshotNodes(String compositeSnapshotNodeUniqueId) throws Exception {
@@ -277,17 +255,12 @@ public List<SnapshotItem> getCompositeSnapshotItems(String compositeSnapshotNode
277255
public CompositeSnapshot saveCompositeSnapshot(Node parentNode, CompositeSnapshot compositeSnapshot) throws Exception {
278256
Future<CompositeSnapshot> future =
279257
executor.submit(() -> saveAndRestoreClient.createCompositeSnapshot(parentNode.getUniqueId(), compositeSnapshot));
280-
CompositeSnapshot newCompositeSnapshot = future.get();
281-
dataChangeListeners.forEach(l -> l.nodeAddedOrRemoved(parentNode.getUniqueId()));
282-
return newCompositeSnapshot;
258+
return future.get();
283259
}
284260

285261
public CompositeSnapshot updateCompositeSnapshot(final CompositeSnapshot compositeSnapshot) throws Exception {
286262
Future<CompositeSnapshot> future = executor.submit(() -> saveAndRestoreClient.updateCompositeSnapshot(compositeSnapshot));
287-
CompositeSnapshot updatedCompositeSnapshot = future.get();
288-
// Associated composite snapshot Node may have a new name
289-
dataChangeListeners.forEach(l -> l.nodeChanged(updatedCompositeSnapshot.getCompositeSnapshotNode()));
290-
return updatedCompositeSnapshot;
263+
return future.get();
291264
}
292265

293266
/**
@@ -323,9 +296,7 @@ public SearchResult search(MultivaluedMap<String, String> searchParams) throws E
323296
public Filter saveFilter(Filter filter) throws Exception {
324297
Future<Filter> future =
325298
executor.submit(() -> saveAndRestoreClient.saveFilter(filter));
326-
Filter addedOrUpdatedFilter = future.get();
327-
dataChangeListeners.forEach(l -> l.filterAddedOrUpdated(filter));
328-
return addedOrUpdatedFilter;
299+
return future.get();
329300
}
330301

331302
/**
@@ -344,7 +315,6 @@ public List<Filter> getAllFilters() throws Exception {
344315
*/
345316
public void deleteFilter(final Filter filter) throws Exception {
346317
executor.submit(() -> saveAndRestoreClient.deleteFilter(filter.getName())).get();
347-
dataChangeListeners.forEach(l -> l.filterRemoved(filter.getName()));
348318
}
349319

350320
/**
@@ -357,9 +327,7 @@ public void deleteFilter(final Filter filter) throws Exception {
357327
public List<Node> addTag(TagData tagData) throws Exception {
358328
Future<List<Node>> future =
359329
executor.submit(() -> saveAndRestoreClient.addTag(tagData));
360-
List<Node> updatedNodes = future.get();
361-
updatedNodes.forEach(n -> dataChangeListeners.forEach(l -> l.nodeChanged(n)));
362-
return updatedNodes;
330+
return future.get();
363331
}
364332

365333
/**
@@ -372,9 +340,7 @@ public List<Node> addTag(TagData tagData) throws Exception {
372340
public List<Node> deleteTag(TagData tagData) throws Exception {
373341
Future<List<Node>> future =
374342
executor.submit(() -> saveAndRestoreClient.deleteTag(tagData));
375-
List<Node> updatedNodes = future.get();
376-
updatedNodes.forEach(n -> dataChangeListeners.forEach(l -> l.nodeChanged(n)));
377-
return updatedNodes;
343+
return future.get();
378344
}
379345

380346
/**

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/WebSocketMessageHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88

99
public interface WebSocketMessageHandler {
1010

11-
void handleWebSocketMessage(SaveAndRestoreWebSocketMessage saveAndRestoreWebSocketMessage);
11+
void handleWebSocketMessage(SaveAndRestoreWebSocketMessage<?> saveAndRestoreWebSocketMessage);
1212
}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/configuration/ConfigurationController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
import java.util.Arrays;
7878
import java.util.Collections;
7979
import java.util.List;
80-
import java.util.Objects;
8180
import java.util.Optional;
8281
import java.util.logging.Level;
8382
import java.util.logging.Logger;
@@ -538,7 +537,7 @@ public boolean handleConfigurationTabClosed() {
538537
}
539538

540539
@Override
541-
public void handleWebSocketMessage(SaveAndRestoreWebSocketMessage saveAndRestoreWebSocketMessage) {
540+
public void handleWebSocketMessage(SaveAndRestoreWebSocketMessage<?> saveAndRestoreWebSocketMessage) {
542541
if (saveAndRestoreWebSocketMessage.messageType().equals(MessageType.NODE_UPDATED)) {
543542
Node node = (Node) saveAndRestoreWebSocketMessage.payload();
544543
if (tabIdProperty.get() != null && node.getUniqueId().equals(tabIdProperty.get())) {

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/configuration/ConfigurationTab.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void configureForNewConfiguration(Node parentNode) {
9999
}
100100

101101
@Override
102-
public void handleWebSocketMessage(SaveAndRestoreWebSocketMessage saveAndRestoreWebSocketMessage) {
102+
public void handleWebSocketMessage(SaveAndRestoreWebSocketMessage<?> saveAndRestoreWebSocketMessage) {
103103
if (saveAndRestoreWebSocketMessage.messageType().equals(MessageType.NODE_REMOVED)) {
104104
String nodeId = (String) saveAndRestoreWebSocketMessage.payload();
105105
if (getId() != null && nodeId.equals(getId())) {

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/search/SearchAndFilterTab.java

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,30 @@
1919

2020
package org.phoebus.applications.saveandrestore.ui.search;
2121

22-
import javafx.application.Platform;
2322
import javafx.fxml.FXMLLoader;
2423
import javafx.scene.Node;
25-
import javafx.scene.control.Alert;
2624
import javafx.scene.image.ImageView;
2725
import org.phoebus.applications.saveandrestore.Messages;
2826
import org.phoebus.applications.saveandrestore.SaveAndRestoreApplication;
29-
import org.phoebus.applications.saveandrestore.model.search.Filter;
30-
import org.phoebus.applications.saveandrestore.ui.DataChangeListener;
3127
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreController;
3228
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreService;
3329
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreTab;
34-
import org.phoebus.framework.jobs.JobManager;
3530
import org.phoebus.framework.nls.NLS;
36-
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
3731
import org.phoebus.ui.javafx.ImageCache;
3832

3933
import java.io.IOException;
40-
import java.text.MessageFormat;
41-
import java.util.List;
42-
import java.util.Optional;
4334
import java.util.ResourceBundle;
4435
import java.util.logging.Level;
4536
import java.util.logging.Logger;
4637

47-
public class SearchAndFilterTab extends SaveAndRestoreTab implements DataChangeListener {
38+
public class SearchAndFilterTab extends SaveAndRestoreTab {
4839
public static final String SEARCH_AND_FILTER_TAB_ID = "SearchAndFilterTab";
4940

5041
private SearchAndFilterViewController searchAndFilterViewController;
51-
private final SaveAndRestoreService saveAndRestoreService;
5242

5343
public SearchAndFilterTab(SaveAndRestoreController saveAndRestoreController) {
5444

5545
setId(SEARCH_AND_FILTER_TAB_ID);
56-
57-
saveAndRestoreService = SaveAndRestoreService.getInstance();
58-
5946
final ResourceBundle bundle = NLS.getMessages(SaveAndRestoreApplication.class);
6047

6148
FXMLLoader loader = new FXMLLoader();
@@ -66,8 +53,7 @@ public SearchAndFilterTab(SaveAndRestoreController saveAndRestoreController) {
6653
if (clazz.isAssignableFrom(SearchAndFilterViewController.class)) {
6754
return clazz.getConstructor(SaveAndRestoreController.class)
6855
.newInstance(saveAndRestoreController);
69-
}
70-
else if(clazz.isAssignableFrom(SearchResultTableViewController.class)){
56+
} else if (clazz.isAssignableFrom(SearchResultTableViewController.class)) {
7157
return clazz.getConstructor()
7258
.newInstance();
7359
}
@@ -91,45 +77,5 @@ else if(clazz.isAssignableFrom(SearchResultTableViewController.class)){
9177

9278
setText(Messages.search);
9379
setGraphic(new ImageView(ImageCache.getImage(ImageCache.class, "/icons/sar-search_18x18.png")));
94-
95-
setOnCloseRequest(event -> SaveAndRestoreService.getInstance().removeDataChangeListener(this));
96-
97-
saveAndRestoreService.addDataChangeListener(this);
98-
}
99-
100-
101-
@Override
102-
public void nodeChanged(org.phoebus.applications.saveandrestore.model.Node updatedNode) {
103-
searchAndFilterViewController.nodeChanged(updatedNode);
104-
}
105-
106-
/**
107-
* Shows a {@link Filter} in the view. If the filter identified through the specified (unique) id does not
108-
* exist, an error message is show.
109-
*
110-
* @param filterId Unique, case-sensitive name of a persisted {@link Filter}.
111-
*/
112-
public void showFilter(String filterId) {
113-
JobManager.schedule("Show Filter", monitor -> {
114-
List<Filter> allFilters;
115-
try {
116-
allFilters = saveAndRestoreService.getAllFilters();
117-
} catch (Exception e) {
118-
Platform.runLater(() -> ExceptionDetailsErrorDialog.openError(Messages.failedGetFilters, e));
119-
return;
120-
}
121-
Optional<Filter> filterOptional = allFilters.stream().filter(f -> f.getName().equalsIgnoreCase(filterId)).findFirst();
122-
if (filterOptional.isEmpty()) {
123-
Platform.runLater(() -> {
124-
Alert alert = new Alert(Alert.AlertType.ERROR);
125-
alert.setContentText(MessageFormat.format(Messages.filterNotFound, filterId));
126-
alert.show();
127-
});
128-
} else {
129-
Filter filter = filterOptional.get();
130-
Platform.runLater(() ->
131-
searchAndFilterViewController.setFilter(filter));
132-
}
133-
});
13480
}
13581
}

0 commit comments

Comments
 (0)