private int[] getSelectedRows(int[] selectedRowsNumber, Map[] selectedRowsKeys, Tab tab) {
    if (selectedRowsKeys == null || selectedRowsKeys.length == 0) return new int[0];
    // selectedRowsNumber is the most performant so we use it when possible
    else if (selectedRowsNumber.length == selectedRowsKeys.length) return selectedRowsNumber;
    else {
      // find the rows from the selectedKeys

      // This has a poor performance, but it covers the case when the selected
      // rows are not loaded for the tab, something that can occurs if the user
      // select rows and afterwards reorder the list.
      try {
        int[] s = new int[selectedRowsKeys.length];
        List selectedKeys = Arrays.asList(selectedRowsKeys);
        int end = tab.getTableModel().getTotalSize();
        int x = 0;
        for (int i = 0; i < end; i++) {
          Map key = (Map) tab.getTableModel().getObjectAt(i);
          if (selectedKeys.contains(key)) {
            s[x] = i;
            x++;
          }
        }
        return s;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("fails_selected"), ex);
        throw new XavaException("fails_selected");
      }
    }
  }
Ejemplo n.º 2
0
 public void messageChanged(MessageChangedEvent e) {
   Message changedMessage = e.getMessage();
   for (int i = 0; i < messages.size(); ++i) {
     if (messages.get(i) == changedMessage) {
       fireTableRowsUpdated(i, i);
     }
   }
 }
Ejemplo n.º 3
0
 /** Called externally when the underlying corpus has changed. */
 private void dataChanged() {
   List<String> newDocs = new ArrayList<String>();
   if (corpus != null) {
     newDocs.addAll(corpus.getDocumentNames());
   }
   List<String> oldDocs = documentNames;
   documentNames = newDocs;
   oldDocs.clear();
 }
 private boolean calculateWithValidValues() {
   Iterator it = metaProperties.iterator();
   while (it.hasNext()) {
     MetaProperty m = (MetaProperty) it.next();
     if (m.hasValidValues()) return true;
   }
   return false;
 }
Ejemplo n.º 5
0
        public void messagesAdded(MessageCountEvent e) {
          try {
            // I don't think it matters where we put the new messages, but for the sanity of users
            // who don't sort, and because it's the cheapest option, we'll bung them at the end.
            Message[] newMessages = e.getMessages();

            // Work out where the new items will appear.
            final int firstNewRow = messages.size();
            final int lastNewRow = firstNewRow + newMessages.length - 1;

            // Actually insert the new items, and notify the listeners.
            messages.addAll(Arrays.asList(newMessages));
            fireTableRowsInserted(firstNewRow, lastNewRow);
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
Ejemplo n.º 6
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();
 }
Ejemplo n.º 7
0
  private void okActionPerformed(java.awt.event.ActionEvent evt) {
    if (smtp.getText().trim().isEmpty()) {
      CommonFunctions.showErrorMessage(this, "You must enter a SMTP server.");
      return;
    } else if (smtpUsername.getText().trim().isEmpty()) {
      CommonFunctions.showErrorMessage(this, "You must enter the SMTP username.");
      return;
    } else {
      try {
        int port = Integer.parseInt(smtpPort.getText());
        if (port <= 0) throw new NumberFormatException();

        new InternetAddress(email.getText()).validate();
      } catch (NumberFormatException e) {
        CommonFunctions.showErrorMessage(this, "You must enter a valid SMTP port.");
        return;
      } catch (AddressException e) {
        CommonFunctions.showErrorMessage(this, "You must enter a valid source email address.");
        return;
      }
    }

    retval = 0;

    List<Student> selectedStudents = new ArrayList();
    for (int i = 0; i < studentsTbl.getRowCount(); i++) {
      if ((boolean) studentsTbl.getValueAt(i, 0)) {
        selectedStudents.add(students.get(studentsTbl.convertRowIndexToModel(i)));
      }
    }

    output =
        new Object[] {
          email.getText(),
          smtp.getText(),
          smtpPort.getText(),
          smtpUsername.getText(),
          new String(smtpPassword.getPassword()),
          selectedStudents
        };

    setVisible(false);
  }
Ejemplo n.º 8
0
  public void removeMessages(Message[] removedMessages) {
    try {
      // Translate the array of removed Message instances into a list of all the row indexes to be
      // removed from the model.
      // Assumes the list of removed messages is small.
      ArrayList<Integer> deadIndexes = new ArrayList<Integer>();
      for (Message message : removedMessages) {
        int deadIndex = messages.indexOf(message);
        if (deadIndex != -1) {
          deadIndexes.add(deadIndex);
        }
      }

      // Actually remove the rows, notifying the listeners as we go (rather than bother trying to
      // coalesce).
      for (int i = deadIndexes.size() - 1; i >= 0; --i) {
        int deadIndex = deadIndexes.get(i);
        messages.remove(deadIndex);
        fireTableRowsDeleted(deadIndex, deadIndex);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
Ejemplo n.º 9
0
 public final Object getValueAt(int rowIndex, int colIndex) {
   try {
     Method[] m = (Method[]) voGetterMethods.get(attributeNames[colIndex]);
     Object obj = valueObjects.get(rowIndex);
     for (int i = 0; i < m.length - 1; i++) {
       obj = (ValueObject) m[i].invoke(obj, new Object[0]);
       if (obj == null) {
         return null;
       }
     }
     return m[m.length - 1].invoke(obj, new Object[0]);
   } catch (Exception ex) {
     ex.printStackTrace();
     return null;
   }
 }
Ejemplo n.º 10
0
  public void scanWholeFolder() throws MessagingException {
    if (folder.isOpen() == false) {
      folder.open(Folder.READ_WRITE);
    }

    // Bulk-fetch the message envelopes.
    Message[] newMessages = folder.getMessages();
    FetchProfile fetchProfile = new FetchProfile();
    // FIXME: add CONTENT_INFO if we start to display the size
    // fetchProfile.add(FetchProfile.Item.CONTENT_INFO);
    fetchProfile.add(FetchProfile.Item.ENVELOPE);
    fetchProfile.add(FetchProfile.Item.FLAGS);
    folder.fetch(newMessages, fetchProfile);

    this.messages = new ArrayList<Message>();
    messages.addAll(Arrays.asList(newMessages));

    fireTableDataChanged();
  }
Ejemplo n.º 11
0
 /**
  * @param row row number
  * @return ValueObject
  */
 public final ValueObject getValueObject(int row) {
   return (ValueObject) valueObjects.get(row);
 }
Ejemplo n.º 12
0
 /**
  * Constructs a TableModel, starting from the specified list of ValueObjects, having the specified
  * list of attributes
  *
  * @param valueObjects list of ValueObjects
  * @param attributeNames nome of attributes defined within the ValueObjects, used to define the
  *     TableModel
  */
 public VOTableModel(List valueObjects, String[] attributeNames) {
   this.valueObjects = valueObjects;
   this.attributeNames = attributeNames;
   this.valueObjectType = valueObjects.get(0).getClass();
   analyzeClassFields(new Hashtable(), "", new Method[0], valueObjectType);
 }
Ejemplo n.º 13
0
 public final int getRowCount() {
   return valueObjects.size();
 }
 private MetaProperty getMetaProperty(int i) {
   return (MetaProperty) metaProperties.get(i);
 }
Ejemplo n.º 15
0
 public int getRowCount() {
   return messages.size();
 }
Ejemplo n.º 16
0
 public Message getMessage(int row) {
   return messages.get(row);
 }