public void removeRelatedTableRow(DomainGlazedListTable relatedTable, DomainObject model)
     throws ObjectNotRemovedException {
   int selectedRow = relatedTable.getSelectedRow();
   if (selectedRow == -1) {
     JOptionPane.showMessageDialog(
         this, "You must select a row to remove.", "warning", JOptionPane.WARNING_MESSAGE);
   } else {
     int response =
         JOptionPane.showConfirmDialog(
             this,
             "Are you sure you want to delete "
                 + relatedTable.getSelectedRows().length
                 + " record(s)",
             "Delete records",
             JOptionPane.YES_NO_OPTION);
     if (response == JOptionPane.OK_OPTION) {
       ArrayList<DomainObject> relatedObjects = relatedTable.removeSelectedRows();
       for (DomainObject relatedObject : relatedObjects) {
         model.removeRelatedObject(relatedObject);
       }
       int rowCount = relatedTable.getRowCount();
       if (rowCount == 0) {
         // do nothing
       } else if (selectedRow >= rowCount) {
         relatedTable.setRowSelectionInterval(rowCount - 1, rowCount - 1);
       } else {
         relatedTable.setRowSelectionInterval(selectedRow, selectedRow);
       }
       // set record to dirty
       ApplicationFrame.getInstance().setRecordDirty();
     }
   }
 }
  /**
   * Method to load a custom plugin domain editor for viewing the record. Usefull if someone want to
   * implemment an editor that is more suited for their workflow or to load a read only viewer for
   * the record.
   *
   * @param domainObject The record to edit
   * @return Whether any plugin editors where found
   */
  protected boolean usePluginDomainEditor(
      boolean newInstance, DomainObject domainObject, DomainSortableTable callingTable) {
    ATPlugin plugin = ATPluginFactory.getInstance().getEditorPlugin(domainObject);

    if (plugin == null) { // just return false and so that the built in domain object can be used
      return false;
    }

    // set the calling table and editor
    plugin.setEditorField(this);
    plugin.setCallingTable(callingTable);

    if (!newInstance) { // this means that it is a record being edited, so may have to do something
                        // special
      plugin.setModel(domainObject, null);
    } else { // its a new record to just set the model
      plugin.setModel(domainObject, null);
    }

    // set the main program application frame and display it
    plugin.setApplicationFrame(ApplicationFrame.getInstance());
    plugin.showPlugin(getParentEditor());

    return true;
  }
 protected int editRelatedRecord(
     DomainGlazedListTable table, Class clazz, Boolean buffered, DomainEditor domainEditor) {
   int selectedRow = table.getSelectedRow();
   if (selectedRow != -1) {
     DomainObject domainObject = table.getSortedList().get(selectedRow);
     if (domainEditor == null) {
       try {
         domainEditor =
             DomainEditorFactory.getInstance()
                 .createDomainEditorWithParent(clazz, editorField.getParentEditor(), false);
         domainEditor.setCallingTable(table);
       } catch (UnsupportedTableModelException e1) {
         new ErrorDialog(
                 editorField.getParentEditor(),
                 "Error creating editor for " + clazz.getSimpleName(),
                 e1)
             .showDialog();
       } catch (DomainEditorCreationException e) {
         new ErrorDialog(
                 editorField.getParentEditor(),
                 "Error creating editor for " + clazz.getSimpleName(),
                 e)
             .showDialog();
       }
     }
     domainEditor.setBuffered(buffered);
     domainEditor.setSelectedRow(selectedRow);
     domainEditor.setNavigationButtons();
     domainEditor.setModel(domainObject, null);
     int returnValue = domainEditor.showDialog();
     if (domainEditor.getBuffered()) {
       if (returnValue == JOptionPane.CANCEL_OPTION) {
         domainEditor.editorFields.cancelEdit();
       } else {
         domainEditor.editorFields.acceptEdit();
         ApplicationFrame.getInstance()
             .setRecordDirty(); // ok an edit was made, so set the record dirty
       }
     }
     return returnValue;
   } else {
     return JOptionPane.CANCEL_OPTION;
   }
 }
