Esempio n. 1
0
 public void documentRemoved(final CorpusEvent e) {
   docTableModel.dataChanged();
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           changeMessage();
           docTableModel.fireTableRowsDeleted(e.getDocumentIndex(), e.getDocumentIndex());
         }
       });
 }
Esempio n. 2
0
 public void actionPerformed(ActionEvent e) {
   Component root = SwingUtilities.getRoot(CorpusEditor.this);
   if (!(root instanceof MainFrame)) {
     return;
   }
   final MainFrame mainFrame = (MainFrame) root;
   final int[] selectedRows = docTable.getSelectedRows();
   if (selectedRows.length > 10) {
     Object[] possibleValues = {"Open the " + selectedRows.length + " documents", "Don't open"};
     int selectedValue =
         JOptionPane.showOptionDialog(
             docTable,
             "Do you want to open "
                 + selectedRows.length
                 + " documents in the central tabbed pane ?",
             "Warning",
             JOptionPane.DEFAULT_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             null,
             possibleValues,
             possibleValues[1]);
     if (selectedValue == 1 || selectedValue == JOptionPane.CLOSED_OPTION) {
       return;
     }
   }
   for (int row : selectedRows) {
     // load the document if inside a datastore
     corpus.get(docTable.rowViewToModel(row));
   }
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           for (int row : selectedRows) {
             Document doc = (Document) corpus.get(docTable.rowViewToModel(row));
             // show the document in the central view
             mainFrame.select(doc);
           }
         }
       });
 }
Esempio n. 3
0
 public void setTarget(Object target) {
   if (corpus != null && corpus != target) {
     // we already had a different corpus
     corpus.removeCorpusListener(this);
   }
   if (!(target instanceof Corpus)) {
     throw new IllegalArgumentException(
         "The GATE corpus editor can only be used with a GATE corpus!\n"
             + target.getClass().toString()
             + " is not a GATE corpus!");
   }
   this.corpus = (Corpus) target;
   corpus.addCorpusListener(this);
   docTableModel.dataChanged();
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           docTableModel.fireTableDataChanged();
         }
       });
 }
Esempio n. 4
0
 protected void changeMessage() {
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           if (corpus == null || corpus.size() == 0) {
             newDocumentAction.setEnabled(true);
             messageLabel.setText(
                 "<html>To add or remove documents to this corpus:<ul>"
                     + "<li>use the toolbar buttons at the top of this view"
                     + "<li>drag documents from the left resources tree and drop them below"
                     + "<li>right click on the corpus in the resources tree and choose 'Populate'"
                     + "</ul></html>");
             messageLabel.setVisible(true);
           }
           // This is a really stupid way of checking if all the open documents are in the
           // corpus and it seems to be causing more problems than it might possibly be trying
           // to solve
           /*else if (documentsLoadedCount > 0
                   && documentsLoadedCount == corpus.size()) {
             newDocumentAction.setEnabled(false);
             messageLabel.setText("All the documents loaded in the " +
               "system are in this corpus.");
             messageLabel.setVisible(true);
           } */
           else if (documentsLoadedCount == 0) {
             newDocumentAction.setEnabled(false);
             if (corpus.getDataStore() == null) {
               messageLabel.setText(
                   "There are no documents loaded in the system. " + "Press F1 for help.");
             } else {
               messageLabel.setText("Open a document to load it from the datastore.");
             }
             messageLabel.setVisible(true);
           } else {
             newDocumentAction.setEnabled(true);
             messageLabel.setVisible(false);
           }
         }
       });
 }
Esempio n. 5
0
 public void actionPerformed(ActionEvent e) {
   int[] rowsTable = docTable.getSelectedRows();
   int[] rowsCorpus = new int[rowsTable.length];
   for (int i = 0; i < rowsTable.length; i++)
     rowsCorpus[i] = docTable.rowViewToModel(rowsTable[i]);
   Arrays.sort(rowsCorpus);
   // starting from the largest one, move each element down
   for (int i = rowsCorpus.length - 1; i >= 0; i--) {
     if (rowsCorpus[i] < corpus.size() - 1) {
       // swap the doc with the one before
       // serial corpus does not load the document on remove, so we need
       // to load the document explicitly
       boolean wasLoaded = corpus.isDocumentLoaded(rowsCorpus[i]);
       Document doc = (Document) corpus.get(rowsCorpus[i]);
       corpus.remove(rowsCorpus[i]);
       rowsCorpus[i]++;
       corpus.add(rowsCorpus[i], doc);
       if (!wasLoaded) {
         corpus.unloadDocument(doc);
         Factory.deleteResource(doc);
       }
     }
   }
   // restore selection
   // the remove / add events will cause the table to be updated
   // we need to only restore the selection after that happened
   final int[] selectedRowsCorpus = new int[rowsCorpus.length];
   System.arraycopy(rowsCorpus, 0, selectedRowsCorpus, 0, rowsCorpus.length);
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           docTable.clearSelection();
           for (int i = 0; i < selectedRowsCorpus.length; i++) {
             int rowTable = docTable.rowModelToView(selectedRowsCorpus[i]);
             docTable.getSelectionModel().addSelectionInterval(rowTable, rowTable);
           }
         }
       });
 }