/// <summary>
        /// Display the primary data for a component.  This method is called when adding nodes under a group node. </summary>
        /// <param name="comp"> Component to display data. </param>
        /// <param name="node"> Parent node to display under. </param>
        private bool displayDataSetComponent(DataSetComponent comp, SimpleJTree_Node node)
        {
            string routine      = "StateMod_DataSet_JTree.displayDataSetComponent";
            bool   hadData      = false; // No data for component...
            string label        = "";
            int    primary_type = __dataset.lookupPrimaryComponentTypeForComponentGroup(comp.getComponentType());

            if (primary_type >= 0)
            {
                comp = __dataset.getComponentForComponentType(primary_type);
            }
            // Revisit - later may enable even if a component does
            // not have data - for example have an "Add" popup...
            if ((comp == null) || !comp.isVisible() || !comp.hasData())
            {
                return(hadData);
            }
            object data_Object = comp.getData();

            if (data_Object == null)
            {
                return(hadData);
            }
            System.Collections.IList data = null;
            if (data_Object is System.Collections.IList)
            {
                data = (System.Collections.IList)comp.getData();
            }
            else
            {
                // Continue (REVISIT - what components would this happen for?)...
                Message.printWarning(2, routine, "Unexpected non-Vector for " + comp.getComponentName());
                return(hadData);
            }
            StateCU_Data     cudata;
            StateMod_Data    smdata;
            SimpleJTree_Node node2 = null;
            TS  tsdata;
            int dsize = 0;

            if (data != null)
            {
                dsize = data.Count;
            }
            for (int idata = 0; idata < dsize; idata++)
            {
                data_Object = data[idata];
                if (data_Object is StateMod_Data)
                {
                    smdata = (StateMod_Data)data[idata];
                    label  = StateMod_Util.formatDataLabel(smdata.getID(), smdata.getName());
                    node2  = new SimpleJTree_Node(label);
                    node2.setData(smdata);
                }
                else if (data_Object is StateCU_Data)
                {
                    cudata = (StateCU_Data)data[idata];
                    label  = StateMod_Util.formatDataLabel(cudata.getID(), cudata.getName());
                    node2  = new SimpleJTree_Node(label);
                    node2.setData(cudata);
                }
                else if (data_Object is TS)
                {
                    tsdata = (TS)data[idata];
                    label  = StateMod_Util.formatDataLabel(tsdata.getLocation(), tsdata.getDescription());
                    node2  = new SimpleJTree_Node(label);
                    node2.setData(tsdata);
                }
                try
                {
                    addNode(node2, node);
                }
                catch (Exception e)
                {
                    Message.printWarning(2, routine, "Error adding data \"" + label + "\"");
                    Message.printWarning(2, routine, e);
                    continue;
                }
            }
            if (dsize > 0)
            {
                hadData = true;
            }
            // Collapse the node because the lists are usually pretty long...
            try
            {
                collapseNode(node);
            }
            catch (Exception)
            {
                // Ignore.
            }
            return(hadData);    // Needed in the calling code.
        }
Esempio n. 2
0
        /// <summary>
        /// Checks the text fields for validity before they are saved back into the data object. </summary>
        /// <returns> 0 if the text fields are okay, 1 if fatal errors exist, and -1 if only non-fatal errors exist. </returns>
        private int checkInput()
        {
            string routine = "StateMod_Response_JFrame.checkInput";

            string warning     = "";
            int    fatal_count = 0;

            // Check to make sure that no two files have the same name...

            int size = __worksheet.getModel().getRowCount();
            DataSetComponent comp = null, comp2 = null;
            string           file_name, file_name2;

            for (int i = 0; i < size; i++)
            {
                // Get the component corresponding to the line.
                comp      = __dataset_copy.getComponentForComponentType(((StateMod_Response_TableModel)__worksheet.getModel()).getComponentTypeForRow(i));
                file_name = ((string)__worksheet.getValueAt(i, StateMod_Response_TableModel.COL_NAME)).Trim();
                if (file_name.Equals(__dataset_copy.BLANK_FILE_NAME, StringComparison.OrdinalIgnoreCase) && comp.hasData())
                {
                    if (comp.getComponentType() != StateMod_DataSet.COMP_NETWORK)
                    {
                        warning += "\n" + comp.getComponentName() + " has data but no file name is specified.";
                        ++fatal_count;
                    }
                }
                // Check for duplicate file names.  In particular with the new
                // response file format, there is no need for "dum" empty files.
                for (int j = 0; j < size; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    comp2      = __dataset_copy.getComponentForComponentType(((StateMod_Response_TableModel)__worksheet.getModel()).getComponentTypeForRow(j));
                    file_name2 = ((string)__worksheet.getValueAt(j, StateMod_Response_TableModel.COL_NAME)).Trim();
                    if (file_name2.Equals(file_name, StringComparison.OrdinalIgnoreCase) && !file_name2.Equals(__dataset_copy.BLANK_FILE_NAME, StringComparison.OrdinalIgnoreCase))
                    {
                        // Stream gage and stream estimate stations can be the same file name...
                        if (((comp.getComponentType() == StateMod_DataSet.COMP_STREAMGAGE_STATIONS) && (comp2.getComponentType() == StateMod_DataSet.COMP_STREAMESTIMATE_STATIONS)) || ((comp.getComponentType() == StateMod_DataSet.COMP_STREAMESTIMATE_STATIONS) && (comp2.getComponentType() == StateMod_DataSet.COMP_STREAMGAGE_STATIONS)))
                        {
                            // TODO SAM 2006-03-04 Need to finalize how the gage and estimate files are handled.
                            //&&
                            //!__dataset_copy.isFreeFormat() ) {
                            // No need for a warning because the single file is split internally when read...
                        }
                        else
                        {
                            warning += "\n" + comp.getComponentName() +
                                       " file name (" + file_name + ") is the same as another component.";
                            ++fatal_count;
                        }
                        // No need to look at more files...
                        break;
                    }
                }
                // Compare against the original copy...
                // Warn that time series file names cannot be changed from the
                // original because time series were not read in...
                comp2      = __dataset.getComponentForComponentType(comp.getComponentType());
                file_name2 = comp2.getDataFileName();
                if (!file_name.Equals(file_name2) && !__dataset.areTSRead() && __dataset.isDynamicTSComponent(comp.getComponentType()))
                {
                    warning += "\n" + comp.getComponentName() +
                               " time series were not read in - cannot change file name.";
                    ++fatal_count;
                }
            }

            if (warning.Length > 0)
            {
                warning = "\nResponse file:  " + warning + "\nCorrect or Cancel.";
                Message.printWarning(1, routine, warning, this);
                if (fatal_count > 0)
                {
                    // Fatal errors...
                    return(1);
                }
                else
                {
                    // Nonfatal errors...
                    return(-1);
                }
            }
            else
            {
                // No errors...
                return(0);
            }
        }