Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide visual feed-back if alarm actions fail #2572

Merged
merged 2 commits into from
Mar 9, 2023
Merged
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 @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -556,7 +556,7 @@ public void removeComponent(final AlarmTreeItem<?> item) throws Exception
/** @param item Item for which to acknowledge alarm
* @param acknowledge <code>true</code> 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
{
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,8 +28,19 @@ public AcknowledgeAction(final AlarmClient model, final List<AlarmTreeItem<?>> 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;
}
}
});
});
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,11 +26,21 @@ class UnAcknowledgeAction extends MenuItem
public UnAcknowledgeAction(final AlarmClient model, final List<AlarmTreeItem<?>> 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;
}
}
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,13 +63,19 @@ public MoveTreeItemAction(TreeView<AlarmTreeItem<?>> 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);
}
});

});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,10 +58,16 @@ public RenameTreeItemAction(final TreeView<AlarmTreeItem<?>> 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
Expand All @@ -80,12 +88,16 @@ public RenameTreeItemAction(final TreeView<AlarmTreeItem<?>> node,
{
final AlarmTreeItem<BasicState> 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);
}
});
});
}
}


}
Original file line number Diff line number Diff line change
@@ -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)