mirror of https://github.com/zlatinb/muwire
build tabs dynamically based on presence of commments or local copies
parent
4fc5bdd382
commit
d61e4245bd
|
@ -39,7 +39,6 @@ class ResultDetailsModel {
|
||||||
List<UIResultEvent> results
|
List<UIResultEvent> results
|
||||||
|
|
||||||
String key
|
String key
|
||||||
List<SharedFile> localFiles
|
|
||||||
|
|
||||||
private final Set<UIResultEvent> uniqueResults = new HashSet<>()
|
private final Set<UIResultEvent> uniqueResults = new HashSet<>()
|
||||||
List<UIResultEvent> resultsWithComments = []
|
List<UIResultEvent> resultsWithComments = []
|
||||||
|
@ -55,11 +54,6 @@ class ResultDetailsModel {
|
||||||
|
|
||||||
void mvcGroupInit(Map<String,String> args) {
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
key = fileName + Base64.encode(infoHash.getRoot())
|
key = fileName + Base64.encode(infoHash.getRoot())
|
||||||
SharedFile[] locals = core.fileManager.getSharedFiles(infoHash.getRoot())
|
|
||||||
if (locals == null)
|
|
||||||
localFiles = Collections.emptyList()
|
|
||||||
else
|
|
||||||
localFiles = Arrays.asList(locals)
|
|
||||||
|
|
||||||
certificates = new HashMap<>()
|
certificates = new HashMap<>()
|
||||||
collectionFetches = new HashMap<>()
|
collectionFetches = new HashMap<>()
|
||||||
|
@ -86,6 +80,13 @@ class ResultDetailsModel {
|
||||||
core.eventBus.unregister(CollectionFetchStatusEvent.class, this)
|
core.eventBus.unregister(CollectionFetchStatusEvent.class, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> getLocalCopies() {
|
||||||
|
SharedFile[] sharedFiles = core.fileManager.getSharedFiles(infoHash.getRoot())
|
||||||
|
if (sharedFiles == null || sharedFiles.length == 0)
|
||||||
|
return null
|
||||||
|
sharedFiles.collect {it.getCachedPath()}
|
||||||
|
}
|
||||||
|
|
||||||
void addResult(UIResultEvent event) {
|
void addResult(UIResultEvent event) {
|
||||||
if (!uniqueResults.add(event))
|
if (!uniqueResults.add(event))
|
||||||
|
@ -197,12 +198,4 @@ class ResultDetailsModel {
|
||||||
int count
|
int count
|
||||||
final List<FileCollection> collections = new ArrayList<>()
|
final List<FileCollection> collections = new ArrayList<>()
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasComments() {
|
|
||||||
for (UIResultEvent event : results) {
|
|
||||||
if (event.comment != null)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,10 @@ class ResultDetailsView {
|
||||||
int rowHeight
|
int rowHeight
|
||||||
|
|
||||||
JTabbedPane tabs
|
JTabbedPane tabs
|
||||||
|
|
||||||
|
JPanel sendersPanel
|
||||||
JTable sendersTable
|
JTable sendersTable
|
||||||
|
|
||||||
JPanel commentsPanel
|
JPanel commentsPanel
|
||||||
JList<UIResultEvent> commentsList
|
JList<UIResultEvent> commentsList
|
||||||
JTextArea commentTextArea
|
JTextArea commentTextArea
|
||||||
|
@ -59,7 +61,7 @@ class ResultDetailsView {
|
||||||
tabs = tabbedPane(constraints: BorderLayout.CENTER)
|
tabs = tabbedPane(constraints: BorderLayout.CENTER)
|
||||||
}
|
}
|
||||||
|
|
||||||
JPanel sendersPanel = builder.panel {
|
sendersPanel = builder.panel {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
panel(constraints: BorderLayout.NORTH) {
|
panel(constraints: BorderLayout.NORTH) {
|
||||||
label(text: trans("RESULTS_CAME_FROM"))
|
label(text: trans("RESULTS_CAME_FROM"))
|
||||||
|
@ -83,20 +85,6 @@ class ResultDetailsView {
|
||||||
button(text: trans("COPY_FULL_ID"), enabled: bind {model.copyIdActionEnabled}, copyIdAction)
|
button(text: trans("COPY_FULL_ID"), enabled: bind {model.copyIdActionEnabled}, copyIdAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tabs.addTab(trans("SENDERS"), sendersPanel)
|
|
||||||
|
|
||||||
if (!model.localFiles.isEmpty()) {
|
|
||||||
JPanel localCopies = builder.panel {
|
|
||||||
borderLayout()
|
|
||||||
panel(constraints: BorderLayout.NORTH) {
|
|
||||||
label(text: trans("YOU_ALREADY_HAVE_FILE", model.localFiles.size()))
|
|
||||||
}
|
|
||||||
scrollPane(constraints: BorderLayout.CENTER) {
|
|
||||||
list(items : model.localFiles.collect {it.getCachedPath()})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tabs.addTab(trans("LOCAL_COPIES"), localCopies)
|
|
||||||
}
|
|
||||||
|
|
||||||
commentsPanel = builder.panel {
|
commentsPanel = builder.panel {
|
||||||
cardLayout()
|
cardLayout()
|
||||||
|
@ -115,7 +103,31 @@ class ResultDetailsView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tabs.addTab(trans("COMMENTS"), commentsPanel)
|
}
|
||||||
|
|
||||||
|
private JPanel buildLocalCopies() {
|
||||||
|
List<String> localCopies = model.getLocalCopies()
|
||||||
|
if (localCopies == null)
|
||||||
|
return null
|
||||||
|
builder.panel {
|
||||||
|
borderLayout()
|
||||||
|
panel(constraints: BorderLayout.NORTH) {
|
||||||
|
label(text: trans("YOU_ALREADY_HAVE_FILE", localCopies.size()))
|
||||||
|
}
|
||||||
|
scrollPane(constraints: BorderLayout.CENTER) {
|
||||||
|
list(items : localCopies)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void buildTabs() {
|
||||||
|
tabs.removeAll()
|
||||||
|
tabs.addTab(trans("SENDERS"), sendersPanel)
|
||||||
|
JPanel localCopies = buildLocalCopies()
|
||||||
|
if (localCopies != null)
|
||||||
|
tabs.addTab(trans("LOCAL_COPIES"), localCopies)
|
||||||
|
if (!model.resultsWithComments.isEmpty())
|
||||||
|
tabs.addTab(trans("COMMENTS"), commentsPanel)
|
||||||
}
|
}
|
||||||
|
|
||||||
void mvcGroupInit(Map<String,String> args) {
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
|
@ -165,6 +177,9 @@ class ResultDetailsView {
|
||||||
commentsPanel.getLayout().show(commentsPanel,"yes-comments")
|
commentsPanel.getLayout().show(commentsPanel,"yes-comments")
|
||||||
commentsList.setListData(model.resultsWithComments.toArray(new UIResultEvent[0]))
|
commentsList.setListData(model.resultsWithComments.toArray(new UIResultEvent[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildTabs()
|
||||||
|
p.updateUI()
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshCertificates() {
|
void refreshCertificates() {
|
||||||
|
|
|
@ -457,6 +457,7 @@ class SearchTabView {
|
||||||
resultDetails[infoHash] = group
|
resultDetails[infoHash] = group
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group.view.buildTabs()
|
||||||
detailsPanelByFile.add(group.view.p, null)
|
detailsPanelByFile.add(group.view.p, null)
|
||||||
detailsPanelByFile.updateUI()
|
detailsPanelByFile.updateUI()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue