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