Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wikipedia plugin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
JOSM trac
JOSM trac
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JOSM
wikipedia plugin
Commits
adeaa86a
Commit
adeaa86a
authored
Aug 06, 2018
by
Florian Schäfer
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the label tab of WikidataInfoToggleDialog work
parent
e4d84de7
Pipeline
#27299554
passed with stages
in 7 minutes and 52 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
5 deletions
+124
-5
ApiUrl.java
src/main/java/org/wikipedia/api/ApiUrl.java
+0
-4
WikidataInfoLabelPanel.java
src/main/java/org/wikipedia/gui/WikidataInfoLabelPanel.java
+120
-0
WikidataInfoToggleDialog.java
...main/java/org/wikipedia/gui/WikidataInfoToggleDialog.java
+4
-1
No files found.
src/main/java/org/wikipedia/api/ApiUrl.java
View file @
adeaa86a
...
...
@@ -3,10 +3,6 @@ package org.wikipedia.api;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.Arrays
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.openstreetmap.josm.tools.Logging
;
public
class
ApiUrl
{
...
...
src/main/java/org/wikipedia/gui/WikidataInfoLabelPanel.java
0 → 100644
View file @
adeaa86a
package
org
.
wikipedia
.
gui
;
import
java.awt.BorderLayout
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
javax.swing.JPanel
;
import
javax.swing.JProgressBar
;
import
javax.swing.JTable
;
import
javax.swing.table.AbstractTableModel
;
import
org.openstreetmap.josm.gui.Notification
;
import
org.openstreetmap.josm.tools.I18n
;
import
org.openstreetmap.josm.tools.Pair
;
import
org.wikipedia.WikipediaPlugin
;
import
org.wikipedia.api.ApiQueryClient
;
import
org.wikipedia.api.wikidata_action.WikidataActionApiQuery
;
/**
* Panel displaying the labels for a Wikidata item
*/
class
WikidataInfoLabelPanel
extends
JPanel
{
private
static
final
JProgressBar
downloadProgress
=
new
JProgressBar
();
private
final
LabelTableModel
tableModel
=
new
LabelTableModel
(
this
);
static
{
downloadProgress
.
setStringPainted
(
true
);
}
WikidataInfoLabelPanel
()
{
setLayout
(
new
BorderLayout
());
add
(
new
JTable
(
tableModel
),
BorderLayout
.
CENTER
);
}
void
clear
()
{
tableModel
.
clear
();
}
void
downloadLabelsFor
(
final
String
qId
)
{
tableModel
.
downloadLabelsFor
(
qId
);
}
private
synchronized
void
showDownloadProgress
(
final
String
qId
)
{
if
(!
isAncestorOf
(
downloadProgress
))
{
add
(
downloadProgress
,
BorderLayout
.
NORTH
);
}
downloadProgress
.
setIndeterminate
(
true
);
downloadProgress
.
setString
(
I18n
.
tr
(
"Download labels for {0}…"
,
qId
));
revalidate
();
}
private
synchronized
void
hideDownloadProgress
()
{
remove
(
downloadProgress
);
revalidate
();
}
private
static
class
LabelTableModel
extends
AbstractTableModel
{
private
final
WikidataInfoLabelPanel
parent
;
private
String
qIdBeingDownloaded
;
private
final
List
<
Pair
<
String
,
String
>>
valueMap
=
new
ArrayList
<>();
LabelTableModel
(
final
WikidataInfoLabelPanel
parent
)
{
this
.
parent
=
parent
;
}
void
clear
()
{
this
.
valueMap
.
clear
();
}
void
downloadLabelsFor
(
final
String
qId
)
{
synchronized
(
valueMap
)
{
qIdBeingDownloaded
=
qId
;
parent
.
showDownloadProgress
(
qId
);
}
new
Thread
(()
->
{
try
{
final
Map
<
String
,
String
>
newValues
=
ApiQueryClient
.
query
(
WikidataActionApiQuery
.
wbgetentitiesLabels
(
qId
));
synchronized
(
valueMap
)
{
if
(
qIdBeingDownloaded
!=
null
&&
qIdBeingDownloaded
.
equals
(
qId
))
{
valueMap
.
clear
();
valueMap
.
addAll
(
newValues
.
entrySet
().
stream
()
.
map
(
it
->
Pair
.
create
(
it
.
getKey
(),
it
.
getValue
()))
.
sorted
((
x
,
y
)
->
x
.
a
.
compareTo
(
y
.
a
))
.
collect
(
Collectors
.
toList
())
);
}
}
}
catch
(
IOException
e
)
{
new
Notification
(
I18n
.
tr
(
"Failed to download labels for {0}!"
,
qId
)).
setIcon
(
WikipediaPlugin
.
W_IMAGE
.
get
()).
show
();
}
parent
.
hideDownloadProgress
();
}).
start
();
}
@Override
public
int
getRowCount
()
{
return
valueMap
.
size
();
}
@Override
public
int
getColumnCount
()
{
return
2
;
}
@Override
public
Object
getValueAt
(
int
rowIndex
,
int
columnIndex
)
{
return
columnIndex
==
0
?
valueMap
.
get
(
rowIndex
).
a
:
valueMap
.
get
(
rowIndex
).
b
;
}
@Override
public
String
getColumnName
(
int
column
)
{
return
column
==
0
?
"language"
:
"label"
;
}
}
}
src/main/java/org/wikipedia/gui/WikidataInfoToggleDialog.java
View file @
adeaa86a
...
...
@@ -55,7 +55,7 @@ public class WikidataInfoToggleDialog extends ToggleDialog {
private
final
JPanel
infoPanel
=
new
JPanel
(
new
BorderLayout
());
private
final
JTabbedPane
tabs
=
new
JTabbedPane
();
private
final
JPanel
labelTab
=
new
J
Panel
();
private
final
WikidataInfoLabelPanel
labelTab
=
new
WikidataInfoLabel
Panel
();
private
final
JPanel
statementTab
=
new
JPanel
();
private
final
JPanel
linkTab
=
new
JPanel
();
private
final
JButton
webLinkButton
=
new
JButton
();
...
...
@@ -190,6 +190,9 @@ public class WikidataInfoToggleDialog extends ToggleDialog {
descriptionLabel
.
setText
(
description
);
setDisplayedItem
(
qId
);
labelTab
.
clear
();
labelTab
.
downloadLabelsFor
(
qId
);
webLinkButton
.
setAction
(
new
AbstractAction
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
...
...
Florian Schäfer
@floscher
mentioned in commit
7d6525c4
·
Aug 06, 2018
mentioned in commit
7d6525c4
mentioned in commit 7d6525c49c4ea2a04b22397b6b2de9b34b150628
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment