コード例 #1
0
  @Override
  public void activeOntologyChanged() {
    OBDAModel obdaModel = controller.getActiveOBDAModel();
    TargetQueryVocabularyValidator validator = new TargetQueryValidator(obdaModel);

    mappingPanel.setOBDAModel(obdaModel);
    mappingPanel.setTargetQueryValidator(validator);
    datasourceSelector.setDatasourceController(obdaModel);
  }
コード例 #2
0
  @Override
  protected void initialiseOWLView() throws Exception {

    // Retrieve the editor kit.
    final OWLEditorKit editor = getOWLEditorKit();

    controller = (OBDAModelManager) editor.get(OBDAModelImpl.class.getName());
    controller.addListener(this);

    OBDAModel obdaModel = controller.getActiveOBDAModel();

    TargetQueryVocabularyValidator validator = new TargetQueryValidator(obdaModel);

    // Init the Mapping Manager panel.
    mappingPanel = new MappingManagerPanel(obdaModel, validator);

    editor
        .getOWLWorkspace()
        .getOWLSelectionModel()
        .addListener(
            new OWLSelectionModelListener() {
              @Override
              public void selectionChanged() throws Exception {
                OWLEntity entity =
                    editor.getOWLWorkspace().getOWLSelectionModel().getSelectedEntity();
                if (entity == null) return;
                if (!entity.isTopEntity()) {
                  String shortf = entity.getIRI().getFragment();
                  if (shortf == null) {
                    String iri = entity.getIRI().toString();
                    shortf = iri.substring(iri.lastIndexOf("/"));
                  }
                  mappingPanel.setFilter("pred:" + shortf);
                } else {
                  mappingPanel.setFilter("");
                }
              }
            });

    datasourceSelector = new DatasourceSelector(controller.getActiveOBDAModel());
    datasourceSelector.addDatasourceListListener(mappingPanel);

    // Construt the layout of the panel.
    JPanel selectorPanel = new JPanel();
    selectorPanel.setLayout(new GridBagLayout());

    JLabel label = new JLabel("Select datasource: ");
    label.setFont(new Font("Dialog", Font.BOLD, 12));
    label.setForeground(new Color(53, 113, 163));
    // label.setBackground(new java.awt.Color(153, 153, 153));
    // label.setFont(new java.awt.Font("Arial", 1, 11));
    // label.setForeground(new java.awt.Color(153, 153, 153));
    label.setPreferredSize(new Dimension(119, 14));

    GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
    selectorPanel.add(label, gridBagConstraints);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.insets = new Insets(5, 5, 5, 5);
    selectorPanel.add(datasourceSelector, gridBagConstraints);

    selectorPanel.setBorder(new TitledBorder("Datasource selection"));
    mappingPanel.setBorder(new TitledBorder("Mapping manager"));

    setLayout(new BorderLayout());
    add(mappingPanel, BorderLayout.CENTER);
    add(selectorPanel, BorderLayout.NORTH);
  }
