Example #1
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);
            }
        }