Skip to content

Commit 4e3f053

Browse files
ChsudeeptaChsudeepta
authored andcommitted
Global macros related changes
1 parent d0a1c4b commit 4e3f053

File tree

14 files changed

+420
-115
lines changed

14 files changed

+420
-115
lines changed

base/uk.ac.stfc.isis.ibex.configserver.tests/src/uk/ac/stfc/isis/ibex/configserver/tests/json/JsonConvertersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void conversion_config_to_string() throws ConversionException {
242242
//Arrange
243243
Function<Configuration, String> conv = new JsonConverters().configToString();
244244
Configuration testConfig = new Configuration(configName, configDescription);
245-
String expected = "{\"name\":\"" + configName + "\",\"description\":\"" + configDescription + "\",\"isProtected\":false,\"isDynamic\":false,\"configuresBlockGWAndArchiver\":false,\"iocs\":[],\"blocks\":[],\"groups\":[],\"components\":[],\"history\":[]}";
245+
String expected = "{\"name\":\"" + configName + "\",\"description\":\"" + configDescription + "\",\"isProtected\":false,\"isDynamic\":false,\"configuresBlockGWAndArchiver\":false,\"iocs\":[],\"blocks\":[],\"groups\":[],\"components\":[],\"history\":[],\"globalmacros\":[]}";
246246

247247
//Act
248248
String test = conv.apply(testConfig);

base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/Configurations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
* This file is part of the ISIS IBEX application.
4-
* Copyright (C) 2012-2015 Science & Technology Facilities Council.
4+
* Copyright (C) 2012-2025 Science & Technology Facilities Council.
55
* All rights reserved.
66
*
77
* This program is distributed in the hope that it will be useful.

base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/Configuration.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class Configuration extends ModelObject {
5050
private List<Group> groups = new ArrayList<>();
5151
private List<ComponentInfo> components = new ArrayList<>();
5252
private List<String> history = new ArrayList<>();
53-
private List<GlobalMacro> globalMacros = new ArrayList<>();
53+
private List<GlobalMacro> globalmacros = new ArrayList<>();
5454

5555
/**
5656
* Create a new configuration.
@@ -82,12 +82,12 @@ public Configuration(String name, String description) {
8282
* automatically
8383
* @param configuresBlockGWAndArchiver True this configuration includes the block gateway and archive files;
8484
* False these are generated by the block server
85-
* @param globalMacros The global macros
85+
* @param globalmacros The global macros
8686
*/
8787
public Configuration(String name, String description, String defaultSynoptic, Collection<Ioc> iocs,
8888
Collection<Block> blocks, Collection<Group> groups, Collection<ComponentInfo> components,
8989
Collection<String> history, boolean isProtected, boolean isDynamic,
90-
boolean configuresBlockGWAndArchiver, Collection<GlobalMacro> globalMacros) {
90+
boolean configuresBlockGWAndArchiver, Collection<GlobalMacro> globalmacros) {
9191
this.name = name;
9292
this.description = description;
9393
this.synoptic = defaultSynoptic == null || defaultSynoptic.equals("") ? ConfigEditing.NONE_SYNOPTIC_NAME
@@ -117,9 +117,9 @@ public Configuration(String name, String description, String defaultSynoptic, Co
117117
this.history.add(date);
118118
}
119119

120-
if (null != globalMacros) {
121-
for (GlobalMacro globalMacro : globalMacros) {
122-
this.globalMacros.add(new GlobalMacro(globalMacro));
120+
if (null != globalmacros) {
121+
for (GlobalMacro globalMacro : globalmacros) {
122+
this.globalmacros.add(new GlobalMacro(globalMacro));
123123
}
124124
}
125125
}
@@ -159,7 +159,7 @@ public Configuration(String name, String description, String defaultSynoptic, Co
159159
public Configuration(Configuration other) {
160160
this(other.name(), other.description(), other.synoptic(), other.getIocs(), other.getBlocks(), other.getGroups(),
161161
other.getComponents(), other.getHistory(), other.isProtected, other.isDynamic,
162-
other.configuresBlockGWAndArchiver, other.getGlobalMacros());
162+
other.configuresBlockGWAndArchiver, other.getGlobalmacros());
163163
this.pv = other.pv;
164164
}
165165

@@ -291,7 +291,7 @@ public String getName() {
291291
/**
292292
* @return A collection of the configuration's blocks
293293
*/
294-
public List<GlobalMacro> getGlobalMacros() {
295-
return globalMacros != null ? new ArrayList<>(globalMacros) : Collections.<GlobalMacro>emptyList();
294+
public List<GlobalMacro> getGlobalmacros() {
295+
return globalmacros != null ? new ArrayList<>(globalmacros) : Collections.<GlobalMacro>emptyList();
296296
}
297297
}

base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/GlobalMacro.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
package uk.ac.stfc.isis.ibex.configserver.configuration;
2020

21-
import java.util.ArrayList;
22-
import java.util.List;
21+
import java.util.HashMap;
22+
import java.util.Map;
2323
import java.util.Optional;
2424

2525
import uk.ac.stfc.isis.ibex.model.ModelObject;
@@ -30,11 +30,11 @@
3030
* Contains the IOC name, or none, and a list of associated macros
3131
*
3232
*/
33-
public class GlobalMacro extends ModelObject {
33+
public class GlobalMacro extends ModelObject implements Comparable<GlobalMacro> {
3434

3535
private final String name;
3636

37-
private List<Macro> macros;
37+
private Map<String, String> macros;
3838

3939
/**
4040
* Create a Global Macro with a given name.
@@ -52,7 +52,8 @@ public GlobalMacro(String name) {
5252
*/
5353
public GlobalMacro(GlobalMacro globalMacro) {
5454
this.name = globalMacro.getName();
55-
this.macros = new ArrayList<>(globalMacro.getMacros());
55+
//this.macros = new ArrayList<>(globalMacro.getMacros());
56+
this.macros = new HashMap<String, String>(globalMacro.getMacros());
5657
}
5758

5859
/**
@@ -65,16 +66,19 @@ public String getName() {
6566
/**
6667
* @return A collection of macros
6768
*/
68-
public List<Macro> getMacros() {
69-
return Optional.ofNullable(macros).orElseGet(ArrayList::new);
69+
public Map<String, String> getMacros() {
70+
return Optional.ofNullable(macros).orElseGet(HashMap::new);
7071
}
71-
72-
/**
73-
* @param macros
74-
* Set the IOC macros
75-
*/
76-
public void setMacros(List<Macro> macros) {
77-
firePropertyChange("macros", this.macros, this.macros = macros);
72+
73+
/**
74+
* Compares this GlobalMacro to another based on name. Used for sorting.
75+
*/
76+
@Override
77+
public int compareTo(GlobalMacro other) {
78+
if (this.name != null && other.name != null) {
79+
return this.name.compareTo(other.name);
80+
}
81+
return 0;
7882
}
7983

8084
}

base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/editing/EditableConfiguration.java

Lines changed: 86 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/*
3-
* This file is part of the ISIS IBEX application. Copyright (C) 2012-2017
3+
* This file is part of the ISIS IBEX application. Copyright (C) 2012-2025
44
* Science & Technology Facilities Council. All rights reserved.
55
*
66
* This program is distributed in the hope that it will be useful. This program
@@ -36,6 +36,7 @@
3636
import uk.ac.stfc.isis.ibex.configserver.configuration.Block;
3737
import uk.ac.stfc.isis.ibex.configserver.configuration.ComponentInfo;
3838
import uk.ac.stfc.isis.ibex.configserver.configuration.Configuration;
39+
import uk.ac.stfc.isis.ibex.configserver.configuration.GlobalMacro;
3940
import uk.ac.stfc.isis.ibex.configserver.configuration.Group;
4041
import uk.ac.stfc.isis.ibex.configserver.configuration.Ioc;
4142
import uk.ac.stfc.isis.ibex.configserver.configuration.Macro;
@@ -142,7 +143,8 @@ public class EditableConfiguration extends ModelObject implements GroupNamesProv
142143
/** Current error message to be displayed **/
143144
private String currentErrorMessage = noError;
144145

145-
146+
/** The global macros associated with any configuration. */
147+
private List<GlobalMacro> globalmacros;
146148

147149
/**
148150
* Listener for block renaming events.
@@ -180,69 +182,67 @@ public void propertyChange(PropertyChangeEvent evt) {
180182
* @param pvs
181183
* The PVs available to the configuration
182184
*/
183-
public EditableConfiguration(
184-
Configuration config,
185-
Collection<EditableIoc> iocs,
186-
Collection<Configuration> components,
187-
Collection<PV> pvs) {
188-
this.name = config.name();
189-
this.description = config.description();
190-
this.synoptic = config.synoptic();
191-
this.isProtected = config.isProtected();
192-
this.isDynamic = config.isDynamic();
193-
this.configuresBlockGWAndArchiver = config.configuresBlockGWAndArchiver();
194-
originalProtectedFlag = this.isProtected;
195-
this.allIocs = new ArrayList<>();
196-
this.managerMode = ManagerModeModel.getInstance();
197-
this.isSaveButtonEnabled = true;
198-
this.enableSaveAsButton = true;
199-
managerModePv = managerMode.getManagerModeObservable();
200-
201-
for (EditableIoc ioc : iocs) {
202-
EditableIoc newIoc = new EditableIoc(ioc, ioc.getDescription());
203-
newIoc.setAvailableMacros(new ArrayList<>(ioc.getAvailableMacros()));
204-
this.allIocs.add(newIoc);
205-
}
185+
public EditableConfiguration(Configuration config, Collection<EditableIoc> iocs,
186+
Collection<Configuration> components, Collection<PV> pvs) {
187+
this.name = config.name();
188+
this.description = config.description();
189+
this.synoptic = config.synoptic();
190+
this.isProtected = config.isProtected();
191+
this.isDynamic = config.isDynamic();
192+
this.configuresBlockGWAndArchiver = config.configuresBlockGWAndArchiver();
193+
originalProtectedFlag = this.isProtected;
194+
this.allIocs = new ArrayList<>();
195+
this.managerMode = ManagerModeModel.getInstance();
196+
this.isSaveButtonEnabled = true;
197+
this.enableSaveAsButton = true;
198+
managerModePv = managerMode.getManagerModeObservable();
199+
200+
for (EditableIoc ioc : iocs) {
201+
EditableIoc newIoc = new EditableIoc(ioc, ioc.getDescription());
202+
newIoc.setAvailableMacros(new ArrayList<>(ioc.getAvailableMacros()));
203+
this.allIocs.add(newIoc);
204+
}
206205

207-
this.history = new ArrayList<>();
206+
this.history = new ArrayList<>();
208207

209-
for (String date : config.getHistory()) {
210-
this.history.add(date);
211-
}
208+
for (String date : config.getHistory()) {
209+
this.history.add(date);
210+
}
212211

213-
this.pvs = new ArrayList<>(pvs);
212+
this.pvs = new ArrayList<>(pvs);
214213

215-
for (Block block : config.getBlocks()) {
216-
EditableBlock eb = new EditableBlock(block);
217-
allBlocks.add(eb);
218-
addRenameListener(eb);
219-
}
214+
for (Block block : config.getBlocks()) {
215+
EditableBlock eb = new EditableBlock(block);
216+
allBlocks.add(eb);
217+
addRenameListener(eb);
218+
}
220219

221-
for (Group group : config.getGroups()) {
222-
if (!group.hasComponent()) {
223-
editableGroups.add(new EditableGroup(this, group));
220+
for (Group group : config.getGroups()) {
221+
if (!group.hasComponent()) {
222+
editableGroups.add(new EditableGroup(this, group));
223+
}
224224
}
225-
}
226-
227-
editableGroups = new ArrayList<>(DisplayUtils.removeOtherGroup(editableGroups));
228225

229-
for (EditableIoc ioc : allIocs) {
230-
iocMap.put(ioc.getName(), ioc);
231-
}
232-
initMacros(iocMap);
226+
editableGroups = new ArrayList<>(DisplayUtils.removeOtherGroup(editableGroups));
233227

234-
for (Ioc ioc : config.getIocs()) {
235-
addIoc(convertIoc(ioc));
236-
}
228+
for (EditableIoc ioc : allIocs) {
229+
iocMap.put(ioc.getName(), ioc);
230+
}
231+
initMacros(iocMap);
232+
233+
for (Ioc ioc : config.getIocs()) {
234+
addIoc(convertIoc(ioc));
235+
}
237236

238-
Collection<Configuration> selectedComponents = getComponentDetails(config.getComponents(), components);
239-
editableComponents = new EditableComponents(selectedComponents, components);
240-
editableComponents.addPropertyChangeListener(evt -> updateComponents());
237+
Collection<Configuration> selectedComponents = getComponentDetails(config.getComponents(), components);
238+
editableComponents = new EditableComponents(selectedComponents, components);
239+
editableComponents.addPropertyChangeListener(evt -> updateComponents());
241240

242-
updateComponents();
243-
setEnableSaveAsButton();
244-
addObserver();
245-
}
241+
updateComponents();
242+
setEnableSaveAsButton();
243+
addObserver();
244+
this.globalmacros = config.getGlobalmacros();
245+
}
246246

247247
private EditableIoc convertIoc(Ioc ioc) {
248248
final EditableIoc generalIOC = iocMap.get(ioc.getName());
@@ -666,28 +666,31 @@ public void removeGroup(EditableGroup group) {
666666
firePropertyChange("groups", groupsBefore, transformGroups());
667667
}
668668

669-
/**
670-
* Return in a form suitable for saving as a configuration.
671-
*
672-
* @return the underlying configuration
673-
*/
674-
public Configuration asConfiguration() {
675-
Configuration config = new Configuration(getName(), getDescription(), getSynoptic(), transformIocs(), transformBlocks(),
676-
transformGroups(), transformComponents(), getHistory(), getIsProtected(), getIsDynamic(), getIfconfiguresBlockGWAndArchiver());
677-
return new ComponentFilteredConfiguration(config);
678-
}
669+
/**
670+
* Return in a form suitable for saving as a configuration.
671+
*
672+
* @return the underlying configuration
673+
*/
674+
public Configuration asConfiguration() {
675+
Configuration config = new Configuration(getName(), getDescription(), getSynoptic(), transformIocs(),
676+
transformBlocks(), transformGroups(), transformComponents(), getHistory(), getIsProtected(),
677+
getIsDynamic(), getIfconfiguresBlockGWAndArchiver(), getGlobalmacros());
678+
return new ComponentFilteredConfiguration(config);
679+
}
679680

680-
/**
681-
* Return in a form suitable for saving as a component - ie without
682-
* contained components.
683-
*
684-
* @return the configuration as a component
685-
*/
686-
public Configuration asComponent() {
687-
Configuration config = asConfiguration();
688-
return new Configuration(config.name(), config.description(), config.synoptic(), config.getIocs(),
689-
config.getBlocks(), config.getGroups(), Collections.<ComponentInfo>emptyList(), config.getHistory(), config.isProtected(), config.isDynamic(), config.configuresBlockGWAndArchiver());
690-
}
681+
/**
682+
* Return in a form suitable for saving as a component - ie without contained
683+
* components.
684+
*
685+
* @return the configuration as a component
686+
*/
687+
public Configuration asComponent() {
688+
Configuration config = asConfiguration();
689+
return new Configuration(config.name(), config.description(), config.synoptic(), config.getIocs(),
690+
config.getBlocks(), config.getGroups(), Collections.<ComponentInfo>emptyList(), config.getHistory(),
691+
config.isProtected(), config.isDynamic(), config.configuresBlockGWAndArchiver(),
692+
config.getGlobalmacros());
693+
}
691694

692695
/**
693696
* Swaps the indices of two groups in the configuration (for moving them up
@@ -898,4 +901,11 @@ public void close() {
898901
this.managerModeObservable.ifPresent(ManagerModeObserver::close);
899902
this.managerModeObservable = Optional.empty();
900903
}
904+
905+
/**
906+
* @return the globalmacros
907+
*/
908+
public List<GlobalMacro> getGlobalmacros() {
909+
return globalmacros;
910+
}
901911
}

base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/internal/ComponentFilteredConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
* This file is part of the ISIS IBEX application.
4-
* Copyright (C) 2012-2015 Science & Technology Facilities Council.
4+
* Copyright (C) 2012-2025 Science & Technology Facilities Council.
55
* All rights reserved.
66
*
77
* This program is distributed in the hope that it will be useful.
@@ -41,9 +41,10 @@ public class ComponentFilteredConfiguration extends Configuration {
4141
* The unfiltered configuration
4242
*/
4343
public ComponentFilteredConfiguration(Configuration other) {
44-
super(other.name(), other.description(), other.synoptic(), filterIocs(other.getIocs()),
45-
filterBlocks(other.getBlocks()), filterGroups(other.getGroups()), other.getComponents(),
46-
other.getHistory(), other.isProtected(), other.isDynamic(), other.configuresBlockGWAndArchiver());
44+
super(other.name(), other.description(), other.synoptic(), filterIocs(other.getIocs()),
45+
filterBlocks(other.getBlocks()), filterGroups(other.getGroups()), other.getComponents(),
46+
other.getHistory(), other.isProtected(), other.isDynamic(), other.configuresBlockGWAndArchiver(),
47+
other.getGlobalmacros());
4748
}
4849

4950
/**

base/uk.ac.stfc.isis.ibex.targetplatform/targetplatform.target

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
</location>
9292
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
9393
<repository location="http://shadow.nd.rl.ac.uk/ICP_P2/Pydev/features/org.python.pydev.p2-repo/target/repository/"/>
94-
<unit id="org.python.pydev.feature.feature.group" version="11.0.3.202408070859"/>
95-
<unit id="org.python.pydev.feature.source.feature.group" version="11.0.3.202408070859"/>
94+
<unit id="org.python.pydev.feature.feature.group" version="13.1.0.202511051529"/>
95+
<unit id="org.python.pydev.feature.source.feature.group" version="13.1.0.202511051529"/>
9696
</location>
9797
<location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="generate" type="Maven">
9898
<dependencies>

0 commit comments

Comments
 (0)