Пример #4
0
  public void createDomainEditors() {
    ApplicationFrame mainFrame = ApplicationFrame.getInstance();
    DomainTableWorkSurface worksurface;

    // Subjects
    DomainEditor subjectEditor = this.putDialog(Subjects.class, new SubjectEditor(mainFrame));
    subjectEditor.setMainHeaderColorAndTextByClass();
    subjectEditor.setIncludeSaveButton(true);
    this.putSearchDialog(Subjects.class, mainFrame);
    worksurface = mainFrame.getWorkSurface(Subjects.class);
    subjectEditor.setWorkSurface(worksurface);
    subjectEditor.setNavigationButtonListeners(worksurface);

    // Names
    DomainEditor namesEditor =
        this.putDialog(Names.class, new NameEditor(mainFrame, new NameFields()));
    namesEditor.setMainHeaderColorAndTextByClass();
    namesEditor.setIncludeSaveButton(true);
    this.putSearchDialog(Names.class, mainFrame);
    worksurface = mainFrame.getWorkSurface(Names.class);
    namesEditor.setWorkSurface(worksurface);
    namesEditor.setNavigationButtonListeners(worksurface);

    // constants
    DomainEditor constantsEditor =
        new DomainEditor(Constants.class, mainFrame, new ConstantsFields());
    constantsEditor.hidePrintAndNavigationButtons();
    DomainEditorFactory.getInstance()
        .putDialogAndSetListenerToSelf(Constants.class, constantsEditor);

    // Accessions
    DomainEditor accessionEditor =
        DomainEditorFactory.getInstance()
            .putDialog(Accessions.class, new AccessionEditor(mainFrame));
    accessionEditor.setMainHeaderColorAndTextByClass();
    accessionEditor.setIncludeSaveButton(true);
    this.putSearchDialog(Accessions.class, mainFrame);
    worksurface = mainFrame.getWorkSurface(Accessions.class);
    accessionEditor.setWorkSurface(worksurface);
    accessionEditor.setNavigationButtonListeners(worksurface);

    // Resources
    DomainEditor resourceEditor =
        DomainEditorFactory.getInstance().putDialog(Resources.class, new ResourceEditor(mainFrame));
    resourceEditor.setMainHeaderColorAndTextByClass();
    resourceEditor.setIncludeSaveButton(true);
    this.putSearchDialog(Resources.class, mainFrame);
    worksurface = mainFrame.getWorkSurface(Resources.class);
    resourceEditor.setWorkSurface(worksurface);
    resourceEditor.setNavigationButtonListeners(worksurface);

    // Digital Object Editor
    DomainEditor digitalObjectEditor =
        DomainEditorFactory.getInstance()
            .putDialog(DigitalObjects.class, new DigitalObjectEditor(mainFrame));
    digitalObjectEditor.setMainHeaderColorAndTextByClass();
    digitalObjectEditor.setIncludeSaveButton(true);
    this.putSearchDialog(DigitalObjects.class, mainFrame);
    worksurface = mainFrame.getWorkSurface(DigitalObjects.class);
    digitalObjectEditor.setWorkSurface(worksurface);
    digitalObjectEditor.setNavigationButtonListeners(worksurface);
  }
