sort browse host as well
This commit is contained in:
@ -72,4 +72,27 @@ class BrowseModel {
|
||||
void setPercentageLabel(Label percentage) {
|
||||
this.percentage = percentage
|
||||
}
|
||||
|
||||
void sort(SortType type) {
|
||||
Comparator<UIResultEvent> chosen
|
||||
switch(type) {
|
||||
case SortType.NAME_ASC : chosen = ResultComparators.NAME_ASC; break
|
||||
case SortType.NAME_DESC : chosen = ResultComparators.NAME_DESC; break
|
||||
case SortType.SIZE_ASC : chosen = ResultComparators.SIZE_ASC; break
|
||||
case SortType.SIZE_DESC : chosen = ResultComparators.SIZE_DESC; break
|
||||
}
|
||||
|
||||
List<UIResultEvent> l = new ArrayList<>(rootToResult.values())
|
||||
Collections.sort(l, chosen)
|
||||
|
||||
int rowCount = model.getRowCount()
|
||||
rowCount.times { model.removeRow(0) }
|
||||
|
||||
l.each { e ->
|
||||
String size = DataHelper.formatSize2Decimal(e.size, false) + "B"
|
||||
String infoHash = Base64.encode(e.infohash.getRoot())
|
||||
String comment = String.valueOf(e.comment != null)
|
||||
model.addRow(e.name, size, infoHash, comment, e.certificates)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,11 +58,17 @@ class BrowseView extends BasicWindow {
|
||||
}
|
||||
contentPanel.addComponent(table, layoutData)
|
||||
|
||||
Panel buttonsPanel = new Panel()
|
||||
buttonsPanel.setLayoutManager(new GridLayout(2))
|
||||
Button sortButton = new Button("Sort...", {sort()})
|
||||
Button closeButton = new Button("Close",{
|
||||
model.unregister()
|
||||
close()
|
||||
})
|
||||
contentPanel.addComponent(closeButton, layoutData)
|
||||
buttonsPanel.addComponent(sortButton, layoutData)
|
||||
buttonsPanel.addComponent(closeButton, layoutData)
|
||||
|
||||
contentPanel.addComponent(buttonsPanel, layoutData)
|
||||
setComponent(contentPanel)
|
||||
|
||||
}
|
||||
@ -120,4 +126,11 @@ class BrowseView extends BasicWindow {
|
||||
ViewCertificatesView view = new ViewCertificatesView(model, textGUI, core, terminalSize)
|
||||
textGUI.addWindowAndWait(view)
|
||||
}
|
||||
|
||||
private void sort() {
|
||||
SortPrompt prompt = new SortPrompt(textGUI)
|
||||
SortType type = prompt.prompt()
|
||||
if (type != null)
|
||||
model.sort(type)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user