/// <summary>
        /// Refresh a part of the JTree based on the component.  This method is only
        /// designed to work with the detailed display.  It is currently assumed that all
        /// components are represented in the tree, even if no data are listed below the group node. </summary>
        /// <param name="comp_type"> Component type being refreshed.  Use the component groups. </param>
        public virtual void refresh(int comp_type)
        {
            string routine = "StateMod_DataSet_JTree.refresh";

            if (!__display_data_objects)
            {
                return;
            }
            DataSetComponent comp = __dataset.getComponentForComponentType(comp_type);
            // Find the node...
            SimpleJTree_Node node = findNodeByName(comp.getComponentName());

            if (node == null)
            {
                return;
            }
            // Remove the sub-nodes...
            try
            {
                removeChildren(node);
            }
            catch (Exception)
            {
                Message.printWarning(2, routine, "Error removing old nodes - error should not occur.");
            }
            // Now redraw the data...
            setFastAdd(true);
            displayDataSetComponent(comp, node);
            setFastAdd(false);
        }
        /// <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.
        }
        /// <summary>
        /// Display all the information in the data set.  This can be called, for example,
        /// after a data set has been read.
        /// </summary>
        public virtual void displayDataSet()
        {
            string routine = "StateMod_DataSet_JTree.displayDataSet";

            System.Collections.IList v = __dataset.getComponentGroups();
            int size = 0;

            if (v != null)
            {
                size = v.Count;
            }
            SimpleJTree_Node node = null, node2 = null;
            DataSetComponent comp    = null;
            bool             hadData = false;
            bool             isGroup = false;
            int type;

            // Add each component group...
            setFastAdd(true);
            Icon folder_Icon = getClosedIcon();

            for (int i = 0; i < size; i++)
            {
                hadData = false;
                isGroup = false;
                comp    = (DataSetComponent)v[i];
                if ((comp == null) || !comp.isVisible())
                {
                    continue;
                }
                type = comp.getComponentType();
                if (type == StateMod_DataSet.COMP_GEOVIEW_GROUP)
                {
                    // Don't want to list the groups because there is no
                    // way to display edit (or they are displayed elsewhere)...
                    continue;
                }
                node = new SimpleJTree_Node(comp.getComponentName());
                node.setData(comp);

                if (comp.isGroup())
                {
                    isGroup = true;
                }

                // To force groups to be folders, even if no data underneath...
                node.setIcon(folder_Icon);
                try
                {
                    addNode(node);
                }
                catch (Exception e)
                {
                    Message.printWarning(2, routine, "Error adding component group " + comp.getComponentName());
                    Message.printWarning(2, routine, e);
                    continue;
                }
                if (__display_data_objects)
                {
                    // Display the primary object in each group
                    hadData = displayDataSetComponent(comp, node);
                }
                else
                {
                    // Add the components in the group...
                    System.Collections.IList v2 = (System.Collections.IList)comp.getData();
                    int size2 = 0;
                    if (v2 != null)
                    {
                        size2 = v2.Count;
                    }
                    for (int j = 0; j < size2; j++)
                    {
                        comp = (DataSetComponent)v2[j];
                        if ((comp == null) || !comp.isVisible())
                        {
                            continue;
                        }
                        node2 = new SimpleJTree_Node(comp.getComponentName());
                        node2.setData(comp);
                        try
                        {
                            addNode(node2, node);
                        }
                        catch (Exception e)
                        {
                            Message.printWarning(2, routine, "Error adding component " + comp.getComponentName());
                            Message.printWarning(2, routine, e);
                            continue;
                        }
                    }
                    if (size2 > 0)
                    {
                        hadData = true;
                    }
                }
                if (isGroup && !hadData)
                {
                    node.setIcon(__folderIcon);
                }
            }
            setFastAdd(false);
        }
        /// <summary>
        /// Constructor.  This builds the model for displaying the given component data. </summary>
        /// <param name="dataset"> StateCU_DataSet that is being displayed.  If not a group
        /// component, the group component will be determined. </param>
        /// <param name="comp"> the DataSetComponent to be displayed. </param>
        /// <exception cref="Exception"> an invalid component is passed in. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public StateCU_DataSetComponent_TableModel(StateCU_DataSet dataset, RTi.Util.IO.DataSetComponent comp) throws Exception
        public StateCU_DataSetComponent_TableModel(StateCU_DataSet dataset, DataSetComponent comp)
        {
            System.Collections.IList data = null;
            string routine = "StateCU_DataSetComponent_TableModel";

            // Make sure that the list is for a group component...
            if ((comp != null) && !comp.isGroup())
            {
                __component_group = comp.getParentComponent();
                Message.printStatus(1, routine, "Component is not a group.  Parent is:  " + __component_group);
            }
            else
            {
                __component_group = comp;
            }
            if (__component_group == null)
            {
                _rows = 0;
                _data = null;
                return;
            }
            // Figure out the data component that is actually used to get the list
            // of data objects.  For example, if working on climate stations, there
            // is no list with the group so we need to use the climate stations component list...
            int comptype = dataset.lookupPrimaryComponentTypeForComponentGroup(__component_group.getComponentType());

            if (comptype >= 0)
            {
                __component = dataset.getComponentForComponentType(comptype);
            }
            else
            {
                comp = null;
                Message.printWarning(2, routine, "Unable to find primary component for group:  " + __component_group.getComponentName());
            }
            if (__component == null)
            {
                _rows = 0;
            }
            else
            {
                data = ((System.Collections.IList)__component.getData());
                if (data == null)
                {
                    _rows = 0;
                }
                else
                {
                    _rows = data.Count;
                }
            }
            _data = data;
        }
        /// <summary>
        /// Display all the information in the data set.  This can be called, for example,
        /// after a data set has been read.
        /// </summary>
        public virtual void displayDataSet()
        {
            string routine = "StateCU_DataSet_JTree.displayDataSet";

            System.Collections.IList v = __dataset.getComponentGroups();
            int size = 0;

            if (v != null)
            {
                size = v.Count;
            }
            SimpleJTree_Node node = null, node2 = null;
            DataSetComponent comp    = null;
            string           name    = "";
            bool             isGroup = false;
            bool             hasData = false;
            int type;

            // Add each component group...
            setFastAdd(true);
            for (int i = 0; i < size; i++)
            {
                isGroup = false;
                hasData = false;
                comp    = (DataSetComponent)v[i];
                if ((comp == null) || !comp.isVisible())
                {
                    continue;
                }

                if (comp.isGroup())
                {
                    isGroup = true;
                }

                type = comp.getComponentType();
                // Show the control data at the high level.
                if (type == StateCU_DataSet.COMP_GIS_GROUP)
                {
                    // Don't want to list the GIS data...
                    continue;
                }
                if ((type == StateCU_DataSet.COMP_GIS_GROUP) && __display_data_objects)
                {
                    // Currently don't want to list GIS data in
                    // results...
                    continue;
                }
                node = new SimpleJTree_Node(comp.getComponentName());
                node.setData(comp);
                try
                {
                    addNode(node);
                }
                catch (Exception e)
                {
                    Message.printWarning(2, routine, "Error adding component group " + comp.getComponentName());
                    Message.printWarning(2, routine, e);
                    continue;
                }
                if (__display_data_objects)
                {
                    // Display the primary object in each group
                    int primary_type = __dataset.lookupPrimaryComponentTypeForComponentGroup(comp.getComponentType());
                    if (primary_type >= 0)
                    {
                        comp = __dataset.getComponentForComponentType(primary_type);
                    }
                    if ((comp == null) || !comp.isVisible())
                    {
                        continue;
                    }
                    object data_Object = comp.getData();
                    if (data_Object == null)
                    {
                        continue;
                    }
                    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());
                    }
                    StateCU_Data  cudata;
                    StateMod_Data smdata;
                    int           dsize = 0;
                    if (data != null)
                    {
                        dsize = data.Count;
                    }
                    for (int idata = 0; idata < dsize; idata++)
                    {
                        if (comp.getComponentType() == StateCU_DataSet.COMP_DELAY_TABLES_MONTHLY)
                        {
                            // StateMod data object so have to
                            // handle separately because StateCU
                            // uses the StateMod group...
                            smdata = (StateMod_Data)data[idata];
                            name   = smdata.getName();
                            node2  = new SimpleJTree_Node(name);
                            node2.setData(smdata);
                        }
                        else
                        {                 // StateCU data object...
                            cudata = (StateCU_Data)data[idata];
                            name   = cudata.getName();
                            node2  = new SimpleJTree_Node(name);
                            node2.setData(cudata);
                        }
                        try
                        {
                            addNode(node2, node);
                        }
                        catch (Exception e)
                        {
                            Message.printWarning(2, routine, "Error adding data " + name);
                            Message.printWarning(2, routine, e);
                            continue;
                        }
                    }
                    if (dsize > 0)
                    {
                        hasData = true;
                    }
                    // Collapse the node because the lists are
                    // usually pretty long...
                    try
                    {
                        collapseNode(node);
                    }
                    catch (Exception)
                    {
                        // Ignore.
                    }
                }
                else
                {         // Add the components in the group...
                    Message.printStatus(1, "", "Not displaying data objects");
                    System.Collections.IList v2 = (System.Collections.IList)comp.getData();
                    int size2 = 0;
                    if (v2 != null)
                    {
                        size2 = v2.Count;
                    }
                    Message.printStatus(1, "", "group has " + size2 + " subcomponents");
                    for (int j = 0; j < size2; j++)
                    {
                        comp = (DataSetComponent)v2[j];
                        if (!comp.isVisible())
                        {
                            continue;
                        }
                        node2 = new SimpleJTree_Node(comp.getComponentName());
                        node2.setData(comp);
                        try
                        {
                            addNode(node2, node);
                        }
                        catch (Exception e)
                        {
                            Message.printWarning(2, routine, "Error adding component " + comp.getComponentName());
                            Message.printWarning(2, routine, e);
                            continue;
                        }
                    }
                    if (size2 > 0)
                    {
                        hasData = true;
                    }
                }

                if (isGroup && !hasData)
                {
                    node.setIcon(__folderIcon);
                }
            }
            setFastAdd(false);
        }
