-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display the statements of a Wikidata item in the WikidataInfoToggleDi…
…alog
- Loading branch information
Showing
5 changed files
with
139 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.wikipedia.gui; | ||
|
||
import java.awt.BorderLayout; | ||
import javax.swing.JPanel; | ||
import javax.swing.JProgressBar; | ||
|
||
public class ProgressJPanel extends JPanel { | ||
private final JProgressBar PROGRESS_BAR = new JProgressBar(); | ||
|
||
ProgressJPanel() { | ||
setLayout(new BorderLayout()); | ||
PROGRESS_BAR.setStringPainted(true); | ||
} | ||
|
||
protected synchronized void showProgress(final String message) { | ||
if (!isAncestorOf(PROGRESS_BAR)) { | ||
add(PROGRESS_BAR, BorderLayout.NORTH); | ||
} | ||
PROGRESS_BAR.setIndeterminate(true); | ||
PROGRESS_BAR.setString(message); | ||
revalidate(); | ||
repaint(); | ||
} | ||
|
||
protected synchronized void hideProgress() { | ||
remove(PROGRESS_BAR); | ||
revalidate(); | ||
repaint(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/org/wikipedia/gui/WikidataInfoClaimPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.wikipedia.gui; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.GridLayout; | ||
import java.io.IOException; | ||
import javax.swing.JPanel; | ||
import javax.swing.JScrollPane; | ||
import org.openstreetmap.josm.gui.Notification; | ||
import org.openstreetmap.josm.tools.I18n; | ||
import org.wikipedia.WikipediaPlugin; | ||
import org.wikipedia.api.ApiQueryClient; | ||
import org.wikipedia.api.wikidata_action.WikidataActionApiQuery; | ||
import org.wikipedia.api.wikidata_action.json.WbgetclaimsResult; | ||
|
||
class WikidataInfoClaimPanel extends ProgressJPanel { | ||
|
||
private final JPanel mainPanel; | ||
private String qIdBeingDownloaded; | ||
|
||
WikidataInfoClaimPanel() { | ||
super(); | ||
this.mainPanel = new JPanel(); | ||
add(new JScrollPane(mainPanel), BorderLayout.CENTER); | ||
} | ||
|
||
void downloadStatementsFor(final String qId) { | ||
this.qIdBeingDownloaded = qId; | ||
new Thread(() -> { | ||
try { | ||
mainPanel.removeAll(); | ||
showProgress(I18n.tr("Download statements for {0}…", qId)); | ||
final WbgetclaimsResult result = ApiQueryClient.query(WikidataActionApiQuery.wbgetclaims(qId)); | ||
if (qIdBeingDownloaded != null && qIdBeingDownloaded.equals(qId)) { | ||
synchronized (mainPanel) { | ||
mainPanel.removeAll(); | ||
mainPanel.setLayout(new GridLayout(result.getClaims().size(), 1)); | ||
result.getClaims().forEach(claim -> { | ||
final WbgetclaimsResult.Claim.MainSnak.DataValue value = claim.getMainSnak().getDataValue(); // nullable | ||
mainPanel.add(new StatementPanel(claim.getMainSnak().getProperty(), value == null ? I18n.tr("Unknown datatype!") : value.toString())); | ||
}); | ||
hideProgress(); | ||
} | ||
} | ||
} catch (IOException e) { | ||
new Notification(I18n.tr("Failed to download statements for Wikidata item {0}!", qId)) | ||
.setIcon(WikipediaPlugin.W_IMAGE.get()) | ||
.show(); | ||
} | ||
hideProgress(); | ||
}).start(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters