Preserve format if type didn't change

This commit is contained in:
Reinhard Pointner 2016-04-06 14:48:03 +00:00
parent 9e33199776
commit 28ee8b5e30
1 changed files with 10 additions and 2 deletions

View File

@ -69,7 +69,7 @@ public class ListPanel extends JComponent {
list.getRemoveAction().setEnabled(true);
list.setTransferablePolicy(new FileListTransferablePolicy(list::setTitle, editor::setText, this::createItemSequence));
list.setTransferablePolicy(new FileListTransferablePolicy(list::setTitle, this::setFormatTemplate, this::createItemSequence));
FileBotListExportHandler<ListItem> exportHandler = new FileBotListExportHandler<ListItem>(list, (item, out) -> out.println(item.getFormattedValue()));
list.setExportHandler(exportHandler);
@ -188,6 +188,7 @@ public class ListPanel extends JComponent {
}
private ExpressionFormat format;
private String template;
public ListItem createItem(Object object, int i, int from, int to, List<?> context) {
return new ListItem(new IndexedBindingBean(object, i, from, to, context), format);
@ -217,13 +218,20 @@ public class ListPanel extends JComponent {
List<Integer> context = IntStream.rangeClosed(from, to).boxed().collect(toList());
List<ListItem> items = context.stream().map(it -> createItem(it, it.intValue(), from, to, context)).collect(toList());
editor.setText(DEFAULT_SEQUENCE_FORMAT);
setFormatTemplate(DEFAULT_SEQUENCE_FORMAT);
list.setTitle("Sequence");
list.getListComponent().clearSelection();
list.getModel().clear();
list.getModel().addAll(items);
}
public void setFormatTemplate(String format) {
if (template != format) {
template = format;
editor.setText(format);
}
}
@Subscribe
public void handle(Transferable transferable) throws Exception {
TransferablePolicy handler = list.getTransferablePolicy();