From 6b8b0ff81961991ff3f4590a44b32c03a5966de7 Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Fri, 12 Sep 2025 14:53:27 +0100 Subject: [PATCH 1/3] Code refactored and bug fixed --- .../configserver/configuration/Block.java | 145 ++++++++-- .../editing/blocks/BlockAlarmConfigPanel.java | 128 +++++++++ .../blocks/BlockAlarmConfigViewModel.java | 264 ++++++++++++++++++ .../editing/blocks/EditBlockDialog.java | 29 +- 4 files changed, 547 insertions(+), 19 deletions(-) create mode 100644 base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java create mode 100644 base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java diff --git a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java index 3d4f38ff66..d6d14fa5a1 100644 --- a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java +++ b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java @@ -1,7 +1,7 @@ /* * This file is part of the ISIS IBEX application. -* Copyright (C) 2012-2015 Science & Technology Facilities Council. +* Copyright (C) 2012-2025 Science & Technology Facilities Council. * All rights reserved. * * This program is distributed in the hope that it will be useful. @@ -63,6 +63,14 @@ public class Block extends ModelObject implements IRuncontrol, INamedInComponent private boolean set_block; private String set_block_val; + // Alarms config information + private boolean alarmenabled; + private boolean alarmlatched; + private double alarmlowlimit; + private double alarmhighlimit; + private double alarmdelay; + private String alarmguidance; + /** * Creates a new block given input properties. * @@ -71,9 +79,10 @@ public class Block extends ModelObject implements IRuncontrol, INamedInComponent * @param visible whether the block should be shown * @param local whether the PV is local to the instrument */ - public Block(String name, String pv, boolean visible, boolean local) { - this(name, pv, visible, local, null, 0.0f, 0.0f, false, false, true, DEFAULT_SCAN_RATE, 0.0f, false, ""); - } + public Block(String name, String pv, boolean visible, boolean local) { + this(name, pv, visible, local, null, 0.0f, 0.0f, false, false, true, DEFAULT_SCAN_RATE, 0.0f, false, "", false, + false, 0.0d, 0.0d, 0.0d, ""); + } /** * Creates a new block given input properties. @@ -93,23 +102,37 @@ public Block(String name, String pv, boolean visible, boolean local) { * @param logDeadband deadband for the block to be archived * @param blockSet A boolean value indicating whether or not to set a value on block on config change. * @param blockSetVal The value to set the block to on config change if the blockSet is true. - */ - public Block(String name, String pv, boolean visible, boolean local, String component, double lowLimit, - double highLimit, boolean suspendOnInvalid, Boolean runcontrol, boolean logPeriodic, int logRate, float logDeadband, boolean blockSet, String blockSetVal) { + * @param alarmEnabled whether alarm are enabled for this block + * @param alarmLatched whether alarm are latched for this block + * @param alarmLowLimit the low limit for alarm + * @param alarmHighLimit the high limit for alarm + * @param alarmDelay the delay before the alarm is triggered + * @param alarmGuidance guidance text for alarm + */ + public Block(String name, String pv, boolean visible, boolean local, String component, double lowLimit, + double highLimit, boolean suspendOnInvalid, Boolean runcontrol, boolean logPeriodic, int logRate, + float logDeadband, boolean blockSet, String blockSetVal, boolean alarmEnabled, boolean alarmLatched, + Double alarmLowLimit, Double alarmHighLimit, Double alarmDelay, String alarmGuidance) { this.name = name; this.pv = pv; this.visible = visible; this.local = local; this.component = component; - this.lowlimit = lowLimit; - this.highlimit = highLimit; - this.runcontrol = runcontrol; - this.log_deadband = logDeadband; - this.log_periodic = logPeriodic; - this.log_rate = logRate; - this.suspend_on_invalid = suspendOnInvalid; - this.set_block = blockSet; - this.set_block_val = blockSetVal; + this.lowlimit = lowLimit; + this.highlimit = highLimit; + this.runcontrol = runcontrol; + this.log_deadband = logDeadband; + this.log_periodic = logPeriodic; + this.log_rate = logRate; + this.suspend_on_invalid = suspendOnInvalid; + this.set_block = blockSet; + this.set_block_val = blockSetVal; + this.alarmenabled = alarmEnabled; + this.alarmlatched = alarmLatched; + this.alarmlowlimit = alarmLowLimit; + this.alarmhighlimit = alarmHighLimit; + this.alarmdelay = alarmDelay; + this.alarmguidance = alarmGuidance; } /** @@ -118,8 +141,10 @@ public Block(String name, String pv, boolean visible, boolean local, String comp * @param other the block to be copied */ public Block(Block other) { - this(other.name, other.pv, other.visible, other.local, other.component, other.lowlimit, other.highlimit, other.suspend_on_invalid, - other.runcontrol, other.log_periodic, other.log_rate, other.log_deadband, other.set_block, other.set_block_val); + this(other.name, other.pv, other.visible, other.local, other.component, other.lowlimit, other.highlimit, + other.suspend_on_invalid, other.runcontrol, other.log_periodic, other.log_rate, other.log_deadband, + other.set_block, other.set_block_val, other.alarmenabled, other.alarmlatched, other.alarmlowlimit, + other.alarmhighlimit, other.alarmdelay, other.alarmguidance); } /** @@ -385,6 +410,90 @@ public String getblockSetVal() { return set_block_val; } + /** + * @return the alarmEnabled + */ + public boolean isAlarmEnabled() { + return alarmenabled; + } + + /** + * @param alarmEnabled the alarmEnabled to set + */ + public void setAlarmEnabled(boolean alarmEnabled) { + firePropertyChange("alarmEnabled", this.alarmenabled, this.alarmenabled = alarmEnabled); + } + + /** + * @return the alarmLatched + */ + public boolean isAlarmLatched() { + return alarmlatched; + } + + /** + * @param alarmLatched the alarmLatched to set + */ + public void setAlarmLatched(boolean alarmLatched) { + firePropertyChange("alarmLatched", this.alarmlatched, this.alarmlatched = alarmLatched); + } + + /** + * @return the alarmLowLimit + */ + public double getAlarmLowLimit() { + return alarmlowlimit; + } + + /** + * @param alarmLowLimit the alarmLowLimit to set + */ + public void setAlarmLowLimit(double alarmLowLimit) { + firePropertyChange("alarmLowLimit", this.alarmlowlimit, this.alarmlowlimit = alarmLowLimit); + } + + /** + * @return the alarmHighLimit + */ + public double getAlarmHighLimit() { + return alarmhighlimit; + } + + /** + * @param alarmHighLimit the alarmHighLimit to set + */ + public void setAlarmHighLimit(double alarmHighLimit) { + firePropertyChange("alarmHighLimit", this.alarmhighlimit, this.alarmhighlimit = alarmHighLimit); + } + + /** + * @return the alarmDelay + */ + public double getAlarmDelay() { + return alarmdelay; + } + + /** + * @param alarmDelay the alarmDelay to set + */ + public void setAlarmDelay(double alarmDelay) { + firePropertyChange("alarmDelay", this.alarmdelay, this.alarmdelay = alarmDelay); + } + + /** + * @return the alarmGuidance + */ + public String getAlarmGuidance() { + return alarmguidance; + } + + /** + * @param alarmGuidance the alarmGuidance to set + */ + public void setAlarmGuidance(String alarmGuidance) { + firePropertyChange("alarmGuidance", this.alarmguidance, this.alarmguidance = alarmGuidance); + } + @Override public String toString() { return name; diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java new file mode 100644 index 0000000000..a690013cd1 --- /dev/null +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java @@ -0,0 +1,128 @@ +/** + * This file is part of the ISIS IBEX application. Copyright (C) 2012-2025 + * Science & Technology Facilities Council. All rights reserved. + * + * This program is distributed in the hope that it will be useful. This program + * and the accompanying materials are made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution. EXCEPT AS + * EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM AND + * ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more + * details. + * + * You should have received a copy of the Eclipse Public License v1.0 along with + * this program; if not, you can obtain a copy from + * https://www.eclipse.org/org/documents/epl-v10.php or + * http://opensource.org/licenses/eclipse-1.0.php + */ + +package uk.ac.stfc.isis.ibex.ui.configserver.editing.blocks; + +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.beans.typed.BeanProperties; +import org.eclipse.jface.databinding.swt.typed.WidgetProperties; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +import uk.ac.stfc.isis.ibex.ui.widgets.buttons.IBEXButton; + +/** + * A panel in the edit block dialog for the block's alarm configuration settings. + */ +@SuppressWarnings("checkstyle:magicnumber") +public class BlockAlarmConfigPanel extends Composite { + private Text lowLimit; + private Text highLimit; + private Text delay; + private Text guidance; + private Button enabled; + private Button latched; + + /** + * Standard constructor. + * + * @param parent The parent composite. + * @param style The SWT style. + * @param viewModel The viewModel for the block alarm configuration. + */ + public BlockAlarmConfigPanel(Composite parent, int style, BlockAlarmConfigViewModel viewModel) { + super(parent, style); + setLayout(new FillLayout(SWT.HORIZONTAL)); + + Group alarmConfigGroup = new Group(this, SWT.NONE); + alarmConfigGroup.setText("Alarm Configurations"); + alarmConfigGroup.setLayout(new GridLayout(6, false)); + + addLabel(alarmConfigGroup, "Low Limit:"); + lowLimit = new Text(alarmConfigGroup, SWT.BORDER); + lowLimit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + lowLimit.setToolTipText("Low limit for the alarm configuration"); + + addLabel(alarmConfigGroup, "High Limit:"); + highLimit = new Text(alarmConfigGroup, SWT.BORDER); + highLimit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + highLimit.setToolTipText("High limit for the alarm configuration"); + + addLabel(alarmConfigGroup, "Delay:"); + delay = new Text(alarmConfigGroup, SWT.BORDER); + delay.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + delay.setToolTipText("Delay before the alarm is triggered"); + + enabled = new IBEXButton(alarmConfigGroup, SWT.CHECK) + .layoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)) + .text("Enabled").tooltip("Enable or disable the alarm") + .get(); + + latched = new IBEXButton(alarmConfigGroup, SWT.CHECK) + .layoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)) + .text("Latched").tooltip("Enable or disable latched alarm behavior") + .get(); + + addLabel(alarmConfigGroup, "Guidance:"); + guidance = new Text(alarmConfigGroup, SWT.BORDER); + GridData grid = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); + grid.widthHint = 200; + guidance.setLayoutData(grid); + guidance.setToolTipText("Guidance text for the alarm configuration"); + setModel(viewModel); + } + + /** + * @param alarmConfigGroup the group to which the label is added + * @param labelText the text for the label + */ + private void addLabel(Group alarmConfigGroup, String labelText) { + Label label = new Label(alarmConfigGroup, SWT.NONE); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + label.setText(labelText); + } + + /** + * Sets the view model and observers for run control settings. + * @param viewModel The view model for run control settings. + */ + private void setModel(BlockAlarmConfigViewModel viewModel) { + DataBindingContext bindingContext = new DataBindingContext(); + + bindingContext.bindValue(WidgetProperties.buttonSelection().observe(enabled), + BeanProperties.value(BlockAlarmConfigViewModel.ENABLED_BINDING_NAME).observe(viewModel)); + bindingContext.bindValue(WidgetProperties.buttonSelection().observe(latched), + BeanProperties.value(BlockAlarmConfigViewModel.LATCHED_BINDING_NAME).observe(viewModel)); + + bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(lowLimit), + BeanProperties.value(BlockAlarmConfigViewModel.LOW_LIMIT_BINDING_NAME).observe(viewModel)); + bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(highLimit), + BeanProperties.value(BlockAlarmConfigViewModel.HIGH_LIMIT_BINDING_NAME).observe(viewModel)); + bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(delay), + BeanProperties.value(BlockAlarmConfigViewModel.DELAY_BINDING_NAME).observe(viewModel)); + bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(guidance), + BeanProperties.value(BlockAlarmConfigViewModel.GUIDANCE_BINDING_NAME).observe(viewModel)); + } +} diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java new file mode 100644 index 0000000000..2d6adccefc --- /dev/null +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java @@ -0,0 +1,264 @@ +/** + * This file is part of the ISIS IBEX application. Copyright (C) 2012-2025 + * Science & Technology Facilities Council. All rights reserved. + * + * This program is distributed in the hope that it will be useful. This program + * and the accompanying materials are made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution. EXCEPT AS + * EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM AND + * ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more + * details. + * + * You should have received a copy of the Eclipse Public License v1.0 along with + * this program; if not, you can obtain a copy from + * https://www.eclipse.org/org/documents/epl-v10.php or + * http://opensource.org/licenses/eclipse-1.0.php + */ + +package uk.ac.stfc.isis.ibex.ui.configserver.editing.blocks; + +import uk.ac.stfc.isis.ibex.configserver.editing.EditableBlock; +import uk.ac.stfc.isis.ibex.validators.ErrorMessageProvider; + + +/** + * The view model for the log settings for a block. + */ +public class BlockAlarmConfigViewModel extends ErrorMessageProvider { + + private final EditableBlock editingBlock; + + private boolean enabled; + private boolean latched; + private Double lowLimit; + private Double highLimit; + private Double delay; + private String guidance; + + /** + * Field that the GUI should bind to to update low limit. + */ + public static final String LOW_LIMIT_BINDING_NAME = "lowLimitString"; + + /** + * Field that the GUI should bind to to update high limit. + */ + public static final String HIGH_LIMIT_BINDING_NAME = "highLimitString"; + + /** + * Field that the GUI should bind to to update delay value. + */ + public static final String DELAY_BINDING_NAME = "delayString"; + + /** + * Field that the GUI should bind to to update enabled flag. + */ + public static final String ENABLED_BINDING_NAME = "enabled"; + + /** + * Field that the GUI should bind to to update latched flag. + */ + public static final String LATCHED_BINDING_NAME = "latched"; + + /** + * Field that the GUI should bind to to update guidance value. + */ + public static final String GUIDANCE_BINDING_NAME = "guidance"; + + /** + * Constructor. + * + * @param editingBlock the block being edited + */ + public BlockAlarmConfigViewModel(final EditableBlock editingBlock) { + this.editingBlock = editingBlock; + enabled = editingBlock.isAlarmEnabled(); + latched = editingBlock.isAlarmLatched(); + lowLimit = editingBlock.getAlarmLowLimit(); + highLimit = editingBlock.getAlarmHighLimit(); + delay = editingBlock.getAlarmDelay(); + guidance = editingBlock.getAlarmGuidance(); + } + + /** + * Gets whether alarm is enabled. + * + * @return is the alarm enabled + */ + public boolean getEnabled() { + return enabled; + } + + /** + * Sets whether the alarm is enabled. + * + * @param enabled - Is alarm enabled (true) or disabled (false) + */ + public void setEnabled(boolean enabled) { + firePropertyChange("enabled", this.enabled, this.enabled = enabled); + } + + /** + * Gets whether alarm is latched. + * + * @return whether alarm is latched + */ + public boolean getLatched() { + return latched; + } + + /** + * Sets whether alarm is latched. + * + * @param latched - Is alarm latched (true) or not latched (false) + */ + public void setLatched(boolean latched) { + firePropertyChange("latched", this.latched, this.latched = latched); + } + + /** + * Gets the low limit. + * + * @return the low limit + */ + public Double getLowLimit() { + return lowLimit; + } + + /** + * Set the low limit. + * + * @param lowLimit the lower threshold for the alarm + */ + public void setLowLimit(Double lowLimit) { + firePropertyChange("lowLimit", this.lowLimit, this.lowLimit = lowLimit); + } + + /** + * Gets the high limit. + * + * @return the high limit + */ + public Double getHighLimit() { + return highLimit; + } + + /** + * Set the high limit. + * + * @param highLimit the upper threshold for the alarm. + */ + public void setHighLimit(Double highLimit) { + firePropertyChange("highLimit", this.highLimit, this.highLimit = highLimit); + } + + /** + * Gets the delay. + * + * @return the delay + */ + public Double getDelay() { + return delay; + } + + /** + * Set the delay. + * + * @param delay the delay value waited before triggering the alarm + */ + public void setDelay(Double delay) { + firePropertyChange("delay", this.delay, this.delay = delay); + } + + /** + * @return the guidance for the alarm + */ + public String getGuidance() { + return guidance; + } + + /** + * Set the guidance. + * + * @param guidance the guidance for the alarm + */ + public void setGuidance(String guidance) { + firePropertyChange("guidance", this.guidance, this.guidance = guidance); + } + + /** + * Gets the low limit as a string. + * @return the low limit as a string + */ + public String getLowLimitString() { + Double value = getLowLimit(); + return value == null ? "" : value.toString(); + } + + /** + * Sets the low limit from a text value. + * @param lowLimit the low limit as a string + */ + public void setLowLimitString(String lowLimit) { + try { + setLowLimit(Double.valueOf(lowLimit)); + } catch (NumberFormatException | NullPointerException e) { + setLowLimit(null); + } + } + + /** + * Gets the high limit as a string. + * @return the high limit as a string + */ + public String getHighLimitString() { + Double value = getHighLimit(); + return value == null ? "" : value.toString(); + } + + /** + * Sets the high limit from a text value. + * @param highLimit the high limit as a string + */ + public void setHighLimitString(String highLimit) { + try { + setHighLimit(Double.valueOf(highLimit)); + } catch (NumberFormatException | NullPointerException e) { + setHighLimit(null); + } + } + + /** + * Gets the delay value as a string. + * @return the delay as a string + */ + public String getDelayString() { + Double value = getDelay(); + return value == null ? "" : value.toString(); + } + + /** + * Sets the delay value from a text value. + * @param delay the delay value as a string + */ + public void setDelayString(String delay) { + try { + setDelay(Double.valueOf(delay)); + } catch (NumberFormatException | NullPointerException e) { + setDelay(null); + } + } + + /** + * Update the settings on the block. + */ + public void updateBlock() { + editingBlock.setAlarmEnabled(enabled); + editingBlock.setAlarmLatched(latched); + editingBlock.setAlarmLowLimit(lowLimit); + editingBlock.setAlarmHighLimit(highLimit); + editingBlock.setAlarmDelay(delay); + editingBlock.setAlarmGuidance(guidance); + } +} diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/EditBlockDialog.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/EditBlockDialog.java index 32bc4364f1..c682206248 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/EditBlockDialog.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/EditBlockDialog.java @@ -1,3 +1,20 @@ +/** + * This file is part of the ISIS IBEX application. Copyright (C) 2012-2025 + * Science & Technology Facilities Council. All rights reserved. + * + * This program is distributed in the hope that it will be useful. This program + * and the accompanying materials are made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution. EXCEPT AS + * EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM AND + * ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES + * OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more + * details. + * + * You should have received a copy of the Eclipse Public License v1.0 along with + * this program; if not, you can obtain a copy from + * https://www.eclipse.org/org/documents/epl-v10.php or + * http://opensource.org/licenses/eclipse-1.0.php + */ package uk.ac.stfc.isis.ibex.ui.configserver.editing.blocks; import java.beans.PropertyChangeEvent; @@ -45,6 +62,9 @@ public class EditBlockDialog extends TitleAreaDialog { BlockSetPanel blockSetPanel; BlockSetViewModel blockSetViewModel; + + BlockAlarmConfigPanel blockAlarmConfigPanel; + BlockAlarmConfigViewModel blockAlarmConfigViewModel; Button okButton; @@ -95,8 +115,11 @@ public EditBlockDialog(Shell parentShell, EditableBlock block, EditableConfigura blockDetailsViewModel = new BlockDetailsViewModel(this.block, this.config); blockGroupViewModel = new BlockGroupViewModel(this.block, this.config); blockSetViewModel = new BlockSetViewModel(this.block); + blockAlarmConfigViewModel = new BlockAlarmConfigViewModel(this.block); + - viewModels = Arrays.asList(blockLogSettingsViewModel, blockRunControlViewModel, blockDetailsViewModel, blockGroupViewModel); + viewModels = Arrays.asList(blockLogSettingsViewModel, blockRunControlViewModel, blockDetailsViewModel, + blockGroupViewModel, blockAlarmConfigViewModel); for (ErrorMessageProvider provider : viewModels) { provider.addPropertyChangeListener("error", errorListener); @@ -127,6 +150,9 @@ protected Control createDialogArea(Composite parent) { blockSetPanel = new BlockSetPanel(blockDetailsPanel, SWT.NONE, blockSetViewModel); blockSetPanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + + blockAlarmConfigPanel = new BlockAlarmConfigPanel(blockDetailsPanel, SWT.NONE, blockAlarmConfigViewModel); + blockAlarmConfigPanel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); new IBEXHelpButton(parent, HELP_LINK, DESCRIPTION); @@ -140,6 +166,7 @@ protected void okPressed() { blockLogSettingsViewModel.updateBlock(); blockGroupViewModel.updateBlock(); blockSetViewModel.updateBlock(); + blockAlarmConfigViewModel.updateBlock(); try { if (!config.getAllBlocks().contains(this.block)) { config.addNewBlock(this.block); From 8127a612780e1b6c1c85df5d33223107c67bd18a Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Mon, 15 Sep 2025 00:08:42 +0100 Subject: [PATCH 2/3] Changes to get correct alarm limit values --- .../configserver/configuration/Block.java | 43 +---- .../editing/blocks/BlockAlarmConfigPanel.java | 17 +- .../blocks/BlockAlarmConfigViewModel.java | 182 ++++++++++-------- 3 files changed, 113 insertions(+), 129 deletions(-) diff --git a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java index d6d14fa5a1..d15517615f 100644 --- a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java +++ b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Block.java @@ -66,11 +66,9 @@ public class Block extends ModelObject implements IRuncontrol, INamedInComponent // Alarms config information private boolean alarmenabled; private boolean alarmlatched; - private double alarmlowlimit; - private double alarmhighlimit; private double alarmdelay; private String alarmguidance; - + /** * Creates a new block given input properties. * @@ -81,7 +79,7 @@ public class Block extends ModelObject implements IRuncontrol, INamedInComponent */ public Block(String name, String pv, boolean visible, boolean local) { this(name, pv, visible, local, null, 0.0f, 0.0f, false, false, true, DEFAULT_SCAN_RATE, 0.0f, false, "", false, - false, 0.0d, 0.0d, 0.0d, ""); + false, 0.0d, ""); } /** @@ -104,15 +102,13 @@ public Block(String name, String pv, boolean visible, boolean local) { * @param blockSetVal The value to set the block to on config change if the blockSet is true. * @param alarmEnabled whether alarm are enabled for this block * @param alarmLatched whether alarm are latched for this block - * @param alarmLowLimit the low limit for alarm - * @param alarmHighLimit the high limit for alarm * @param alarmDelay the delay before the alarm is triggered * @param alarmGuidance guidance text for alarm */ public Block(String name, String pv, boolean visible, boolean local, String component, double lowLimit, double highLimit, boolean suspendOnInvalid, Boolean runcontrol, boolean logPeriodic, int logRate, float logDeadband, boolean blockSet, String blockSetVal, boolean alarmEnabled, boolean alarmLatched, - Double alarmLowLimit, Double alarmHighLimit, Double alarmDelay, String alarmGuidance) { + Double alarmDelay, String alarmGuidance) { this.name = name; this.pv = pv; this.visible = visible; @@ -129,8 +125,6 @@ public Block(String name, String pv, boolean visible, boolean local, String comp this.set_block_val = blockSetVal; this.alarmenabled = alarmEnabled; this.alarmlatched = alarmLatched; - this.alarmlowlimit = alarmLowLimit; - this.alarmhighlimit = alarmHighLimit; this.alarmdelay = alarmDelay; this.alarmguidance = alarmGuidance; } @@ -143,8 +137,7 @@ public Block(String name, String pv, boolean visible, boolean local, String comp public Block(Block other) { this(other.name, other.pv, other.visible, other.local, other.component, other.lowlimit, other.highlimit, other.suspend_on_invalid, other.runcontrol, other.log_periodic, other.log_rate, other.log_deadband, - other.set_block, other.set_block_val, other.alarmenabled, other.alarmlatched, other.alarmlowlimit, - other.alarmhighlimit, other.alarmdelay, other.alarmguidance); + other.set_block, other.set_block_val, other.alarmenabled, other.alarmlatched, other.alarmdelay, other.alarmguidance); } /** @@ -438,34 +431,6 @@ public void setAlarmLatched(boolean alarmLatched) { firePropertyChange("alarmLatched", this.alarmlatched, this.alarmlatched = alarmLatched); } - /** - * @return the alarmLowLimit - */ - public double getAlarmLowLimit() { - return alarmlowlimit; - } - - /** - * @param alarmLowLimit the alarmLowLimit to set - */ - public void setAlarmLowLimit(double alarmLowLimit) { - firePropertyChange("alarmLowLimit", this.alarmlowlimit, this.alarmlowlimit = alarmLowLimit); - } - - /** - * @return the alarmHighLimit - */ - public double getAlarmHighLimit() { - return alarmhighlimit; - } - - /** - * @param alarmHighLimit the alarmHighLimit to set - */ - public void setAlarmHighLimit(double alarmHighLimit) { - firePropertyChange("alarmHighLimit", this.alarmhighlimit, this.alarmhighlimit = alarmHighLimit); - } - /** * @return the alarmDelay */ diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java index a690013cd1..48d8612bde 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigPanel.java @@ -63,12 +63,16 @@ public BlockAlarmConfigPanel(Composite parent, int style, BlockAlarmConfigViewMo addLabel(alarmConfigGroup, "Low Limit:"); lowLimit = new Text(alarmConfigGroup, SWT.BORDER); lowLimit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - lowLimit.setToolTipText("Low limit for the alarm configuration"); + lowLimit.setToolTipText("Alarm Low limit - not managed at block level"); + lowLimit.setEnabled(false); // Low limit is currently not editable. + //lowLimit.setText(viewModel.getLowLimit()); addLabel(alarmConfigGroup, "High Limit:"); highLimit = new Text(alarmConfigGroup, SWT.BORDER); highLimit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - highLimit.setToolTipText("High limit for the alarm configuration"); + highLimit.setToolTipText("Alarm High limit - not managed at block level"); + highLimit.setEnabled(false); // High limit is currently not editable. + //highLimit.setText(viewModel.getHighLimit()); addLabel(alarmConfigGroup, "Delay:"); delay = new Text(alarmConfigGroup, SWT.BORDER); @@ -115,14 +119,13 @@ private void setModel(BlockAlarmConfigViewModel viewModel) { BeanProperties.value(BlockAlarmConfigViewModel.ENABLED_BINDING_NAME).observe(viewModel)); bindingContext.bindValue(WidgetProperties.buttonSelection().observe(latched), BeanProperties.value(BlockAlarmConfigViewModel.LATCHED_BINDING_NAME).observe(viewModel)); - - bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(lowLimit), - BeanProperties.value(BlockAlarmConfigViewModel.LOW_LIMIT_BINDING_NAME).observe(viewModel)); - bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(highLimit), - BeanProperties.value(BlockAlarmConfigViewModel.HIGH_LIMIT_BINDING_NAME).observe(viewModel)); bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(delay), BeanProperties.value(BlockAlarmConfigViewModel.DELAY_BINDING_NAME).observe(viewModel)); bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(guidance), BeanProperties.value(BlockAlarmConfigViewModel.GUIDANCE_BINDING_NAME).observe(viewModel)); + bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(lowLimit), + BeanProperties.value(BlockAlarmConfigViewModel.LOWLIMIT_BINDING_NAME).observe(viewModel)); + bindingContext.bindValue(WidgetProperties.text(SWT.Modify).observe(highLimit), + BeanProperties.value(BlockAlarmConfigViewModel.HIGHLIMIT_BINDING_NAME).observe(viewModel)); } } diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java index 2d6adccefc..c05e272f04 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java @@ -19,9 +19,14 @@ package uk.ac.stfc.isis.ibex.ui.configserver.editing.blocks; import uk.ac.stfc.isis.ibex.configserver.editing.EditableBlock; +import uk.ac.stfc.isis.ibex.epics.observing.BaseObserver; +import uk.ac.stfc.isis.ibex.epics.observing.ForwardingObservable; +import uk.ac.stfc.isis.ibex.epics.switching.ObservableFactory; +import uk.ac.stfc.isis.ibex.epics.switching.OnInstrumentSwitch; +import uk.ac.stfc.isis.ibex.instrument.channels.DoubleChannel; +import uk.ac.stfc.isis.ibex.logger.IsisLog; import uk.ac.stfc.isis.ibex.validators.ErrorMessageProvider; - /** * The view model for the log settings for a block. */ @@ -31,20 +36,55 @@ public class BlockAlarmConfigViewModel extends ErrorMessageProvider { private boolean enabled; private boolean latched; - private Double lowLimit; - private Double highLimit; private Double delay; private String guidance; - - /** - * Field that the GUI should bind to to update low limit. - */ - public static final String LOW_LIMIT_BINDING_NAME = "lowLimitString"; - /** - * Field that the GUI should bind to to update high limit. - */ - public static final String HIGH_LIMIT_BINDING_NAME = "highLimitString"; + // Observables for alarm limits + ObservableFactory observableFactory = new ObservableFactory(OnInstrumentSwitch.CLOSE); + private ForwardingObservable alarmLowLimitObservable = null; + private ForwardingObservable alarmHighLimitObservable = null; + private String lowLimit = null; + private String highLimit = null; + + private final BaseObserver alarmLowLimitAdapter = new BaseObserver() { + @Override + public void onValue(Double value) { + setLowLimit((null == value) ? "" : value.toString()); + } + + @Override + public void onError(Exception e) { + lowLimit = ""; + IsisLog.getLogger(getClass()).error("Exception in alarm low limit adapter: " + e.getMessage()); + } + + @Override + public void onConnectionStatus(boolean isConnected) { + if (!isConnected) { + lowLimit = ""; + } + } + }; + + private final BaseObserver alarmHighLimitAdapter = new BaseObserver() { + @Override + public void onValue(Double value) { + setHighLimit((null == value) ? "" : value.toString()); + } + + @Override + public void onError(Exception e) { + highLimit = ""; + IsisLog.getLogger(getClass()).error("Exception in alarm high limit adapter: " + e.getMessage()); + } + + @Override + public void onConnectionStatus(boolean isConnected) { + if (!isConnected) { + highLimit = ""; + } + } + }; /** * Field that the GUI should bind to to update delay value. @@ -66,6 +106,16 @@ public class BlockAlarmConfigViewModel extends ErrorMessageProvider { */ public static final String GUIDANCE_BINDING_NAME = "guidance"; + /** + * Field that the GUI should bind to to update lowLimit value. + */ + public static final String LOWLIMIT_BINDING_NAME = "lowLimit"; + + /** + * Field that the GUI should bind to to update highLimit value. + */ + public static final String HIGHLIMIT_BINDING_NAME = "highLimit"; + /** * Constructor. * @@ -75,13 +125,14 @@ public BlockAlarmConfigViewModel(final EditableBlock editingBlock) { this.editingBlock = editingBlock; enabled = editingBlock.isAlarmEnabled(); latched = editingBlock.isAlarmLatched(); - lowLimit = editingBlock.getAlarmLowLimit(); - highLimit = editingBlock.getAlarmHighLimit(); delay = editingBlock.getAlarmDelay(); guidance = editingBlock.getAlarmGuidance(); + + // Create the observables to monitor the alarm limits + createAlarmObservables(); } - /** + /** * Gets whether alarm is enabled. * * @return is the alarm enabled @@ -117,42 +168,6 @@ public void setLatched(boolean latched) { firePropertyChange("latched", this.latched, this.latched = latched); } - /** - * Gets the low limit. - * - * @return the low limit - */ - public Double getLowLimit() { - return lowLimit; - } - - /** - * Set the low limit. - * - * @param lowLimit the lower threshold for the alarm - */ - public void setLowLimit(Double lowLimit) { - firePropertyChange("lowLimit", this.lowLimit, this.lowLimit = lowLimit); - } - - /** - * Gets the high limit. - * - * @return the high limit - */ - public Double getHighLimit() { - return highLimit; - } - - /** - * Set the high limit. - * - * @param highLimit the upper threshold for the alarm. - */ - public void setHighLimit(Double highLimit) { - firePropertyChange("highLimit", this.highLimit, this.highLimit = highLimit); - } - /** * Gets the delay. * @@ -188,47 +203,37 @@ public void setGuidance(String guidance) { } /** - * Gets the low limit as a string. - * @return the low limit as a string + * Gets the low limit . + * @return the low limit */ - public String getLowLimitString() { - Double value = getLowLimit(); - return value == null ? "" : value.toString(); + public String getLowLimit() { + return lowLimit; } - + /** - * Sets the low limit from a text value. - * @param lowLimit the low limit as a string + * Sets the low limit. + * @param lowLimit */ - public void setLowLimitString(String lowLimit) { - try { - setLowLimit(Double.valueOf(lowLimit)); - } catch (NumberFormatException | NullPointerException e) { - setLowLimit(null); - } + public void setLowLimit(String lowLimit) {; + firePropertyChange("lowLimit", this.lowLimit, this.lowLimit = lowLimit); } - + /** - * Gets the high limit as a string. - * @return the high limit as a string + * Gets the high limit. + * @return the high limit */ - public String getHighLimitString() { - Double value = getHighLimit(); - return value == null ? "" : value.toString(); + public String getHighLimit() { + return highLimit; } - + /** - * Sets the high limit from a text value. - * @param highLimit the high limit as a string + * Sets the High limit. + * @param highLimit */ - public void setHighLimitString(String highLimit) { - try { - setHighLimit(Double.valueOf(highLimit)); - } catch (NumberFormatException | NullPointerException e) { - setHighLimit(null); - } + public void setHighLimit(String highLimit) {; + firePropertyChange("highLimit", this.highLimit, this.highLimit = highLimit); } - + /** * Gets the delay value as a string. * @return the delay as a string @@ -256,9 +261,20 @@ public void setDelayString(String delay) { public void updateBlock() { editingBlock.setAlarmEnabled(enabled); editingBlock.setAlarmLatched(latched); - editingBlock.setAlarmLowLimit(lowLimit); - editingBlock.setAlarmHighLimit(highLimit); editingBlock.setAlarmDelay(delay); editingBlock.setAlarmGuidance(guidance); } + + /** + * Creates an observable for the PV holding the current state of this banner + * item. + */ + private void createAlarmObservables() { + alarmLowLimitObservable = observableFactory.getSwitchableObservable(new DoubleChannel(), + editingBlock.getPV() + ".LOW"); + alarmHighLimitObservable = observableFactory.getSwitchableObservable(new DoubleChannel(), + editingBlock.getPV() + ".HIGH"); + alarmLowLimitObservable.subscribe(alarmLowLimitAdapter); + alarmHighLimitObservable.subscribe(alarmHighLimitAdapter); + } } From e7723287268993dfe07f016b646626230b976c9e Mon Sep 17 00:00:00 2001 From: Chsudeepta Date: Mon, 15 Sep 2025 14:06:46 +0100 Subject: [PATCH 3/3] Fixed some checkstyle issues --- .../editing/blocks/BlockAlarmConfigViewModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java index c05e272f04..0b2d8e1b13 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/blocks/BlockAlarmConfigViewModel.java @@ -214,7 +214,7 @@ public String getLowLimit() { * Sets the low limit. * @param lowLimit */ - public void setLowLimit(String lowLimit) {; + public void setLowLimit(String lowLimit) { firePropertyChange("lowLimit", this.lowLimit, this.lowLimit = lowLimit); } @@ -230,7 +230,7 @@ public String getHighLimit() { * Sets the High limit. * @param highLimit */ - public void setHighLimit(String highLimit) {; + public void setHighLimit(String highLimit) { firePropertyChange("highLimit", this.highLimit, this.highLimit = highLimit); }