diff --git a/app/alarm/datasource/src/main/java/org/phoebus/pv/alarm/AlarmContext.java b/app/alarm/datasource/src/main/java/org/phoebus/pv/alarm/AlarmContext.java index 075cf875d4..c4b077d009 100644 --- a/app/alarm/datasource/src/main/java/org/phoebus/pv/alarm/AlarmContext.java +++ b/app/alarm/datasource/src/main/java/org/phoebus/pv/alarm/AlarmContext.java @@ -116,7 +116,11 @@ public static synchronized void acknowledgePV(AlarmPV alarmPV, boolean ack) } if (node != null) { - alarmModels.get(alarmPV.getInfo().getRoot()).acknowledge(node, ack); + try { + alarmModels.get(alarmPV.getInfo().getRoot()).acknowledge(node, ack); + } catch (Exception e) { + logger.log(Level.WARNING, "Failed to acknowledge alarm", e); + } } } } diff --git a/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClient.java b/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClient.java index 1e67adfe27..44ca4c0426 100644 --- a/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClient.java +++ b/app/alarm/model/src/main/java/org/phoebus/applications/alarm/client/AlarmClient.java @@ -470,7 +470,7 @@ private AlarmTreeItem findOrCreateNode(final String path, final boolean is_le * @param path_name to parent Root or parent component under which to add the component * @param new_name Name of the new component */ - public void addComponent(final String path_name, final String new_name) + public void addComponent(final String path_name, final String new_name) throws Exception { try { @@ -556,7 +556,7 @@ public void removeComponent(final AlarmTreeItem item) throws Exception /** @param item Item for which to acknowledge alarm * @param acknowledge true to acknowledge, else un-acknowledge */ - public void acknowledge(final AlarmTreeItem item, final boolean acknowledge) + public void acknowledge(final AlarmTreeItem item, final boolean acknowledge) throws Exception { try { @@ -568,6 +568,7 @@ public void acknowledge(final AlarmTreeItem item, final boolean acknowledge) catch (final Exception ex) { logger.log(Level.WARNING, "Cannot acknowledge component " + item, ex); + throw ex; } } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/AcknowledgeAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/AcknowledgeAction.java index 247ff22b9c..13679a8130 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/AcknowledgeAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/AcknowledgeAction.java @@ -7,14 +7,15 @@ *******************************************************************************/ package org.phoebus.applications.alarm.ui; -import java.util.List; - +import javafx.application.Platform; +import javafx.scene.control.MenuItem; import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; -import javafx.scene.control.MenuItem; +import java.util.List; /** Action to acknowledge alarm * @author Kay Kasemir @@ -27,8 +28,19 @@ public AcknowledgeAction(final AlarmClient model, final List> a super("Acknowledge", ImageCache.getImageView(AlarmUI.class, "/icons/acknowledge.png")); setOnAction(event -> { - JobManager.schedule(getText(), monitor -> - active.forEach(item -> model.acknowledge(item, true))); + JobManager.schedule(getText(), monitor -> { + for(AlarmTreeItem item : active){ + try { + model.acknowledge(item, true); + } catch (Exception e) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.acknowledgeFailed, + e); + // Breaking under the assumption that if one acknowledge fails, all will fail. + break; + } + } + }); }); } } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java new file mode 100644 index 0000000000..389fb7e00a --- /dev/null +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/Messages.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2018 Oak Ridge National Laboratory. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.phoebus.applications.alarm.ui; + +import org.phoebus.framework.nls.NLS; + +public class Messages +{ + public static String error; + + public static String acknowledgeFailed; + public static String addComponentFailed; + public static String moveItemFailed; + public static String removeComponentFailed; + public static String renameItemFailed; + public static String unacknowledgeFailed; + + static + { + // initialize resource bundle + NLS.initializeMessages(Messages.class); + } + + private Messages() + { + // prevent instantiation + } +} diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/UnAcknowledgeAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/UnAcknowledgeAction.java index 110883553d..f5c07f242d 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/UnAcknowledgeAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/UnAcknowledgeAction.java @@ -7,14 +7,15 @@ *******************************************************************************/ package org.phoebus.applications.alarm.ui; -import java.util.List; - +import javafx.application.Platform; +import javafx.scene.control.MenuItem; import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; -import javafx.scene.control.MenuItem; +import java.util.List; /** Action to acknowledge alarm * @author Kay Kasemir @@ -25,11 +26,21 @@ class UnAcknowledgeAction extends MenuItem public UnAcknowledgeAction(final AlarmClient model, final List> active) { super("Un-Acknowledge", ImageCache.getImageView(AlarmUI.class, "/icons/unacknowledge.png")); - - JobManager.schedule(getText(), monitor -> + setOnAction(event -> { - setOnAction(event -> - active.forEach(item -> model.acknowledge(item, false))); + JobManager.schedule(getText(), monitor -> { + for (AlarmTreeItem item : active) { + try { + model.acknowledge(item, false); + } catch (Exception e) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.unacknowledgeFailed, + e); + // Breaking under the assumption that if one unacknowledge fails, all will fail. + break; + } + } + }); }); } } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AddComponentAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AddComponentAction.java index 3c1300032c..34dd990263 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AddComponentAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/AddComponentAction.java @@ -12,9 +12,11 @@ import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreeLeaf; +import org.phoebus.applications.alarm.ui.Messages; import org.phoebus.framework.jobs.JobManager; import org.phoebus.ui.autocomplete.PVAutocompleteMenu; import org.phoebus.ui.dialog.DialogHelper; +import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; import javafx.application.Platform; @@ -198,8 +200,15 @@ public AddComponentAction(final Node node, final AlarmClient model, final AlarmT .replace('\n', ' ') .replaceAll(" +", " ") .trim(); - if (! haveExistingItem(node, parent, comp_name)) - model.addComponent(parent.getPathName(), comp_name); + if (! haveExistingItem(node, parent, comp_name)) { + try { + model.addComponent(parent.getPathName(), comp_name); + } catch (Exception e) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.addComponentFailed, + e); + } + } } }); }); diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java index 44570d77a6..69f99a68c8 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/MoveTreeItemAction.java @@ -10,7 +10,9 @@ import org.phoebus.applications.alarm.AlarmSystem; import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.model.AlarmTreeItem; +import org.phoebus.applications.alarm.ui.Messages; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; import javafx.scene.control.MenuItem; @@ -61,13 +63,19 @@ public MoveTreeItemAction(TreeView> node, // On a background thread, send the item configuration updates for the item to be moved and all its children. JobManager.schedule(getText(), monitor -> { - // Move the item. - model.sendItemConfigurationUpdate(new_path, item); - // Move the item's children. - AlarmTreeHelper.rebuildTree(model, item, new_path); - // Delete the old item. This deletes the old item's children as well. - model.removeComponent(item); - }); + try { + // Move the item. + model.sendItemConfigurationUpdate(new_path, item); + // Move the item's children. + AlarmTreeHelper.rebuildTree(model, item, new_path); + // Delete the old item. This deletes the old item's children as well. + model.removeComponent(item); + } catch (Exception e) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.moveItemFailed, + e); + } + }); }); } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RemoveComponentAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RemoveComponentAction.java index ea7eaa163d..8844ab90c7 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RemoveComponentAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RemoveComponentAction.java @@ -9,10 +9,13 @@ import java.util.List; +import javafx.application.Platform; import org.phoebus.applications.alarm.client.AlarmClient; import org.phoebus.applications.alarm.model.AlarmTreeItem; +import org.phoebus.applications.alarm.ui.Messages; import org.phoebus.framework.jobs.JobManager; import org.phoebus.ui.dialog.DialogHelper; +import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; import javafx.scene.Node; @@ -68,8 +71,18 @@ public RemoveComponentAction(final Node node, final AlarmClient model, final Lis JobManager.schedule(getText(), monitor -> { - for (AlarmTreeItem item : items) - model.removeComponent(item); + for (AlarmTreeItem item : items){ + try { + model.removeComponent(item); + } catch (Exception e) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.removeComponentFailed, + e); + // Breaking under the assumption that if one fails, all will fail + break; + } + } + }); }); } diff --git a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java index 74b7d31b52..cbca4c91a1 100644 --- a/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java +++ b/app/alarm/ui/src/main/java/org/phoebus/applications/alarm/ui/tree/RenameTreeItemAction.java @@ -13,7 +13,9 @@ import org.phoebus.applications.alarm.model.AlarmTreeItem; import org.phoebus.applications.alarm.model.AlarmTreePath; import org.phoebus.applications.alarm.model.BasicState; +import org.phoebus.applications.alarm.ui.Messages; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.javafx.ImageCache; import javafx.scene.control.MenuItem; @@ -56,10 +58,16 @@ public RenameTreeItemAction(final TreeView> node, // Remove the item and all its children. // Add the new item, and then rebuild all its children. final String new_path = AlarmTreePath.makePath(parent.getPathName(), new_name); - model.sendItemConfigurationUpdate(new_path, item); - AlarmTreeHelper.rebuildTree(model, item, new_path); - model.removeComponent(item); - }); + try { + model.sendItemConfigurationUpdate(new_path, item); + AlarmTreeHelper.rebuildTree(model, item, new_path); + model.removeComponent(item); + } catch (Exception e) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.renameItemFailed, + e); + } + }); }); } else @@ -80,12 +88,16 @@ public RenameTreeItemAction(final TreeView> node, { final AlarmTreeItem parent = item.getParent(); final String new_path = AlarmTreePath.makePath(parent.getPathName(), new_name); - model.sendItemConfigurationUpdate(new_path, item); - model.removeComponent(item); - }); + try { + model.sendItemConfigurationUpdate(new_path, item); + model.removeComponent(item); + } catch (Exception e) { + ExceptionDetailsErrorDialog.openError(Messages.error, + Messages.renameItemFailed, + e); + } + }); }); } } - - } diff --git a/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties new file mode 100644 index 0000000000..998f2ba791 --- /dev/null +++ b/app/alarm/ui/src/main/resources/org/phoebus/applications/alarm/ui/messages.properties @@ -0,0 +1,26 @@ +# +# Copyright (C) 2020 European Spallation Source ERIC. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# + +error=Error +acknowledgeFailed=Failed to acknowledge alarm(s) +addComponentFailed=Failed to add component +moveItemFailed=Failed to move item +removeComponentFailed=Failed to remove component +renameItemFailed=Failed to rename item +unacknowledgeFailed=Failed to unacknowledge alarm(s) \ No newline at end of file