org.archiviststoolkit.model.Resources.java Source code

Java tutorial

Introduction

Here is the source code for org.archiviststoolkit.model.Resources.java

Source

/**
 * Archivists' Toolkit(TM) Copyright  2005-2007 Regents of the University of California, New York University, & Five Colleges, Inc.
 * All rights reserved.
 *
 * This software is free. You can redistribute it and / or modify it under the terms of the Educational Community License (ECL)
 * version 1.0 (http://www.opensource.org/licenses/ecl1.php)
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ECL license for more details about permissions and limitations.
 *
 *
 * Archivists' Toolkit(TM)
 * http://www.archiviststoolkit.org
 * info@archiviststoolkit.org
 */

package org.archiviststoolkit.model;

import java.util.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreeSelectionModel;
import javax.swing.*;

import org.archiviststoolkit.mydomain.*;
import org.archiviststoolkit.structure.*;
import org.archiviststoolkit.swing.InfiniteProgressPanel;
import org.archiviststoolkit.dialog.ErrorDialog;
import org.archiviststoolkit.util.StringHelper;
import org.archiviststoolkit.util.ResourceUtils;
import org.archiviststoolkit.util.NoteEtcTypesUtils;
import org.archiviststoolkit.exceptions.DuplicateLinkException;
import org.archiviststoolkit.exceptions.ObjectNotRemovedException;
import org.hibernate.TransientObjectException;
import org.hibernate.LockMode;
import ca.odell.glazedlists.SortedList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.BasicEventList;

/**
 * Accessions generated by hbm2java
 */
public class Resources extends ResourcesCommon {

    public static final String PROPERTYNAME_RESOURCE_IDENTIFIER = "resourceIdentifier";
    public static final String PROPERTYNAME_RESOURCE_IDENTIFIER_1 = "resourceIdentifier1";
    public static final String PROPERTYNAME_RESOURCE_IDENTIFIER_2 = "resourceIdentifier2";
    public static final String PROPERTYNAME_RESOURCE_IDENTIFIER_3 = "resourceIdentifier3";
    public static final String PROPERTYNAME_RESOURCE_IDENTIFIER_4 = "resourceIdentifier4";
    public static final String PROPERTYNAME_ACCESSIONS = "accessions";
    public static final String PROPERTYNAME_SPONSOR_NOTE = "sponsorNote";
    public static final String PROPERTYNAME_EAD_FA_UNIQUE_IDENTIFIER = "eadFaUniqueIdentifier";
    public static final String PROPERTYNAME_EAD_FA_LOCATION = "eadFaLocation";
    public static final String PROPERTYNAME_FINDING_AID_TITLE = "findingAidTitle";
    public static final String PROPERTYNAME_FINDING_AID_SUBTITLE = "findingAidSubtitle";
    public static final String PROPERTYNAME_FINDING_AID_FILING_TITLE = "findingAidFilingTitle";
    public static final String PROPERTYNAME_FINDING_AID_DATE = "findingAidDate";
    public static final String PROPERTYNAME_AUTHOR = "author";
    public static final String PROPERTYNAME_DESCRIPTION_RULES = "descriptionRules";
    public static final String PROPERTYNAME_LANGUAGE_OF_FINDING_AID = "languageOfFindingAid";
    public static final String PROPERTYNAME_EDITION_STATEMENT = "editionStatement";
    public static final String PROPERTYNAME_SERIES = "series";
    public static final String PROPERTYNAME_REVISION_DATE = "revisionDate";
    public static final String PROPERTYNAME_REVISION_DESCRIPTION = "revisionDescription";
    public static final String PROPERTYNAME_FINDING_AID_NOTE = "findingAidNote";
    public static final String PROPERTYNAME_FINDING_AID_STATUS = "findingAidStatus";
    public static final String PROPERTYNAME_REPOSITORY = "repository";
    public static final String PROPERTYNAME_RESOURCE_ID = "resourceId";
    public static final String PROPERTYNAME_LOCATION_LIST = "locationList";
    public static final String PROPERTYNAME_USER_DEFINED_STRING1 = "userDefinedString1";
    public static final String PROPERTYNAME_USER_DEFINED_STRING2 = "userDefinedString2";

    // Fields
    private int queries = 0;

    @IncludeInApplicationConfiguration(3)
    @ExcludeFromDefaultValues
    private Long resourceId;

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried(20)
    private String resourceIdentifier1 = "";

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried(20)
    private String resourceIdentifier2 = "";

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried(20)
    private String resourceIdentifier3 = "";

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried(20)
    private String resourceIdentifier4 = "";

    @IncludeInApplicationConfiguration
    private String sponsorNote = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    @StringLengthValidationRequried
    private String eadFaUniqueIdentifier = "";

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried
    private String eadFaLocation = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    private String findingAidTitle = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    private String findingAidSubtitle = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    private String findingAidFilingTitle = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    @StringLengthValidationRequried
    private String findingAidDate = "";

    @IncludeInApplicationConfiguration
    private String author = "";

    @IncludeInApplicationConfiguration
    private String descriptionRules = "";

    @IncludeInApplicationConfiguration
    private String languageOfFindingAid = "";

    @IncludeInApplicationConfiguration
    private String editionStatement = "";

    @IncludeInApplicationConfiguration
    private String series = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    @StringLengthValidationRequried
    private String revisionDate = "";

    @IncludeInApplicationConfiguration
    private String revisionDescription = "";

    @IncludeInApplicationConfiguration
    private String findingAidNote = "";

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried
    private String findingAidStatus = "";

    private Integer nextPersistentId = 1;

    private transient DnDResourceTree resourceJTree = null;
    private transient JTree plainJTree = null;

    private Set accessions = new HashSet();

    @IncludeInApplicationConfiguration
    @DefaultIncludeInSearchEditor
    @ExcludeFromDefaultValues
    private Repositories repository;

    private boolean isNewRecord = false;

    private boolean hitAtComponentLevel = false;

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    @StringLengthValidationRequried
    private String displayCreator = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    @StringLengthValidationRequried
    private String displayRepository = "";

    @IncludeInApplicationConfiguration
    @ExcludeFromDefaultValues
    @StringLengthValidationRequried
    private String displaySource = "";

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried
    private String userDefinedString1 = "";

    @IncludeInApplicationConfiguration
    @StringLengthValidationRequried
    private String userDefinedString2 = "";

    private ArrayList<ResourcesComponents> componentsToDelete = new ArrayList<ResourcesComponents>();

    // Property accessors

    public void markRecordAsNew() {
        isNewRecord = true;
    }

    /**
     *
     */
    public String getResourceIdentifier1() {
        if (this.resourceIdentifier1 != null) {
            return this.resourceIdentifier1;
        } else {
            return "";
        }
    }

    public void setResourceIdentifier1(String resourceIdentifier1) {
        this.resourceIdentifier1 = resourceIdentifier1;
    }

    /**
     *
     */
    public String getResourceIdentifier2() {
        if (this.resourceIdentifier2 != null) {
            return this.resourceIdentifier2;
        } else {
            return "";
        }
    }

    public void setResourceIdentifier2(String resourceIdentifier2) {
        this.resourceIdentifier2 = resourceIdentifier2;
    }

    /**
     *
     */
    public String getResourceIdentifier3() {
        if (this.resourceIdentifier3 != null) {
            return this.resourceIdentifier3;
        } else {
            return "";
        }
    }

    public void setResourceIdentifier3(String resourceIdentifier3) {
        this.resourceIdentifier3 = resourceIdentifier3;
    }

    /**
     *
     */
    public String getResourceIdentifier4() {
        if (this.resourceIdentifier4 != null) {
            return this.resourceIdentifier4;
        } else {
            return "";
        }
    }

    public void setResourceIdentifier4(String resourceIdentifier4) {
        this.resourceIdentifier4 = resourceIdentifier4;
    }

    public Long getIdentifier() {
        return getResourceId();
    }

    public void setIdentifier(Long identifier) {
        this.setResourceId(identifier);
    }

    public Long getResourceId() {
        return resourceId;
    }

    public void setResourceId(Long resourceId) {
        this.resourceId = resourceId;
    }

    /**
     * A dummy place holder to be overridden by classes that have related objects
     *
     * @param domainObject the domain object to be removed
     */
    @Override
    public void removeRelatedObject(DomainObject domainObject) throws ObjectNotRemovedException {
        if (domainObject instanceof ResourcesComponents) {
            removeResourcesComponents((ResourcesComponents) domainObject);
        } else {
            super.removeRelatedObject(domainObject);
        }
    }

