diff --git a/source/net/filebot/ui/rename/RenameModel.java b/source/net/filebot/ui/rename/RenameModel.java index 05434424..3f757a3a 100644 --- a/source/net/filebot/ui/rename/RenameModel.java +++ b/source/net/filebot/ui/rename/RenameModel.java @@ -1,5 +1,6 @@ package net.filebot.ui.rename; +import static java.util.Collections.*; import static net.filebot.util.FileUtilities.*; import java.beans.PropertyChangeEvent; @@ -134,7 +135,13 @@ public class RenameModel extends MatchModel { return defaultFormatter; } - public Map getMatchContext() { + public Map getMatchContext(Match match) { + // incomplete matches have no context + if (match.getValue() == null || match.getCandidate() == null) { + return emptyMap(); + } + + // provide matches context on demand return new AbstractMap() { @Override @@ -207,7 +214,7 @@ public class RenameModel extends MatchModel { Match match = getMatch(index); // create new future - final FormattedFuture future = new FormattedFuture(match, getFormatter(match), getMatchContext()); + final FormattedFuture future = new FormattedFuture(match, getFormatter(match), getMatchContext(match)); // update data if (type == ListEvent.INSERT) { @@ -254,7 +261,8 @@ public class RenameModel extends MatchModel { for (int i = 0; i < size(); i++) { FormattedFuture obsolete = futures.get(i); - FormattedFuture future = new FormattedFuture(obsolete.getMatch(), getFormatter(obsolete.getMatch()), getMatchContext()); + Match match = obsolete.getMatch(); + FormattedFuture future = new FormattedFuture(match, getFormatter(match), getMatchContext(match)); // replace and cancel old future cancel(futures.set(i, future)); diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 8e5676a5..35a54789 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -292,7 +292,7 @@ public class RenamePanel extends JComponent { JList list = (JList) evt.getSource(); if (list.getSelectedIndex() >= 0) { Match match = renameModel.getMatch(list.getSelectedIndex()); - Map context = renameModel.getMatchContext(); + Map context = renameModel.getMatchContext(match); MediaBindingBean sample = new MediaBindingBean(match.getValue(), match.getCandidate(), context); showFormatEditor(sample);