1
1
/*
2
+ * *****************************************************************************
3
+ * Copyright (C) 2014-2024 Dennis Sheirer
2
4
*
3
- * * ******************************************************************************
4
- * * Copyright (C) 2014-2020 Dennis Sheirer
5
- * *
6
- * * This program is free software: you can redistribute it and/or modify
7
- * * it under the terms of the GNU General Public License as published by
8
- * * the Free Software Foundation, either version 3 of the License, or
9
- * * (at your option) any later version.
10
- * *
11
- * * This program is distributed in the hope that it will be useful,
12
- * * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * * GNU General Public License for more details.
15
- * *
16
- * * You should have received a copy of the GNU General Public License
17
- * * along with this program. If not, see <http://www.gnu.org/licenses/>
18
- * * *****************************************************************************
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
19
9
*
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
20
14
*
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
17
+ * ****************************************************************************
21
18
*/
22
19
package io .github .dsheirer .controller .channel ;
23
20
26
23
import io .github .dsheirer .controller .channel .ChannelEvent .Event ;
27
24
import io .github .dsheirer .sample .Broadcaster ;
28
25
import io .github .dsheirer .sample .Listener ;
29
- import javafx .collections .FXCollections ;
30
- import javafx .collections .ListChangeListener ;
31
- import javafx .collections .ObservableList ;
32
-
33
26
import java .util .ArrayList ;
34
27
import java .util .Collections ;
35
- import java .util .Comparator ;
36
28
import java .util .List ;
29
+ import javafx .collections .FXCollections ;
30
+ import javafx .collections .ListChangeListener ;
31
+ import javafx .collections .ObservableList ;
37
32
38
33
/**
39
34
* Channel Model
@@ -55,6 +50,58 @@ public ChannelModel(AliasModel aliasModel)
55
50
mTrafficChannels .addListener (changeListener );
56
51
}
57
52
53
+ /**
54
+ * Get a deduplicated list of alias list names from across the channel configurations.
55
+ * @return list of alias list names.
56
+ */
57
+ public List <String > getAliasListNames ()
58
+ {
59
+ List <String > aliasListNames = new ArrayList <>();
60
+
61
+ for (Channel channel : mChannels )
62
+ {
63
+ String aliasListName = channel .getAliasListName ();
64
+
65
+ if (aliasListName != null && !aliasListName .isEmpty () && !aliasListNames .contains (aliasListName ))
66
+ {
67
+ aliasListNames .add (aliasListName );
68
+ }
69
+ }
70
+
71
+ return aliasListNames ;
72
+ }
73
+
74
+ /**
75
+ * Renames the alias list across the set of aliases.
76
+ * @param oldName currently used by the alias
77
+ * @param newName to apply to the alias
78
+ */
79
+ public void renameAliasList (String oldName , String newName )
80
+ {
81
+ if (oldName == null || oldName .isEmpty () || newName == null || newName .isEmpty ())
82
+ {
83
+ return ;
84
+ }
85
+
86
+ mChannels .stream ().filter (channel -> channel .getAliasListName ().equals (oldName ))
87
+ .forEach (channel -> channel .setAliasListName (newName ));
88
+ }
89
+
90
+ /**
91
+ * Deletes any aliases that have the alias list name
92
+ * @param aliasListName to delete
93
+ */
94
+ public void deleteAliasList (String aliasListName )
95
+ {
96
+ if (aliasListName == null || aliasListName .isEmpty ())
97
+ {
98
+ return ;
99
+ }
100
+
101
+ mChannels .stream ().filter (channel -> channel .getAliasListName ().equals (aliasListName ))
102
+ .forEach (channel -> channel .setAliasListName (null ));
103
+ }
104
+
58
105
/**
59
106
* Observable list of channel configurations managed by this model
60
107
*/
@@ -109,6 +156,45 @@ public Channel getChannelAtIndex(int row)
109
156
return null ;
110
157
}
111
158
159
+ /**
160
+ * Renames the alias list across all channels.
161
+ * @param existing alias list name
162
+ * @param renamed alias list name.
163
+ */
164
+ public void renameAliaslistForChannels (String existing , String renamed )
165
+ {
166
+ if (existing == null || existing .isEmpty () || renamed == null || renamed .isEmpty ())
167
+ {
168
+ return ;
169
+ }
170
+
171
+ mChannels .forEach (channel -> {
172
+ if (channel .getAliasListName () != null && channel .getAliasListName ().equals (existing ))
173
+ {
174
+ channel .setAliasListName (renamed );
175
+ }
176
+ });
177
+ }
178
+
179
+ /**
180
+ * Removes the alias list name from any channels.
181
+ * @param name to delete
182
+ */
183
+ public void deleteAliasListName (String name )
184
+ {
185
+ if (name == null || name .isEmpty ())
186
+ {
187
+ return ;
188
+ }
189
+
190
+ mChannels .forEach (channel -> {
191
+ if (channel .getAliasListName () != null && channel .getAliasListName ().equals (name ))
192
+ {
193
+ channel .setAliasListName (null );
194
+ }
195
+ });
196
+ }
197
+
112
198
/**
113
199
* Returns a list of unique system values from across the channel set
114
200
*/
0 commit comments