    /**
     * A dummy place holder to be overridden by classes that have related objects
     *
     * @param domainObject the domain object to be removed
     */
    public Collection getRelatedCollection(DomainObject domainObject) {
        if (domainObject instanceof ResourcesComponents) {
            return getResourcesComponents();
        } else {
            return super.getRelatedCollection(domainObject);
        }
    }

    /**
     * A dummy place holder to be overridden by classes that have related objects
     *
     * @param rowNumber the row of the object to retrieve
     */
    @Override
    public DomainObject getRelatedObject(DomainObject domainObject, int rowNumber) {
        if (domainObject instanceof ResourcesComponents) {
            return getResourcesComponent(rowNumber);
        } else {
            return super.getRelatedObject(domainObject, rowNumber);
        }
    }

    //   public void incrementOrder(Double start) {
    //      for (ResourcesComponents component: getResourcesComponents()) {
    //         if (component.getSequenceNumber() >= start) {
    //            component.setSequenceNumber(component.getSequenceNumber() + 1);
    //         }
    //      }
    //   }
    //
    //   public void removeComponent(ResourcesComponents component) {
    //      removeRelatedObject(component);
    //   }
    //
    //   public void addComponent(ResourcesComponents component) {
    //      addResourcesComponents(component);
    //   }

    @IncludeMethodInApplicationConfiguration(fieldName = PROPERTYNAME_RESOURCE_IDENTIFIER, value = 4)
    @DefaultIncludeInSearchEditor
    @ExcludeFromDefaultValues
    public String getResourceIdentifier() {
        return StringHelper.concat(".", this.getResourceIdentifier1(), this.getResourceIdentifier2(),
                this.getResourceIdentifier3(), this.getResourceIdentifier4());
    }

    public Set getAccessions() {
        return accessions;
    }

    public void setAccessions(Set accessions) {
        this.accessions = accessions;
    }

    public Repositories getRepository() {
        return repository;
    }

    //    @IncludeMethodInApplicationConfiguration(fieldName = PROPERTYNAME_REPOSITORY_NAME)

    public String getRepositoryName() {
        if (getRepository() == null) {
            return "";
        } else {
            return getRepository().getRepositoryName();
        }
    }

    public void setRepository(Repositories repository) {
        this.repository = repository;
    }

    public DnDResourceTree getResourceJtree(InfiniteProgressPanel progressPanel) {
        if (resourceJTree == null)
            buildResourceJTree(progressPanel);
        return resourceJTree;
    }

    public JTree getPlainResourceJtree(InfiniteProgressPanel progressPanel) {
        if (plainJTree == null)
            buildResourceJTree(progressPanel);
        plainJTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        return plainJTree;
    }

    public void setResourceJtree(DnDResourceTree resourceJTree) {
        this.resourceJTree = resourceJTree;
    }

    public TreePath getTreePathFromComponent(ResourcesComponents component) {
        JTree tree = getPlainJTree();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
        return getTreePathFromComponent(component, root);
    }

    //todo try to get this into one while loop possibly with a depth first traverse
    private TreePath getTreePathFromComponent(ResourcesComponents component, DefaultMutableTreeNode node) {

        DefaultMutableTreeNode childNode;
        ResourcesComponents childResourceTreeNode;

        //first go through the children to look for the hit
        Enumeration children = node.children();
        while (children.hasMoreElements()) {
            childNode = (DefaultMutableTreeNode) children.nextElement();
            childResourceTreeNode = (ResourcesComponents) childNode.getUserObject();
            if (childResourceTreeNode != null && childResourceTreeNode.equals(component)) {
                return new TreePath(childNode.getPath());
            }
        }
        //if we get here then look through the children
        children = node.children();
        TreePath treePath;
        while (children.hasMoreElements()) {
            childNode = (DefaultMutableTreeNode) children.nextElement();
            childResourceTreeNode = (ResourcesComponents) childNode.getUserObject();
            treePath = getTreePathFromComponent(component, childNode);
            if (treePath != null) {
                return treePath;
            }
        }
        return null;
    }

