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();
     }
   }
 }
  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);
  }