Esempio n. 6
0
        /// <summary>
        /// Save the data. </summary>
        /// <returns> true if the save was successful, false if not. </returns>
        private bool saveData()
        {
            string routine = "StateMod_Save_JDialog.saveData";

            if (checkInput() == 1)
            {
                return(false);
            }

            // Else save the data...

            int[]            selectedRows = __worksheet.getSelectedRows();
            int              comp_type;
            DataSetComponent comp         = null;
            int              error_count  = 0;    // Counter for save errors.
            string           newFilename0 = null; // Used within path
            string           newFilename  = null;
            string           oldFilename  = null;
            IList <string>   comments     = new List <string>();

            // TODO - add a checkbox to the display.
            //if ( __add_revision_comments_JCheckBox.isSelected() ) {
            comments.Add("Modification to data made interactively by user with " + IOUtil.getProgramName() + " " + IOUtil.getProgramVersion());
            if (__updateCheckbox.isSelected())
            {
                comments.Add("Updated by StateModGUI");
            }
            //}
            for (int i = 0; i < selectedRows.Length; i++)
            {
                try
                {
                    comp_type = __tableModel.getRowComponentNum(i);

                    comp         = (DataSetComponent)__dataset.getComponentForComponentType(comp_type);
                    newFilename0 = comp.getDataFileName();
                    newFilename  = __dataset.getDataFilePathAbsolute(comp);

                    if (__updateCheckbox.isSelected())
                    {
                        oldFilename = newFilename;
                    }
                    else
                    {
                        oldFilename = null;
                    }

                    if (comp_type == StateMod_DataSet.COMP_RESPONSE)
                    {
                        // TODO - need to track the original file name...
                        StateMod_DataSet.writeStateModFile(__dataset, oldFilename, newFilename, comments);
                        // Mark the component clean...
                        comp.setDirty(false);
                    }
                    else if (newFilename0.Length == 0)
                    {
                        // SAM 2006-03-04...
                        // Just set to not dirty.  If someone sets a filename to blank and actually makes
                        // changes, they don't know what they are doing.
                        comp.setDirty(false);
                    }
                    else if (newFilename0.Length > 0)
                    {
                        try
                        {
                            saveComponent(comp, oldFilename, newFilename, comments);
                        }
                        catch (Exception e)
                        {
                            Message.printWarning(1, routine, "Error saving file \"" + newFilename + "\"");
                            Message.printWarning(2, routine, e);
                        }
                    }
                }
                catch (Exception e)
                {
                    Message.printWarning(1, routine, "Error saving " + comp.getComponentName() + " to \"" + newFilename + "\"");
                    Message.printWarning(2, routine, e);
                    ++error_count;
                }
            }

            if (error_count > 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 7
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);
            }
        }