示例#1
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);
           }
         }
       });
 }
示例#2
0
  /**
   * Loads any custom operators and annotation accessors into the ConstraintFactory.
   *
   * @throws ResourceInstantiationException
   */
  protected void initCustomConstraints() throws ResourceInstantiationException {
    // Load operators
    if (operators != null) {
      for (String opName : operators) {
        Class<? extends ConstraintPredicate> clazz = null;
        try {
          clazz =
              Class.forName(opName, true, Gate.getClassLoader())
                  .asSubclass(ConstraintPredicate.class);
        } catch (ClassNotFoundException e) {
          // if couldn't find it that way, try with current thread class loader
          try {
            clazz =
                Class.forName(opName, true, Thread.currentThread().getContextClassLoader())
                    .asSubclass(ConstraintPredicate.class);
          } catch (ClassNotFoundException e1) {
            throw new ResourceInstantiationException(
                "Cannot load class for operator: " + opName, e1);
          }
        } catch (ClassCastException cce) {
          throw new ResourceInstantiationException(
              "Operator class '" + opName + "' must implement ConstraintPredicate");
        }

        // instantiate an instance of the class so can get the operator string
        try {
          ConstraintPredicate predicate = clazz.newInstance();
          String opSymbol = predicate.getOperator();
          // now store it in ConstraintFactory
          Factory.getConstraintFactory().addOperator(opSymbol, clazz);
        } catch (Exception e) {
          throw new ResourceInstantiationException(
              "Cannot instantiate class for operator: " + opName, e);
        }
      }
    }

    // Load annotationAccessors
    if (annotationAccessors != null) {
      for (String accessorName : annotationAccessors) {
        Class<? extends AnnotationAccessor> clazz = null;
        try {
          clazz =
              Class.forName(accessorName, true, Gate.getClassLoader())
                  .asSubclass(AnnotationAccessor.class);
        } catch (ClassNotFoundException e) {
          // if couldn't find it that way, try with current thread class loader
          try {
            clazz =
                Class.forName(accessorName, true, Thread.currentThread().getContextClassLoader())
                    .asSubclass(AnnotationAccessor.class);
          } catch (ClassNotFoundException e1) {
            throw new ResourceInstantiationException(
                "Cannot load class for accessor: " + accessorName, e1);
          }
        } catch (ClassCastException cce) {
          throw new ResourceInstantiationException(
              "Operator class '" + accessorName + "' must implement AnnotationAccessor");
        }

        // instantiate an instance of the class so can get the meta-property name string
        try {
          AnnotationAccessor aa = clazz.newInstance();
          String accSymbol = (String) aa.getKey();
          // now store it in ConstraintFactory
          Factory.getConstraintFactory().addMetaProperty(accSymbol, clazz);
        } catch (Exception e) {
          throw new ResourceInstantiationException(
              "Cannot instantiate class for accessor: " + accessorName, e);
        }
      }
    }
  }