コード例 #3
0
  @Override
  protected void initialiseOWLView() throws Exception {
    obdaController = (OBDAModelManager) getOWLEditorKit().get(OBDAModelImpl.class.getName());
    obdaController.addListener(this);

    prefixManager = obdaController.getActiveOBDAModel().getPrefixManager();

    queryEditorPanel =
        new QueryInterfacePanel(
            obdaController.getActiveOBDAModel(), obdaController.getQueryController());
    queryEditorPanel.setPreferredSize(new Dimension(400, 250));
    queryEditorPanel.setMinimumSize(new Dimension(400, 250));

    resultTablePanel = new ResultViewTablePanel(queryEditorPanel);
    resultTablePanel.setMinimumSize(new java.awt.Dimension(400, 250));
    resultTablePanel.setPreferredSize(new java.awt.Dimension(400, 250));

    JSplitPane splQueryInterface = new JSplitPane();
    splQueryInterface.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splQueryInterface.setResizeWeight(0.5);
    splQueryInterface.setDividerLocation(0.5);
    splQueryInterface.setOneTouchExpandable(true);
    splQueryInterface.setTopComponent(queryEditorPanel);
    splQueryInterface.setBottomComponent(resultTablePanel);

    JPanel pnlQueryInterfacePane = new JPanel();
    pnlQueryInterfacePane.setLayout(new BorderLayout());
    pnlQueryInterfacePane.add(splQueryInterface, BorderLayout.CENTER);
    setLayout(new BorderLayout());
    add(pnlQueryInterfacePane, BorderLayout.CENTER);

    // Setting up model listeners
    ontologyListener =
        new OWLOntologyChangeListener() {
          @Override
          public void ontologiesChanged(List<? extends OWLOntologyChange> changes)
              throws OWLException {
            Runnable runner =
                new Runnable() {
                  public void run() {
                    resultTablePanel.setTableModel(new DefaultTableModel());
                  }
                };
            SwingUtilities.invokeLater(runner);
          }
        };

    this.getOWLModelManager().addOntologyChangeListener(ontologyListener);
    setupListeners();

    // Setting up actions for all the buttons of this view.
    resultTablePanel.setCountAllTuplesActionForUCQ(
        new OBDADataQueryAction<Integer>("Counting tuples...", QueryInterfaceView.this) {
          @Override
          public OWLEditorKit getEditorKit() {
            return getOWLEditorKit();
          }

          @Override
          public int getNumberOfRows() {
            return -1;
          }

          @Override
          public void handleResult(Integer result) {
            updateTablePanelStatus(result);
          }

          @Override
          public Integer executeQuery(QuestOWLStatement st, String query) throws OWLException {
            return st.getTupleCount(query);
          }

          @Override
          public boolean isRunning() {
            return false;
          }
        });

    queryEditorPanel.setExecuteSelectAction(
        new OBDADataQueryAction<QuestOWLResultSet>(
            "Executing queries...", QueryInterfaceView.this) {

          @Override
          public OWLEditorKit getEditorKit() {
            return getOWLEditorKit();
          }

          @Override
          public void handleResult(QuestOWLResultSet result) throws OWLException {
            createTableModelFromResultSet(result);
            showTupleResultInTablePanel();
          }

          @Override
          public void run(String query) {
            removeResultTable();
            super.run(query);
          }

          @Override
          public int getNumberOfRows() {
            OWLResultSetTableModel tm = getTableModel();
            if (tm == null) return 0;
            return getTableModel().getRowCount();
          }

          public boolean isRunning() {
            OWLResultSetTableModel tm = getTableModel();
            if (tm == null) return false;
            return tm.isFetching();
          }

          @Override
          public QuestOWLResultSet executeQuery(QuestOWLStatement st, String queryString)
              throws OWLException {
            return st.executeTuple(queryString);
          }
        });

    queryEditorPanel.setExecuteGraphQueryAction(
        new OBDADataQueryAction<List<OWLAxiom>>("Executing queries...", QueryInterfaceView.this) {

          @Override
          public OWLEditorKit getEditorKit() {
            return getOWLEditorKit();
          }

          @Override
          public List<OWLAxiom> executeQuery(QuestOWLStatement st, String queryString)
              throws OWLException {
            return st.executeGraph(queryString);
          }

          @Override
          public void handleResult(List<OWLAxiom> result) {
            OWLAxiomToTurtleVisitor owlVisitor = new OWLAxiomToTurtleVisitor(prefixManager);
            populateResultUsingVisitor(result, owlVisitor);
            showGraphResultInTextPanel(owlVisitor);
          }

          @Override
          public int getNumberOfRows() {
            OWLResultSetTableModel tm = getTableModel();
            if (tm == null) return 0;
            return getTableModel().getRowCount();
          }

          public boolean isRunning() {
            OWLResultSetTableModel tm = getTableModel();
            if (tm == null) return false;
            return tm.isFetching();
          }
        });

    queryEditorPanel.setRetrieveUCQExpansionAction(
        new OBDADataQueryAction<String>("Rewriting query...", QueryInterfaceView.this) {

          @Override
          public String executeQuery(QuestOWLStatement st, String query) throws OWLException {
            return st.getRewriting(query);
          }

          @Override
          public OWLEditorKit getEditorKit() {
            return getOWLEditorKit();
          }

          @Override
          public void handleResult(String result) {
            showActionResultInTextPanel("UCQ Expansion Result", result);
          }

          @Override
          public int getNumberOfRows() {
            return -1;
          }

          @Override
          public boolean isRunning() {
            return false;
          }
        });

    queryEditorPanel.setRetrieveUCQUnfoldingAction(
        new OBDADataQueryAction<String>("Unfolding queries...", QueryInterfaceView.this) {
          @Override
          public String executeQuery(QuestOWLStatement st, String query) throws OWLException {
            return st.getUnfolding(query);
          }

          @Override
          public OWLEditorKit getEditorKit() {
            return getOWLEditorKit();
          }

          @Override
          public void handleResult(String result) {
            showActionResultInTextPanel("UCQ Unfolding Result", result);
          }

          @Override
          public int getNumberOfRows() {
            return -1;
          }

          @Override
          public boolean isRunning() {
            return false;
          }
        });

    resultTablePanel.setOBDASaveQueryToFileAction(
        new OBDASaveQueryResultToFileAction() {
          @Override
          public void run(String fileLocation) {
            OBDAProgessMonitor monitor = null;
            try {
              monitor = new OBDAProgessMonitor("Writing output files...");
              monitor.start();
              CountDownLatch latch = new CountDownLatch(1);
              List<String[]> data = tableModel.getTabularData();
              if (monitor.isCanceled()) return;
              File output = new File(fileLocation);
              BufferedWriter writer = new BufferedWriter(new FileWriter(output, false));
              SaveQueryToFileAction action = new SaveQueryToFileAction(latch, data, writer);
              monitor.addProgressListener(action);
              action.run();
              latch.await();
              monitor.stop();
            } catch (Exception e) {
              DialogUtils.showQuickErrorDialog(QueryInterfaceView.this, e);
            }
          }
        });
    log.debug("Query Manager view initialized");
  }
