#1547 Updates playlist alias editor to make add/delete operations more efficient. (#1560)

Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
Denny Sheirer
2023-05-21 04:54:26 -04:00
committed by GitHub
parent 77629000b2
commit 9502ca3069
3 changed files with 73 additions and 49 deletions

View File

@@ -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
@@ -23,17 +23,16 @@ import io.github.dsheirer.alias.id.AliasIDType;
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
@@ -184,10 +183,8 @@ public class AliasModel
*/
public void addAliases(List<Alias> aliases)
{
for(Alias alias : aliases)
{
addAlias(alias);
}
removeAliases(aliases);
mAliases.addAll(aliases);
}
/**
@@ -241,6 +238,26 @@ public class AliasModel
}
}
/**
* 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

View File

@@ -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
@@ -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;
@@ -37,6 +28,10 @@ import io.github.dsheirer.gui.playlist.Editor;
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;
@@ -74,6 +69,9 @@ import javafx.util.Callback;
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
@@ -532,11 +530,10 @@ public class AliasConfigurationEditor extends SplitPane
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?");
@@ -547,11 +544,7 @@ public class AliasConfigurationEditor extends SplitPane
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);
}
});
}

View File

@@ -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
@@ -34,6 +34,12 @@ import io.github.dsheirer.protocol.Protocol;
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;
@@ -71,12 +77,6 @@ import org.controlsfx.control.textfield.TextFields;
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);
@@ -323,13 +323,20 @@ public class SystemTalkgroupSelectionEditor extends GridPane
}
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);
}
}
});
}
@@ -338,24 +345,31 @@ public class SystemTalkgroupSelectionEditor extends GridPane
}
/**
* 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);
}
/**