Skip to content

#1547 Playlist Fails To Save When Add/Delete Large Quantity of Aliases #1560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions src/main/java/io/github/dsheirer/alias/AliasModel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2022 Dennis Sheirer
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -23,17 +23,16 @@
import io.github.dsheirer.alias.id.broadcast.BroadcastChannel;
import io.github.dsheirer.identifier.IdentifierCollection;
import io.github.dsheirer.identifier.configuration.AliasListConfigurationIdentifier;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Alias Model contains all aliases and is responsible for creation and management of alias lists. Alias lists are a
Expand Down Expand Up @@ -184,10 +183,8 @@ public List<String> getGroupNames()
*/
public void addAliases(List<Alias> aliases)
{
for(Alias alias : aliases)
{
addAlias(alias);
}
removeAliases(aliases);
mAliases.addAll(aliases);
}

/**
Expand Down Expand Up @@ -241,6 +238,26 @@ public void removeAlias(Alias alias)
}
}

/**
* Removes the list of aliases from this model and any alias lists that might contain each alias.
* @param aliases
*/
public void removeAliases(List<Alias> aliases)
{
if(aliases != null && !aliases.isEmpty())
{
mAliases.removeAll(aliases);

for(Alias alias: aliases)
{
if(hasAliasList(alias.getAliasListName()))
{
getAliasList(alias.getAliasListName()).removeAlias(alias);
}
}
}
}

/**
* Retrieves all aliases that match the alias list and have at least one alias ID of the specified type
* @param aliasListName to search
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2021 Dennis Sheirer
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,15 +19,6 @@

package io.github.dsheirer.gui.playlist.alias;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

import org.controlsfx.control.textfield.TextFields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.github.dsheirer.alias.Alias;
import io.github.dsheirer.alias.AliasFactory;
import io.github.dsheirer.alias.AliasList;
Expand All @@ -37,6 +28,10 @@
import io.github.dsheirer.icon.Icon;
import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import javafx.application.Platform;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue;
Expand Down Expand Up @@ -74,6 +69,9 @@
import jiconfont.IconCode;
import jiconfont.icons.font_awesome.FontAwesome;
import jiconfont.javafx.IconNode;
import org.controlsfx.control.textfield.TextFields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Editor for aliases
Expand Down Expand Up @@ -532,11 +530,10 @@ private Button getDeleteAliasButton()
mDeleteAliasButton.setMaxWidth(Double.MAX_VALUE);
mDeleteAliasButton.setOnAction(event ->
{

boolean multiple = getAliasTableView().getSelectionModel().getSelectedItems().size() > 1;
int count = getAliasTableView().getSelectionModel().getSelectedItems().size();

Alert alert = new Alert(Alert.AlertType.CONFIRMATION,
"Do you want to delete the selected alias" + (multiple ? "es?" : "?"),
"Do you want to delete [" + count + "] selected alias" + ((count > 1) ? "es?" : "?"),
ButtonType.NO, ButtonType.YES);
alert.setTitle("Delete Alias");
alert.setHeaderText("Are you sure?");
Expand All @@ -547,11 +544,7 @@ private Button getDeleteAliasButton()
if(result.get() == ButtonType.YES)
{
List<Alias> selectedAliases = new ArrayList<>(getAliasTableView().getSelectionModel().getSelectedItems());

for(Alias selected : selectedAliases)
{
mPlaylistManager.getAliasModel().removeAlias(selected);
}
mPlaylistManager.getAliasModel().removeAliases(selectedAliases);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2020 Dennis Sheirer
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -34,6 +34,12 @@
import io.github.dsheirer.rrapi.type.System;
import io.github.dsheirer.rrapi.type.Talkgroup;
import io.github.dsheirer.rrapi.type.TalkgroupCategory;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import javafx.animation.RotateTransition;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
Expand Down Expand Up @@ -71,12 +77,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;

public class SystemTalkgroupSelectionEditor extends GridPane
{
private static final Logger mLog = LoggerFactory.getLogger(SystemTalkgroupSelectionEditor.class);
Expand Down Expand Up @@ -323,13 +323,20 @@ private Button getImportAllTalkgroupsButton()
}
else
{
List<Talkgroup> aliasesToCreate = new ArrayList<>();

for(AliasedTalkgroup aliasedTalkgroup : mTalkgroupFilteredList)
{
if(!aliasedTalkgroup.hasAlias())
{
createAlias(aliasedTalkgroup.getTalkgroup());
aliasesToCreate.add(aliasedTalkgroup.getTalkgroup());
}
}

if(!aliasesToCreate.isEmpty())
{
createAliases(aliasesToCreate);
}
}
});
}
Expand All @@ -338,24 +345,31 @@ private Button getImportAllTalkgroupsButton()
}

/**
* Creates an alias for the specified talkgroup and adds it to the currently selected alias list
* @param talkgroup to alias
* Creates an alias for each of the specified talkgroups and adds it to the currently selected alias list
* @param talkgroups to alias
*/
public void createAlias(Talkgroup talkgroup)
public void createAliases(List<Talkgroup> talkgroups)
{
TalkgroupCategory talkgroupCategory = getTalkgroupCategory(talkgroup);
String group = (talkgroupCategory != null ? talkgroupCategory.getName() : null);
Alias alias = getRadioReferenceDecoder().createAlias(talkgroup, getCurrentSystem(),
getAliasListNameComboBox().getSelectionModel().getSelectedItem(), group);
List<Alias> createdAliases = new ArrayList<>();

if(getEncryptedAsDoNotMonitorCheckBox().selectedProperty().get() &&
TalkgroupEncryption.lookup(talkgroup.getEncryptionState()) == TalkgroupEncryption.FULL)
for(Talkgroup talkgroup: talkgroups)
{
int priority = io.github.dsheirer.alias.id.priority.Priority.DO_NOT_MONITOR;
alias.addAliasID(new io.github.dsheirer.alias.id.priority.Priority(priority));
TalkgroupCategory talkgroupCategory = getTalkgroupCategory(talkgroup);
String group = (talkgroupCategory != null ? talkgroupCategory.getName() : null);
Alias alias = getRadioReferenceDecoder().createAlias(talkgroup, getCurrentSystem(),
getAliasListNameComboBox().getSelectionModel().getSelectedItem(), group);

if(getEncryptedAsDoNotMonitorCheckBox().selectedProperty().get() &&
TalkgroupEncryption.lookup(talkgroup.getEncryptionState()) == TalkgroupEncryption.FULL)
{
int priority = io.github.dsheirer.alias.id.priority.Priority.DO_NOT_MONITOR;
alias.addAliasID(new io.github.dsheirer.alias.id.priority.Priority(priority));
}

createdAliases.add(alias);
}

mPlaylistManager.getAliasModel().addAlias(alias);
mPlaylistManager.getAliasModel().addAliases(createdAliases);
}

/**
Expand Down