#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 * 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 * 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.alias.id.broadcast.BroadcastChannel;
import io.github.dsheirer.identifier.IdentifierCollection; import io.github.dsheirer.identifier.IdentifierCollection;
import io.github.dsheirer.identifier.configuration.AliasListConfigurationIdentifier; 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; 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 * 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) public void addAliases(List<Alias> aliases)
{ {
for(Alias alias : aliases) removeAliases(aliases);
{ mAliases.addAll(aliases);
addAlias(alias);
}
} }
/** /**
@@ -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 * Retrieves all aliases that match the alias list and have at least one alias ID of the specified type
* @param aliasListName to search * @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 * 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 * it under the terms of the GNU General Public License as published by
@@ -19,15 +19,6 @@
package io.github.dsheirer.gui.playlist.alias; 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.Alias;
import io.github.dsheirer.alias.AliasFactory; import io.github.dsheirer.alias.AliasFactory;
import io.github.dsheirer.alias.AliasList; 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.icon.Icon;
import io.github.dsheirer.playlist.PlaylistManager; import io.github.dsheirer.playlist.PlaylistManager;
import io.github.dsheirer.preference.UserPreferences; 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.application.Platform;
import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
@@ -74,6 +69,9 @@ import javafx.util.Callback;
import jiconfont.IconCode; import jiconfont.IconCode;
import jiconfont.icons.font_awesome.FontAwesome; import jiconfont.icons.font_awesome.FontAwesome;
import jiconfont.javafx.IconNode; import jiconfont.javafx.IconNode;
import org.controlsfx.control.textfield.TextFields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Editor for aliases * Editor for aliases
@@ -532,11 +530,10 @@ public class AliasConfigurationEditor extends SplitPane
mDeleteAliasButton.setMaxWidth(Double.MAX_VALUE); mDeleteAliasButton.setMaxWidth(Double.MAX_VALUE);
mDeleteAliasButton.setOnAction(event -> mDeleteAliasButton.setOnAction(event ->
{ {
int count = getAliasTableView().getSelectionModel().getSelectedItems().size();
boolean multiple = getAliasTableView().getSelectionModel().getSelectedItems().size() > 1;
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, 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); ButtonType.NO, ButtonType.YES);
alert.setTitle("Delete Alias"); alert.setTitle("Delete Alias");
alert.setHeaderText("Are you sure?"); alert.setHeaderText("Are you sure?");
@@ -547,11 +544,7 @@ public class AliasConfigurationEditor extends SplitPane
if(result.get() == ButtonType.YES) if(result.get() == ButtonType.YES)
{ {
List<Alias> selectedAliases = new ArrayList<>(getAliasTableView().getSelectionModel().getSelectedItems()); List<Alias> selectedAliases = new ArrayList<>(getAliasTableView().getSelectionModel().getSelectedItems());
mPlaylistManager.getAliasModel().removeAliases(selectedAliases);
for(Alias selected : selectedAliases)
{
mPlaylistManager.getAliasModel().removeAlias(selected);
}
} }
}); });
} }

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 * 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 * 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.System;
import io.github.dsheirer.rrapi.type.Talkgroup; import io.github.dsheirer.rrapi.type.Talkgroup;
import io.github.dsheirer.rrapi.type.TalkgroupCategory; 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.animation.RotateTransition;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
@@ -71,12 +77,6 @@ import org.controlsfx.control.textfield.TextFields;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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 public class SystemTalkgroupSelectionEditor extends GridPane
{ {
private static final Logger mLog = LoggerFactory.getLogger(SystemTalkgroupSelectionEditor.class); private static final Logger mLog = LoggerFactory.getLogger(SystemTalkgroupSelectionEditor.class);
@@ -323,13 +323,20 @@ public class SystemTalkgroupSelectionEditor extends GridPane
} }
else else
{ {
List<Talkgroup> aliasesToCreate = new ArrayList<>();
for(AliasedTalkgroup aliasedTalkgroup : mTalkgroupFilteredList) for(AliasedTalkgroup aliasedTalkgroup : mTalkgroupFilteredList)
{ {
if(!aliasedTalkgroup.hasAlias()) 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 * Creates an alias for each of the specified talkgroups and adds it to the currently selected alias list
* @param talkgroup to alias * @param talkgroups to alias
*/ */
public void createAlias(Talkgroup talkgroup) public void createAliases(List<Talkgroup> talkgroups)
{ {
TalkgroupCategory talkgroupCategory = getTalkgroupCategory(talkgroup); List<Alias> createdAliases = new ArrayList<>();
String group = (talkgroupCategory != null ? talkgroupCategory.getName() : null);
Alias alias = getRadioReferenceDecoder().createAlias(talkgroup, getCurrentSystem(),
getAliasListNameComboBox().getSelectionModel().getSelectedItem(), group);
if(getEncryptedAsDoNotMonitorCheckBox().selectedProperty().get() && for(Talkgroup talkgroup: talkgroups)
TalkgroupEncryption.lookup(talkgroup.getEncryptionState()) == TalkgroupEncryption.FULL)
{ {
int priority = io.github.dsheirer.alias.id.priority.Priority.DO_NOT_MONITOR; TalkgroupCategory talkgroupCategory = getTalkgroupCategory(talkgroup);
alias.addAliasID(new io.github.dsheirer.alias.id.priority.Priority(priority)); 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);
} }
/** /**