diff --git a/base/uk.ac.stfc.isis.ibex.configserver.tests/src/uk/ac/stfc/isis/ibex/configserver/tests/json/JsonConvertersTest.java b/base/uk.ac.stfc.isis.ibex.configserver.tests/src/uk/ac/stfc/isis/ibex/configserver/tests/json/JsonConvertersTest.java index ad42fa3b73..ab0eca5731 100644 --- a/base/uk.ac.stfc.isis.ibex.configserver.tests/src/uk/ac/stfc/isis/ibex/configserver/tests/json/JsonConvertersTest.java +++ b/base/uk.ac.stfc.isis.ibex.configserver.tests/src/uk/ac/stfc/isis/ibex/configserver/tests/json/JsonConvertersTest.java @@ -242,7 +242,7 @@ public void conversion_config_to_string() throws ConversionException { //Arrange Function conv = new JsonConverters().configToString(); Configuration testConfig = new Configuration(configName, configDescription); - String expected = "{\"name\":\"" + configName + "\",\"description\":\"" + configDescription + "\",\"isProtected\":false,\"isDynamic\":false,\"configuresBlockGWAndArchiver\":false,\"iocs\":[],\"blocks\":[],\"groups\":[],\"components\":[],\"history\":[]}"; + String expected = "{\"name\":\"" + configName + "\",\"description\":\"" + configDescription + "\",\"isProtected\":false,\"isDynamic\":false,\"configuresBlockGWAndArchiver\":false,\"iocs\":[],\"blocks\":[],\"groups\":[],\"components\":[],\"history\":[],\"globalmacros\":[]}"; //Act String test = conv.apply(testConfig); diff --git a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Configuration.java b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Configuration.java index 935fb1f7cb..0204387756 100644 --- a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Configuration.java +++ b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Configuration.java @@ -50,6 +50,7 @@ public class Configuration extends ModelObject { private List groups = new ArrayList<>(); private List components = new ArrayList<>(); private List history = new ArrayList<>(); + private List globalmacros = new ArrayList<>(); /** * Create a new configuration. @@ -81,11 +82,12 @@ public Configuration(String name, String description) { * automatically * @param configuresBlockGWAndArchiver True this configuration includes the block gateway and archive files; * False these are generated by the block server + * @param globalmacros The global macros */ public Configuration(String name, String description, String defaultSynoptic, Collection iocs, Collection blocks, Collection groups, Collection components, Collection history, boolean isProtected, boolean isDynamic, - boolean configuresBlockGWAndArchiver) { + boolean configuresBlockGWAndArchiver, Collection globalmacros) { this.name = name; this.description = description; this.synoptic = defaultSynoptic == null || defaultSynoptic.equals("") ? ConfigEditing.NONE_SYNOPTIC_NAME @@ -114,6 +116,39 @@ public Configuration(String name, String description, String defaultSynoptic, Co for (String date : history) { this.history.add(date); } + + if (null != globalmacros) { + for (GlobalMacro globalMacro : globalmacros) { + this.globalmacros.add(new GlobalMacro(globalMacro)); + } + } + } + + /** + * Create a new configuration. + * + * @param name The configuration name + * @param description The configuration description + * @param defaultSynoptic The default synoptic to open when the configuration is + * current + * @param iocs The IOCs associated with the configuration + * @param blocks The configuration's blocks + * @param groups The configuration's groups + * @param components The configuration's components + * @param history A collection of dates when the configuration was + * updated + * @param isProtected Config is protected and can only be modified or + * deleted in manager mode + * @param isDynamic Config is marked as dynamic and can be changed + * automatically + * @param configuresBlockGWAndArchiver True this configuration includes the block gateway and archive files; + * False these are generated by the block server + */ + public Configuration(String name, String description, String defaultSynoptic, Collection iocs, + Collection blocks, Collection groups, Collection components, + Collection history, boolean isProtected, boolean isDynamic, boolean configuresBlockGWAndArchiver) { + this(name, description, defaultSynoptic, iocs, blocks, groups, components, history, isProtected, isDynamic, + configuresBlockGWAndArchiver, null); } /** @@ -123,7 +158,8 @@ public Configuration(String name, String description, String defaultSynoptic, Co */ public Configuration(Configuration other) { this(other.name(), other.description(), other.synoptic(), other.getIocs(), other.getBlocks(), other.getGroups(), - other.getComponents(), other.getHistory(), other.isProtected, other.isDynamic, other.configuresBlockGWAndArchiver); + other.getComponents(), other.getHistory(), other.isProtected, other.isDynamic, + other.configuresBlockGWAndArchiver, other.getGlobalmacros()); this.pv = other.pv; } @@ -251,4 +287,11 @@ public String toString() { public String getName() { return name; } + + /** + * @return A collection of the configuration's blocks + */ + public List getGlobalmacros() { + return globalmacros != null ? new ArrayList<>(globalmacros) : Collections.emptyList(); + } } diff --git a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/GlobalMacro.java b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/GlobalMacro.java new file mode 100644 index 0000000000..17b38ed45a --- /dev/null +++ b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/GlobalMacro.java @@ -0,0 +1,111 @@ +/* +* 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.configserver.configuration; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import uk.ac.stfc.isis.ibex.model.ModelObject; + +/** + * Represents a global macro. + * + * Contains the IOC name, or none, and a list of associated macros + * + */ +public class GlobalMacro extends ModelObject implements Comparable { + + private final String name; + + private Map macros; + + /** + * Create a Global Macro with a given name. + * + * @param name The IOC name (or global) + */ + public GlobalMacro(String name) { + this.name = name; + } + + /** + * Create a copy of a Global Macro list for an IOC (or global). + * + * @param globalMacro The Global Macro to copy + */ + public GlobalMacro(GlobalMacro globalMacro) { + this.name = globalMacro.getName(); + //this.macros = new ArrayList<>(globalMacro.getMacros()); + this.macros = new HashMap(globalMacro.getMacros()); + } + + /** + * @return The IOC name + */ + public String getName() { + return name; + } + + /** + * @return A collection of macros + */ + public Map getMacros() { + return Optional.ofNullable(macros).orElseGet(HashMap::new); + } + + /** + * Compares this GlobalMacro to another based on name. Used for sorting. + */ + @Override + public int compareTo(GlobalMacro other) { + if (this.name != null && other.name != null) { + return this.name.compareTo(other.name); + } + return 0; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + GlobalMacro other = (GlobalMacro) obj; + if (this.name == null && other.name == null) { + return true; + } + if (this.name == null || other.name == null) { + return false; + } + return this.name.equals(other.name); + } + + @Override + public int hashCode() { + return name == null ? 0 : name.hashCode(); + } + + @Override + public String toString() { + return "GlobalMacro [name=" + name + ", macros=" + macros + "]"; + } +} diff --git a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/editing/EditableConfiguration.java b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/editing/EditableConfiguration.java index 45d02ff007..44e354a706 100644 --- a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/editing/EditableConfiguration.java +++ b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/editing/EditableConfiguration.java @@ -1,6 +1,6 @@ /* - * This file is part of the ISIS IBEX application. Copyright (C) 2012-2017 + * 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 @@ -36,6 +36,7 @@ import uk.ac.stfc.isis.ibex.configserver.configuration.Block; import uk.ac.stfc.isis.ibex.configserver.configuration.ComponentInfo; import uk.ac.stfc.isis.ibex.configserver.configuration.Configuration; +import uk.ac.stfc.isis.ibex.configserver.configuration.GlobalMacro; import uk.ac.stfc.isis.ibex.configserver.configuration.Group; import uk.ac.stfc.isis.ibex.configserver.configuration.Ioc; import uk.ac.stfc.isis.ibex.configserver.configuration.Macro; @@ -142,7 +143,8 @@ public class EditableConfiguration extends ModelObject implements GroupNamesProv /** Current error message to be displayed **/ private String currentErrorMessage = noError; - + /** The global macros associated with any configuration. */ + private List globalmacros; /** * Listener for block renaming events. @@ -180,69 +182,67 @@ public void propertyChange(PropertyChangeEvent evt) { * @param pvs * The PVs available to the configuration */ - public EditableConfiguration( - Configuration config, - Collection iocs, - Collection components, - Collection pvs) { - this.name = config.name(); - this.description = config.description(); - this.synoptic = config.synoptic(); - this.isProtected = config.isProtected(); - this.isDynamic = config.isDynamic(); - this.configuresBlockGWAndArchiver = config.configuresBlockGWAndArchiver(); - originalProtectedFlag = this.isProtected; - this.allIocs = new ArrayList<>(); - this.managerMode = ManagerModeModel.getInstance(); - this.isSaveButtonEnabled = true; - this.enableSaveAsButton = true; - managerModePv = managerMode.getManagerModeObservable(); - - for (EditableIoc ioc : iocs) { - EditableIoc newIoc = new EditableIoc(ioc, ioc.getDescription()); - newIoc.setAvailableMacros(new ArrayList<>(ioc.getAvailableMacros())); - this.allIocs.add(newIoc); - } + public EditableConfiguration(Configuration config, Collection iocs, + Collection components, Collection pvs) { + this.name = config.name(); + this.description = config.description(); + this.synoptic = config.synoptic(); + this.isProtected = config.isProtected(); + this.isDynamic = config.isDynamic(); + this.configuresBlockGWAndArchiver = config.configuresBlockGWAndArchiver(); + originalProtectedFlag = this.isProtected; + this.allIocs = new ArrayList<>(); + this.managerMode = ManagerModeModel.getInstance(); + this.isSaveButtonEnabled = true; + this.enableSaveAsButton = true; + managerModePv = managerMode.getManagerModeObservable(); + + for (EditableIoc ioc : iocs) { + EditableIoc newIoc = new EditableIoc(ioc, ioc.getDescription()); + newIoc.setAvailableMacros(new ArrayList<>(ioc.getAvailableMacros())); + this.allIocs.add(newIoc); + } - this.history = new ArrayList<>(); + this.history = new ArrayList<>(); - for (String date : config.getHistory()) { - this.history.add(date); - } + for (String date : config.getHistory()) { + this.history.add(date); + } - this.pvs = new ArrayList<>(pvs); + this.pvs = new ArrayList<>(pvs); - for (Block block : config.getBlocks()) { - EditableBlock eb = new EditableBlock(block); - allBlocks.add(eb); - addRenameListener(eb); - } + for (Block block : config.getBlocks()) { + EditableBlock eb = new EditableBlock(block); + allBlocks.add(eb); + addRenameListener(eb); + } - for (Group group : config.getGroups()) { - if (!group.hasComponent()) { - editableGroups.add(new EditableGroup(this, group)); + for (Group group : config.getGroups()) { + if (!group.hasComponent()) { + editableGroups.add(new EditableGroup(this, group)); + } } - } - - editableGroups = new ArrayList<>(DisplayUtils.removeOtherGroup(editableGroups)); - for (EditableIoc ioc : allIocs) { - iocMap.put(ioc.getName(), ioc); - } - initMacros(iocMap); + editableGroups = new ArrayList<>(DisplayUtils.removeOtherGroup(editableGroups)); - for (Ioc ioc : config.getIocs()) { - addIoc(convertIoc(ioc)); - } + for (EditableIoc ioc : allIocs) { + iocMap.put(ioc.getName(), ioc); + } + initMacros(iocMap); + + for (Ioc ioc : config.getIocs()) { + addIoc(convertIoc(ioc)); + } - Collection selectedComponents = getComponentDetails(config.getComponents(), components); - editableComponents = new EditableComponents(selectedComponents, components); - editableComponents.addPropertyChangeListener(evt -> updateComponents()); + Collection selectedComponents = getComponentDetails(config.getComponents(), components); + editableComponents = new EditableComponents(selectedComponents, components); + editableComponents.addPropertyChangeListener(evt -> updateComponents()); - updateComponents(); - setEnableSaveAsButton(); - addObserver(); - } + updateComponents(); + setEnableSaveAsButton(); + addObserver(); + this.globalmacros = config.getGlobalmacros(); + } private EditableIoc convertIoc(Ioc ioc) { final EditableIoc generalIOC = iocMap.get(ioc.getName()); @@ -666,28 +666,31 @@ public void removeGroup(EditableGroup group) { firePropertyChange("groups", groupsBefore, transformGroups()); } - /** - * Return in a form suitable for saving as a configuration. - * - * @return the underlying configuration - */ - public Configuration asConfiguration() { - Configuration config = new Configuration(getName(), getDescription(), getSynoptic(), transformIocs(), transformBlocks(), - transformGroups(), transformComponents(), getHistory(), getIsProtected(), getIsDynamic(), getIfconfiguresBlockGWAndArchiver()); - return new ComponentFilteredConfiguration(config); - } + /** + * Return in a form suitable for saving as a configuration. + * + * @return the underlying configuration + */ + public Configuration asConfiguration() { + Configuration config = new Configuration(getName(), getDescription(), getSynoptic(), transformIocs(), + transformBlocks(), transformGroups(), transformComponents(), getHistory(), getIsProtected(), + getIsDynamic(), getIfconfiguresBlockGWAndArchiver(), getGlobalmacros()); + return new ComponentFilteredConfiguration(config); + } - /** - * Return in a form suitable for saving as a component - ie without - * contained components. - * - * @return the configuration as a component - */ - public Configuration asComponent() { - Configuration config = asConfiguration(); - return new Configuration(config.name(), config.description(), config.synoptic(), config.getIocs(), - config.getBlocks(), config.getGroups(), Collections.emptyList(), config.getHistory(), config.isProtected(), config.isDynamic(), config.configuresBlockGWAndArchiver()); - } + /** + * Return in a form suitable for saving as a component - ie without contained + * components. + * + * @return the configuration as a component + */ + public Configuration asComponent() { + Configuration config = asConfiguration(); + return new Configuration(config.name(), config.description(), config.synoptic(), config.getIocs(), + config.getBlocks(), config.getGroups(), Collections.emptyList(), config.getHistory(), + config.isProtected(), config.isDynamic(), config.configuresBlockGWAndArchiver(), + config.getGlobalmacros()); + } /** * Swaps the indices of two groups in the configuration (for moving them up @@ -898,4 +901,11 @@ public void close() { this.managerModeObservable.ifPresent(ManagerModeObserver::close); this.managerModeObservable = Optional.empty(); } + + /** + * @return the globalmacros + */ + public List getGlobalmacros() { + return globalmacros; + } } diff --git a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/internal/ComponentFilteredConfiguration.java b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/internal/ComponentFilteredConfiguration.java index ee5ab96453..175f9b8175 100644 --- a/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/internal/ComponentFilteredConfiguration.java +++ b/base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/internal/ComponentFilteredConfiguration.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. @@ -41,9 +41,10 @@ public class ComponentFilteredConfiguration extends Configuration { * The unfiltered configuration */ public ComponentFilteredConfiguration(Configuration other) { - super(other.name(), other.description(), other.synoptic(), filterIocs(other.getIocs()), - filterBlocks(other.getBlocks()), filterGroups(other.getGroups()), other.getComponents(), - other.getHistory(), other.isProtected(), other.isDynamic(), other.configuresBlockGWAndArchiver()); + super(other.name(), other.description(), other.synoptic(), filterIocs(other.getIocs()), + filterBlocks(other.getBlocks()), filterGroups(other.getGroups()), other.getComponents(), + other.getHistory(), other.isProtected(), other.isDynamic(), other.configuresBlockGWAndArchiver(), + other.getGlobalmacros()); } /** diff --git a/base/uk.ac.stfc.isis.ibex.targetplatform/targetplatform.target b/base/uk.ac.stfc.isis.ibex.targetplatform/targetplatform.target index f9b1ad2dd0..82801c13b5 100644 --- a/base/uk.ac.stfc.isis.ibex.targetplatform/targetplatform.target +++ b/base/uk.ac.stfc.isis.ibex.targetplatform/targetplatform.target @@ -91,8 +91,8 @@ - - + + diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/AddBlockToConfigHelper.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/AddBlockToConfigHelper.java index 9d44f04843..424ffc96aa 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/AddBlockToConfigHelper.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/AddBlockToConfigHelper.java @@ -1,6 +1,25 @@ +/** +* 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.commands.helpers; import java.io.IOException; +import java.util.Optional; + import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import uk.ac.stfc.isis.ibex.configserver.ConfigServer; @@ -40,8 +59,10 @@ public void openDialogs(EditableConfiguration config, boolean isCurrent, boolean boolean openEditBlockDialog, String pvName) throws IOException { config.setIsComponent(false); final String configName = getConfigDisplayName(config, isCurrent); - final String subTitle = "Editing the " + configName + " configuration"; - + String subTitle = "Editing the " + configName + " configuration"; + if (Optional.ofNullable(config.getGlobalmacros()).map(l -> l.isEmpty()).orElse(true)) { + subTitle += "\n\nNote: There also are global macros defined. See the Global Macros tab.\\n\\nThey over-ride IOC level macro"; + } EditConfigDialog dialog = new EditConfigDialog(shell, title, subTitle, config, false, configurationViewModels, editBlockFirst, openEditBlockDialog, pvName); // Creating dialog to edit configuration dialog.addNew(config); // Open edit block dialog before editing the configuration diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/EditConfigHelper.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/EditConfigHelper.java index 6d0f617e04..3941e8d019 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/EditConfigHelper.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/EditConfigHelper.java @@ -1,7 +1,7 @@ /* * This file is part of the ISIS IBEX application. - * Copyright (C) 2012-2016 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. @@ -58,7 +58,10 @@ public EditConfigHelper(Shell shell, ConfigServer server) { protected void openDialog(EditableConfiguration config, boolean isCurrent, boolean editBlockFirst) { config.setIsComponent(false); final String configName = getConfigDisplayName(config, isCurrent); - final String subTitle = "Editing the " + configName + " configuration"; + String subTitle = "Editing the " + configName + " configuration"; + if (!(null == config.getGlobalmacros()) && !config.getGlobalmacros().isEmpty()) { + subTitle += "\nNote: There also are global macros defined. See the Global Macros tab.\nThey over-ride IOC level macro"; + } EditConfigDialog dialog = new EditConfigDialog(shell, title, subTitle, config, false, configurationViewModels, editBlockFirst); diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/ViewConfigHelper.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/ViewConfigHelper.java index e381ae732f..386df2e94b 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/ViewConfigHelper.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/commands/helpers/ViewConfigHelper.java @@ -1,7 +1,6 @@ - /* * This file is part of the ISIS IBEX application. - * Copyright (C) 2012-2016 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. @@ -22,6 +21,8 @@ */ package uk.ac.stfc.isis.ibex.ui.configserver.commands.helpers; +import java.util.Optional; + import org.eclipse.swt.widgets.Shell; import uk.ac.stfc.isis.ibex.configserver.editing.EditableConfiguration; @@ -58,7 +59,10 @@ public ViewConfigHelper(Shell shell) { protected void openDialog(EditableConfiguration config, boolean isCurrent, boolean editBlockFirst) { final String configName = getConfigDisplayName(config, isCurrent); - final String subTitle = "Viewing the " + configName + " configuration"; + String subTitle = "Viewing the " + configName + " configuration"; + if (Optional.ofNullable(config.getGlobalmacros()).map(l -> l.isEmpty()).orElse(true)) { + subTitle += "\nNote: There also are global macros defined. See the Global Macros tab.\nThey over-ride IOC level macro"; + } config.setIsComponent(false); ConfigDetailsDialog dialog = diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/ConfigEditorPanel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/ConfigEditorPanel.java index 890c55843e..de66c3c3b3 100644 --- a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/ConfigEditorPanel.java +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/ConfigEditorPanel.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. @@ -35,6 +35,7 @@ import uk.ac.stfc.isis.ibex.ui.configserver.editing.components.ComponentEditorPanel; import uk.ac.stfc.isis.ibex.ui.configserver.editing.groups.GroupsEditorPanel; import uk.ac.stfc.isis.ibex.ui.configserver.editing.iocs.IocOverviewPanel; +import uk.ac.stfc.isis.ibex.ui.configserver.editing.macros.GlobalMacroOverviewPanel; import uk.ac.stfc.isis.ibex.ui.configserver.editing.summary.SummaryPanel; import uk.ac.stfc.isis.ibex.validators.MessageDisplayer; @@ -122,6 +123,13 @@ public void widgetSelected(SelectionEvent e) { groupsTab.setControl(groups); setConfigToEdit(config); + + if (!config.getGlobalmacros().isEmpty()) { + final GlobalMacroOverviewPanel globalMacros = new GlobalMacroOverviewPanel(editorTabs, config); + TabItem globalMacrosTab = new TabItem(editorTabs, SWT.NONE); + globalMacrosTab.setText("Global Macros"); + globalMacrosTab.setControl(globalMacros); + } } /** diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroOverviewPanel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroOverviewPanel.java new file mode 100644 index 0000000000..c1ca746fd8 --- /dev/null +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroOverviewPanel.java @@ -0,0 +1,73 @@ +/* +* 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.macros; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; + +import uk.ac.stfc.isis.ibex.configserver.configuration.GlobalMacro; +import uk.ac.stfc.isis.ibex.configserver.editing.EditableConfiguration; + +/** + * Panel showing an overview of all global macros. + */ +@SuppressWarnings("checkstyle:magicnumber") +public class GlobalMacroOverviewPanel extends Composite { + private Collection macros; + private final GlobalMacroTable table; + + /** + * Constructor for the Macro panel. + * + * @param parent The parent composite. + * @param config The configuration details. + */ + public GlobalMacroOverviewPanel(Composite parent, EditableConfiguration config) { + super(parent, SWT.NONE); + setLayout(new FillLayout(SWT.HORIZONTAL)); + table = new GlobalMacroTable(this, SWT.NONE, SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); + GridData grid = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + grid.widthHint = 428; + table.setLayoutData(grid); + setMacros(config.getGlobalmacros()); + table.setRows(macros); + } + + /** + * Sets the macros to be displayed by the panel. + * + * @param globalmacros The macros that are defined at the global level. + */ + public void setMacros(final List globalmacros) { + macros = (globalmacros == null) ? new ArrayList<>() + : globalmacros.stream().sorted().filter(Objects::nonNull) + .flatMap(macro -> macro.getMacros().entrySet().stream().sorted(Map.Entry.comparingByKey()).map( + entry -> new GlobalMacroViewModel(macro.getName(), entry.getKey(), entry.getValue()))) + .collect(Collectors.toList()); + } +} diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroTable.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroTable.java new file mode 100644 index 0000000000..23e3332f8b --- /dev/null +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroTable.java @@ -0,0 +1,113 @@ +/* +* 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.macros; + +import java.util.Collection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import uk.ac.stfc.isis.ibex.ui.tables.DataboundCellLabelProvider; +import uk.ac.stfc.isis.ibex.ui.tables.DataboundTable; + +/** + * The table for viewing global macros. + */ +public class GlobalMacroTable extends DataboundTable { + private static final int COLUMN_WIDTH = 5; + private enum Columns { + IOC_NAME("IOC Name", "iocName"), MACRO_NAME("Macro Name", "macroName"), MACRO_VALUE("Macro Value", "macroValue"); + + private String columnName; + private String propertyName; + Columns(String columnName, String propertyName) { + this.columnName = columnName; + this.propertyName = propertyName; + } + } + + /** + * Constructor for the table. + * + * @param parent The composite to put the table in. + * @param style The SWT style of this databound table. + * @param tableStyle The SWT style of the inner table object. + */ + public GlobalMacroTable(Composite parent, int style, int tableStyle) { + super(parent, style, tableStyle | SWT.BORDER); + initialise(); + } + + /** + * Sets the rows of the table. + * @param rows The rows to set. + */ + @Override + public void setRows(Collection rows) { + super.setRows(rows); + super.refresh(); + } + + /** + * Adds the columns to the table. + */ + @Override + protected void addColumns() { + iocName(); + macroName(); + macroValue(); + } + + /** + * Creates the IOC Name column. + */ + private void iocName() { + createColumn(Columns.IOC_NAME.columnName, COLUMN_WIDTH, + new DataboundCellLabelProvider(observeProperty(Columns.IOC_NAME.propertyName)) { + @Override + protected String stringFromRow(GlobalMacroViewModel row) { + return row.getIocName(); + } + }); + } + + /** + * Creates the Macro Name column. + */ + private void macroName() { + createColumn(Columns.MACRO_NAME.columnName, COLUMN_WIDTH, + new DataboundCellLabelProvider(observeProperty(Columns.MACRO_NAME.propertyName)) { + @Override + protected String stringFromRow(GlobalMacroViewModel row) { + return row.getMacroName(); + } + }); + } + + /** + * Creates the Macro value column. + */ + private void macroValue() { + createColumn(Columns.MACRO_VALUE.columnName, COLUMN_WIDTH, new DataboundCellLabelProvider( + observeProperty(Columns.MACRO_VALUE.propertyName)) { + @Override + protected String stringFromRow(GlobalMacroViewModel row) { + return row.getMacroValue(); + } + }); + } +} diff --git a/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroViewModel.java b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroViewModel.java new file mode 100644 index 0000000000..6e14f7d75f --- /dev/null +++ b/base/uk.ac.stfc.isis.ibex.ui.configserver/src/uk/ac/stfc/isis/ibex/ui/configserver/editing/macros/GlobalMacroViewModel.java @@ -0,0 +1,67 @@ +/* +* 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.macros; + +import uk.ac.stfc.isis.ibex.model.ModelObject; + +/** + * View model for the global macro, just a container for the global macro values. + */ +public class GlobalMacroViewModel extends ModelObject { + + private final String iocName; + private final String macroName; + private final String macroValue; + + private static final String IOC_SEPARATOR = "__"; + private static final String ALL_IOCS = "All IOCs"; + + /** + * Constructor. Sets the use default based on provided macro. + * + * @param iocName The IOC Name. + * @param macroName The Macro Name. + * @param macroValue The Macro Value. + */ + public GlobalMacroViewModel(String iocName, String macroName, String macroValue) { + this.iocName = !IOC_SEPARATOR.equals(iocName) ? iocName : ALL_IOCS; + this.macroName = macroName; + this.macroValue = macroValue; + } + + /** + * @return the iocName + */ + public String getIocName() { + return iocName; + } + + /** + * @return the macroName + */ + public String getMacroName() { + return macroName; + } + + /** + * @return the macroValue + */ + public String getMacroValue() { + return macroValue; + } +}