Exemple #1
0
  public static void bindModelToView(ArrayList fieldsToBind, DomainObject model) {

    BeanAdapter adapter = new BeanAdapter(model, true);
    ValueModel valueModel = null;
    Object field = null;
    ATFieldInfo fieldInfo;
    String fieldName = "";
    ComboBoxAdapter comboBoxAdapter = null;

    for (int i = 0; i < fieldsToBind.size(); i++) {
      field = fieldsToBind.get(i);
      fieldName = ((JComponent) field).getName();
      valueModel = adapter.getValueModel(fieldName);
      if (!ignoreArray.contains(fieldName)) {
        if (field instanceof JFormattedTextField) {
          Bindings.bind((JFormattedTextField) field, valueModel);
        } else if (field instanceof JTextComponent) {
          //						Bindings.bind((JTextComponent) field, valueModel);
        } else if (field instanceof JCheckBox) {
          Bindings.bind((JCheckBox) field, valueModel);
        } else if (field instanceof JComboBox) {
          fieldInfo = ATFieldInfo.getFieldInfo(model.getClass().getName() + "." + fieldName);
          if (fieldInfo != null) {
            Vector<String> values = LookupListUtils.getLookupListValues(fieldInfo.getLookupList());
            if (values != null) {
              comboBoxAdapter = new ComboBoxAdapter(values, valueModel);
              ((JComboBox) field).setModel(comboBoxAdapter);
            }
          }
        } else {
          System.out.println(fieldName + " not bound");
        }
      }
    }
  }
  /**
   * Import the file.
   *
   * @param importFile the file to import.
   * @param controller the controller to use.
   * @param progressPanel - the progress panel to display heartbeat messages
   * @return if we succeded
   */
  public boolean importFile(
      File importFile, DomainImportController controller, InfiniteProgressPanel progressPanel)
      throws ImportException {

    Collection<DomainObject> collection = new ArrayList<DomainObject>();

    if (importFile != null) {
      JAXBContext context;
      try {
        LookupListUtils.initIngestReport();
        context = JAXBContext.newInstance("org.archiviststoolkit.structure.accessionImport");
        AccessionRecords accessionRecords =
            (AccessionRecords) context.createUnmarshaller().unmarshal(importFile);
        Accessions accession;
        int recordCount = 1;
        progressPanel.setTextLine("Importing...", 1);
        PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(RecordType.class);
        for (RecordType record : accessionRecords.getRecord()) {
          // check to see if the process was cancelled  at this point if so just return
          if (progressPanel.isProcessCancelled()) {
            return false;
          }

          progressPanel.setTextLine("Processing record " + recordCount, 2);
          accession = new Accessions();
          accession.setRepository(repository);

          for (PropertyDescriptor descriptor : descriptors) {
            Class propertyType = descriptor.getPropertyType();
            if (propertyType == XMLGregorianCalendar.class) {
              ImportUtils.nullSafeDateSet(
                  accession,
                  descriptor.getName(),
                  (XMLGregorianCalendar) descriptor.getReadMethod().invoke(record));
            } else if (propertyType == String.class
                || propertyType == BigInteger.class
                || propertyType == BigDecimal.class) {
              ImportUtils.nullSafeSet(
                  accession, descriptor.getName(), descriptor.getReadMethod().invoke(record));

            } else if (propertyType == Boolean.class) {
              // this hack is needed because jaxb has a bug and the read method starts
              // with "is" instead of "get"
              String writeMethodName = descriptor.getWriteMethod().getName();
              String readMethodName = writeMethodName.replaceFirst("set", "is");
              Method readMethod = RecordType.class.getMethod(readMethodName);
              ImportUtils.nullSafeSet(accession, descriptor.getName(), readMethod.invoke(record));
            }
          }
          parseAccessionNumber(accession, record.getAccessionNumber());
          addSubjects(accession, record.getSubjectLink());
          addNames(accession, record.getNameLink());
          addResource(
              accession,
              record.getResourceIdentifier(),
              controller,
              accession.getAccessionNumber(),
              recordCount);
          collection.add(accession);
          recordCount++;
        }
        controller.domainImport(collection, ApplicationFrame.getInstance(), progressPanel);
        ImportExportLogDialog dialog =
            new ImportExportLogDialog(
                controller.constructFinalImportLogText()
                    + "\n\n"
                    + LookupListUtils.getIngestReport(),
                ImportExportLogDialog.DIALOG_TYPE_IMPORT);
        progressPanel.close();
        dialog.showDialog();
      } catch (JAXBException e) {
        progressPanel.close();
        new ErrorDialog(
                ApplicationFrame.getInstance(), "There is a problem importing accessions.", e)
            .showDialog();
      } catch (IllegalAccessException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (InvocationTargetException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (UnknownLookupListException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (ValidationException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (PersistenceException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (DuplicateLinkException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (NoSuchMethodException e) {
        progressPanel.close();
        new ErrorDialog("", e).showDialog();
      } catch (NoSuchAlgorithmException e) {
        new ErrorDialog("", e).showDialog();
      } catch (UnsupportedEncodingException e) {
        new ErrorDialog("", e).showDialog();
      }
    }
    return (true);
  }
  private void addInstanceButtonActionPerformed() {
    //		ArchDescription archDescriptionModel = (ArchDescription) super.getModel();
    ArchDescriptionInstances newInstance = null;
    Vector<String> possibilities =
        LookupListUtils.getLookupListValues(LookupListUtils.LIST_NAME_INSTANCE_TYPES);
    ImageIcon icon = null;
    try {
      // add a special entry for digital object link to the possibilities vector
      possibilities.add(ArchDescriptionInstances.DIGITAL_OBJECT_INSTANCE_LINK);
      Collections.sort(possibilities);

      dialogInstances =
          (ArchDescriptionInstancesEditor)
              DomainEditorFactory.getInstance()
                  .createDomainEditorWithParent(
                      ArchDescriptionInstances.class, getParentEditor(), getInstancesTable());
    } catch (DomainEditorCreationException e) {
      new ErrorDialog(getParentEditor(), "Error creating editor for ArchDescriptionInstances", e)
          .showDialog();
    }

    dialogInstances.setNewRecord(true);

    int returnStatus;
    Boolean done = false;
    while (!done) {
      defaultInstanceType =
          (String)
              JOptionPane.showInputDialog(
                  getParentEditor(),
                  "What type of instance would you like to create",
                  "",
                  JOptionPane.PLAIN_MESSAGE,
                  icon,
                  possibilities.toArray(),
                  defaultInstanceType);
      System.out.println("adding new instance");
      if ((defaultInstanceType != null) && (defaultInstanceType.length() > 0)) {
        if (defaultInstanceType.equalsIgnoreCase(
            ArchDescriptionInstances.DIGITAL_OBJECT_INSTANCE)) {
          System.out.println("adding new digital instance");
          newInstance = new ArchDescriptionDigitalInstances(resourceComponentModel);
          addDatesToNewDigitalInstance(
              (ArchDescriptionDigitalInstances) newInstance, resourceComponentModel);
        } else if (defaultInstanceType.equalsIgnoreCase(
            ArchDescriptionInstances.DIGITAL_OBJECT_INSTANCE_LINK)) {
          // add a digital object link or links instead
          addDigitalInstanceLink((Resources) editorField.getModel());
          return;
        } else {
          newInstance = new ArchDescriptionAnalogInstances(resourceComponentModel);
        }

        newInstance.setInstanceType(defaultInstanceType);

        // see whether to use a plugin
        if (usePluginDomainEditor(true, newInstance, getInstancesTable())) {
          return;
        }

        dialogInstances.setModel(newInstance, null);
        //				dialogInstances.setResourceInfo((Resources) editorField.getModel());
        returnStatus = dialogInstances.showDialog();
        if (returnStatus == JOptionPane.OK_OPTION) {
          dialogInstances.commitChangesToCurrentRecord();
          resourceComponentModel.addInstance(newInstance);
          getInstancesTable().getEventList().add(newInstance);
          findLocationForInstance(newInstance);
          ApplicationFrame.getInstance().setRecordDirty(); // set the record dirty
          done = true;
        } else if (returnStatus == StandardEditor.OK_AND_ANOTHER_OPTION) {
          dialogInstances.commitChangesToCurrentRecord();
          resourceComponentModel.addInstance(newInstance);
          getInstancesTable().getEventList().add(newInstance);
          findLocationForInstance(newInstance);
          ApplicationFrame.getInstance().setRecordDirty(); // set the record dirty
        } else {
          done = true;
        }
      } else {
        done = true;
      }
    }
    dialogInstances.setNewRecord(false);
  }