    public void initTree(InfiniteProgressPanel progressPanel) {
        progressPanel.setTextLine("Resource: " + this.getTitle(), 2);

        this.getRepeatingData();
        for (ResourcesComponents component : getResourcesComponents()) {
            initTree(component, progressPanel, null, 3);
        }

    }

    private void initTree(ResourcesComponents component, InfiniteProgressPanel progressPanel,
            List<String> additionalLines, int depth) {
        progressPanel.setTextLine(component.getTitle(), depth);

        component.getRepeatingData();
        if (component.isHasChild()) {
            for (ResourcesComponents childComponent : component.getResourcesComponents()) {
                initTree(childComponent, progressPanel, additionalLines, depth + 1);
            }
        }
    }

    private void buildResourceJTree(InfiniteProgressPanel progressPanel) {
        if (progressPanel != null) {
            progressPanel.setTextLine("Resource: " + this.getTitle(), 2);
        }

        //      ResourceTreeNode topResourceTreeNode = new ResourceTreeNode();
        //      topResourceTreeNode.setResource(this);
        //      topResourceTreeNode.setResourceTreeNodeTitle(this.getLabelForTree());
        //      topResourceTreeNode.setResourceTreeNodeClass(this.getClass());
        //      DefaultMutableTreeNode top = new DefaultMutableTreeNode(topResourceTreeNode);
        DefaultMutableTreeNode top = new DefaultMutableTreeNode(this);

        ResourceUtils.initPersistentIdList();

        if (this.isNewRecord) {

        } else {

            for (ArchDescriptionRepeatingData repeatingData : this.getRepeatingData()) {
                ResourceUtils.addToPersistentIdList(repeatingData.getFullDescription(),
                        repeatingData.getPersistentId());
            }

            for (ResourcesComponents component : getResourcesComponents()) {
                buildNodes(component, top, "  ", progressPanel, 3);
            }
        }
        // TODO 8/15/08 DnDResourceTree is proable not needed any more as such should be deleted
        DnDResourceTree tree = new DnDResourceTree(top, this);
        this.setResourceJtree(tree);
        this.setPlainJTree(new JTree(top));
    }

    private void buildNodes(ResourcesComponents resourceComponent, DefaultMutableTreeNode top, String indent,
            InfiniteProgressPanel progressPanel, int depth) {
        if (progressPanel != null) {
            progressPanel.setTextLine(resourceComponent.getTitle(), depth);
        }
        //      DefaultMutableTreeNode component = null;
        //      ResourceTreeNode resourceTreeNode = new ResourceTreeNode();
        //      resourceTreeNode.setResourceComponent(resourceComponent);
        //      resourceTreeNode.setResourceTreeNodeTitle(resourceComponent.getLabelForTree());
        //      resourceTreeNode.setResourceTreeNodeClass(resourceComponent.getClass());
        //      resourceTreeNode.setSequenceNumber(resourceComponent.getSequenceNumber());
        //      component = new DefaultMutableTreeNode(resourceTreeNode);
        DefaultMutableTreeNode component = new DefaultMutableTreeNode(resourceComponent);
        top.add(component);

        ResourceUtils.addToPersistentIdList(indent + "Component: " + resourceComponent.getLabelForTree(),
                resourceComponent.getPersistentId());

        if (resourceComponent.getHasNotes()) {
            String description = "";
            ArchDescriptionNotes note;
            ArchDescriptionStructuredData structuredData;
            for (ArchDescriptionRepeatingData repeatingData : resourceComponent.getRepeatingData()) {
                if (repeatingData instanceof ArchDescriptionNotes) {
                    note = (ArchDescriptionNotes) repeatingData;
                    description = indent + "   " + note.getType() + ": " + note.getNoteContent();
                    ResourceUtils.addToPersistentIdList(description, repeatingData.getPersistentId());
                } else if (repeatingData instanceof ArchDescriptionStructuredData) {
                    structuredData = (ArchDescriptionStructuredData) repeatingData;
                    description = indent + "   " + structuredData.getType() + ": " + structuredData.getNote();
                    ResourceUtils.addToPersistentIdList(description, repeatingData.getPersistentId());
                } else {
                    //todo throw class not supported exception
                }

            }
            //         repeatingDataDAO.gatherPersistentIds(resourceComponent, session, indent);
        }
        if (resourceComponent.isHasChild()) {
            for (ResourcesComponents childComponent : resourceComponent.getResourcesComponents()) {
                buildNodes(childComponent, component, indent + "  ", progressPanel, depth + 1);
            }
        }
    }

