Skip to content

Commit 66a0b25

Browse files
DSheirerDennis Sheirer
andauthored
#1060 Adds Alias List delete and rename operations to playlist editor (#2038)
Original code changes implemented by @whelgeson Co-authored-by: Dennis Sheirer <[email protected]>
1 parent 378841b commit 66a0b25

File tree

6 files changed

+378
-37
lines changed

6 files changed

+378
-37
lines changed

src/main/java/io/github/dsheirer/alias/AliasModel.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* *****************************************************************************
3-
* Copyright (C) 2014-2023 Dennis Sheirer
3+
* Copyright (C) 2014-2024 Dennis Sheirer
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -63,6 +63,69 @@ public ObservableList<String> aliasListNames()
6363
return mAliasListNames;
6464
}
6565

66+
/**
67+
* Clears and reloads the list of alias list names from the current set of aliases.
68+
*/
69+
public void refreshAliasListNames()
70+
{
71+
mAliasListNames.clear();
72+
73+
for(Alias alias : mAliases)
74+
{
75+
String aliasListName = alias.getAliasListName();
76+
77+
if(aliasListName != null && !aliasListName.isEmpty() && !mAliasListNames.contains(aliasListName))
78+
{
79+
mAliasListNames.add(aliasListName);
80+
}
81+
}
82+
}
83+
84+
/**
85+
* Renames the alias list across the set of aliases.
86+
* @param oldName currently used by the alias
87+
* @param newName to apply to the alias
88+
*/
89+
public void renameAliasList(String oldName, String newName)
90+
{
91+
if(oldName == null || oldName.isEmpty() || newName == null || newName.isEmpty())
92+
{
93+
return;
94+
}
95+
96+
mAliases.stream().filter(alias -> alias.getAliasListName().equals(oldName)).forEach(alias -> alias.setAliasListName(newName));
97+
}
98+
99+
/**
100+
* Deletes any aliases that have the alias list name
101+
* @param aliasListName to delete
102+
*/
103+
public void deleteAliasList(String aliasListName)
104+
{
105+
if(aliasListName == null || aliasListName.isEmpty())
106+
{
107+
return;
108+
}
109+
110+
mAliases.removeIf(alias -> alias.getAliasListName().equals(aliasListName));
111+
mAliasListMap.remove(aliasListName);
112+
}
113+
114+
/**
115+
* Adds the list of alias list names to the currently managed set of alias list names.
116+
* @param aliasListNames to add
117+
*/
118+
public void addAliasListNames(List<String> aliasListNames)
119+
{
120+
for(String aliasListName : aliasListNames)
121+
{
122+
if(!mAliasListNames.contains(aliasListName))
123+
{
124+
mAliasListNames.add(aliasListName);
125+
}
126+
}
127+
}
128+
66129
/**
67130
* Unmodifiable list of all aliases currently in the model
68131
*/

src/main/java/io/github/dsheirer/controller/channel/ChannelModel.java

Lines changed: 107 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
/*
2+
* *****************************************************************************
3+
* Copyright (C) 2014-2024 Dennis Sheirer
24
*
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.
199
*
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.
2014
*
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+
* ****************************************************************************
2118
*/
2219
package io.github.dsheirer.controller.channel;
2320

@@ -26,14 +23,12 @@
2623
import io.github.dsheirer.controller.channel.ChannelEvent.Event;
2724
import io.github.dsheirer.sample.Broadcaster;
2825
import io.github.dsheirer.sample.Listener;
29-
import javafx.collections.FXCollections;
30-
import javafx.collections.ListChangeListener;
31-
import javafx.collections.ObservableList;
32-
3326
import java.util.ArrayList;
3427
import java.util.Collections;
35-
import java.util.Comparator;
3628
import java.util.List;
29+
import javafx.collections.FXCollections;
30+
import javafx.collections.ListChangeListener;
31+
import javafx.collections.ObservableList;
3732

3833
/**
3934
* Channel Model
@@ -55,6 +50,58 @@ public ChannelModel(AliasModel aliasModel)
5550
mTrafficChannels.addListener(changeListener);
5651
}
5752

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+
58105
/**
59106
* Observable list of channel configurations managed by this model
60107
*/
@@ -109,6 +156,45 @@ public Channel getChannelAtIndex(int row)
109156
return null;
110157
}
111158

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+
112198
/**
113199
* Returns a list of unique system values from across the channel set
114200
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* *****************************************************************************
3+
* Copyright (C) 2014-2024 Dennis Sheirer
4+
*
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.
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.
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+
* ****************************************************************************
18+
*/
19+
20+
package io.github.dsheirer.gui.playlist;
21+
22+
/**
23+
* Interface for editors that use alias list controls that can trigger when the playlist manager updates the observable
24+
* set of alias list names and cause the editor to prompt the user to save changes.
25+
*
26+
* Implementors should clear any currently selected/editing element that could be impacted by a behind-the-scenes update
27+
* to the list of alias list names such as delete or rename operations.
28+
*/
29+
public interface IAliasListRefreshListener
30+
{
31+
/**
32+
* Preparate foran alias list refresh. For alias editors, this can be a clear the currently selected
33+
* alias so that if the value is changed, the editor doesn't think that the user has modified the alias and
34+
* prompt the user to save the changes.
35+
*/
36+
void prepareForAliasListRefresh();
37+
}

0 commit comments

Comments
 (0)