Example usage for org.apache.commons.collections15 OrderedMap keySet

List of usage examples for org.apache.commons.collections15 OrderedMap keySet

Introduction

In this page you can find the example usage for org.apache.commons.collections15 OrderedMap keySet.

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:org.isatools.isacreator.gui.DataEntryForm.java

/**
 * Adds the fields describing a section to a Container (e.g. JPanel, Box, etc.)
 *
 * @param containerToAddTo @see JPanel, @see Box, @see  Container
 * @param sectionToAddTo   - @see InvestigationFileSection as a reference for where the fields are being added
 * @param fieldValues      - Map of field name to values.
 * @param referenceObject  - A @see DataEntryReferenceObject which gives information about
 *///from ww w  .j  a  v a2 s  .  co  m
public void addFieldsToPanel(Container containerToAddTo, InvestigationFileSection sectionToAddTo,
        OrderedMap<String, String> fieldValues, DataEntryReferenceObject referenceObject) {

    if (fieldDefinitions == null) {
        fieldDefinitions = new ListOrderedMap<String, JComponent>();
    }

    Set<String> ontologyFields = referenceObject.getOntologyTerms(sectionToAddTo);
    Set<String> fieldsToIgnore = referenceObject.getFieldsToIgnore();

    for (String fieldName : fieldValues.keySet()) {

        if (!fieldsToIgnore.contains(fieldName)) {
            FieldObject fieldDescriptor = referenceObject.getFieldDefinition(fieldName);

            if (!fieldDescriptor.isHidden()) {
                String tmpFieldName = fieldName;

                if (realNamesToAliases.containsKey(fieldName)) {
                    tmpFieldName = realNamesToAliases.get(fieldName);
                }

                JPanel fieldPanel = createFieldPanel(1, 2);
                JLabel fieldLabel = createLabel(tmpFieldName);

                JComponent textComponent;

                if (fieldDescriptor.getDatatype() == DataTypes.STRING
                        || fieldDescriptor.getDatatype() == DataTypes.ONTOLOGY_TERM
                        || fieldDescriptor.getDatatype() == DataTypes.DATE) {
                    textComponent = new RoundedJTextField(10);
                } else if (fieldDescriptor.getDatatype() == DataTypes.LONG_STRING) {
                    textComponent = new JTextArea();

                    ((JTextArea) textComponent).setSelectionColor(UIHelper.LIGHT_GREEN_COLOR);
                    ((JTextArea) textComponent).setSelectedTextColor(UIHelper.BG_COLOR);

                    ((JTextArea) textComponent).setWrapStyleWord(true);
                    ((JTextArea) textComponent).setLineWrap(true);
                    textComponent.setBackground(UIHelper.BG_COLOR);
                    textComponent.setBorder(UIHelper.GREEN_ROUNDED_BORDER);
                } else if (fieldDescriptor.getDatatype() == DataTypes.LIST) {
                    textComponent = new JComboBox(fieldDescriptor.getFieldList());
                } else {
                    textComponent = new RoundedJTextField(10);
                }

                if (textComponent instanceof JTextArea || textComponent instanceof JTextComponent) {
                    ((JTextComponent) textComponent)
                            .setText(fieldValues.get(fieldName).equals("") ? fieldDescriptor.getDefaultVal()
                                    : fieldValues.get(fieldName));
                }
                textComponent.setToolTipText(fieldDescriptor.getDescription());

                UIHelper.renderComponent(textComponent, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR,
                        false);

                fieldPanel.add(fieldLabel);

                if (textComponent instanceof JTextArea) {

                    JScrollPane invDescScroll = new JScrollPane(textComponent,
                            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                    invDescScroll.setPreferredSize(new Dimension(200, 75));

                    invDescScroll.getViewport().setBackground(UIHelper.BG_COLOR);

                    ((JTextArea) textComponent).getDocument().addDocumentListener(new DocumentChangeListener());

                    IAppWidgetFactory.makeIAppScrollPane(invDescScroll);
                    fieldPanel.add(
                            UIHelper.createTextEditEnableJTextArea(invDescScroll, (JTextArea) textComponent));
                } else if (textComponent instanceof JTextComponent) {

                    if (fieldDescriptor.getDatatype() == DataTypes.ONTOLOGY_TERM
                            || ontologyFields.contains(fieldName)) {
                        fieldPanel.add(createOntologyDropDown(fieldName, (JTextComponent) textComponent, true,
                                false, fieldDescriptor.getRecommmendedOntologySource()));
                    } else if (fieldDescriptor.getDatatype() == DataTypes.DATE) {
                        fieldPanel.add(createDateDropDown((JTextComponent) textComponent));
                    } else if (fieldDescriptor.isAcceptsFileLocations()) {
                        fieldPanel.add(createFileField((JTextComponent) textComponent));
                    } else {
                        fieldPanel.add(textComponent);
                    }
                    ((JTextComponent) textComponent).getDocument()
                            .addDocumentListener(new DocumentChangeListener());
                } else {
                    fieldPanel.add(textComponent);
                }

                fieldDefinitions.put(tmpFieldName, textComponent);

                containerToAddTo.add(fieldPanel);
                containerToAddTo.add(Box.createVerticalStrut(5));
            }
        }
    }
}

From source file:org.isatools.isacreator.io.importisa.InvestigationImport.java

/**
 * Checks to make sure all required Investigation file sections have been entered
 *
 * @param investigationFile - Map containing investigation file structure
 * @return - true if valid, false otherwise.
 *///from  www .  j  a  va  2 s .  c  o m
private boolean isValidInvestigationSections(
        OrderedMap<String, OrderedMap<InvestigationFileSection, OrderedMap<String, List<String>>>> investigationFile) {

    InvestigationStructureLoader loader = new InvestigationStructureLoader();
    Map<InvestigationFileSection, InvestigationSection> sections = loader.loadInvestigationStructure();

    MessageFormat fmt = new MessageFormat(
            "The field {0} is missing from the {1} section of the investigation file");

    for (String mainSection : investigationFile.keySet()) {

        // checking major section, e.g. study or investigation
        Set<InvestigationFileSection> majorSectionParts = new HashSet<InvestigationFileSection>();

        for (InvestigationFileSection section : investigationFile.get(mainSection).keySet()) {
            majorSectionParts.add(section);

            Set<String> minorSectionParts = new HashSet<String>();
            // we also want to check if the salient information for each minor section is in place.
            for (String sectionLabelsAndValues : investigationFile.get(mainSection).get(section).keySet()) {
                minorSectionParts.add(sectionLabelsAndValues.toLowerCase());
            }

            SetUtils<String> setUtils = new SetUtils<String>();

            Set<String> requiredValuesAsLowercase = setUtils
                    .getLowerCaseSetContents(sections.get(section).getRequiredValues());

            Pair<Boolean, Set<String>> equalityResult = setUtils.compareSets(minorSectionParts,
                    requiredValuesAsLowercase, false);
            if (!equalityResult.fst) {
                for (String sectionValue : equalityResult.snd) {
                    messages.add(new ErrorMessage(ErrorLevel.ERROR,
                            fmt.format(new Object[] { sectionValue, section })));
                }
            }
            // check minor section for salient information
        }

        // check major section for salient information

        // the mainsection string is investigation-1 or study-2 - here we strip away from - onwards.
        Set<InvestigationFileSection> requiredSections = loader
                .getRequiredSections(mainSection.substring(0, mainSection.lastIndexOf("-")));
        SetUtils<InvestigationFileSection> setUtils = new SetUtils<InvestigationFileSection>();
        Pair<Boolean, Set<InvestigationFileSection>> equalityResult = setUtils.compareSets(majorSectionParts,
                requiredSections, true);

        // if false,
        if (!equalityResult.fst) {
            if (equalityResult.snd != null) {
                for (InvestigationFileSection section : equalityResult.snd) {
                    messages.add(new ErrorMessage(ErrorLevel.ERROR, fmt.format(
                            new Object[] { section, mainSection.substring(0, mainSection.lastIndexOf("-")) })));
                }
            } else {
                messages.add(new ErrorMessage(ErrorLevel.ERROR, "Incorrect number of sections defined for "
                        + mainSection.substring(0, mainSection.lastIndexOf("-"))));
            }
        }
    }

    // if the message size is 0, there are no errors...
    return messages.size() == 0;
}

From source file:org.isatools.isacreator.io.importisa.StructureToInvestigationMapper.java

public Pair<Boolean, Investigation> createInvestigationFromDataStructure(
        OrderedMap<String, OrderedMap<InvestigationFileSection, OrderedMap<String, List<String>>>> investigationStructure) {

    Investigation investigation = null;//w  ww.j a  v  a  2s.  c  om

    List<Study> studies = new ArrayList<Study>();

    for (String majorSection : investigationStructure.keySet()) {
        if (majorSection.contains("Investigation")) {

            investigation = processInvestigation(investigationStructure.get(majorSection));
            System.out.println(investigation.getInvestigationTitle());
        }

        if (majorSection.contains("Study")) {

            Study newStudy = processStudy(investigationStructure.get(majorSection));
            studies.add(newStudy);
        }
    }

    if (investigation != null) {
        for (Study study : studies) {
            investigation.addStudy(study);
        }
    }

    return new Pair<Boolean, Investigation>(validateInvestigationFile(investigation), investigation);
}

From source file:org.isatools.isacreator.io.importisa.StructureToInvestigationMapper.java

private Investigation processInvestigation(
        OrderedMap<InvestigationFileSection, OrderedMap<String, List<String>>> investigationSections) {
    Set<OntologySourceRefObject> ontologySources = new HashSet<OntologySourceRefObject>();
    List<Contact> contacts = new ArrayList<Contact>();
    List<Publication> publications = new ArrayList<Publication>();

    Investigation tmpInvestigation = null;

    OrderedMap<InvestigationFileSection, Set<String>> sectionFields = new ListOrderedMap<InvestigationFileSection, Set<String>>();

    for (InvestigationFileSection investigationSection : investigationSections.keySet()) {
        if (investigationSection == InvestigationFileSection.INVESTIGATION_SECTION) {

            Pair<Set<String>, Investigation> processedInvestigationSection = processInvestigationSection(
                    investigationSections.get(investigationSection));
            sectionFields.put(investigationSection, processedInvestigationSection.fst);
            tmpInvestigation = processedInvestigationSection.snd;

        } else if (investigationSection == InvestigationFileSection.ONTOLOGY_SECTION) {

            Pair<Set<String>, List<OntologySourceRefObject>> processedOntologySection = processOntologySourceReferences(
                    investigationSections.get(investigationSection));
            sectionFields.put(investigationSection, processedOntologySection.fst);
            ontologySources = new HashSet<OntologySourceRefObject>(processedOntologySection.snd);

        } else if (investigationSection == InvestigationFileSection.INVESTIGATION_PUBLICATIONS_SECTION) {

            Pair<Set<String>, List<Publication>> processedPublicationSection = processPublication(
                    investigationSection, investigationSections.get(investigationSection));
            sectionFields.put(investigationSection, processedPublicationSection.fst);
            publications = processedPublicationSection.snd;

        } else if (investigationSection == InvestigationFileSection.INVESTIGATION_CONTACTS_SECTION) {
            Pair<Set<String>, List<Contact>> processedContactSection = processContacts(investigationSection,
                    investigationSections.get(investigationSection));
            sectionFields.put(investigationSection, processedContactSection.fst);
            contacts = processedContactSection.snd;
        }/*ww  w  . j a v a2  s.c om*/

    }

    if (tmpInvestigation != null) {
        OntologyManager.setOntologySources(ontologySources);
        tmpInvestigation.addToPublications(publications);
        tmpInvestigation.addToContacts(contacts);

        tmpInvestigation.addToReferenceObject(sectionFields);
    }

    return tmpInvestigation;
}

From source file:org.isatools.isacreator.io.importisa.StructureToInvestigationMapper.java

private Study processStudy(
        OrderedMap<InvestigationFileSection, OrderedMap<String, List<String>>> studySections) {
    Study study = null;//from ww  w . j a v a2 s.  co  m

    List<Protocol> protocols = new ArrayList<Protocol>();
    List<Factor> factors = new ArrayList<Factor>();
    List<Contact> contacts = new ArrayList<Contact>();
    List<Publication> publications = new ArrayList<Publication>();
    List<Assay> assays = new ArrayList<Assay>();
    List<StudyDesign> studyDesigns = new ArrayList<StudyDesign>();

    OrderedMap<InvestigationFileSection, Set<String>> sectionFields = new ListOrderedMap<InvestigationFileSection, Set<String>>();

    for (InvestigationFileSection studySection : studySections.keySet()) {
        if (studySection == InvestigationFileSection.STUDY_SECTION) {

            Pair<Set<String>, Study> processedStudySection = processStudySection(
                    studySections.get(studySection));
            study = processedStudySection.snd;
            sectionFields.put(studySection, processedStudySection.fst);

        } else if (studySection == InvestigationFileSection.STUDY_FACTORS) {

            Pair<Set<String>, List<Factor>> processedFactorsSection = processFactors(
                    studySections.get(studySection));
            sectionFields.put(studySection, processedFactorsSection.fst);
            factors = processedFactorsSection.snd;

        } else if (studySection == InvestigationFileSection.STUDY_DESIGN_SECTION) {

            Pair<Set<String>, List<StudyDesign>> processedStudyDesignSection = processStudyDesigns(
                    studySections.get(studySection));
            sectionFields.put(studySection, processedStudyDesignSection.fst);

            studyDesigns = processedStudyDesignSection.snd;

        } else if (studySection == InvestigationFileSection.STUDY_ASSAYS) {

            Pair<Set<String>, List<Assay>> processedAssaySection = processAssay(
                    studySections.get(studySection));
            sectionFields.put(studySection, processedAssaySection.fst);
            assays = processedAssaySection.snd;

        } else if (studySection == InvestigationFileSection.STUDY_PUBLICATIONS) {

            Pair<Set<String>, List<Publication>> processedPublicationSection = processPublication(studySection,
                    studySections.get(studySection));
            sectionFields.put(studySection, processedPublicationSection.fst);
            publications = processedPublicationSection.snd;

        } else if (studySection == InvestigationFileSection.STUDY_PROTOCOLS) {

            Pair<Set<String>, List<Protocol>> processedProtocolSection = processProtocol(
                    studySections.get(studySection));
            sectionFields.put(studySection, processedProtocolSection.fst);
            protocols = processedProtocolSection.snd;

        } else if (studySection == InvestigationFileSection.STUDY_CONTACTS) {

            Pair<Set<String>, List<Contact>> processedContactSection = processContacts(studySection,
                    studySections.get(studySection));
            sectionFields.put(studySection, processedContactSection.fst);
            contacts = processedContactSection.snd;
        }

    }

    if (study != null) {
        study.addToAssays(assays);
        study.setProtocols(protocols);
        study.setContacts(contacts);

        study.setStudyDesigns(studyDesigns);
        study.setFactors(factors);
        study.setPublications(publications);

        // we want to add new fields, but want to keep the general working of the configuration. So we do just that.
        // new fields (unknown) will be treated as Strings, other known values will acquire the properties
        // specified of them in the configuration XML.
        study.addToReferenceObject(sectionFields);
    }

    return study;
}

From source file:org.isatools.isacreator.model.ISASection.java

public void addToReferenceObject(OrderedMap<InvestigationFileSection, Set<String>> sectionFields) {
    for (InvestigationFileSection section : sectionFields.keySet()) {
        if (!referenceObject.getSectionDefinition().containsKey(section)) {
            referenceObject.getSectionDefinition().put(section, new ListOrderedSet<String>());
        }//from   w  w  w .  j  a  va2s  .  c  o m
        referenceObject.getSectionDefinition().get(section).addAll(sectionFields.get(section));
    }
}