    public Collection<ContainerGroup> gatherContainers(InfiniteProgressPanel progressPanel) {
        TreeMap<String, ContainerGroup> containers = new TreeMap<String, ContainerGroup>();
        progressPanel.setTextLine("Resource: " + this.getTitle(), 2);
        String containerName;
        ArchDescriptionAnalogInstances instance;
        ContainerGroup group;

        try {
            for (Object o : getInstances(ArchDescriptionAnalogInstances.class)) {
                instance = (ArchDescriptionAnalogInstances) o;
                containerName = instance.getTopLevelLabel();
                if (StringHelper.isNotEmpty(instance.getBarcode())) {
                    containerName = instance.getTopLevelLabel() + " (" + instance.getBarcode() + ")";
                }
                group = containers.get(containerName);
                if (group == null) {
                    group = new ContainerGroup(containerName, instance.getContainer1NumericIndicator(),
                            instance.getContainer1AlphaNumericIndicator());
                    group.addInstance(instance);
                    containers.put(containerName, group);
                } else {
                    group.addInstance(instance);
                }
            }

            for (ResourcesComponents component : getResourcesComponents()) {
                gatherContainers(progressPanel, component, containers, 3);
            }

        } catch (TransientObjectException e) {
            progressPanel.close();
            new ErrorDialog("Resource must be saved", e).showDialog();
        }
        ArrayList<ContainerGroup> returnValues = new ArrayList<ContainerGroup>(containers.values());
        Collections.sort(returnValues);
        return returnValues;
    }

    private void gatherContainers(InfiniteProgressPanel progressPanel, ResourcesComponents component,
            TreeMap<String, ContainerGroup> containers, int depth) {

        String containerName;
        ArchDescriptionAnalogInstances newInstance;
        ContainerGroup group;
        progressPanel.setTextLine(component.getTitle(), depth);

        for (Object o : component.getInstances(ArchDescriptionAnalogInstances.class)) {
            newInstance = (ArchDescriptionAnalogInstances) o;
            containerName = newInstance.getTopLevelLabel();
            if (StringHelper.isNotEmpty(newInstance.getBarcode())) {
                containerName = newInstance.getTopLevelLabel() + " (" + newInstance.getBarcode() + ")";
            }
            group = containers.get(containerName);
            if (group == null) {
                group = new ContainerGroup(containerName, newInstance.getContainer1NumericIndicator(),
                        newInstance.getContainer1AlphaNumericIndicator());
                group.addInstance(newInstance);
                containers.put(containerName, group);
            } else {
                group.addInstance(newInstance);
            }
        }

        if (component.isHasChild()) {
            for (ResourcesComponents childComponent : component.getResourcesComponents()) {
                gatherContainers(progressPanel, childComponent, containers, depth + 1);
            }
        }
    }

    public synchronized Locations findLocationForContainer(String targetContainer,
            InfiniteProgressPanel progressPanel) {

        ArchDescriptionAnalogInstances instance;
        progressPanel.setTextLine("Resource: " + this.getTitle(), 2);
        Locations location;

        for (Object o : getInstances(ArchDescriptionAnalogInstances.class)) {
            instance = (ArchDescriptionAnalogInstances) o;
            location = instance.getLocation();
            if (location != null) {
                if (instance.getTopLevelLabel().equalsIgnoreCase(targetContainer)) {
                    return location;
                }
            }
        }
        for (ResourcesComponents component : getResourcesComponents()) {
            location = findLocationForContainer(targetContainer, progressPanel, component, 2);
            if (location != null) {
                return location;
            }
        }
        return null;
    }

    private Locations findLocationForContainer(String targetContainer, InfiniteProgressPanel progressPanel,
            ResourcesComponents component, int depth) {

        progressPanel.setTextLine(component.getTitle(), depth);

        ArchDescriptionAnalogInstances instance;
        Locations location;
        for (Object o : component.getInstances(ArchDescriptionAnalogInstances.class)) {
            instance = (ArchDescriptionAnalogInstances) o;
            location = instance.getLocation();
            if (location != null) {
                if (instance.getTopLevelLabel().equalsIgnoreCase(targetContainer)) {
                    return location;
                }
            }
        }
        for (ResourcesComponents childComponent : component.getResourcesComponents()) {
            location = findLocationForContainer(targetContainer, progressPanel, childComponent, depth + 1);
            if (location != null) {
                return location;
            }
        }
        return null;
    }