Пример #5
0
  public DomainEditor createDomainEditorWithParent(
      final Class clazz, final JDialog parent, boolean useParentAsEventListener)
      throws DomainEditorCreationException {

    DomainEditor domainEditor = null;
    if (clazz == BibItems.class) {
      domainEditor =
          new DomainEditor(BibItems.class, parent, "Bibliographic Items", new BibItemsFields());

    } else if (clazz == ChronologyItems.class) {
      domainEditor = new DomainEditor(ChronologyItems.class, parent, new ChronologyItemsFields());

    } else if (clazz == IndexItems.class) {
      domainEditor =
          new DomainEditor(IndexItems.class, parent, "Index Items", new IndexItemsFields());

    } else if (clazz == ListOrderedItems.class) {
      domainEditor =
          new DomainEditor(
              ListOrderedItems.class, parent, "List Items", new ListOrderedItemsFields());

    } else if (clazz == ListDefinitionItems.class) {
      domainEditor =
          new DomainEditor(
              ListDefinitionItems.class, parent, "List Items", new ListDefinitionItemsFields());

    } else if (clazz == Subjects.class) {
      domainEditor = new DomainEditor(Subjects.class, parent, new SubjectFields());

    } else if (clazz == AccessionsLocations.class) {
      domainEditor =
          new DomainEditor(AccessionsLocations.class, parent, new AccessionsLocationsFields());

    } else if (clazz == Names.class) {
      domainEditor = new NameEditor(parent, new NameFields());

    } else if (clazz == NameContactNotes.class) {
      domainEditor = new DomainEditor(NameContactNotes.class, parent, new NameContactNoteFields());

    } else if (clazz == NonPreferredNames.class) {
      domainEditor = new NonPreferredNameEditor(parent);

    } else if (clazz == Users.class) {
      domainEditor = new UserEditor(parent);

    } else if (clazz == LookupList.class) {
      domainEditor = new DomainEditor(LookupList.class, parent, new LookupListFields());

    } else if (clazz == RDEScreen.class) {
      domainEditor = new DomainEditor(RDEScreen.class, parent, new RDEScreenFields());

    } else if (clazz == ArchDescriptionRepeatingData.class) {
      domainEditor = new ArchDescriptionRepeatingDataEditor(parent);

    } else if (clazz == ArchDescriptionNames.class) {
      domainEditor =
          new DomainEditor(
              ArchDescriptionNames.class, parent, "dummy text", new ArchDescriptionNamesFields());

    } else if (clazz == RepositoryNotesDefaultValues.class) {
      domainEditor =
          new DomainEditor(
              RepositoryNotesDefaultValues.class, parent, new RepositoryNotesDefaultValuesFields());

    } else if (clazz == RepositoryNotes.class) {
      domainEditor = new DomainEditor(RepositoryNotes.class, parent, new RepositoryNoteFields());

    } else if (clazz == RepositoryStatistics.class) {
      domainEditor =
          new DomainEditor(RepositoryStatistics.class, parent, new RepositoryStatisticsFields());

    } else if (clazz == DefaultValues.class) {
      domainEditor = new DomainEditor(DefaultValues.class, parent, new DefaultValuesFields());

    } else if (clazz == Deaccessions.class) {
      domainEditor = new DomainEditor(Deaccessions.class, parent, new DeaccessionsFields());
      Class parentModelClass = ((DomainEditor) parent).getModel().getClass();
      domainEditor.setMainHeaderColorAndTextByClass(clazz, parentModelClass);

    } else if (clazz == Events.class) {
      domainEditor = new DomainEditor(Events.class, parent, new EventsFields());

    } else if (clazz == RDEScreenPanels.class) {
      domainEditor = new DomainEditor(RDEScreenPanels.class, parent, new RDEScreenPanelFields());

    } else if (clazz == NotesEtcTypes.class) {
      domainEditor = new DomainEditor(NotesEtcTypes.class, parent, new NotesEtcTypesFields());

    } else if (clazz == Locations.class) {
      domainEditor = new LocationEditor(parent);

    } else if (clazz == Repositories.class) {
      domainEditor = new RepositoryEditor(parent);

    } else if (clazz == Constants.class) {
      domainEditor = new DomainEditor(Constants.class, parent, new ConstantsFields());

    } else if (clazz == ArchDescriptionInstances.class) {
      domainEditor = new ArchDescriptionInstancesEditor(parent);

    } else if (clazz == ArchDescriptionRepeatingData.class) {
      domainEditor = new ArchDescriptionRepeatingDataEditor(parent);

    } else if (clazz == FileVersions.class) {
      domainEditor = new FileVersionsEditor(parent);

    } else if (clazz == DatabaseTables.class) {
      domainEditor = new DatabaseTableEditor(parent);
      if (!ApplicationFrame.getInstance()
          .getCurrentUserName()
          .equalsIgnoreCase(Users.USERNAME_DEVELOPER)) {
        ((DatabaseTableEditor) domainEditor).hideAddRemoveButtons();
      }

    } else if (clazz == DatabaseFields.class) {
      domainEditor = new DatabaseFieldsEditor(parent);

    } else if (clazz == Assessments.class) {
      domainEditor = new DomainEditor(Assessments.class, parent, new AssessmentsFields());
    }

    if (domainEditor == null) {
      return null;
    } else if (useParentAsEventListener) {
      if (parent instanceof ActionListener) {
        domainEditor.setNavigationButtonListeners((ActionListener) parent);
        return domainEditor;
      } else {
        throw new DomainEditorCreationException(parent + " is not an action listener");
      }
    } else {
      domainEditor.setNavigationButtonListeners(domainEditor);
      return domainEditor;
    }
  }
Пример #6
0
  /**
   * 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);
  }