I think the optimal place to insert the code to re-number load priorities would be in the com.affymetrix.igb.general package in the file:
DataProviderTableModel.java.
The new code should probably go in the sortDataSources function. If that function is called overly often (at times when we might not want to re-number the load priorities) then the re-number can be its own function, probably still in that file and it would start by calling the sortDataSources. Before implementing this change, we would need to get a complete view of where sortDataSources is called.
public void sortDataSources()
{
sortedDataProviders = Lists.newArrayList(DataProviderManager.getAllServers());
Collections.sort(sortedDataProviders, new DataProviderComparator());
ThreadUtils.runOnEventQueue(() -> fireTableDataChanged());
}
This code is not run until the Data Sources table is opened (so we will probably avoid colliding with the initial start-up period where only some of the data providers have been loaded). Since the Data Sources table is the only place where a user can change the load priority of the data providers, this is an optimal place for code that ensures the functionality of that feature.
The code that is executed when the up/down buttons are pressed is spelled out in DataProviderManaementGui.java, in the functions initLoadPriorityUpBtn and initLoadPriorityDownBtn respectively. Each of these calls the sortDataSources function.
So if the re-numbering is part of sort, then its already set to be triggered by these events.
We also need to make sure the re-numbering code is triggered by the adding or removing a data provider.
The add function is handled by the AddDataProvider class though a function called addServerButtonActionPerformed. The code to remove a data provider is in the DataProviderManager class in a function called: removeDataProvider.
Both end with this call:
eventBus.post(new DataProviderServiceChangeEvent());
I don't know how this DataProviderServiceChangeEvent object works, but I think it might be helpful. If this is meant to signal that the set of data providers has changed, then we need to find whatever code it triggers and make sure our sort and re-number code in triggered by it. Something like that would be cleaner than adding code to each function to call the sort function.
A potential solution:
There is a sort function for the data providers.
--Add code to that function to renumber the load priorities after sorting.
--make sure the sort function is called any time the set is modified and when the set is first called (ie, to populate the table)
This sort and re-number cycle will usually have no affect, but it will smooth out all of the cases where multiple data providers have the same load priority. If each new user-added data provider is added with a load priority of -1, and the set is immediately sorted and re-numbered, the -1 will become 0 and all other data providers will have subsequent unique consecutive load priority values.
The only hazard this can make is in the initial loading phase. We must NOT re-number the load priorities until IGB has read all of the data providers into the set.