    public ArrayList<InstanceLocations> getLocationList() {
        return getLocationList(null);
    }

    public ArrayList<InstanceLocations> getLocationList(InfiniteProgressPanel progressPanel) {
        TreeMap<Locations, InstanceLocations> locations = new TreeMap<Locations, InstanceLocations>();

        Locations location;
        ArchDescriptionAnalogInstances instance;
        InstanceLocations containerList;
        //      List<String> additionalLines = Collections.synchronizedList(new ArrayList<String>());
        if (progressPanel != null) {
            //            additionalLines.add("Resource: " + this.getTitle());
            progressPanel.setTextLine("Resource: " + this.getTitle(), 2);
        }

        try {
            for (Object o : getInstances(ArchDescriptionAnalogInstances.class)) {
                instance = (ArchDescriptionAnalogInstances) o;
                location = instance.getLocation();
                if (location != null) {
                    containerList = locations.get(location);
                    if (containerList == null) {
                        containerList = new InstanceLocations(location.toString(), instance.getTopLevelLabel());
                        locations.put(location, containerList);
                    } else {
                        containerList.addContainer(instance.getTopLevelLabel());
                    }
                }
            }

            for (ResourcesComponents component : getResourcesComponents()) {
                gatherLocations(progressPanel, component, locations, 3);
            }

        } catch (TransientObjectException e) {
            new ErrorDialog("Resource must be saved", e).showDialog();
        }

        return new ArrayList<InstanceLocations>(locations.values());
    }

    private void gatherLocations(InfiniteProgressPanel progressPanel, ResourcesComponents component,
            TreeMap<Locations, InstanceLocations> locations, int depth) {

        Locations location;
        ArchDescriptionAnalogInstances newInstance;
        InstanceLocations containerList;

        if (progressPanel != null) {
            progressPanel.setTextLine(component.getTitle(), depth);
        }
        for (Object o : component.getInstances(ArchDescriptionAnalogInstances.class)) {
            newInstance = (ArchDescriptionAnalogInstances) o;
            location = newInstance.getLocation();
            if (location != null) {
                containerList = locations.get(location);
                if (containerList == null) {
                    containerList = new InstanceLocations(location.toString(), newInstance.getTopLevelLabel());
                    locations.put(location, containerList);
                } else {
                    containerList.addContainer(newInstance.getTopLevelLabel());
                }
            }
        }
        if (component.isHasChild()) {
            for (ResourcesComponents childComponent : component.getResourcesComponents()) {
                gatherLocations(progressPanel, childComponent, locations, depth + 1);
            }
        }
    }

    public void populateResourceFromAccession(Accessions accession) throws DuplicateLinkException {
        setTitle(accession.getTitle());
        setExtentNumber(accession.getExtentNumber());
        setExtentType(accession.getExtentType());
        setContainerSummary(accession.getContainerSummary());
        setDateExpression(accession.getDateExpression());
        setDateBegin(accession.getDateBegin());
        setDateEnd(accession.getDateEnd());
        setBulkDateBegin(accession.getBulkDateBegin());
        setBulkDateEnd(accession.getBulkDateEnd());
        setRestrictionsApply(accession.getRestrictionsApply());
        setRepository(accession.getRepository());
        for (ArchDescriptionNames nameLink : accession.getNames()) {
            try {
                addName(nameLink.getName(), nameLink.getNameLinkFunction(), nameLink.getRole(), nameLink.getForm());
            } catch (DuplicateLinkException e) {
                new ErrorDialog("", e).showDialog();
            }
        }
        for (ArchDescriptionSubjects subjectLink : accession.getSubjects()) {
            addSubject(subjectLink.getSubject());
        }
        addNoteToResource(accession.getAccessRestrictionsNote(),
                NotesEtcTypes.CANNONICAL_NAME_CONDITIONS_GIVERNING_ACCESS);
        addNoteToResource(accession.getDescription(), NotesEtcTypes.CANNONICAL_NAME_SCOPE_CONTENT);
        addNoteToResource(accession.getConditionNote(), NotesEtcTypes.CANNONICAL_NAME_GENERAL_PHYSICAL_DESCRIPTION);
    }

