Example #1
0
 public void actionPerformed(ActionEvent e) {
   List<Resource> loadedDocuments;
   try {
     // get all the documents loaded in the system
     loadedDocuments = Gate.getCreoleRegister().getAllInstances("gate.Document");
   } catch (GateException ge) {
     // gate.Document is not registered in creole.xml....what is!?
     throw new GateRuntimeException(
         "gate.Document is not registered in the creole register!\n"
             + "Something must be terribly wrong...take a vacation!");
   }
   Vector<String> docNames = new Vector<String>();
   for (Resource loadedDocument : new ArrayList<Resource>(loadedDocuments)) {
     if (corpus.contains(loadedDocument)) {
       loadedDocuments.remove(loadedDocument);
     } else {
       docNames.add(loadedDocument.getName());
     }
   }
   JList docList = new JList(docNames);
   docList.getSelectionModel().setSelectionInterval(0, docNames.size() - 1);
   docList.setCellRenderer(renderer);
   final JOptionPane optionPane =
       new JOptionPane(
           new JScrollPane(docList), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog =
       optionPane.createDialog(CorpusEditor.this, "Add document(s) to this corpus");
   docList.addMouseListener(
       new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
           if (e.getClickCount() == 2) {
             optionPane.setValue(JOptionPane.OK_OPTION);
             dialog.dispose();
           }
         }
       });
   dialog.setVisible(true);
   if (optionPane.getValue().equals(JOptionPane.OK_OPTION)) {
     int[] selectedIndices = docList.getSelectedIndices();
     for (int selectedIndice : selectedIndices) {
       corpus.add((Document) loadedDocuments.get(selectedIndice));
     }
   }
   changeMessage();
 }
Example #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);
           }
         }
       });
 }