コード例 #4
0
  @Override
  public void actionPerformed(ActionEvent e) {

    currentOnto = owlManager.getActiveOntology();
    currentModel = modelManager.getActiveOBDAModel();

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
    JLabel dsource = new JLabel("Choose a datasource to bootstrap: ");
    dsource.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(dsource);
    List<String> options = new ArrayList<String>();
    for (OBDADataSource source : currentModel.getSources())
      options.add(source.getSourceID().toString());
    JComboBox combo = new JComboBox(options.toArray());
    combo.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(combo);
    Dimension minsize = new Dimension(10, 10);
    panel.add(new Box.Filler(minsize, minsize, minsize));
    JLabel ouri =
        new JLabel("Base URI - the prefix to be used for all generated classes and properties: ");
    ouri.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(ouri);
    JTextField base_uri = new JTextField();
    base_uri.setText(currentModel.getPrefixManager().getDefaultPrefix().replace("#", "/"));
    base_uri.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(base_uri);
    int res =
        JOptionPane.showOptionDialog(
            workspace,
            panel,
            "Bootstrapping",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            null,
            null);
    if (res == JOptionPane.OK_OPTION) {
      int index = combo.getSelectedIndex();
      currentSource = currentModel.getSources().get(index);
      if (currentSource != null) {
        this.baseUri = base_uri.getText().trim();
        if (baseUri.contains("#")) {
          JOptionPane.showMessageDialog(workspace, "Base Uri cannot contain the character '#'");
          throw new RuntimeException("Base URI " + baseUri + " contains '#' character!");
        } else {
          Thread th =
              new Thread(
                  new Runnable() {
                    @Override
                    public void run() {
                      try {
                        OBDAProgessMonitor monitor =
                            new OBDAProgessMonitor("Bootstrapping ontology and mappings...");
                        BootstrapperThread t = new BootstrapperThread();
                        monitor.addProgressListener(t);
                        monitor.start();
                        t.run(baseUri, currentOnto, currentModel, currentSource);
                        currentModel.fireSourceParametersUpdated();
                        monitor.stop();
                        JOptionPane.showMessageDialog(
                            workspace,
                            "Task is completed.",
                            "Done",
                            JOptionPane.INFORMATION_MESSAGE);
                      } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        JOptionPane.showMessageDialog(
                            null, "Error occured during bootstrapping data source.");
                      }
                    }
                  });
          th.start();
        }
      }
    }
  }