1 | package hozo.sparql.gui;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.Desktop;
|
---|
5 | import java.awt.Dialog.ModalityType;
|
---|
6 | import java.awt.Dimension;
|
---|
7 | import java.awt.FlowLayout;
|
---|
8 | import java.awt.Insets;
|
---|
9 | import java.awt.Point;
|
---|
10 | import java.awt.Window;
|
---|
11 | import java.awt.event.ActionEvent;
|
---|
12 | import java.awt.event.ActionListener;
|
---|
13 | import java.awt.event.KeyAdapter;
|
---|
14 | import java.awt.event.KeyEvent;
|
---|
15 | import java.awt.event.MouseAdapter;
|
---|
16 | import java.awt.event.MouseEvent;
|
---|
17 | import java.io.IOException;
|
---|
18 | import java.net.URI;
|
---|
19 | import java.net.URISyntaxException;
|
---|
20 | import java.net.URLEncoder;
|
---|
21 | import java.util.ArrayList;
|
---|
22 | import java.util.Date;
|
---|
23 | import java.util.LinkedHashMap;
|
---|
24 | import java.util.List;
|
---|
25 | import java.util.Map;
|
---|
26 |
|
---|
27 | import javax.swing.BoxLayout;
|
---|
28 | import javax.swing.ButtonGroup;
|
---|
29 | import javax.swing.DefaultListModel;
|
---|
30 | import javax.swing.JButton;
|
---|
31 | import javax.swing.JCheckBox;
|
---|
32 | import javax.swing.JComboBox;
|
---|
33 | import javax.swing.JDialog;
|
---|
34 | import javax.swing.JLabel;
|
---|
35 | import javax.swing.JMenuItem;
|
---|
36 | import javax.swing.JOptionPane;
|
---|
37 | import javax.swing.JPanel;
|
---|
38 | import javax.swing.JPopupMenu;
|
---|
39 | import javax.swing.JRadioButton;
|
---|
40 | import javax.swing.JScrollPane;
|
---|
41 | import javax.swing.JSeparator;
|
---|
42 | import javax.swing.JSplitPane;
|
---|
43 | import javax.swing.JTable;
|
---|
44 | import javax.swing.JTextField;
|
---|
45 | import javax.swing.SwingConstants;
|
---|
46 | import javax.swing.SwingUtilities;
|
---|
47 | import javax.swing.event.ListDataEvent;
|
---|
48 | import javax.swing.event.ListDataListener;
|
---|
49 | import javax.swing.table.DefaultTableModel;
|
---|
50 |
|
---|
51 | import hozo.sparql.EndpointSettings;
|
---|
52 | import hozo.sparql.EndpointSettingsManager;
|
---|
53 | import hozo.sparql.SparqlAccessor;
|
---|
54 | import hozo.sparql.SparqlAccessorFactory;
|
---|
55 | import hozo.sparql.SparqlQueryListener;
|
---|
56 | import hozo.sparql.SparqlResultListener;
|
---|
57 | import hozo.sparql.SparqlResultSet;
|
---|
58 | import hozo.sparql.ThreadedSparqlAccessor;
|
---|
59 | import hozo.sparql.util.EditableListItem;
|
---|
60 | import hozo.sparql.util.EditableList;
|
---|
61 | import hozo.sparql.util.StringUtil;
|
---|
62 |
|
---|
63 | import com.hp.hpl.jena.rdf.model.RDFNode;
|
---|
64 |
|
---|
65 | public class CrossKeywordSearchPanel extends JPanel {
|
---|
66 |
|
---|
67 | private static final long serialVersionUID = 1L;
|
---|
68 | private JPanel keywordPanel = null;
|
---|
69 | private JLabel keywordLabel = null;
|
---|
70 | private JTextField keywordTextField = null;
|
---|
71 | private JTable subjectList = null;
|
---|
72 | private JScrollPane subjectScrollPane = null;
|
---|
73 | private JPanel centerPanel = null;
|
---|
74 | private JPanel footerPanel = null;
|
---|
75 | private JScrollPane resultListScrollPane = null; // @jve:decl-index=0:visual-constraint="153,224"
|
---|
76 | private JTable resultList = null; // @jve:decl-index=0:visual-constraint="369,21"
|
---|
77 | private JButton runQueryButton = null; // @jve:decl-index=0:visual-constraint="390,64"
|
---|
78 | private JSplitPane mainSplitPane = null;
|
---|
79 | private JPanel optionPanel = null;
|
---|
80 | private JPanel findTypePanel = null;
|
---|
81 | private JRadioButton fullMatchRadioButton = null;
|
---|
82 | private JRadioButton partMatchRadioButton = null;
|
---|
83 | private JSeparator findSeparator = null;
|
---|
84 |
|
---|
85 | private boolean processing = false;
|
---|
86 | private JPanel headerPanel = null;
|
---|
87 | private JPanel limitPanel = null;
|
---|
88 | private JCheckBox limitEnableCheckBox = null;
|
---|
89 | private JLabel limitLabel = null;
|
---|
90 | private JComboBox limitComboBox = null;
|
---|
91 | private JRadioButton findSubjectRadioButton = null;
|
---|
92 | private JRadioButton findObjectRadioButton = null;
|
---|
93 | private JRadioButton findAllRadioButton = null;
|
---|
94 | private JRadioButton findLabelObjectRadioButton = null;
|
---|
95 | private Date fromDate;
|
---|
96 | private JPanel movePanel = null;
|
---|
97 | private JButton prevButton = null;
|
---|
98 | private JButton nextButton = null;
|
---|
99 | private JPanel limitMainPanel = null;
|
---|
100 | private JButton limitPrevButton = null;
|
---|
101 | private JButton limitNextButton = null;
|
---|
102 |
|
---|
103 |
|
---|
104 |
|
---|
105 | private SparqlAccessorForm parent;
|
---|
106 |
|
---|
107 | private DefaultTableModel listModel;
|
---|
108 | private DefaultTableModel tableModel;
|
---|
109 |
|
---|
110 | private ThreadedSparqlAccessor sa; // @jve:decl-index=0:
|
---|
111 |
|
---|
112 | /* subject繧ク繝」繝ウ繝励ヲ繧ケ繝医Μ */
|
---|
113 | private int historyIndex = 0;
|
---|
114 | private List<String> history; // @jve:decl-index=0:
|
---|
115 | private LinkedHashMap<String, List<String>> subjectHistoryList;
|
---|
116 |
|
---|
117 | /* limit繝偵せ繝医Μ */
|
---|
118 | private Integer limit = null; // @jve:decl-index=0:
|
---|
119 | private int page = 0;
|
---|
120 | private String word;
|
---|
121 | private boolean fullMatch = false;
|
---|
122 | private int type;
|
---|
123 | private boolean hasLimitNext = false;
|
---|
124 |
|
---|
125 | private static final String DEFAULT_PROPERTY_TYPE = "http://www.w3.org/2000/01/rdf-schema#label";
|
---|
126 |
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * This is the default constructor
|
---|
130 | */
|
---|
131 | public CrossKeywordSearchPanel(SparqlAccessorForm parent) {
|
---|
132 | super();
|
---|
133 | initialize();
|
---|
134 | this.parent = parent;
|
---|
135 | }
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * This method initializes this
|
---|
139 | *
|
---|
140 | * @return void
|
---|
141 | */
|
---|
142 | private void initialize() {
|
---|
143 | this.setSize(300, 200);
|
---|
144 | this.setLayout(new BorderLayout());
|
---|
145 | this.add(getHeaderPanel(), BorderLayout.NORTH);
|
---|
146 | this.add(getMainSplitPane(), BorderLayout.CENTER);
|
---|
147 | }
|
---|
148 |
|
---|
149 | private JSplitPane getMainSplitPane(){
|
---|
150 | if (mainSplitPane == null){
|
---|
151 | mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, getCenterPanel(), getFooterPanel());
|
---|
152 | mainSplitPane.setDividerLocation(200);
|
---|
153 | }
|
---|
154 |
|
---|
155 | return mainSplitPane;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * This method initializes keywordPanel
|
---|
160 | *
|
---|
161 | * @return javax.swing.JPanel
|
---|
162 | */
|
---|
163 | private JPanel getKeywordPanel() {
|
---|
164 | if (keywordPanel == null) {
|
---|
165 | keywordPanel = new JPanel();
|
---|
166 | keywordPanel.setLayout(new BorderLayout());
|
---|
167 | keywordLabel = new JLabel();
|
---|
168 | keywordLabel.setText("Enter Keyword");
|
---|
169 | keywordPanel.add(keywordLabel, BorderLayout.WEST);
|
---|
170 | keywordPanel.add(getKeywordTextField(), BorderLayout.CENTER);
|
---|
171 | keywordPanel.add(getRunQueryButton(), BorderLayout.EAST);
|
---|
172 | }
|
---|
173 | return keywordPanel;
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * This method initializes optionPanel
|
---|
179 | *
|
---|
180 | * @return javax.swing.JPanel
|
---|
181 | */
|
---|
182 | private JPanel getOptionPanel() {
|
---|
183 | if (optionPanel == null) {
|
---|
184 | optionPanel = new JPanel();
|
---|
185 | optionPanel.setLayout(new BorderLayout());
|
---|
186 | optionPanel.add(getFindTypePanel(), BorderLayout.CENTER);
|
---|
187 | optionPanel.add(getLimitPanel(), BorderLayout.EAST);
|
---|
188 | }
|
---|
189 | return optionPanel;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * This method initializes findTypePanel
|
---|
194 | *
|
---|
195 | * @return javax.swing.JPanel
|
---|
196 | */
|
---|
197 | private JPanel getFindTypePanel() {
|
---|
198 | if (findTypePanel == null) {
|
---|
199 | FlowLayout flowLayout = new FlowLayout();
|
---|
200 | flowLayout.setHgap(10);
|
---|
201 | flowLayout.setVgap(0);
|
---|
202 | findTypePanel = new JPanel();
|
---|
203 | findTypePanel.setLayout(flowLayout);
|
---|
204 | findTypePanel.add(getFullMatchRadioButton(), null);
|
---|
205 | findTypePanel.add(getPartMatchRadioButton(), null);
|
---|
206 | findTypePanel.add(getFindSeparator(), null);
|
---|
207 | findTypePanel.add(getFindAllRadioButton(), null);
|
---|
208 | findTypePanel.add(getFindSubjectRadioButton(), null);
|
---|
209 | findTypePanel.add(getFindObjectRadioButton(), null);
|
---|
210 | findTypePanel.add(getFindLabelObjectRadioButton(), null);
|
---|
211 | ButtonGroup bg = new ButtonGroup();
|
---|
212 | bg.add(getFullMatchRadioButton());
|
---|
213 | bg.add(getPartMatchRadioButton());
|
---|
214 | getFullMatchRadioButton().setSelected(true);
|
---|
215 | ButtonGroup bg2 = new ButtonGroup();
|
---|
216 | bg2.add(getFindAllRadioButton());
|
---|
217 | bg2.add(getFindSubjectRadioButton());
|
---|
218 | bg2.add(getFindObjectRadioButton());
|
---|
219 | bg2.add(getFindLabelObjectRadioButton());
|
---|
220 | getFindSubjectRadioButton().setSelected(true);
|
---|
221 | }
|
---|
222 | return findTypePanel;
|
---|
223 | }
|
---|
224 |
|
---|
225 | private boolean isFullMatch(){
|
---|
226 | return getFullMatchRadioButton().isSelected();
|
---|
227 | }
|
---|
228 |
|
---|
229 | private int getFindType(){
|
---|
230 | if (getFindSubjectRadioButton().isSelected()){
|
---|
231 | return SparqlAccessor.FIND_TARGET_SUBJECT;
|
---|
232 | }
|
---|
233 | if (getFindObjectRadioButton().isSelected()){
|
---|
234 | return SparqlAccessor.FIND_TARGET_OBJECT;
|
---|
235 | }
|
---|
236 | if (getFindLabelObjectRadioButton().isSelected()){
|
---|
237 | return SparqlAccessor.FIND_TARGET_SPECIFIC_OBJECT;
|
---|
238 | }
|
---|
239 | return SparqlAccessor.FIND_TARGET_ALL;
|
---|
240 | }
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * This method initializes fulMatchRadioButton
|
---|
244 | *
|
---|
245 | * @return javax.swing.JRadioButton
|
---|
246 | */
|
---|
247 | private JRadioButton getFullMatchRadioButton() {
|
---|
248 | if (fullMatchRadioButton == null) {
|
---|
249 | fullMatchRadioButton = new JRadioButton("Full Match");
|
---|
250 | }
|
---|
251 | return fullMatchRadioButton;
|
---|
252 | }
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * This method initializes partMatchRadioButton
|
---|
256 | *
|
---|
257 | * @return javax.swing.JRadioButton
|
---|
258 | */
|
---|
259 | private JRadioButton getPartMatchRadioButton() {
|
---|
260 | if (partMatchRadioButton == null) {
|
---|
261 | partMatchRadioButton = new JRadioButton("Part Match");
|
---|
262 | }
|
---|
263 | return partMatchRadioButton;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * This method initializes findSeparator
|
---|
268 | *
|
---|
269 | * @return JSeparator
|
---|
270 | */
|
---|
271 | private JSeparator getFindSeparator() {
|
---|
272 | if (findSeparator == null) {
|
---|
273 | findSeparator = new JSeparator(SwingConstants.VERTICAL);
|
---|
274 | findSeparator.setPreferredSize(new Dimension(5, 20));
|
---|
275 | }
|
---|
276 | return findSeparator;
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * This method initializes keywordTextField
|
---|
282 | *
|
---|
283 | * @return javax.swing.JTextField
|
---|
284 | */
|
---|
285 | private JTextField getKeywordTextField() {
|
---|
286 | if (keywordTextField == null) {
|
---|
287 | keywordTextField = new JTextField();
|
---|
288 | keywordTextField.addKeyListener(new KeyAdapter() {
|
---|
289 | @Override
|
---|
290 | public void keyTyped(KeyEvent arg0) {
|
---|
291 | if (arg0.getKeyChar() == KeyEvent.VK_ENTER){
|
---|
292 | doSearch();
|
---|
293 | }
|
---|
294 | }
|
---|
295 | });
|
---|
296 | }
|
---|
297 | return keywordTextField;
|
---|
298 | }
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * 讀懃エ「繝ッ繝シ繝峨r蜿門セ励☆繧� |
---|
302 | * @return
|
---|
303 | */
|
---|
304 | private String getFindWord(){
|
---|
305 | return getKeywordTextField().getText();
|
---|
306 | }
|
---|
307 |
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * This method initializes subjectList
|
---|
311 | *
|
---|
312 | * @return javax.swing.JList
|
---|
313 | */
|
---|
314 | private JTable getSubjectList() {
|
---|
315 | if (subjectList == null) {
|
---|
316 | subjectList = new JTable(){
|
---|
317 | /**
|
---|
318 | *
|
---|
319 | */
|
---|
320 | private static final long serialVersionUID = -3850550815070973157L;
|
---|
321 |
|
---|
322 | public String getToolTipText(MouseEvent e){
|
---|
323 | // 繧、繝吶Φ繝医°繧峨�繧ヲ繧ケ菴咲スョ繧貞叙蠕励@縲√ユ繝シ繝悶Ν蜀��繧サ繝ォ繧貞牡繧雁�縺� |
---|
324 | Object cell = getModel().getValueAt(rowAtPoint(e.getPoint()), columnAtPoint(e.getPoint()));
|
---|
325 | return cell == null ? "" : StringUtil.makeHtmlString(StringUtil.splitString(cell.toString()));
|
---|
326 | }
|
---|
327 | };
|
---|
328 | subjectList.setDefaultEditor(Object.class, null);
|
---|
329 | subjectList.addMouseListener(new MouseAdapter() {
|
---|
330 |
|
---|
331 | @Override
|
---|
332 | public void mouseClicked(MouseEvent e) {
|
---|
333 | int index = subjectList.getSelectedRow();
|
---|
334 | Object val = (subjectList.getValueAt(index, 1));
|
---|
335 | String subject = val.toString();
|
---|
336 | if (e.getClickCount() >= 2){
|
---|
337 |
|
---|
338 | if (findSubjectTriple(subject)){
|
---|
339 | addHistory(subject);
|
---|
340 | }
|
---|
341 | }
|
---|
342 |
|
---|
343 | if (SwingUtilities.isRightMouseButton(e)){
|
---|
344 | awakePopupIfHtml(val, e.getLocationOnScreen());
|
---|
345 | }
|
---|
346 |
|
---|
347 | }
|
---|
348 | });
|
---|
349 |
|
---|
350 | }
|
---|
351 | return subjectList;
|
---|
352 | }
|
---|
353 |
|
---|
354 | private SparqlResultListener createSparqlResultListener2(){
|
---|
355 | return new SparqlResultListener() {
|
---|
356 |
|
---|
357 | @Override
|
---|
358 | public void resultReceived(SparqlResultSet result) {
|
---|
359 | // 邨先棡繧偵∪縺壹�list縺ォ霑ス蜉
|
---|
360 | setProcessing(false);
|
---|
361 | setResults(result);
|
---|
362 | }
|
---|
363 |
|
---|
364 | @Override
|
---|
365 | public void uncaughtException(Thread t, Throwable e) {
|
---|
366 | JOptionPane.showMessageDialog(parent, "Execute error:"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
---|
367 | setProcessing(false);
|
---|
368 |
|
---|
369 | }
|
---|
370 | };
|
---|
371 | }
|
---|
372 |
|
---|
373 | private void setSubjectList(String endpoint, String obj){
|
---|
374 | listModel.addRow(new String[]{endpoint, obj});
|
---|
375 | }
|
---|
376 |
|
---|
377 | private DefaultTableModel clearSubjectList(){
|
---|
378 | listModel = new DefaultTableModel(new String[]{"endpoint", "result"}, 0);
|
---|
379 | getSubjectList().setModel(listModel);
|
---|
380 | return listModel;
|
---|
381 | }
|
---|
382 |
|
---|
383 | private void clearHistory(){
|
---|
384 | subjectHistoryList = new LinkedHashMap<String, List<String>>();
|
---|
385 | }
|
---|
386 |
|
---|
387 | private void setSubjectList(String endpoint, List<String> list){
|
---|
388 | subjectHistoryList.put(endpoint, list);
|
---|
389 | for (String item : list){
|
---|
390 | listModel.addRow(new String[]{endpoint, item});
|
---|
391 | }
|
---|
392 | getSubjectList().setModel(listModel);
|
---|
393 | }
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * This method initializes subjectScrollPane
|
---|
397 | *
|
---|
398 | * @return javax.swing.JScrollPane
|
---|
399 | */
|
---|
400 | private JScrollPane getSubjectScrollPane() {
|
---|
401 | if (subjectScrollPane == null) {
|
---|
402 | subjectScrollPane = new JScrollPane(getSubjectList());
|
---|
403 | }
|
---|
404 | return subjectScrollPane;
|
---|
405 | }
|
---|
406 |
|
---|
407 | /**
|
---|
408 | * This method initializes centerPanel
|
---|
409 | *
|
---|
410 | * @return javax.swing.JPanel
|
---|
411 | */
|
---|
412 | private JPanel getCenterPanel() {
|
---|
413 | if (centerPanel == null) {
|
---|
414 | centerPanel = new JPanel();
|
---|
415 | centerPanel.setLayout(new BorderLayout());
|
---|
416 | centerPanel.add(getSubjectScrollPane(), BorderLayout.CENTER);
|
---|
417 | }
|
---|
418 | return centerPanel;
|
---|
419 | }
|
---|
420 |
|
---|
421 | /**
|
---|
422 | * This method initializes footerPanel
|
---|
423 | *
|
---|
424 | * @return javax.swing.JPanel
|
---|
425 | */
|
---|
426 | private JPanel getFooterPanel() {
|
---|
427 | if (footerPanel == null) {
|
---|
428 | footerPanel = new JPanel();
|
---|
429 | footerPanel.setLayout(new BorderLayout());
|
---|
430 | footerPanel.add(getResultListScrollPane(), BorderLayout.CENTER);
|
---|
431 | }
|
---|
432 | return footerPanel;
|
---|
433 | }
|
---|
434 |
|
---|
435 | /**
|
---|
436 | * This method initializes resultListScrollPane
|
---|
437 | *
|
---|
438 | * @return javax.swing.JScrollPane
|
---|
439 | */
|
---|
440 | private JScrollPane getResultListScrollPane() {
|
---|
441 | if (resultListScrollPane == null) {
|
---|
442 | resultListScrollPane = new JScrollPane(getResultList());
|
---|
443 | }
|
---|
444 | return resultListScrollPane;
|
---|
445 | }
|
---|
446 |
|
---|
447 | /**
|
---|
448 | * This method initializes resultList
|
---|
449 | *
|
---|
450 | * @return javax.swing.JList
|
---|
451 | */
|
---|
452 | private JTable getResultList() {
|
---|
453 | if (resultList == null) {
|
---|
454 | resultList = new JTable(){
|
---|
455 | /**
|
---|
456 | *
|
---|
457 | */
|
---|
458 | private static final long serialVersionUID = 3332757068706348175L;
|
---|
459 |
|
---|
460 | public String getToolTipText(MouseEvent e){
|
---|
461 | // 繧、繝吶Φ繝医°繧峨�繧ヲ繧ケ菴咲スョ繧貞叙蠕励@縲√ユ繝シ繝悶Ν蜀��繧サ繝ォ繧貞牡繧雁�縺� |
---|
462 | Object cell = getModel().getValueAt(rowAtPoint(e.getPoint()), columnAtPoint(e.getPoint()));
|
---|
463 | return cell == null ? "" : StringUtil.makeHtmlString(StringUtil.splitString(cell.toString()));
|
---|
464 | }
|
---|
465 | };
|
---|
466 | resultList.setDefaultEditor(Object.class, null);
|
---|
467 | resultList.addMouseListener(new MouseAdapter() {
|
---|
468 | @Override
|
---|
469 | public void mouseClicked(MouseEvent e) {
|
---|
470 | int index = resultList.getSelectedRow();
|
---|
471 |
|
---|
472 | Object val = (resultList.getValueAt(index, 1));
|
---|
473 | String o = val.toString();
|
---|
474 |
|
---|
475 | if (e.getClickCount() >= 2){
|
---|
476 |
|
---|
477 | if (findSubjectTriple(o)){
|
---|
478 | clearSubjectList();
|
---|
479 |
|
---|
480 | setSubjectList("", o); // TODO endpoint
|
---|
481 | addHistory(o);
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | if (SwingUtilities.isRightMouseButton(e)){
|
---|
486 | awakePopupIfHtml(val, e.getLocationOnScreen());
|
---|
487 | }
|
---|
488 |
|
---|
489 | }
|
---|
490 | });
|
---|
491 |
|
---|
492 | }
|
---|
493 | return resultList;
|
---|
494 | }
|
---|
495 |
|
---|
496 | private void setResults(SparqlResultSet result){
|
---|
497 |
|
---|
498 | if (result == null || result.getDefaultResult() == null || result.getDefaultResult().size() == 0){
|
---|
499 | tableModel = new DefaultTableModel();
|
---|
500 | getResultList().setModel(tableModel);
|
---|
501 | return;
|
---|
502 | }
|
---|
503 | List<Map<String, RDFNode>> list = result.getDefaultResult();
|
---|
504 |
|
---|
505 | // header繧サ繝�ヨ
|
---|
506 | Map<String, RDFNode> columns = list.get(0);
|
---|
507 | List<String> clm = new ArrayList<String>();
|
---|
508 | for (String key : columns.keySet()){
|
---|
509 | clm.add(key);
|
---|
510 | }
|
---|
511 | tableModel = new DefaultTableModel(clm.toArray(new String[]{}), 0);
|
---|
512 |
|
---|
513 |
|
---|
514 | // 荳ュ霄ォ繧サ繝�ヨ
|
---|
515 | for (Map<String, RDFNode> r : list){
|
---|
516 | List<Object> row = new ArrayList<Object>();
|
---|
517 | for (String key : clm){
|
---|
518 | RDFNode node = r.get(key);
|
---|
519 | row.add(node);
|
---|
520 | }
|
---|
521 | tableModel.addRow(row.toArray(new Object[]{}));
|
---|
522 | }
|
---|
523 |
|
---|
524 | getResultList().setModel(tableModel);
|
---|
525 |
|
---|
526 | parent.setResults(result);
|
---|
527 |
|
---|
528 | }
|
---|
529 |
|
---|
530 | private void setProcessing(boolean processing){
|
---|
531 | this. processing = processing;
|
---|
532 | getSubjectList().setEnabled(!processing);
|
---|
533 | getRunQueryButton().setEnabled(!processing);
|
---|
534 | getResultList().setEnabled(!processing);
|
---|
535 | getKeywordTextField().setEnabled(!processing);
|
---|
536 | getFullMatchRadioButton().setEnabled(!processing);
|
---|
537 | getPartMatchRadioButton().setEnabled(!processing);
|
---|
538 | // getFindAllRadioButton().setEnabled(!processing);
|
---|
539 | getFindSubjectRadioButton().setEnabled(!processing);
|
---|
540 | getFindObjectRadioButton().setEnabled(!processing);
|
---|
541 | getFindLabelObjectRadioButton().setEnabled(!processing);
|
---|
542 |
|
---|
543 | updateButtonStates();
|
---|
544 | updateLimitButtonStates();
|
---|
545 |
|
---|
546 | parent.setProcessing(processing);
|
---|
547 | }
|
---|
548 |
|
---|
549 | private boolean isProcessing(){
|
---|
550 | return this.processing;
|
---|
551 | }
|
---|
552 |
|
---|
553 | /**
|
---|
554 | * This method initializes runQueryButton
|
---|
555 | *
|
---|
556 | * @return javax.swing.JButton
|
---|
557 | */
|
---|
558 | private JButton getRunQueryButton() {
|
---|
559 | if (runQueryButton == null) {
|
---|
560 | runQueryButton = new JButton("Find");
|
---|
561 | runQueryButton.addActionListener(new ActionListener() {
|
---|
562 |
|
---|
563 | @Override
|
---|
564 | public void actionPerformed(ActionEvent e) {
|
---|
565 | doSearch();
|
---|
566 | }
|
---|
567 | });
|
---|
568 | }
|
---|
569 | return runQueryButton;
|
---|
570 | }
|
---|
571 |
|
---|
572 | private void doSearch(){
|
---|
573 | if (isProcessing()){
|
---|
574 | return;
|
---|
575 | }
|
---|
576 |
|
---|
577 | initHistory();
|
---|
578 | initLimit();
|
---|
579 |
|
---|
580 | sa = createSparqlAccessor(true);
|
---|
581 | if (sa == null){
|
---|
582 | return;
|
---|
583 | }
|
---|
584 | setResults(null);
|
---|
585 | setProcessing(true);
|
---|
586 |
|
---|
587 |
|
---|
588 | // page蛻�崛逕ィ縺ォ繝舌ャ繧ッ繧「繝��
|
---|
589 | this.word = getFindWord();
|
---|
590 | this.fullMatch = isFullMatch();
|
---|
591 | this.limit = getLimit();
|
---|
592 | this.type = getFindType();
|
---|
593 |
|
---|
594 | sa.findSubject(word, fullMatch, limit, (limit != null ? (limit * page) : null), type, getTargetPropertyList(), createSparqlResultListener());
|
---|
595 |
|
---|
596 |
|
---|
597 | }
|
---|
598 |
|
---|
599 | private ThreadedSparqlAccessor createSparqlAccessor(boolean needEndpointDialog){
|
---|
600 | List<EndpointSettings> settings = getEndpointSettings(needEndpointDialog);
|
---|
601 | if (settings == null || settings.size() == 0){
|
---|
602 | return null;
|
---|
603 | }
|
---|
604 | ThreadedSparqlAccessor tsa = SparqlAccessorFactory.createSparqlAccessor(settings, new SparqlQueryListener() {
|
---|
605 | @Override
|
---|
606 | public void sparqlExecuted(String query) {
|
---|
607 | fromDate = new Date();
|
---|
608 | parent.addLogText("----------------");
|
---|
609 | parent.addLogText(query);
|
---|
610 | }
|
---|
611 | });
|
---|
612 |
|
---|
613 | return tsa;
|
---|
614 | }
|
---|
615 |
|
---|
616 | private List<EndpointSettings> getEndpointSettings(boolean withUi){
|
---|
617 | List<EndpointSettings> settings = new ArrayList<EndpointSettings>();
|
---|
618 |
|
---|
619 | EndpointSelector es = new EndpointSelector(null, EndpointSettingsManager.instance.getSettings());
|
---|
620 | if (withUi){
|
---|
621 | es.setVisible(true);
|
---|
622 | if (!es.isValid()){
|
---|
623 | return null;
|
---|
624 | }
|
---|
625 | }
|
---|
626 | EndpointSettings[] result = es.getSettings();
|
---|
627 |
|
---|
628 | for (EndpointSettings setting : result){
|
---|
629 | if (setting.isTarget()){
|
---|
630 | settings.add(setting);
|
---|
631 | }
|
---|
632 | }
|
---|
633 |
|
---|
634 | return settings;
|
---|
635 | }
|
---|
636 |
|
---|
637 | private SparqlResultListener createSparqlResultListener(){
|
---|
638 | return new SparqlResultListener() {
|
---|
639 |
|
---|
640 | @Override
|
---|
641 | public void resultReceived(SparqlResultSet result) {
|
---|
642 |
|
---|
643 | hasLimitNext = result.isHasNext();
|
---|
644 |
|
---|
645 | Date now = new Date();
|
---|
646 | long time = now.getTime() - fromDate.getTime();
|
---|
647 | parent.addLogText("---------------- result:"+time+" ms");
|
---|
648 | clearHistory();
|
---|
649 | clearSubjectList();
|
---|
650 | // 邨先棡繧偵∪縺壹�list縺ォ霑ス蜉
|
---|
651 | for (String endpoint : result.getResult().keySet()){
|
---|
652 | List<String> resultList = new ArrayList<String>();
|
---|
653 | List<Map<String, RDFNode>> results = result.getResult().get(endpoint);
|
---|
654 | for (Map<String, RDFNode> item : results){
|
---|
655 | RDFNode node = item.get("s");
|
---|
656 | resultList.add(node.toString());
|
---|
657 | }
|
---|
658 | setSubjectList(endpoint, resultList);
|
---|
659 | }
|
---|
660 |
|
---|
661 | setProcessing(false);
|
---|
662 | }
|
---|
663 |
|
---|
664 | @Override
|
---|
665 | public void uncaughtException(Thread t, Throwable e) {
|
---|
666 | JOptionPane.showMessageDialog(parent, "Execute error:"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
---|
667 | setProcessing(false);
|
---|
668 |
|
---|
669 | }
|
---|
670 | };
|
---|
671 | }
|
---|
672 |
|
---|
673 | /**
|
---|
674 | * This method initializes headerPanel
|
---|
675 | *
|
---|
676 | * @return javax.swing.JPanel
|
---|
677 | */
|
---|
678 | private JPanel getHeaderPanel() {
|
---|
679 | if (headerPanel == null) {
|
---|
680 | headerPanel = new JPanel();
|
---|
681 | headerPanel.setLayout(new BorderLayout());
|
---|
682 | headerPanel.add(getKeywordPanel(), BorderLayout.CENTER);
|
---|
683 | headerPanel.add(getOptionPanel(), BorderLayout.SOUTH);
|
---|
684 | headerPanel.add(getMovePanel(), BorderLayout.WEST);
|
---|
685 | }
|
---|
686 | return headerPanel;
|
---|
687 | }
|
---|
688 |
|
---|
689 | /**
|
---|
690 | * This method initializes limitPanel
|
---|
691 | *
|
---|
692 | * @return javax.swing.JPanel
|
---|
693 | */
|
---|
694 | private JPanel getLimitPanel() {
|
---|
695 | if (limitPanel == null) {
|
---|
696 | limitLabel = new JLabel();
|
---|
697 | limitLabel.setText(" LIMIT ");
|
---|
698 | limitLabel.setEnabled(false);
|
---|
699 | limitPanel = new JPanel();
|
---|
700 | limitPanel.setLayout(new BorderLayout());
|
---|
701 | limitPanel.add(getLimitEnableCheckBox(), BorderLayout.WEST);
|
---|
702 | limitPanel.add(limitLabel, BorderLayout.CENTER);
|
---|
703 | limitPanel.add(getLimitMainPanel(), BorderLayout.EAST);
|
---|
704 | }
|
---|
705 | return limitPanel;
|
---|
706 | }
|
---|
707 |
|
---|
708 | private Integer getLimit(){
|
---|
709 | try {
|
---|
710 | if (getLimitComboBox().isEnabled()){
|
---|
711 | return Integer.parseInt((String)getLimitComboBox().getSelectedItem());
|
---|
712 | }
|
---|
713 | } catch(Exception e){}
|
---|
714 | return null;
|
---|
715 | }
|
---|
716 |
|
---|
717 | /**
|
---|
718 | * This method initializes limitEnableCheckBox
|
---|
719 | *
|
---|
720 | * @return javax.swing.JCheckBox
|
---|
721 | */
|
---|
722 | private JCheckBox getLimitEnableCheckBox() {
|
---|
723 | if (limitEnableCheckBox == null) {
|
---|
724 | limitEnableCheckBox = new JCheckBox();
|
---|
725 | limitEnableCheckBox.addActionListener(new ActionListener() {
|
---|
726 |
|
---|
727 | @Override
|
---|
728 | public void actionPerformed(ActionEvent e) {
|
---|
729 | boolean enabled = getLimitEnableCheckBox().isSelected();
|
---|
730 | getLimitComboBox().setEnabled(enabled);
|
---|
731 | limitLabel.setEnabled(enabled);
|
---|
732 | updateLimitButtonStates();
|
---|
733 | }
|
---|
734 | });
|
---|
735 | }
|
---|
736 | return limitEnableCheckBox;
|
---|
737 | }
|
---|
738 |
|
---|
739 | /**
|
---|
740 | * This method initializes limitComboBox
|
---|
741 | *
|
---|
742 | * @return javax.swing.JComboBox
|
---|
743 | */
|
---|
744 | private JComboBox getLimitComboBox() {
|
---|
745 | if (limitComboBox == null) {
|
---|
746 | String[] limits = {"100","250","500","1000"};
|
---|
747 | limitComboBox = new JComboBox(limits);
|
---|
748 | limitComboBox.setEnabled(false);
|
---|
749 | }
|
---|
750 | return limitComboBox;
|
---|
751 | }
|
---|
752 |
|
---|
753 | /**
|
---|
754 | * This method initializes findSubjectRadioButton
|
---|
755 | *
|
---|
756 | * @return javax.swing.JRadioButton
|
---|
757 | */
|
---|
758 | private JRadioButton getFindSubjectRadioButton() {
|
---|
759 | if (findSubjectRadioButton == null) {
|
---|
760 | findSubjectRadioButton = new JRadioButton("Find Subject");
|
---|
761 | }
|
---|
762 | return findSubjectRadioButton;
|
---|
763 | }
|
---|
764 |
|
---|
765 | /**
|
---|
766 | * This method initializes findObjectRadioButton
|
---|
767 | *
|
---|
768 | * @return javax.swing.JRadioButton
|
---|
769 | */
|
---|
770 | private JRadioButton getFindObjectRadioButton() {
|
---|
771 | if (findObjectRadioButton == null) {
|
---|
772 | findObjectRadioButton = new JRadioButton("Find All Object");
|
---|
773 | }
|
---|
774 | return findObjectRadioButton;
|
---|
775 | }
|
---|
776 |
|
---|
777 | /**
|
---|
778 | * This method initializes findAllRadioButton
|
---|
779 | *
|
---|
780 | * @return javax.swing.JRadioButton
|
---|
781 | */
|
---|
782 | private JRadioButton getFindAllRadioButton() {
|
---|
783 | if (findAllRadioButton == null) {
|
---|
784 | findAllRadioButton = new JRadioButton("Find All");
|
---|
785 | findAllRadioButton.setEnabled(false);
|
---|
786 | }
|
---|
787 | return findAllRadioButton;
|
---|
788 | }
|
---|
789 |
|
---|
790 | /**
|
---|
791 | * This method initializes findLabelObjectRadioButton
|
---|
792 | *
|
---|
793 | * @return javax.swing.JRadioButton
|
---|
794 | */
|
---|
795 | private JRadioButton getFindLabelObjectRadioButton() {
|
---|
796 | if (findLabelObjectRadioButton == null) {
|
---|
797 | findLabelObjectRadioButton = new JRadioButton("Find Specific Object");
|
---|
798 | findLabelObjectRadioButton.addMouseListener(new MouseAdapter() {
|
---|
799 | @Override
|
---|
800 | public void mouseClicked(MouseEvent e) {
|
---|
801 | awakePropertyListPopup(e.getLocationOnScreen());
|
---|
802 | }
|
---|
803 | });
|
---|
804 | }
|
---|
805 | return findLabelObjectRadioButton;
|
---|
806 | }
|
---|
807 |
|
---|
808 | /**
|
---|
809 | * This method initializes movePanel
|
---|
810 | *
|
---|
811 | * @return javax.swing.JPanel
|
---|
812 | */
|
---|
813 | private JPanel getMovePanel() {
|
---|
814 | if (movePanel == null) {
|
---|
815 | movePanel = new JPanel();
|
---|
816 | movePanel.setLayout(new BoxLayout(movePanel, BoxLayout.X_AXIS));
|
---|
817 | movePanel.add(getPrevButton(), null);
|
---|
818 | movePanel.add(getNextButton(), null);
|
---|
819 | }
|
---|
820 | return movePanel;
|
---|
821 | }
|
---|
822 |
|
---|
823 | /**
|
---|
824 | * This method initializes prevButton
|
---|
825 | *
|
---|
826 | * @return javax.swing.JButton
|
---|
827 | */
|
---|
828 | private JButton getPrevButton() {
|
---|
829 | if (prevButton == null) {
|
---|
830 | prevButton = new JButton("竊�);
|
---|
831 | prevButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
832 | prevButton.setEnabled(false);
|
---|
833 | prevButton.addActionListener(new ActionListener() {
|
---|
834 |
|
---|
835 | @Override
|
---|
836 | public void actionPerformed(ActionEvent arg0) {
|
---|
837 | String s = getPrev();
|
---|
838 | if (s != null){
|
---|
839 | clearSubjectList();
|
---|
840 | if (historyIndex == 0){
|
---|
841 | for (String key : subjectHistoryList.keySet()){
|
---|
842 | setSubjectList(key, subjectHistoryList.get(key)); // 蜈ィ菴薙�繝偵せ繝医Μ繝ェ繧ケ繝� |
---|
843 | }
|
---|
844 | } else {
|
---|
845 | setSubjectList("", s);
|
---|
846 | }
|
---|
847 | findSubjectTriple(s);
|
---|
848 | }
|
---|
849 | }
|
---|
850 | });
|
---|
851 | }
|
---|
852 | return prevButton;
|
---|
853 | }
|
---|
854 |
|
---|
855 | /**
|
---|
856 | * This method initializes nextButton
|
---|
857 | *
|
---|
858 | * @return javax.swing.JButton
|
---|
859 | */
|
---|
860 | private JButton getNextButton() {
|
---|
861 | if (nextButton == null) {
|
---|
862 | nextButton = new JButton("竊�);
|
---|
863 | nextButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
864 | nextButton.setEnabled(false);
|
---|
865 | nextButton.addActionListener(new ActionListener() {
|
---|
866 |
|
---|
867 | @Override
|
---|
868 | public void actionPerformed(ActionEvent arg0) {
|
---|
869 | String s = getNext();
|
---|
870 | if (s != null){
|
---|
871 | clearSubjectList();
|
---|
872 | setSubjectList("", s); // TODO endpoint
|
---|
873 | findSubjectTriple(s);
|
---|
874 | }
|
---|
875 | }
|
---|
876 | });
|
---|
877 | }
|
---|
878 | return nextButton;
|
---|
879 | }
|
---|
880 |
|
---|
881 | private boolean findSubjectTriple(String s){
|
---|
882 | if (isProcessing()){
|
---|
883 | return false;
|
---|
884 | }
|
---|
885 | setProcessing(true);
|
---|
886 | if (!sa.findTripleFromSubject(s, createSparqlResultListener2())){
|
---|
887 | //
|
---|
888 | setProcessing(false);
|
---|
889 | // awakeIfHtml(s);
|
---|
890 | return false;
|
---|
891 | }
|
---|
892 | // table繧ッ繝ェ繧「
|
---|
893 | setResults(null);
|
---|
894 | return true;
|
---|
895 | }
|
---|
896 |
|
---|
897 | private boolean awakePopupIfHtml(Object o, Point p){
|
---|
898 |
|
---|
899 | if (o == null || o.toString().trim().isEmpty()){
|
---|
900 | return false;
|
---|
901 | }
|
---|
902 | String s = o.toString();
|
---|
903 |
|
---|
904 | if (o instanceof RDFNode){
|
---|
905 | if (((RDFNode)o).isLiteral()){
|
---|
906 | s = ((RDFNode)o).asLiteral().getString();
|
---|
907 | }
|
---|
908 | }
|
---|
909 | JPopupMenu popup = new JPopupMenu(s);
|
---|
910 |
|
---|
911 | if (s.startsWith("http://") || s.startsWith("https://")){
|
---|
912 | JMenuItem menu = new JMenuItem("Show on Web Browser");
|
---|
913 | menu.addActionListener(new ActionListener() {
|
---|
914 |
|
---|
915 | @Override
|
---|
916 | public void actionPerformed(ActionEvent e) {
|
---|
917 | JMenuItem menu = (JMenuItem)e.getSource();
|
---|
918 | JPopupMenu parent = (JPopupMenu)menu.getParent();
|
---|
919 | try {
|
---|
920 | awakeHtml(parent.getLabel());
|
---|
921 | } catch (URISyntaxException ex) {
|
---|
922 | ex.printStackTrace();
|
---|
923 | } catch (IOException ex) {
|
---|
924 | ex.printStackTrace();
|
---|
925 | }
|
---|
926 | }
|
---|
927 | });
|
---|
928 | popup.add(menu);
|
---|
929 | } else {
|
---|
930 | JMenuItem menu1 = new JMenuItem("Search By Google");
|
---|
931 | menu1.addActionListener(new ActionListener() {
|
---|
932 |
|
---|
933 | @Override
|
---|
934 | public void actionPerformed(ActionEvent e) {
|
---|
935 | JMenuItem menu = (JMenuItem)e.getSource();
|
---|
936 | JPopupMenu parent = (JPopupMenu)menu.getParent();
|
---|
937 | try {
|
---|
938 | awakeHtml("https://www.google.co.jp/search?q=" + URLEncoder.encode(parent.getLabel(), "UTF-8"));
|
---|
939 | } catch (URISyntaxException ex) {
|
---|
940 | ex.printStackTrace();
|
---|
941 | } catch (IOException ex) {
|
---|
942 | ex.printStackTrace();
|
---|
943 | }
|
---|
944 | }
|
---|
945 | });
|
---|
946 | popup.add(menu1);
|
---|
947 | JMenuItem menu2 = new JMenuItem("Search By GoogleMaps");
|
---|
948 | menu2.addActionListener(new ActionListener() {
|
---|
949 |
|
---|
950 | @Override
|
---|
951 | public void actionPerformed(ActionEvent e) {
|
---|
952 | JMenuItem menu = (JMenuItem)e.getSource();
|
---|
953 | JPopupMenu parent = (JPopupMenu)menu.getParent();
|
---|
954 | try {
|
---|
955 | awakeHtml("https://maps.google.com/maps?q=" + URLEncoder.encode(parent.getLabel(), "UTF-8"));
|
---|
956 | } catch (URISyntaxException ex) {
|
---|
957 | ex.printStackTrace();
|
---|
958 | } catch (IOException ex) {
|
---|
959 | ex.printStackTrace();
|
---|
960 | }
|
---|
961 | }
|
---|
962 | });
|
---|
963 | popup.add(menu2);
|
---|
964 | }
|
---|
965 |
|
---|
966 | popup.setLocation(p);
|
---|
967 |
|
---|
968 | SwingUtilities.convertPointFromScreen(p, this.parent);
|
---|
969 |
|
---|
970 | popup.show(this.parent, p.x, p.y);
|
---|
971 |
|
---|
972 | return false;
|
---|
973 | }
|
---|
974 |
|
---|
975 | private void awakeHtml(String url) throws IOException, URISyntaxException{
|
---|
976 | Desktop desktop = Desktop.getDesktop();
|
---|
977 | URI uri = new URI(url);
|
---|
978 | desktop.browse(uri);
|
---|
979 | }
|
---|
980 |
|
---|
981 | // 縺薙%縺九i縲}roperty驕ク謚樒畑
|
---|
982 |
|
---|
983 | private PropertyDialog propDialog;
|
---|
984 |
|
---|
985 | private List<EditableListItem> targetObjectTypes;
|
---|
986 |
|
---|
987 | /**
|
---|
988 | * proeprty驕ク謚樒畑POPUP陦ィ遉コ
|
---|
989 | * @param p
|
---|
990 | * @return
|
---|
991 | */
|
---|
992 | private boolean awakePropertyListPopup(Point p){
|
---|
993 | DefaultListModel model = new DefaultListModel();
|
---|
994 | for (EditableListItem tp : getTargetPropertyListItem()){
|
---|
995 | model.addElement(tp);
|
---|
996 | }
|
---|
997 |
|
---|
998 | EditableList properties = new EditableList(model);
|
---|
999 | propDialog = new PropertyDialog(this.parent,properties);
|
---|
1000 | properties.getTextField().addKeyListener(new KeyAdapter() {
|
---|
1001 |
|
---|
1002 | @Override
|
---|
1003 | public void keyReleased(KeyEvent e) {
|
---|
1004 | List<String> propList = getPropertyList();
|
---|
1005 | String word = ((JTextField)e.getSource()).getText();
|
---|
1006 |
|
---|
1007 | if (word.length() > 2){
|
---|
1008 | List<String> candidates = StringUtil.getPartHitString(propList, word);
|
---|
1009 |
|
---|
1010 | if (candidates.size() < 20){
|
---|
1011 | awakeCandidateList(candidates, propDialog.getList().getTextField().getLocationOnScreen());
|
---|
1012 | }
|
---|
1013 | } else {
|
---|
1014 | if (popup != null){
|
---|
1015 | popup.setVisible(false);
|
---|
1016 | popup = null;
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | }
|
---|
1021 | });
|
---|
1022 | properties.getModel().addListDataListener(new ListDataListener() {
|
---|
1023 |
|
---|
1024 | @Override
|
---|
1025 | public void intervalRemoved(ListDataEvent e) {
|
---|
1026 | propDialog.pack();
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | @Override
|
---|
1030 | public void intervalAdded(ListDataEvent e) {
|
---|
1031 | propDialog.pack();
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | @Override
|
---|
1035 | public void contentsChanged(ListDataEvent e) {
|
---|
1036 | }
|
---|
1037 | });
|
---|
1038 | properties.getTextField().addActionListener(new ActionListener() {
|
---|
1039 |
|
---|
1040 | @Override
|
---|
1041 | public void actionPerformed(ActionEvent e) {
|
---|
1042 | if (propDialog.getList().getTextField().getText().isEmpty()){
|
---|
1043 | //
|
---|
1044 | propDialog.setOK(true);
|
---|
1045 | propDialog.setVisible(false);
|
---|
1046 | }
|
---|
1047 | }
|
---|
1048 | });
|
---|
1049 | propDialog.setLocation(p);
|
---|
1050 | propDialog.pack();
|
---|
1051 | propDialog.setModalityType(ModalityType.DOCUMENT_MODAL);
|
---|
1052 | propDialog.setVisible(true);
|
---|
1053 |
|
---|
1054 | if (popup != null){
|
---|
1055 | popup.setVisible(false);
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | if (!propDialog.isOK()){
|
---|
1059 | return false;
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | model = (DefaultListModel)properties.getModel();
|
---|
1063 |
|
---|
1064 | getTargetPropertyListItem().clear();
|
---|
1065 | for (int i=0; i<model.getSize(); i++){
|
---|
1066 | Object item = model.getElementAt(i);
|
---|
1067 | if (item instanceof EditableListItem){
|
---|
1068 | getTargetPropertyListItem().add((EditableListItem)item);
|
---|
1069 | }
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | return true;
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | private List<String> propertyList;
|
---|
1076 | private boolean isProcessingProperty = false;
|
---|
1077 |
|
---|
1078 | private List<String> getPropertyList(){
|
---|
1079 | if (propertyList == null && !isProcessingProperty){
|
---|
1080 | try {
|
---|
1081 | ThreadedSparqlAccessor tsa = createSparqlAccessor(false);
|
---|
1082 | if (tsa != null){
|
---|
1083 | /*
|
---|
1084 | List<Map<String, RDFNode>> results = tsa.findPropertyList();
|
---|
1085 | for (Map<String, RDFNode> result : results){
|
---|
1086 | for (String nodeStr : result.keySet()){
|
---|
1087 | if (nodeStr != null && !propertyList.contains(nodeStr)){
|
---|
1088 | propertyList.add(nodeStr);
|
---|
1089 | }
|
---|
1090 | }
|
---|
1091 | }
|
---|
1092 | */
|
---|
1093 | isProcessingProperty = true;
|
---|
1094 | tsa.findPropertyList(new SparqlResultListener() {
|
---|
1095 |
|
---|
1096 | @Override
|
---|
1097 | public void uncaughtException(Thread t, Throwable e) {
|
---|
1098 | JOptionPane.showMessageDialog(parent, "Execute error:"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
---|
1099 | setProcessing(false);
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | @Override
|
---|
1103 | public void resultReceived(SparqlResultSet resultSet) {
|
---|
1104 | propertyList = new ArrayList<String>();
|
---|
1105 | Map<String, List<Map<String, RDFNode>>> resultByEndpoint = resultSet.getResult();
|
---|
1106 | for (List<Map<String, RDFNode>> results : resultByEndpoint.values()){
|
---|
1107 | for (Map<String, RDFNode> result : results){
|
---|
1108 | for (String nodeStr : result.keySet()){
|
---|
1109 | if (nodeStr != null && !propertyList.contains(nodeStr)){
|
---|
1110 | propertyList.add(nodeStr);
|
---|
1111 | }
|
---|
1112 | }
|
---|
1113 | }
|
---|
1114 | }
|
---|
1115 | isProcessingProperty = false;
|
---|
1116 | }
|
---|
1117 | });
|
---|
1118 | }
|
---|
1119 | } catch (Exception e){
|
---|
1120 | // 繧ィ繝ゥ繝シ縺ッ闖ッ鮗励↓繧ケ繝ォ繝シ
|
---|
1121 | }
|
---|
1122 | }
|
---|
1123 |
|
---|
1124 | return propertyList;
|
---|
1125 | }
|
---|
1126 |
|
---|
1127 | private List<EditableListItem> getTargetPropertyListItem(){
|
---|
1128 | if (targetObjectTypes == null){
|
---|
1129 | targetObjectTypes = new ArrayList<EditableListItem>();
|
---|
1130 | targetObjectTypes.add(new EditableListItem(DEFAULT_PROPERTY_TYPE, false));
|
---|
1131 | }
|
---|
1132 | return targetObjectTypes;
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | JPopupMenu popup;
|
---|
1136 |
|
---|
1137 | private void awakeCandidateList(List<String> candidates, Point p){
|
---|
1138 | if (popup != null){
|
---|
1139 | popup.setVisible(false);
|
---|
1140 | }
|
---|
1141 | popup = new JPopupMenu();
|
---|
1142 |
|
---|
1143 | for (String candidate : candidates){
|
---|
1144 | JMenuItem item = new JMenuItem(candidate);
|
---|
1145 | item.addActionListener(new ActionListener() {
|
---|
1146 |
|
---|
1147 | @Override
|
---|
1148 | public void actionPerformed(ActionEvent e) {
|
---|
1149 | propDialog.getList().getTextField().setText(((JMenuItem)e.getSource()).getText());
|
---|
1150 | popup.setVisible(false);
|
---|
1151 | popup = null;
|
---|
1152 | }
|
---|
1153 | });
|
---|
1154 | popup.add(item);
|
---|
1155 | }
|
---|
1156 | popup.setLocation(p.x + 400, p.y + 20);
|
---|
1157 | popup.setVisible(true);
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | private void initHistory(){
|
---|
1161 | this.history = new ArrayList<String>();
|
---|
1162 | this.historyIndex = -1;
|
---|
1163 | updateButtonStates();
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 | private void addHistory(String item){
|
---|
1167 |
|
---|
1168 | if (this.historyIndex >= 0 && this.historyIndex < (this.history.size() - 1)){
|
---|
1169 | for (int i=this.history.size()-1; i > this.historyIndex; i--){
|
---|
1170 | this.history.remove(i);
|
---|
1171 | }
|
---|
1172 | }
|
---|
1173 | this.history.add(item);
|
---|
1174 | this.historyIndex++;
|
---|
1175 | updateButtonStates();
|
---|
1176 | }
|
---|
1177 |
|
---|
1178 | private String getPrev(){
|
---|
1179 | if (hasPrev()){
|
---|
1180 | --historyIndex;
|
---|
1181 | updateButtonStates();
|
---|
1182 | return this.history.get(historyIndex);
|
---|
1183 | }
|
---|
1184 | return null;
|
---|
1185 | }
|
---|
1186 |
|
---|
1187 | private String getNext(){
|
---|
1188 | if (hasNext()){
|
---|
1189 | ++historyIndex;
|
---|
1190 | updateButtonStates();
|
---|
1191 | return this.history.get(historyIndex);
|
---|
1192 | }
|
---|
1193 | return null;
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | private void updateButtonStates(){
|
---|
1197 | if (!this.processing){
|
---|
1198 | this.getPrevButton().setEnabled(hasPrev());
|
---|
1199 | this.getNextButton().setEnabled(hasNext());
|
---|
1200 | } else {
|
---|
1201 | this.getPrevButton().setEnabled(false);
|
---|
1202 | this.getNextButton().setEnabled(false);
|
---|
1203 | }
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | private boolean hasPrev(){
|
---|
1207 | if (history.size() != 0 && historyIndex > 0){
|
---|
1208 | return true;
|
---|
1209 | }
|
---|
1210 | return false;
|
---|
1211 | }
|
---|
1212 |
|
---|
1213 | private boolean hasNext(){
|
---|
1214 | if ((historyIndex + 1) < history.size()){
|
---|
1215 | return true;
|
---|
1216 | }
|
---|
1217 | return false;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | /**
|
---|
1221 | * This method initializes limitMainPanel
|
---|
1222 | *
|
---|
1223 | * @return javax.swing.JPanel
|
---|
1224 | */
|
---|
1225 | private JPanel getLimitMainPanel() {
|
---|
1226 | if (limitMainPanel == null) {
|
---|
1227 | limitMainPanel = new JPanel();
|
---|
1228 | limitMainPanel.setLayout(new BorderLayout());
|
---|
1229 | limitMainPanel.add(getLimitComboBox(), BorderLayout.WEST);
|
---|
1230 | limitMainPanel.add(getLimitPrevButton(), BorderLayout.CENTER);
|
---|
1231 | limitMainPanel.add(getLimitNextButton(), BorderLayout.EAST);
|
---|
1232 | }
|
---|
1233 | return limitMainPanel;
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | /**
|
---|
1237 | * This method initializes limitPrevButton
|
---|
1238 | *
|
---|
1239 | * @return javax.swing.JButton
|
---|
1240 | */
|
---|
1241 | private JButton getLimitPrevButton() {
|
---|
1242 | if (limitPrevButton == null) {
|
---|
1243 | limitPrevButton = new JButton("竊�);
|
---|
1244 | limitPrevButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
1245 | limitPrevButton.setEnabled(false);
|
---|
1246 | limitPrevButton.addActionListener(new ActionListener() {
|
---|
1247 | @Override
|
---|
1248 | public void actionPerformed(ActionEvent arg0) {
|
---|
1249 | setProcessing(true);
|
---|
1250 | sa.findSubject(word, fullMatch, limit, (limit * (--page)), type, getTargetPropertyList(), createSparqlResultListener());
|
---|
1251 | }
|
---|
1252 | });
|
---|
1253 | }
|
---|
1254 | return limitPrevButton;
|
---|
1255 | }
|
---|
1256 |
|
---|
1257 | /**
|
---|
1258 | * This method initializes limitNextButton
|
---|
1259 | *
|
---|
1260 | * @return javax.swing.JButton
|
---|
1261 | */
|
---|
1262 | private JButton getLimitNextButton() {
|
---|
1263 | if (limitNextButton == null) {
|
---|
1264 | limitNextButton = new JButton("竊�);
|
---|
1265 | limitNextButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
1266 | limitNextButton.setEnabled(false);
|
---|
1267 | limitNextButton.addActionListener(new ActionListener() {
|
---|
1268 | @Override
|
---|
1269 | public void actionPerformed(ActionEvent arg0) {
|
---|
1270 | setProcessing(true);
|
---|
1271 |
|
---|
1272 | sa.findSubject(word, fullMatch, limit, (limit * (++page)), type, getTargetPropertyList(), createSparqlResultListener());
|
---|
1273 | }
|
---|
1274 | });
|
---|
1275 | }
|
---|
1276 | return limitNextButton;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | private void initLimit(){
|
---|
1280 | limit = this.getLimit();
|
---|
1281 | page = 0;
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | private String[] getTargetPropertyList(){
|
---|
1285 | List<String> ret = new ArrayList<String>();
|
---|
1286 | if (targetObjectTypes != null && targetObjectTypes.size() > 0){
|
---|
1287 | for (EditableListItem item : targetObjectTypes){
|
---|
1288 | ret.add(item.text);
|
---|
1289 | }
|
---|
1290 | } else {
|
---|
1291 | ret.add(DEFAULT_PROPERTY_TYPE);
|
---|
1292 | }
|
---|
1293 | return ret.toArray(new String[0]);
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | private void updateLimitButtonStates(){
|
---|
1297 | if (!this.processing && this.getLimitEnableCheckBox().isSelected()){
|
---|
1298 | this.getLimitPrevButton().setEnabled(page != 0);
|
---|
1299 | this.getLimitNextButton().setEnabled(hasLimitNext);
|
---|
1300 | } else {
|
---|
1301 | this.getLimitPrevButton().setEnabled(false);
|
---|
1302 | this.getLimitNextButton().setEnabled(false);
|
---|
1303 | }
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | class PropertyDialog extends JDialog {
|
---|
1307 | /**
|
---|
1308 | *
|
---|
1309 | */
|
---|
1310 | private static final long serialVersionUID = -638100288439239858L;
|
---|
1311 | private EditableList list;
|
---|
1312 | private boolean isOK;
|
---|
1313 |
|
---|
1314 | public PropertyDialog(Window parent, EditableList list){
|
---|
1315 | super(parent);
|
---|
1316 |
|
---|
1317 | // this.setUndecorated(true);
|
---|
1318 | this.setLayout(new BorderLayout());
|
---|
1319 | this.list = list;
|
---|
1320 | this.add(list, BorderLayout.CENTER);
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | public EditableList getList(){
|
---|
1324 | return this.list;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | public void setOK(boolean value){
|
---|
1328 | this.isOK = value;
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | public boolean isOK(){
|
---|
1332 | return this.isOK;
|
---|
1333 | }
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | }
|
---|