    private void addNoteToResource(String noteContent, String cannonicalName) {
        if (noteContent.length() > 0) {
            try {
                ArchDescriptionNotes note = new ArchDescriptionNotes(this,
                        NoteEtcTypesUtils.lookupDefaultTitleByCannonicalName(cannonicalName),
                        NotesEtcTypes.DATA_TYPE_NOTE,
                        NoteEtcTypesUtils.lookupNoteEtcTypeByCannonicalName(cannonicalName), noteContent);
                note.setPersistentId(this.getNextPersistentIdAndIncrement());
                addRepeatingData(note);
            } catch (UnsupportedRepeatingDataTypeException e) {
                new ErrorDialog("", e).showDialog();
            }
        }

    }

    public String getSponsorNote() {
        if (this.sponsorNote != null) {
            return this.sponsorNote;
        } else {
            return "";
        }
    }

    public void setSponsorNote(String sponsorNote) {
        this.sponsorNote = sponsorNote;
    }

    public boolean isHitAtComponentLevel() {
        return hitAtComponentLevel;
    }

    public void setHitAtComponentLevel(boolean hitAtComponentLevel) {
        this.hitAtComponentLevel = hitAtComponentLevel;
    }

    public String getEadFaUniqueIdentifier() {
        if (this.eadFaUniqueIdentifier != null) {
            return this.eadFaUniqueIdentifier;
        } else {
            return "";
        }
    }

    public void setEadFaUniqueIdentifier(String eadFaUniqueIdentifier) {
        this.eadFaUniqueIdentifier = eadFaUniqueIdentifier;
    }

    public String getFindingAidTitle() {
        if (this.findingAidTitle != null) {
            return this.findingAidTitle;
        } else {
            return "";
        }
    }

    public void setFindingAidTitle(String findingAidTitle) {
        this.findingAidTitle = findingAidTitle;
    }

    public String getFindingAidSubtitle() {
        if (this.findingAidSubtitle != null) {
            return this.findingAidSubtitle;
        } else {
            return "";
        }
    }

    public void setFindingAidSubtitle(String findingAidSubtitle) {
        this.findingAidSubtitle = findingAidSubtitle;
    }

    public String getFindingAidFilingTitle() {
        if (this.findingAidFilingTitle != null) {
            return this.findingAidFilingTitle;
        } else {
            return "";
        }
    }

    public void setFindingAidFilingTitle(String findingAidFilingTitle) {
        this.findingAidFilingTitle = findingAidFilingTitle;
    }

    public String getFindingAidDate() {
        return findingAidDate;
    }

    public void setFindingAidDate(String findingAidDate) {
        this.findingAidDate = findingAidDate;
    }

