[9] | 1 | package hozo.sparql.gui;
|
---|
| 2 |
|
---|
| 3 | import java.awt.BorderLayout;
|
---|
| 4 | import java.awt.Desktop;
|
---|
| 5 | import java.awt.Dimension;
|
---|
| 6 | import java.awt.FlowLayout;
|
---|
| 7 | import java.awt.Insets;
|
---|
| 8 | import java.awt.Point;
|
---|
| 9 | import java.awt.Window;
|
---|
| 10 | import java.awt.Dialog.ModalityType;
|
---|
| 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.HashMap;
|
---|
| 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.JList;
|
---|
| 36 | import javax.swing.JMenuItem;
|
---|
| 37 | import javax.swing.JOptionPane;
|
---|
| 38 | import javax.swing.JPanel;
|
---|
| 39 | import javax.swing.JPopupMenu;
|
---|
| 40 | import javax.swing.JRadioButton;
|
---|
| 41 | import javax.swing.JScrollPane;
|
---|
| 42 | import javax.swing.JSeparator;
|
---|
| 43 | import javax.swing.JSplitPane;
|
---|
| 44 | import javax.swing.JTable;
|
---|
| 45 | import javax.swing.JTextField;
|
---|
| 46 | import javax.swing.SwingConstants;
|
---|
| 47 | import javax.swing.SwingUtilities;
|
---|
| 48 | import javax.swing.event.ListDataEvent;
|
---|
| 49 | import javax.swing.event.ListDataListener;
|
---|
| 50 | import javax.swing.table.DefaultTableModel;
|
---|
| 51 |
|
---|
[17] | 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.EditableList;
|
---|
| 60 | import hozo.sparql.util.EditableListItem;
|
---|
| 61 | import hozo.sparql.util.StringUtil;
|
---|
[9] | 62 |
|
---|
| 63 | import com.hp.hpl.jena.rdf.model.RDFNode;
|
---|
| 64 |
|
---|
| 65 | public class KeywordSearchPanel 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 JList 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 DefaultListModel 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 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 KeywordSearchPanel(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 JList getSubjectList() {
|
---|
| 315 | if (subjectList == null) {
|
---|
| 316 | subjectList = new JList();
|
---|
| 317 | subjectList.addMouseListener(new MouseAdapter() {
|
---|
| 318 |
|
---|
| 319 | @Override
|
---|
| 320 | public void mouseClicked(MouseEvent e) {
|
---|
| 321 |
|
---|
| 322 | Object var = getSubjectList().getSelectedValue();
|
---|
| 323 |
|
---|
| 324 | String subject = var.toString();
|
---|
| 325 | if (e.getClickCount() >= 2){
|
---|
| 326 |
|
---|
| 327 | if (findSubjectTriple(subject)){
|
---|
| 328 | addHistory(subject);
|
---|
| 329 | }
|
---|
| 330 | }
|
---|
| 331 | if (SwingUtilities.isRightMouseButton(e)){
|
---|
| 332 | awakePopupIfHtml(var, e.getLocationOnScreen());
|
---|
| 333 | }
|
---|
| 334 |
|
---|
| 335 | }
|
---|
| 336 | });
|
---|
| 337 |
|
---|
| 338 | }
|
---|
| 339 | return subjectList;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | private SparqlResultListener createSparqlResultListener2(){
|
---|
| 343 | return new SparqlResultListener() {
|
---|
| 344 |
|
---|
| 345 | @Override
|
---|
| 346 | public void resultReceived(SparqlResultSet result) {
|
---|
| 347 | // 邨先棡繧偵∪縺壹�list縺ォ霑ス蜉
|
---|
| 348 | setProcessing(false);
|
---|
| 349 | setResults(result);
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 | @Override
|
---|
| 353 | public void uncaughtException(Thread t, Throwable e) {
|
---|
| 354 | JOptionPane.showMessageDialog(parent, "Execute error:"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
---|
| 355 | setProcessing(false);
|
---|
| 356 |
|
---|
| 357 | }
|
---|
| 358 | };
|
---|
| 359 | }
|
---|
| 360 |
|
---|
| 361 | private void setSubjectList(String obj){
|
---|
| 362 | listModel = new DefaultListModel();
|
---|
| 363 | listModel.addElement(obj);
|
---|
| 364 | getSubjectList().setModel(listModel);
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | private void setSubjectList(List<String> list){
|
---|
| 368 | subjectHistoryList = list;
|
---|
| 369 | listModel = new DefaultListModel();
|
---|
| 370 | for (String item : list){
|
---|
| 371 | listModel.addElement(item);
|
---|
| 372 | }
|
---|
| 373 | getSubjectList().setModel(listModel);
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | /**
|
---|
| 377 | * This method initializes subjectScrollPane
|
---|
| 378 | *
|
---|
| 379 | * @return javax.swing.JScrollPane
|
---|
| 380 | */
|
---|
| 381 | private JScrollPane getSubjectScrollPane() {
|
---|
| 382 | if (subjectScrollPane == null) {
|
---|
| 383 | subjectScrollPane = new JScrollPane(getSubjectList());
|
---|
| 384 | }
|
---|
| 385 | return subjectScrollPane;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | /**
|
---|
| 389 | * This method initializes centerPanel
|
---|
| 390 | *
|
---|
| 391 | * @return javax.swing.JPanel
|
---|
| 392 | */
|
---|
| 393 | private JPanel getCenterPanel() {
|
---|
| 394 | if (centerPanel == null) {
|
---|
| 395 | centerPanel = new JPanel();
|
---|
| 396 | centerPanel.setLayout(new BorderLayout());
|
---|
| 397 | centerPanel.add(getSubjectScrollPane(), BorderLayout.CENTER);
|
---|
| 398 | }
|
---|
| 399 | return centerPanel;
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | /**
|
---|
| 403 | * This method initializes footerPanel
|
---|
| 404 | *
|
---|
| 405 | * @return javax.swing.JPanel
|
---|
| 406 | */
|
---|
| 407 | private JPanel getFooterPanel() {
|
---|
| 408 | if (footerPanel == null) {
|
---|
| 409 | footerPanel = new JPanel();
|
---|
| 410 | footerPanel.setLayout(new BorderLayout());
|
---|
| 411 | footerPanel.add(getResultListScrollPane(), BorderLayout.CENTER);
|
---|
| 412 | }
|
---|
| 413 | return footerPanel;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | /**
|
---|
| 417 | * This method initializes resultListScrollPane
|
---|
| 418 | *
|
---|
| 419 | * @return javax.swing.JScrollPane
|
---|
| 420 | */
|
---|
| 421 | private JScrollPane getResultListScrollPane() {
|
---|
| 422 | if (resultListScrollPane == null) {
|
---|
| 423 | resultListScrollPane = new JScrollPane(getResultList());
|
---|
| 424 | }
|
---|
| 425 | return resultListScrollPane;
|
---|
| 426 | }
|
---|
| 427 |
|
---|
| 428 | /**
|
---|
| 429 | * This method initializes resultList
|
---|
| 430 | *
|
---|
| 431 | * @return javax.swing.JList
|
---|
| 432 | */
|
---|
| 433 | private JTable getResultList() {
|
---|
| 434 | if (resultList == null) {
|
---|
| 435 | resultList = new JTable(){
|
---|
| 436 | /**
|
---|
| 437 | *
|
---|
| 438 | */
|
---|
| 439 | private static final long serialVersionUID = 2013472265872397926L;
|
---|
| 440 |
|
---|
| 441 | public String getToolTipText(MouseEvent e){
|
---|
| 442 | // 繧、繝吶Φ繝医°繧峨�繧ヲ繧ケ菴咲スョ繧貞叙蠕励@縲√ユ繝シ繝悶Ν蜀��繧サ繝ォ繧貞牡繧雁�縺� |
---|
| 443 | Object cell = getModel().getValueAt(rowAtPoint(e.getPoint()), columnAtPoint(e.getPoint()));
|
---|
| 444 | return cell == null ? "" : StringUtil.makeHtmlString(StringUtil.splitString(cell.toString()));
|
---|
| 445 | }
|
---|
| 446 | };
|
---|
| 447 | resultList.setDefaultEditor(Object.class, null);
|
---|
| 448 | resultList.addMouseListener(new MouseAdapter() {
|
---|
| 449 | @Override
|
---|
| 450 | public void mouseClicked(MouseEvent e) {
|
---|
| 451 | int index = resultList.getSelectedRow();
|
---|
| 452 |
|
---|
| 453 | Object var = (resultList.getValueAt(index, 1));
|
---|
| 454 | String o = var.toString();
|
---|
| 455 |
|
---|
| 456 | if (e.getClickCount() >= 2){
|
---|
| 457 |
|
---|
| 458 | setSubjectList(o);
|
---|
| 459 |
|
---|
| 460 | if (findSubjectTriple(o)){
|
---|
| 461 | addHistory(o);
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
| 464 |
|
---|
| 465 | if (SwingUtilities.isRightMouseButton(e)){
|
---|
| 466 | awakePopupIfHtml(var, e.getLocationOnScreen());
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
| 469 | });
|
---|
| 470 |
|
---|
| 471 | }
|
---|
| 472 | return resultList;
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | private void setResults(SparqlResultSet result){
|
---|
| 476 |
|
---|
| 477 | if (result == null || result.getDefaultResult() == null || result.getDefaultResult().size() == 0){
|
---|
| 478 | tableModel = new DefaultTableModel();
|
---|
| 479 | getResultList().setModel(tableModel);
|
---|
| 480 | return;
|
---|
| 481 | }
|
---|
| 482 | List<Map<String, RDFNode>> list = result.getDefaultResult();
|
---|
| 483 |
|
---|
| 484 | // header繧サ繝�ヨ
|
---|
| 485 | Map<String, RDFNode> columns = list.get(0);
|
---|
| 486 | List<String> clm = new ArrayList<String>();
|
---|
| 487 | for (String key : columns.keySet()){
|
---|
| 488 | clm.add(key);
|
---|
| 489 | }
|
---|
| 490 | tableModel = new DefaultTableModel(clm.toArray(new String[]{}), 0);
|
---|
| 491 |
|
---|
| 492 |
|
---|
| 493 | // 荳ュ霄ォ繧サ繝�ヨ
|
---|
| 494 | for (Map<String, RDFNode> r : list){
|
---|
| 495 | List<Object> row = new ArrayList<Object>();
|
---|
| 496 | for (String key : clm){
|
---|
| 497 | RDFNode node = r.get(key);
|
---|
| 498 | row.add(node);
|
---|
| 499 | }
|
---|
| 500 | tableModel.addRow(row.toArray(new Object[]{}));
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | getResultList().setModel(tableModel);
|
---|
| 504 |
|
---|
| 505 | parent.setResults(result);
|
---|
| 506 |
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | private void setProcessing(boolean processing){
|
---|
| 510 | this. processing = processing;
|
---|
| 511 | getSubjectList().setEnabled(!processing);
|
---|
| 512 | getRunQueryButton().setEnabled(!processing);
|
---|
| 513 | getResultList().setEnabled(!processing);
|
---|
| 514 | getKeywordTextField().setEnabled(!processing);
|
---|
| 515 | getFullMatchRadioButton().setEnabled(!processing);
|
---|
| 516 | getPartMatchRadioButton().setEnabled(!processing);
|
---|
| 517 | // getFindAllRadioButton().setEnabled(!processing);
|
---|
| 518 | getFindSubjectRadioButton().setEnabled(!processing);
|
---|
| 519 | getFindObjectRadioButton().setEnabled(!processing);
|
---|
| 520 | getFindLabelObjectRadioButton().setEnabled(!processing);
|
---|
| 521 |
|
---|
| 522 | updateButtonStates();
|
---|
| 523 | updateLimitButtonStates();
|
---|
| 524 |
|
---|
| 525 | parent.setProcessing(processing);
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | private boolean isProcessing(){
|
---|
| 529 | return this.processing;
|
---|
| 530 | }
|
---|
| 531 |
|
---|
| 532 | /**
|
---|
| 533 | * This method initializes runQueryButton
|
---|
| 534 | *
|
---|
| 535 | * @return javax.swing.JButton
|
---|
| 536 | */
|
---|
| 537 | private JButton getRunQueryButton() {
|
---|
| 538 | if (runQueryButton == null) {
|
---|
| 539 | runQueryButton = new JButton("Find");
|
---|
| 540 | runQueryButton.addActionListener(new ActionListener() {
|
---|
| 541 |
|
---|
| 542 | @Override
|
---|
| 543 | public void actionPerformed(ActionEvent e) {
|
---|
| 544 | doSearch();
|
---|
| 545 | }
|
---|
| 546 | });
|
---|
| 547 | }
|
---|
| 548 | return runQueryButton;
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 | private void doSearch(){
|
---|
| 552 | if (isProcessing()){
|
---|
| 553 | return;
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | initHistory();
|
---|
| 557 | initLimit();
|
---|
| 558 |
|
---|
| 559 | setResults(null);
|
---|
| 560 | setProcessing(true);
|
---|
| 561 |
|
---|
| 562 | sa = createSparqlAccessor();
|
---|
| 563 |
|
---|
| 564 | // page蛻�崛逕ィ縺ォ繝舌ャ繧ッ繧「繝��
|
---|
| 565 | this.word = getFindWord();
|
---|
| 566 | this.fullMatch = isFullMatch();
|
---|
| 567 | this.limit = getLimit();
|
---|
| 568 | this.type = getFindType();
|
---|
| 569 |
|
---|
| 570 | sa.findSubject(word, fullMatch, limit, (limit != null ? (limit * page) : null), type, getTargetPropertyList(), createSparqlResultListener());
|
---|
| 571 | }
|
---|
| 572 |
|
---|
| 573 | private ThreadedSparqlAccessor createSparqlAccessor(){
|
---|
| 574 | ThreadedSparqlAccessor sa = SparqlAccessorFactory.createSparqlAccessor(EndpointSettingsManager.instance.getSetting(parent.getCurrentEndPoint()), new SparqlQueryListener() {
|
---|
| 575 | @Override
|
---|
| 576 | public void sparqlExecuted(String query) {
|
---|
| 577 | fromDate = new Date();
|
---|
| 578 | parent.addLogText("----------------");
|
---|
| 579 | parent.addLogText(query);
|
---|
| 580 | }
|
---|
| 581 | });
|
---|
| 582 | return sa;
|
---|
| 583 | }
|
---|
| 584 |
|
---|
| 585 | private SparqlResultListener createSparqlResultListener(){
|
---|
| 586 | return new SparqlResultListener() {
|
---|
| 587 |
|
---|
| 588 | @Override
|
---|
| 589 | public void resultReceived(SparqlResultSet result) {
|
---|
| 590 |
|
---|
| 591 | hasLimitNext = result.isHasNext();
|
---|
| 592 |
|
---|
| 593 | Date now = new Date();
|
---|
| 594 | long time = now.getTime() - fromDate.getTime();
|
---|
| 595 | parent.addLogText("---------------- result:"+time+" ms");
|
---|
| 596 | // 邨先棡繧偵∪縺壹�list縺ォ霑ス蜉
|
---|
| 597 | List<String> resultList = new ArrayList<String>();
|
---|
| 598 | for (Map<String, RDFNode> item : result.getDefaultResult()){
|
---|
| 599 | RDFNode node = item.get("s");
|
---|
| 600 | resultList.add(node.toString());
|
---|
| 601 | }
|
---|
| 602 |
|
---|
| 603 | setSubjectList(resultList);
|
---|
| 604 | setProcessing(false);
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | @Override
|
---|
| 608 | public void uncaughtException(Thread t, Throwable e) {
|
---|
| 609 | JOptionPane.showMessageDialog(parent, "Execute error:"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
---|
| 610 | setProcessing(false);
|
---|
| 611 |
|
---|
| 612 | }
|
---|
| 613 | };
|
---|
| 614 | }
|
---|
| 615 |
|
---|
| 616 | /**
|
---|
| 617 | * This method initializes headerPanel
|
---|
| 618 | *
|
---|
| 619 | * @return javax.swing.JPanel
|
---|
| 620 | */
|
---|
| 621 | private JPanel getHeaderPanel() {
|
---|
| 622 | if (headerPanel == null) {
|
---|
| 623 | headerPanel = new JPanel();
|
---|
| 624 | headerPanel.setLayout(new BorderLayout());
|
---|
| 625 | headerPanel.add(getKeywordPanel(), BorderLayout.CENTER);
|
---|
| 626 | headerPanel.add(getOptionPanel(), BorderLayout.SOUTH);
|
---|
| 627 | headerPanel.add(getMovePanel(), BorderLayout.WEST);
|
---|
| 628 | }
|
---|
| 629 | return headerPanel;
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 | /**
|
---|
| 633 | * This method initializes limitPanel
|
---|
| 634 | *
|
---|
| 635 | * @return javax.swing.JPanel
|
---|
| 636 | */
|
---|
| 637 | private JPanel getLimitPanel() {
|
---|
| 638 | if (limitPanel == null) {
|
---|
| 639 | limitLabel = new JLabel();
|
---|
| 640 | limitLabel.setText(" LIMIT ");
|
---|
| 641 | limitLabel.setEnabled(false);
|
---|
| 642 | limitPanel = new JPanel();
|
---|
| 643 | limitPanel.setLayout(new BorderLayout());
|
---|
| 644 | limitPanel.add(getLimitEnableCheckBox(), BorderLayout.WEST);
|
---|
| 645 | limitPanel.add(limitLabel, BorderLayout.CENTER);
|
---|
| 646 | limitPanel.add(getLimitMainPanel(), BorderLayout.EAST);
|
---|
| 647 | }
|
---|
| 648 | return limitPanel;
|
---|
| 649 | }
|
---|
| 650 |
|
---|
| 651 | private Integer getLimit(){
|
---|
| 652 | try {
|
---|
| 653 | if (getLimitComboBox().isEnabled()){
|
---|
| 654 | return Integer.parseInt((String)getLimitComboBox().getSelectedItem());
|
---|
| 655 | }
|
---|
| 656 | } catch(Exception e){}
|
---|
| 657 | return null;
|
---|
| 658 | }
|
---|
| 659 |
|
---|
| 660 | /**
|
---|
| 661 | * This method initializes limitEnableCheckBox
|
---|
| 662 | *
|
---|
| 663 | * @return javax.swing.JCheckBox
|
---|
| 664 | */
|
---|
| 665 | private JCheckBox getLimitEnableCheckBox() {
|
---|
| 666 | if (limitEnableCheckBox == null) {
|
---|
| 667 | limitEnableCheckBox = new JCheckBox();
|
---|
| 668 | limitEnableCheckBox.addActionListener(new ActionListener() {
|
---|
| 669 |
|
---|
| 670 | @Override
|
---|
| 671 | public void actionPerformed(ActionEvent e) {
|
---|
| 672 | boolean enabled = getLimitEnableCheckBox().isSelected();
|
---|
| 673 | getLimitComboBox().setEnabled(enabled);
|
---|
| 674 | limitLabel.setEnabled(enabled);
|
---|
| 675 | updateLimitButtonStates();
|
---|
| 676 | }
|
---|
| 677 | });
|
---|
| 678 | }
|
---|
| 679 | return limitEnableCheckBox;
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | /**
|
---|
| 683 | * This method initializes limitComboBox
|
---|
| 684 | *
|
---|
| 685 | * @return javax.swing.JComboBox
|
---|
| 686 | */
|
---|
| 687 | private JComboBox getLimitComboBox() {
|
---|
| 688 | if (limitComboBox == null) {
|
---|
| 689 | String[] limits = {"100","250","500","1000"};
|
---|
| 690 | limitComboBox = new JComboBox(limits);
|
---|
| 691 | limitComboBox.setEnabled(false);
|
---|
| 692 | }
|
---|
| 693 | return limitComboBox;
|
---|
| 694 | }
|
---|
| 695 |
|
---|
| 696 | /**
|
---|
| 697 | * This method initializes findSubjectRadioButton
|
---|
| 698 | *
|
---|
| 699 | * @return javax.swing.JRadioButton
|
---|
| 700 | */
|
---|
| 701 | private JRadioButton getFindSubjectRadioButton() {
|
---|
| 702 | if (findSubjectRadioButton == null) {
|
---|
| 703 | findSubjectRadioButton = new JRadioButton("Find Subject");
|
---|
| 704 | }
|
---|
| 705 | return findSubjectRadioButton;
|
---|
| 706 | }
|
---|
| 707 |
|
---|
| 708 | /**
|
---|
| 709 | * This method initializes findObjectRadioButton
|
---|
| 710 | *
|
---|
| 711 | * @return javax.swing.JRadioButton
|
---|
| 712 | */
|
---|
| 713 | private JRadioButton getFindObjectRadioButton() {
|
---|
| 714 | if (findObjectRadioButton == null) {
|
---|
| 715 | findObjectRadioButton = new JRadioButton("Find All Object");
|
---|
| 716 | }
|
---|
| 717 | return findObjectRadioButton;
|
---|
| 718 | }
|
---|
| 719 |
|
---|
| 720 | /**
|
---|
| 721 | * This method initializes findAllRadioButton
|
---|
| 722 | *
|
---|
| 723 | * @return javax.swing.JRadioButton
|
---|
| 724 | */
|
---|
| 725 | private JRadioButton getFindAllRadioButton() {
|
---|
| 726 | if (findAllRadioButton == null) {
|
---|
| 727 | findAllRadioButton = new JRadioButton("Find All");
|
---|
| 728 | findAllRadioButton.setEnabled(false);
|
---|
| 729 | }
|
---|
| 730 | return findAllRadioButton;
|
---|
| 731 | }
|
---|
| 732 |
|
---|
| 733 | /**
|
---|
| 734 | * This method initializes findLabelObjectRadioButton
|
---|
| 735 | *
|
---|
| 736 | * @return javax.swing.JRadioButton
|
---|
| 737 | */
|
---|
| 738 | private JRadioButton getFindLabelObjectRadioButton() {
|
---|
| 739 | if (findLabelObjectRadioButton == null) {
|
---|
| 740 | findLabelObjectRadioButton = new JRadioButton("Find Specific Object");
|
---|
| 741 | findLabelObjectRadioButton.addMouseListener(new MouseAdapter() {
|
---|
| 742 | @Override
|
---|
| 743 | public void mouseClicked(MouseEvent e) {
|
---|
| 744 | awakePropertyListPopup(e.getLocationOnScreen());
|
---|
| 745 | }
|
---|
| 746 | });
|
---|
| 747 | }
|
---|
| 748 | return findLabelObjectRadioButton;
|
---|
| 749 | }
|
---|
| 750 |
|
---|
| 751 | /**
|
---|
| 752 | * This method initializes movePanel
|
---|
| 753 | *
|
---|
| 754 | * @return javax.swing.JPanel
|
---|
| 755 | */
|
---|
| 756 | private JPanel getMovePanel() {
|
---|
| 757 | if (movePanel == null) {
|
---|
| 758 | movePanel = new JPanel();
|
---|
| 759 | movePanel.setLayout(new BoxLayout(movePanel, BoxLayout.X_AXIS));
|
---|
| 760 | movePanel.add(getPrevButton(), null);
|
---|
| 761 | movePanel.add(getNextButton(), null);
|
---|
| 762 | }
|
---|
| 763 | return movePanel;
|
---|
| 764 | }
|
---|
| 765 |
|
---|
| 766 | /**
|
---|
| 767 | * This method initializes prevButton
|
---|
| 768 | *
|
---|
| 769 | * @return javax.swing.JButton
|
---|
| 770 | */
|
---|
| 771 | private JButton getPrevButton() {
|
---|
| 772 | if (prevButton == null) {
|
---|
| 773 | prevButton = new JButton("竊�);
|
---|
| 774 | prevButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
| 775 | prevButton.setEnabled(false);
|
---|
| 776 | prevButton.addActionListener(new ActionListener() {
|
---|
| 777 |
|
---|
| 778 | @Override
|
---|
| 779 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 780 | String s = getPrev();
|
---|
| 781 | if (s != null){
|
---|
| 782 | if (historyIndex == 0){
|
---|
| 783 | setSubjectList(subjectHistoryList);
|
---|
| 784 | } else {
|
---|
| 785 | setSubjectList(s);
|
---|
| 786 | }
|
---|
| 787 | findSubjectTriple(s);
|
---|
| 788 | }
|
---|
| 789 | }
|
---|
| 790 | });
|
---|
| 791 | }
|
---|
| 792 | return prevButton;
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 | /**
|
---|
| 796 | * This method initializes nextButton
|
---|
| 797 | *
|
---|
| 798 | * @return javax.swing.JButton
|
---|
| 799 | */
|
---|
| 800 | private JButton getNextButton() {
|
---|
| 801 | if (nextButton == null) {
|
---|
| 802 | nextButton = new JButton("竊�);
|
---|
| 803 | nextButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
| 804 | nextButton.setEnabled(false);
|
---|
| 805 | nextButton.addActionListener(new ActionListener() {
|
---|
| 806 |
|
---|
| 807 | @Override
|
---|
| 808 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 809 | String s = getNext();
|
---|
| 810 | if (s != null){
|
---|
| 811 | setSubjectList(s);
|
---|
| 812 | findSubjectTriple(s);
|
---|
| 813 | }
|
---|
| 814 | }
|
---|
| 815 | });
|
---|
| 816 | }
|
---|
| 817 | return nextButton;
|
---|
| 818 | }
|
---|
| 819 |
|
---|
| 820 | private boolean findSubjectTriple(String s){
|
---|
| 821 | if (isProcessing()){
|
---|
| 822 | return false;
|
---|
| 823 | }
|
---|
| 824 | setProcessing(true);
|
---|
| 825 | // table繧ッ繝ェ繧「
|
---|
| 826 | setResults(null);
|
---|
| 827 | sa.findTripleFromSubject(s, createSparqlResultListener2());
|
---|
| 828 | return true;
|
---|
| 829 | }
|
---|
| 830 |
|
---|
| 831 | private boolean awakePopupIfHtml(Object o, Point p){
|
---|
| 832 |
|
---|
| 833 | if (o == null || o.toString().trim().isEmpty()){
|
---|
| 834 | return false;
|
---|
| 835 | }
|
---|
| 836 | String s = o.toString();
|
---|
| 837 |
|
---|
| 838 | if (o instanceof RDFNode){
|
---|
| 839 | if (((RDFNode)o).isLiteral()){
|
---|
| 840 | s = ((RDFNode)o).asLiteral().getString();
|
---|
| 841 | }
|
---|
| 842 | }
|
---|
| 843 | JPopupMenu popup = new JPopupMenu(s);
|
---|
| 844 |
|
---|
| 845 | if (s.startsWith("http://") || s.startsWith("https://")){
|
---|
| 846 | JMenuItem menu = new JMenuItem("Show on Web Browser");
|
---|
| 847 | menu.addActionListener(new ActionListener() {
|
---|
| 848 |
|
---|
| 849 | @Override
|
---|
| 850 | public void actionPerformed(ActionEvent e) {
|
---|
| 851 | JMenuItem menu = (JMenuItem)e.getSource();
|
---|
| 852 | JPopupMenu parent = (JPopupMenu)menu.getParent();
|
---|
| 853 | try {
|
---|
| 854 | awakeHtml(parent.getLabel());
|
---|
| 855 | } catch (URISyntaxException ex) {
|
---|
| 856 | ex.printStackTrace();
|
---|
| 857 | } catch (IOException ex) {
|
---|
| 858 | ex.printStackTrace();
|
---|
| 859 | }
|
---|
| 860 | }
|
---|
| 861 | });
|
---|
| 862 | popup.add(menu);
|
---|
| 863 | } else {
|
---|
| 864 | JMenuItem menu1 = new JMenuItem("Search By Google");
|
---|
| 865 | menu1.addActionListener(new ActionListener() {
|
---|
| 866 |
|
---|
| 867 | @Override
|
---|
| 868 | public void actionPerformed(ActionEvent e) {
|
---|
| 869 | JMenuItem menu = (JMenuItem)e.getSource();
|
---|
| 870 | JPopupMenu parent = (JPopupMenu)menu.getParent();
|
---|
| 871 | try {
|
---|
| 872 | awakeHtml("https://www.google.co.jp/search?q=" + URLEncoder.encode(parent.getLabel(), "UTF-8"));
|
---|
| 873 | } catch (URISyntaxException ex) {
|
---|
| 874 | ex.printStackTrace();
|
---|
| 875 | } catch (IOException ex) {
|
---|
| 876 | ex.printStackTrace();
|
---|
| 877 | }
|
---|
| 878 | }
|
---|
| 879 | });
|
---|
| 880 | popup.add(menu1);
|
---|
| 881 | JMenuItem menu2 = new JMenuItem("Search By GoogleMaps");
|
---|
| 882 | menu2.addActionListener(new ActionListener() {
|
---|
| 883 |
|
---|
| 884 | @Override
|
---|
| 885 | public void actionPerformed(ActionEvent e) {
|
---|
| 886 | JMenuItem menu = (JMenuItem)e.getSource();
|
---|
| 887 | JPopupMenu parent = (JPopupMenu)menu.getParent();
|
---|
| 888 | try {
|
---|
| 889 | awakeHtml("https://maps.google.com/maps?q=" + URLEncoder.encode(parent.getLabel(), "UTF-8"));
|
---|
| 890 | } catch (URISyntaxException ex) {
|
---|
| 891 | ex.printStackTrace();
|
---|
| 892 | } catch (IOException ex) {
|
---|
| 893 | ex.printStackTrace();
|
---|
| 894 | }
|
---|
| 895 | }
|
---|
| 896 | });
|
---|
| 897 | popup.add(menu2);
|
---|
| 898 | }
|
---|
| 899 |
|
---|
| 900 | popup.setLocation(p);
|
---|
| 901 |
|
---|
| 902 | SwingUtilities.convertPointFromScreen(p, this.parent);
|
---|
| 903 |
|
---|
| 904 | popup.show(this.parent, p.x, p.y);
|
---|
| 905 |
|
---|
| 906 | return false;
|
---|
| 907 | }
|
---|
| 908 |
|
---|
| 909 | private void awakeHtml(String url) throws IOException, URISyntaxException{
|
---|
| 910 | Desktop desktop = Desktop.getDesktop();
|
---|
| 911 | URI uri = new URI(url);
|
---|
| 912 | desktop.browse(uri);
|
---|
| 913 | }
|
---|
| 914 |
|
---|
| 915 |
|
---|
| 916 | private PropertyDialog propDialog;
|
---|
| 917 |
|
---|
| 918 | private List<EditableListItem> targetObjectTypes;
|
---|
| 919 |
|
---|
| 920 | /**
|
---|
| 921 | * proeprty驕ク謚樒畑POPUP陦ィ遉コ
|
---|
| 922 | * @param p
|
---|
| 923 | * @return
|
---|
| 924 | */
|
---|
| 925 | private boolean awakePropertyListPopup(Point p){
|
---|
| 926 | DefaultListModel model = new DefaultListModel();
|
---|
| 927 | for (EditableListItem tp : getTargetPropertyListItem()){
|
---|
| 928 | model.addElement(tp);
|
---|
| 929 | }
|
---|
| 930 |
|
---|
| 931 | EditableList properties = new EditableList(model);
|
---|
| 932 | propDialog = new PropertyDialog(this.parent, properties);
|
---|
| 933 | properties.getTextField().addKeyListener(new KeyAdapter() {
|
---|
| 934 |
|
---|
| 935 | @Override
|
---|
| 936 | public void keyReleased(KeyEvent e) {
|
---|
| 937 | List<String> propList = getPropertyList(parent.getCurrentEndPoint());
|
---|
| 938 | String word = ((JTextField)e.getSource()).getText();
|
---|
| 939 |
|
---|
| 940 | if (word.length() > 2){
|
---|
| 941 | List<String> candidates = StringUtil.getPartHitString(propList, word);
|
---|
| 942 |
|
---|
| 943 | if (candidates.size() < 20){
|
---|
| 944 | awakeCandidateList(candidates, propDialog.getList().getTextField().getLocationOnScreen());
|
---|
| 945 | }
|
---|
| 946 | } else {
|
---|
| 947 | if (popup != null){
|
---|
| 948 | popup.setVisible(false);
|
---|
| 949 | popup = null;
|
---|
| 950 | }
|
---|
| 951 | }
|
---|
| 952 |
|
---|
| 953 | }
|
---|
| 954 | }); properties.getModel().addListDataListener(new ListDataListener() {
|
---|
| 955 |
|
---|
| 956 | @Override
|
---|
| 957 | public void intervalRemoved(ListDataEvent e) {
|
---|
| 958 | propDialog.pack();
|
---|
| 959 | }
|
---|
| 960 |
|
---|
| 961 | @Override
|
---|
| 962 | public void intervalAdded(ListDataEvent e) {
|
---|
| 963 | propDialog.pack();
|
---|
| 964 | }
|
---|
| 965 |
|
---|
| 966 | @Override
|
---|
| 967 | public void contentsChanged(ListDataEvent e) {
|
---|
| 968 | }
|
---|
| 969 | });
|
---|
| 970 | properties.getTextField().addActionListener(new ActionListener() {
|
---|
| 971 |
|
---|
| 972 | @Override
|
---|
| 973 | public void actionPerformed(ActionEvent e) {
|
---|
| 974 | if (propDialog.getList().getTextField().getText().isEmpty()){
|
---|
| 975 | //
|
---|
| 976 | propDialog.setOK(true);
|
---|
| 977 | propDialog.setVisible(false);
|
---|
| 978 | }
|
---|
| 979 | }
|
---|
| 980 | });
|
---|
| 981 | propDialog.setLocation(p);
|
---|
| 982 | propDialog.pack();
|
---|
| 983 | propDialog.setModalityType(ModalityType.DOCUMENT_MODAL);
|
---|
| 984 | propDialog.setVisible(true);
|
---|
| 985 |
|
---|
| 986 | if (popup != null){
|
---|
| 987 | popup.setVisible(false);
|
---|
| 988 | }
|
---|
| 989 |
|
---|
| 990 | if (!propDialog.isOK()){
|
---|
| 991 | return false;
|
---|
| 992 | }
|
---|
| 993 | model = (DefaultListModel)properties.getModel();
|
---|
| 994 |
|
---|
| 995 | getTargetPropertyListItem().clear();
|
---|
| 996 | for (int i=0; i<model.getSize(); i++){
|
---|
| 997 | Object item = model.getElementAt(i);
|
---|
| 998 | if (item instanceof EditableListItem){
|
---|
| 999 | getTargetPropertyListItem().add((EditableListItem)item);
|
---|
| 1000 | }
|
---|
| 1001 | }
|
---|
| 1002 |
|
---|
| 1003 | return true;
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | private Map<String,List<String>> propertyList = new HashMap<String, List<String>>();
|
---|
| 1007 | private List<String> processingPropertyList = new ArrayList<String>(); // @jve:decl-index=0:
|
---|
| 1008 |
|
---|
| 1009 | private List<String> getPropertyList(String endpoint){
|
---|
| 1010 | List<String> ret = propertyList.get(endpoint);
|
---|
| 1011 | if (ret == null && !processingPropertyList.contains(endpoint)){
|
---|
| 1012 | try {
|
---|
| 1013 | ThreadedSparqlAccessor tsa = createSparqlAccessor();
|
---|
| 1014 | if (tsa != null){
|
---|
| 1015 | processingPropertyList.add(endpoint);
|
---|
| 1016 | tsa.findPropertyList(new SparqlResultListener() {
|
---|
| 1017 |
|
---|
| 1018 | @Override
|
---|
| 1019 | public void uncaughtException(Thread t, Throwable e) {
|
---|
| 1020 | JOptionPane.showMessageDialog(parent, "Execute error:"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
|
---|
| 1021 | setProcessing(false);
|
---|
| 1022 | }
|
---|
| 1023 |
|
---|
| 1024 | @Override
|
---|
| 1025 | public void resultReceived(SparqlResultSet resultSet) {
|
---|
| 1026 | String endpoint = parent.getCurrentEndPoint();
|
---|
| 1027 | List<String> ret = propertyList.get(endpoint);
|
---|
| 1028 | if (ret == null){
|
---|
| 1029 | ret = new ArrayList<String>();
|
---|
| 1030 | propertyList.put(endpoint, ret);
|
---|
| 1031 | }
|
---|
| 1032 | List<Map<String, RDFNode>> results = resultSet.getDefaultResult();
|
---|
| 1033 | for (Map<String, RDFNode> result : results){
|
---|
| 1034 | for (String nodeStr : result.keySet()){
|
---|
| 1035 | if (nodeStr != null && !ret.contains(nodeStr)){
|
---|
| 1036 | ret.add(nodeStr);
|
---|
| 1037 | }
|
---|
| 1038 | }
|
---|
| 1039 | }
|
---|
| 1040 | propertyList.put(endpoint, ret);
|
---|
| 1041 | processingPropertyList.remove(endpoint);
|
---|
| 1042 | }
|
---|
| 1043 | });
|
---|
| 1044 | }
|
---|
| 1045 | } catch (Exception e){
|
---|
| 1046 | // 繧ィ繝ゥ繝シ縺ッ闖ッ鮗励↓繧ケ繝ォ繝シ
|
---|
| 1047 | }
|
---|
| 1048 | }
|
---|
| 1049 |
|
---|
| 1050 | return propertyList.get(endpoint);
|
---|
| 1051 | }
|
---|
| 1052 |
|
---|
| 1053 | private List<EditableListItem> getTargetPropertyListItem(){
|
---|
| 1054 | if (targetObjectTypes == null){
|
---|
| 1055 | targetObjectTypes = new ArrayList<EditableListItem>();
|
---|
| 1056 | targetObjectTypes.add(new EditableListItem(DEFAULT_PROPERTY_TYPE, false));
|
---|
| 1057 | }
|
---|
| 1058 | return targetObjectTypes;
|
---|
| 1059 | }
|
---|
| 1060 |
|
---|
| 1061 | JPopupMenu popup;
|
---|
| 1062 |
|
---|
| 1063 | private void awakeCandidateList(List<String> candidates, Point p){
|
---|
| 1064 | if (popup != null){
|
---|
| 1065 | popup.setVisible(false);
|
---|
| 1066 | }
|
---|
| 1067 | popup = new JPopupMenu();
|
---|
| 1068 |
|
---|
| 1069 | for (String candidate : candidates){
|
---|
| 1070 | JMenuItem item = new JMenuItem(candidate);
|
---|
| 1071 | item.addActionListener(new ActionListener() {
|
---|
| 1072 |
|
---|
| 1073 | @Override
|
---|
| 1074 | public void actionPerformed(ActionEvent e) {
|
---|
| 1075 | propDialog.getList().getTextField().setText(((JMenuItem)e.getSource()).getText());
|
---|
| 1076 | popup.setVisible(false);
|
---|
| 1077 | popup = null;
|
---|
| 1078 | }
|
---|
| 1079 | });
|
---|
| 1080 | popup.add(item);
|
---|
| 1081 | }
|
---|
| 1082 | popup.setLocation(p.x + 400, p.y + 20);
|
---|
| 1083 | popup.setVisible(true);
|
---|
| 1084 | }
|
---|
| 1085 |
|
---|
| 1086 |
|
---|
| 1087 | private void initHistory(){
|
---|
| 1088 | this.history = new ArrayList<String>();
|
---|
| 1089 | this.historyIndex = -1;
|
---|
| 1090 | updateButtonStates();
|
---|
| 1091 | }
|
---|
| 1092 |
|
---|
| 1093 | private void addHistory(String item){
|
---|
| 1094 |
|
---|
| 1095 | if (this.historyIndex >= 0 && this.historyIndex < (this.history.size() - 1)){
|
---|
| 1096 | for (int i=this.history.size()-1; i > this.historyIndex; i--){
|
---|
| 1097 | this.history.remove(i);
|
---|
| 1098 | }
|
---|
| 1099 | }
|
---|
| 1100 | this.history.add(item);
|
---|
| 1101 | this.historyIndex++;
|
---|
| 1102 | updateButtonStates();
|
---|
| 1103 | }
|
---|
| 1104 |
|
---|
| 1105 | private String getPrev(){
|
---|
| 1106 | if (hasPrev()){
|
---|
| 1107 | --historyIndex;
|
---|
| 1108 | updateButtonStates();
|
---|
| 1109 | return this.history.get(historyIndex);
|
---|
| 1110 | }
|
---|
| 1111 | return null;
|
---|
| 1112 | }
|
---|
| 1113 |
|
---|
| 1114 | private String getNext(){
|
---|
| 1115 | if (hasNext()){
|
---|
| 1116 | ++historyIndex;
|
---|
| 1117 | updateButtonStates();
|
---|
| 1118 | return this.history.get(historyIndex);
|
---|
| 1119 | }
|
---|
| 1120 | return null;
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
| 1123 | private void updateButtonStates(){
|
---|
| 1124 | if (!this.processing){
|
---|
| 1125 | this.getPrevButton().setEnabled(hasPrev());
|
---|
| 1126 | this.getNextButton().setEnabled(hasNext());
|
---|
| 1127 | } else {
|
---|
| 1128 | this.getPrevButton().setEnabled(false);
|
---|
| 1129 | this.getNextButton().setEnabled(false);
|
---|
| 1130 | }
|
---|
| 1131 | }
|
---|
| 1132 |
|
---|
| 1133 | private boolean hasPrev(){
|
---|
| 1134 | if (history.size() != 0 && historyIndex > 0){
|
---|
| 1135 | return true;
|
---|
| 1136 | }
|
---|
| 1137 | return false;
|
---|
| 1138 | }
|
---|
| 1139 |
|
---|
| 1140 | private boolean hasNext(){
|
---|
| 1141 | if ((historyIndex + 1) < history.size()){
|
---|
| 1142 | return true;
|
---|
| 1143 | }
|
---|
| 1144 | return false;
|
---|
| 1145 | }
|
---|
| 1146 |
|
---|
| 1147 | /**
|
---|
| 1148 | * This method initializes limitMainPanel
|
---|
| 1149 | *
|
---|
| 1150 | * @return javax.swing.JPanel
|
---|
| 1151 | */
|
---|
| 1152 | private JPanel getLimitMainPanel() {
|
---|
| 1153 | if (limitMainPanel == null) {
|
---|
| 1154 | limitMainPanel = new JPanel();
|
---|
| 1155 | limitMainPanel.setLayout(new BorderLayout());
|
---|
| 1156 | limitMainPanel.add(getLimitComboBox(), BorderLayout.WEST);
|
---|
| 1157 | limitMainPanel.add(getLimitPrevButton(), BorderLayout.CENTER);
|
---|
| 1158 | limitMainPanel.add(getLimitNextButton(), BorderLayout.EAST);
|
---|
| 1159 | }
|
---|
| 1160 | return limitMainPanel;
|
---|
| 1161 | }
|
---|
| 1162 |
|
---|
| 1163 | /**
|
---|
| 1164 | * This method initializes limitPrevButton
|
---|
| 1165 | *
|
---|
| 1166 | * @return javax.swing.JButton
|
---|
| 1167 | */
|
---|
| 1168 | private JButton getLimitPrevButton() {
|
---|
| 1169 | if (limitPrevButton == null) {
|
---|
| 1170 | limitPrevButton = new JButton("竊�);
|
---|
| 1171 | limitPrevButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
| 1172 | limitPrevButton.setEnabled(false);
|
---|
| 1173 | limitPrevButton.addActionListener(new ActionListener() {
|
---|
| 1174 | @Override
|
---|
| 1175 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 1176 | setProcessing(true);
|
---|
| 1177 | sa.findSubject(word, fullMatch, limit, (limit * (--page)), type, getTargetPropertyList(), createSparqlResultListener());
|
---|
| 1178 | }
|
---|
| 1179 | });
|
---|
| 1180 | }
|
---|
| 1181 | return limitPrevButton;
|
---|
| 1182 | }
|
---|
| 1183 |
|
---|
| 1184 | /**
|
---|
| 1185 | * This method initializes limitNextButton
|
---|
| 1186 | *
|
---|
| 1187 | * @return javax.swing.JButton
|
---|
| 1188 | */
|
---|
| 1189 | private JButton getLimitNextButton() {
|
---|
| 1190 | if (limitNextButton == null) {
|
---|
| 1191 | limitNextButton = new JButton("竊�);
|
---|
| 1192 | limitNextButton.setMargin(new Insets(0, 10, 0, 10));
|
---|
| 1193 | limitNextButton.setEnabled(false);
|
---|
| 1194 | limitNextButton.addActionListener(new ActionListener() {
|
---|
| 1195 | @Override
|
---|
| 1196 | public void actionPerformed(ActionEvent arg0) {
|
---|
| 1197 | setProcessing(true);
|
---|
| 1198 |
|
---|
| 1199 | sa.findSubject(word, fullMatch, limit, (limit * (++page)), type, getTargetPropertyList(), createSparqlResultListener());
|
---|
| 1200 | }
|
---|
| 1201 | });
|
---|
| 1202 | }
|
---|
| 1203 | return limitNextButton;
|
---|
| 1204 | }
|
---|
| 1205 |
|
---|
| 1206 | private void initLimit(){
|
---|
| 1207 | limit = this.getLimit();
|
---|
| 1208 | page = 0;
|
---|
| 1209 | }
|
---|
| 1210 |
|
---|
| 1211 | private void updateLimitButtonStates(){
|
---|
| 1212 | if (!this.processing && this.getLimitEnableCheckBox().isSelected()){
|
---|
| 1213 | this.getLimitPrevButton().setEnabled(page != 0);
|
---|
| 1214 | this.getLimitNextButton().setEnabled(hasLimitNext);
|
---|
| 1215 | } else {
|
---|
| 1216 | this.getLimitPrevButton().setEnabled(false);
|
---|
| 1217 | this.getLimitNextButton().setEnabled(false);
|
---|
| 1218 | }
|
---|
| 1219 | }
|
---|
| 1220 |
|
---|
| 1221 | private String[] getTargetPropertyList(){
|
---|
| 1222 | List<String> ret = new ArrayList<String>();
|
---|
| 1223 | if (targetObjectTypes != null && targetObjectTypes.size() > 0){
|
---|
| 1224 | for (EditableListItem item : targetObjectTypes){
|
---|
| 1225 | ret.add(item.text);
|
---|
| 1226 | }
|
---|
| 1227 | } else {
|
---|
| 1228 | ret.add(DEFAULT_PROPERTY_TYPE);
|
---|
| 1229 | }
|
---|
| 1230 | return ret.toArray(new String[0]);
|
---|
| 1231 | }
|
---|
| 1232 |
|
---|
| 1233 | class PropertyDialog extends JDialog {
|
---|
| 1234 | /**
|
---|
| 1235 | *
|
---|
| 1236 | */
|
---|
| 1237 | private static final long serialVersionUID = -638100288439239858L;
|
---|
| 1238 | private EditableList list;
|
---|
| 1239 | private boolean isOK;
|
---|
| 1240 |
|
---|
| 1241 | public PropertyDialog(Window parent, EditableList list){
|
---|
| 1242 | super(parent);
|
---|
| 1243 |
|
---|
| 1244 | // this.setUndecorated(true);
|
---|
| 1245 | this.setLayout(new BorderLayout());
|
---|
| 1246 | this.list = list;
|
---|
| 1247 | this.add(list, BorderLayout.CENTER);
|
---|
| 1248 | }
|
---|
| 1249 |
|
---|
| 1250 | public EditableList getList(){
|
---|
| 1251 | return this.list;
|
---|
| 1252 | }
|
---|
| 1253 |
|
---|
| 1254 | public void setOK(boolean value){
|
---|
| 1255 | this.isOK = value;
|
---|
| 1256 | }
|
---|
| 1257 |
|
---|
| 1258 | public boolean isOK(){
|
---|
| 1259 | return this.isOK;
|
---|
| 1260 | }
|
---|
| 1261 | }
|
---|
| 1262 |
|
---|
| 1263 |
|
---|
| 1264 | }
|
---|