示例#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();
 }
示例#2
0
  /**
   * Populates this Persistence with the data that needs to be stored from the original source
   * object.
   */
  @Override
  public void extractDataFromSource(Object source) throws PersistenceException {
    if (!(source instanceof ProcessingResource)) {
      throw new UnsupportedOperationException(
          getClass().getName()
              + " can only be used for "
              + ProcessingResource.class.getName()
              + " objects!\n"
              + source.getClass().getName()
              + " is not a "
              + ProcessingResource.class.getName());
    }

    super.extractDataFromSource(source);
    Resource res = (Resource) source;

    ResourceData rData = Gate.getCreoleRegister().get(res.getClass().getName());
    if (rData == null)
      throw new PersistenceException("Could not find CREOLE data for " + res.getClass().getName());

    // now get the runtime params
    ParameterList params = rData.getParameterList();
    try {
      // get the values for the init time parameters
      runtimeParams = Factory.newFeatureMap();
      // this is a list of lists
      Iterator<List<Parameter>> parDisjIter = params.getRuntimeParameters().iterator();
      while (parDisjIter.hasNext()) {
        Iterator<Parameter> parIter = parDisjIter.next().iterator();
        while (parIter.hasNext()) {
          Parameter parameter = parIter.next();
          String parName = parameter.getName();
          Object parValue = res.getParameterValue(parName);
          ((FeatureMap) runtimeParams).put(parName, parValue);
        }
      }
      runtimeParams = PersistenceManager.getPersistentRepresentation(runtimeParams);
    } catch (ResourceInstantiationException rie) {
      throw new PersistenceException(rie);
    }
  }
示例#3
0
 /**
  * Creates a new object from the data contained. This new object is supposed to be a copy for the
  * original object used as source for data extraction.
  */
 @Override
 public Object createObject() throws PersistenceException, ResourceInstantiationException {
   Object res = super.createObject();
   // now add the runtime parameters
   if (runtimeParams != null) {
     runtimeParams =
         PersistenceManager.getTransientRepresentation(
             runtimeParams, containingControllerName, initParamOverrides);
     ((Resource) res).setParameterValues((FeatureMap) runtimeParams);
   }
   return res;
 }