    public String getAuthor() {
        if (this.author != null) {
            return this.author;
        } else {
            return "";
        }
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getDescriptionRules() {
        if (this.descriptionRules != null) {
            return this.descriptionRules;
        } else {
            return "";
        }
    }

    public void setDescriptionRules(String descriptionRules) {
        this.descriptionRules = descriptionRules;
    }

    public String getLanguageOfFindingAid() {
        if (this.languageOfFindingAid != null) {
            return this.languageOfFindingAid;
        } else {
            return "";
        }
    }

    public void setLanguageOfFindingAid(String languageOfFindingAid) {
        this.languageOfFindingAid = languageOfFindingAid;
    }

    public String getEditionStatement() {
        if (this.editionStatement != null) {
            return this.editionStatement;
        } else {
            return "";
        }
    }

    public void setEditionStatement(String editionStatement) {
        this.editionStatement = editionStatement;
    }

    public String getSeries() {
        if (series != null) {
            return series;
        } else {
            return "";
        }
    }

    public void setSeries(String series) {
        this.series = series;
    }

    public String getRevisionDate() {
        if (revisionDate != null) {
            return revisionDate;
        } else {
            return "";
        }
    }

    public void setRevisionDate(String revisionDate) {
        this.revisionDate = revisionDate;
    }

    public String getRevisionDescription() {
        if (revisionDescription != null) {
            return revisionDescription;
        } else {
            return "";
        }
    }

    public void setRevisionDescription(String revisionDescription) {
        this.revisionDescription = revisionDescription;
    }

    public String getFindingAidNote() {
        if (this.findingAidNote != null) {
            return this.findingAidNote;
        } else {
            return "";
        }
    }

    public void setFindingAidNote(String findingAidNote) {
        this.findingAidNote = findingAidNote;
    }

    public String getFindingAidStatus() {
        if (this.findingAidStatus != null) {
            return this.findingAidStatus;
        } else {
            return "";
        }
    }

    public void setFindingAidStatus(String findingAidStatus) {
        this.findingAidStatus = findingAidStatus;
    }

    public String getEadFaLocation() {
        if (this.eadFaLocation != null) {
            return this.eadFaLocation;
        } else {
            return "";
        }
    }

    public void setEadFaLocation(String eadFaLocation) {
        this.eadFaLocation = eadFaLocation;
    }

    private static SortedList resourcesGlazedList;
    /**
     * event list that hosts the issues
     */
    private static EventList resourcesEventList = new BasicEventList();

    public static SortedList getResourcesGlazedList() {
        return resourcesGlazedList;
    }

    public static void initResourcesLookupList() {
        try {
            resourcesEventList.addAll(new ResourcesDAO().findAll(LockMode.READ));
            resourcesGlazedList = new SortedList(resourcesEventList);
        } catch (LookupException e) {
            new ErrorDialog("", StringHelper.getStackTrace(e)).showDialog();
        }
    }

    public static void addResourceToLookupList(Resources resource) {
        resourcesEventList.add(resource);
    }

    public static void removeResourceFromLookupList(Resources resource) {
        resourcesEventList.remove(resource);
    }

    public String getNextPersistentIdAndIncrement() {
        String returnID = "ref" + nextPersistentId;
        nextPersistentId++;
        return returnID;
    }

    public Integer getNextPersistentId() {
        return nextPersistentId;
    }

    public void setNextPersistentId(Integer nextPersistentId) {
        this.nextPersistentId = nextPersistentId;
    }

    public String toString() {
        return this.getResourceIdentifier() + ": " + this.getLabelForTree();
    }

    public String getDisplayCreator() {
        if (this.displayCreator != null) {
            return this.displayCreator;
        } else {
            return "";
        }
    }

    public void setDisplayCreator(String displayCreator) {
        this.displayCreator = displayCreator;
    }

    public String getDisplayRepository() {
        if (this.displayRepository != null) {
            return this.displayRepository;
        } else {
            return "";
        }
    }

    public void setDisplayRepository(String displayRepository) {
        this.displayRepository = displayRepository;
    }

    public String getDisplaySource() {
        if (this.displaySource != null) {
            return this.displaySource;
        } else {
            return "";
        }
    }

    public void setDisplaySource(String displaySource) {
        this.displaySource = displaySource;
    }

    public ArrayList<ResourcesComponents> getComponentsToDelete() {
        return componentsToDelete;
    }

    public void addComponentToDelete(ResourcesComponents component) {
        componentsToDelete.add(component);
    }

    public void clearComponentsToDelete() {
        componentsToDelete = new ArrayList<ResourcesComponents>();
    }

    public JTree getPlainJTree() {
        return plainJTree;
    }

    public void setPlainJTree(JTree plainJTree) {
        this.plainJTree = plainJTree;
    }

    public void clearPlainJTree() {
        this.plainJTree = null;
    }

    public class InstanceLocations {

        private String location;
        private String container;

        public InstanceLocations(String location, String container) {
            this.location = location;
            this.container = container;
        }

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public String getContainer() {
            return container;
        }

        public void setContainer(String container) {
            this.container = container;
        }

        private void addContainer(String containerToAdd) {
            if (!container.contains(containerToAdd)) {
                container += ", " + containerToAdd;
            }
        }
    }

    public String getUserDefinedString1() {
        return userDefinedString1;
    }

    public void setUserDefinedString1(String userDefinedString1) {
        this.userDefinedString1 = userDefinedString1;
    }

    public String getUserDefinedString2() {
        return userDefinedString2;
    }

    public void setUserDefinedString2(String userDefinedString2) {
        this.userDefinedString2 = userDefinedString2;
    }
}