diff --git a/src/main/java/io/github/dsheirer/gui/nowplaying/ChannelMetadataView.java b/src/main/java/io/github/dsheirer/gui/nowplaying/ChannelMetadataView.java index 6d28cca4..0a0d0a51 100644 --- a/src/main/java/io/github/dsheirer/gui/nowplaying/ChannelMetadataView.java +++ b/src/main/java/io/github/dsheirer/gui/nowplaying/ChannelMetadataView.java @@ -361,6 +361,17 @@ public class ChannelMetadataView extends VBox implements ChannelMetadataModel.Li columns.add(NowPlayingCells.column("tuner", "Tuner", null, Pos.CENTER, row -> getTunerName(row.getChannelMetadata()), Row::revisionProperty)); + //System and site labels from the channel configuration, hidden by default + TableColumn system = NowPlayingCells.column("system", "System", null, Pos.CENTER, + row -> toText(row.getChannelMetadata().getSystemConfigurationIdentifier()), Row::revisionProperty); + system.setVisible(false); + columns.add(system); + + TableColumn site = NowPlayingCells.column("site", "Site", null, Pos.CENTER, + row -> toText(row.getChannelMetadata().getSiteConfigurationIdentifier()), Row::revisionProperty); + site.setVisible(false); + columns.add(site); + columns.add(NowPlayingCells.column("channel.name", "Channel Name", null, Pos.CENTER, row -> toText(row.getChannelMetadata().getChannelNameConfigurationIdentifier()), Row::revisionProperty)); @@ -370,7 +381,8 @@ public class ChannelMetadataView extends VBox implements ChannelMetadataModel.Li column.setSortable(false); } - //Column numbers in the Swing version of the table, for its stored column widths. Talker and Tuner are new columns. + //Column numbers in the Swing version of the table, for its stored column widths. Talker, Tuner, System and Site are new + //columns. String[] swingColumns = {"status", "decoder", "from", "from.alias", "to", "to.alias", "channel", "frequency", "channel.name"}; diff --git a/src/main/java/io/github/dsheirer/gui/table/TableColumnMonitor.java b/src/main/java/io/github/dsheirer/gui/table/TableColumnMonitor.java index d4d13669..50a2450e 100644 --- a/src/main/java/io/github/dsheirer/gui/table/TableColumnMonitor.java +++ b/src/main/java/io/github/dsheirer/gui/table/TableColumnMonitor.java @@ -57,6 +57,7 @@ public class TableColumnMonitor public static final String LEGACY_INDEX = "column.legacy.index"; private static final String ORDER = ".column.order"; private static final String HIDDEN = ".column.hidden"; + private static final String KNOWN = ".column.known"; private static final String WIDTH = ".column.width."; private static final String SEPARATOR = ","; @@ -230,6 +231,7 @@ public class TableColumnMonitor mPreferences.remove(mKey + ORDER); mPreferences.remove(mKey + HIDDEN); + mPreferences.remove(mKey + KNOWN); } /** @@ -328,10 +330,13 @@ public class TableColumnMonitor if(hidden != null) { Set hiddenIds = Set.of(hidden.isEmpty() ? new String[0] : hidden.split(SEPARATOR)); + Set knownIds = getKnownIds(); for(TableColumn column: mDefaultOrder) { - column.setVisible(!hiddenIds.contains(column.getId())); + //Columns that weren't in the table when the visibility was stored are new, so use the default + column.setVisible(knownIds.contains(column.getId()) ? !hiddenIds.contains(column.getId()) : + mDefaultVisibility.get(column)); } if(getVisibleColumnCount() == 0) @@ -375,6 +380,32 @@ public class TableColumnMonitor } } + /** + * IDs of the columns that were in the table when the visibility was stored. Settings stored before the known + * columns were stored only had columns that are shown by default. + */ + private Set getKnownIds() + { + String known = mPreferences.get(mKey + KNOWN, null); + + if(known != null) + { + return Set.of(known.isEmpty() ? new String[0] : known.split(SEPARATOR)); + } + + Set ids = new HashSet<>(); + + for(TableColumn column: mDefaultOrder) + { + if(mDefaultVisibility.get(column)) + { + ids.add(column.getId()); + } + } + + return ids; + } + private int getVisibleColumnCount() { int count = 0; @@ -405,9 +436,12 @@ public class TableColumnMonitor private void storeVisibility() { List ids = new ArrayList<>(); + List known = new ArrayList<>(); for(TableColumn column: mDefaultOrder) { + known.add(column.getId()); + if(!column.isVisible()) { ids.add(column.getId()); @@ -415,6 +449,7 @@ public class TableColumnMonitor } mPreferences.put(mKey + HIDDEN, String.join(SEPARATOR, ids)); + mPreferences.put(mKey + KNOWN, String.join(SEPARATOR, known)); } private String getWidthKey(TableColumn column) diff --git a/src/test/java/io/github/dsheirer/gui/table/TableColumnMonitorTest.java b/src/test/java/io/github/dsheirer/gui/table/TableColumnMonitorTest.java index ef305cdc..3669f77a 100644 --- a/src/test/java/io/github/dsheirer/gui/table/TableColumnMonitorTest.java +++ b/src/test/java/io/github/dsheirer/gui/table/TableColumnMonitorTest.java @@ -212,6 +212,27 @@ public class TableColumnMonitorTest }); } + @Test + public void newHiddenByDefaultColumnStaysHidden() throws Exception + { + onFx(() -> { + //Stored by a version without the hidden by default 'site' column and without the known columns + mPreferences.put(KEY + ".column.hidden", "a"); + TableView table = createTable("a", "b", "site"); + table.getColumns().get(2).setVisible(false); + monitor(table); + assertEquals(List.of("b"), visibleIds(table)); + + //The user shows the column, which is kept in the next session + table.getColumns().get(2).setVisible(true); + TableView restored = createTable("a", "b", "site", "system"); + restored.getColumns().get(2).setVisible(false); + restored.getColumns().get(3).setVisible(false); + monitor(restored); + assertEquals(List.of("b", "site"), visibleIds(restored)); + }); + } + @Test public void lastVisibleColumnCantBeHidden() throws Exception {