Ejemplo n.º 1
0
 private synchronized void createTableModelFromResultSet(QuestOWLResultSet result)
     throws OWLException {
   if (result == null)
     throw new NullPointerException(
         "An error occured. createTableModelFromResultSet cannot use a null QuestOWLResultSet");
   if (result != null) {
     tableModel =
         new OWLResultSetTableModel(
             result,
             prefixManager,
             queryEditorPanel.isShortURISelect(),
             queryEditorPanel.isFetchAllSelect(),
             queryEditorPanel.getFetchSize());
     tableModel.addTableModelListener(queryEditorPanel);
   }
 }
Ejemplo n.º 2
0
 private void showActionResultInTextPanel(String title, String result) {
   if (result == null) {
     return;
   }
   OBDADataQueryAction<?> action = queryEditorPanel.getRetrieveUCQExpansionAction();
   UCQExpansionPanel alter_result_panel = new UCQExpansionPanel(title, result, action);
   SwingUtilities.invokeLater(alter_result_panel);
 }
Ejemplo n.º 3
0
 @Override
 public void activeOntologyChanged() {
   queryEditorPanel.setOBDAModel(this.obdaController.getActiveOBDAModel());
 }
Ejemplo n.º 4
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");
  }