/// <summary> /// Creates a list of objects suitable for use in the worksheet from the data /// read from a delta plot file. </summary> /// <param name="fileData"> the fileData to process. </param> /// <returns> a list of objects suitable for use within a form. </returns> public virtual IList <StateMod_GraphNode> formLoadData(IList <StateMod_GraphNode> fileData) { int rows = fileData.Count; if (rows == 0) { return(new List <StateMod_GraphNode>()); } // gnf will be a node used to read data FROM the _F_ile nodes StateMod_GraphNode gnf = fileData[0]; string pfile = ""; string ptype = ""; string pyear = ""; string file = null; string type = null; string dtype = null; string year = null; // gnw will be a node used for creating the _W_orksheet nodes StateMod_GraphNode gnw = null; IList <StateMod_GraphNode> v = new List <StateMod_GraphNode>(); int ids = 0; for (int i = 0; i < rows; i++) { gnf = fileData[i]; ids = gnf.getIDVectorSize(); file = gnf.getFileName().Trim(); type = gnf.getType().Trim(); dtype = gnf.getDtype().Trim(); year = gnf.getYrAve().Trim(); for (int j = 0; j < ids; j++) { if (j == 0) { gnw = new StateMod_GraphNode(); if (!file.Equals(pfile)) { gnw.setFileName(file); } else { gnw.setFileName(""); } if (!type.Equals(ptype)) { gnw.setType(type); } else { gnw.setType(""); } if (!dtype.Equals(dtype)) { gnw.setDtype(dtype); } else { gnw.setDtype(""); } if (!year.Equals(pyear)) { gnw.setYrAve(year); } else { gnw.setYrAve(""); } gnw.setID(gnf.getID(0).Trim()); } else { gnw.setFileName(""); gnw.setType(""); gnw.setDtype(""); gnw.setYrAve(""); gnw.setID(gnf.getID(j).Trim()); } gnw.setSwitch(gnf.getSwitch()); v.Add(gnw); } pfile = file; ptype = type; pyear = year; } return(v); }
/// <summary> /// Saves form data to the data set. </summary> /// <param name="worksheetData"> the data in the worksheet to save. </param> /// <returns> a list of data objects created from the data in the worksheet. </returns> public virtual IList <StateMod_GraphNode> formSaveData(IList <StateMod_GraphNode> worksheetData) { int rows = worksheetData.Count; if (rows == 0) { return(new List <StateMod_GraphNode>()); } // gnw will be a node used to read data FROM the _W_orksheet nodes StateMod_GraphNode gnw = worksheetData[0]; string pfile = gnw.getFileName().Trim(); string ptype = gnw.getType().Trim(); string pdtype = gnw.getDtype().Trim(); string pyear = gnw.getYrAve().Trim(); string pid = gnw.getID().Trim(); string file = null; string type = null; string dtype = null; string year = null; string id = null; // gno will be a node used for creating the _O_utput nodes StateMod_GraphNode gno = new StateMod_GraphNode(); gno.setFileName(pfile); gno.setType(ptype); gno.setDtype(pdtype); gno.setYrAve(pyear); int paren = pid.IndexOf("(", StringComparison.Ordinal); if (paren > -1) { gno.addID(pid.Substring(0, paren).Trim()); } else { gno.addID(pid); } IList <StateMod_GraphNode> v = new List <StateMod_GraphNode>(); for (int i = 1; i < rows; i++) { gnw = worksheetData[i]; file = gnw.getFileName().Trim(); if (file.Equals("")) { file = pfile; } type = gnw.getType().Trim(); if (type.Equals("")) { type = ptype; } dtype = gnw.getDtype().Trim(); if (dtype.Equals("")) { dtype = pdtype; } year = gnw.getYrAve().Trim(); if (year.Equals("")) { year = pyear; } id = gnw.getID().Trim(); if (id.Equals("")) { id = pid; } if (file.Equals(pfile) && type.Equals(ptype) && dtype.Equals(pdtype) && year.Equals(pyear)) { // all the fields match, so this is a different ID // added to the Vector of IDs in the node's vector. paren = id.IndexOf("(", StringComparison.Ordinal); if (paren > -1) { gno.addID(id.Substring(0, paren).Trim()); } else { gno.addID(id); } } else { // otherwise, values other than just the ID are // different, so a new node needs created v.Add(gno); gno = new StateMod_GraphNode(); gno.setFileName(file); gno.setType(type); gno.setDtype(dtype); gno.setYrAve(year); paren = id.IndexOf("(", StringComparison.Ordinal); if (paren > -1) { gno.addID(id.Substring(0, paren).Trim()); } else { gno.addID(id); } } pfile = file; ptype = type; pdtype = dtype; pyear = year; pid = id; } v.Add(gno); return(v); }
/// <summary> /// Inserts the specified value into the table at the given position. </summary> /// <param name="value"> the object to store in the table cell. </param> /// <param name="row"> the row of the cell in which to place the object. </param> /// <param name="col"> the column of the cell in which to place the object. </param> public virtual void setValueAt(object value, int row, int col) { if (_sortOrder != null) { row = _sortOrder[row]; } if (row >= _data.size()) { // this is probably happening as a result of an edit that did not end in time. } StateMod_GraphNode gn = (StateMod_GraphNode)_data.get(row); //Message.printStatus(1, "", "Set value at: " + row + ", " + col + " '" + value + "'"); switch (col) { case COL_FILE: string filename = (string)value; string oldFilename = (string)(getValueAt(row, col)); if (filename.Equals(oldFilename)) { return; } if (filename.Equals(StateMod_RunSmDelta_JFrame.OPTION_BROWSE, StringComparison.OrdinalIgnoreCase)) { string newfile = browseForFile(); gn.setFileName(newfile); if (row == 0) { if (newfile.Trim().Equals("")) { setCellAttributes(row, col, true); } else { setCellAttributes(row, col, false); } } base.setValueAt(newfile, row, col); return; } else { gn.setFileName(filename); } if (row == 0) { if (filename.Trim().Equals("")) { setCellAttributes(row, col, true); } else { setCellAttributes(row, col, false); } } break; case COL_TYPE: string type = (string)value; string oldType = (string)(getValueAt(row, col)); if (type.Equals(oldType)) { return; } gn.setType(type); if (type.Equals("")) { if (row == 0) { setCellAttributes(row, col, true); emptyParmIDComboBoxes(0); } else { string aboveType = getNearestType(row); if (aboveType.Equals("")) { // error! emptyParmIDComboBoxes(row); } else { setParmIDComboBoxes(row, aboveType); } } } else { if (row == 0) { setCellAttributes(row, col, false); } string aboveType = getNearestType(row); if (!type.Equals(aboveType)) { setCellAttributes(row, COL_PARM, true); setParmIDComboBoxes(row, type); } else { setCellAttributes(row, COL_PARM, false); } } break; case COL_PARM: string dtype = ((string)value).Trim(); // FIXME SAM 2008-03-24 No need to do this with newer StateMod // since binary file uses underscores for data types. //dtype = dtype.replace(' ', '_'); string oldDtype = (string)(getValueAt(row, col)); if (dtype.Equals(oldDtype)) { return; } gn.setDtype(dtype); if (row == 0) { if (dtype.Trim().Equals("")) { setCellAttributes(row, col, true); } else { setCellAttributes(row, col, false); } } else if (!dtype.Trim().Equals("")) { setCellAttributes(row, col, false); } break; case COL_YEAR: string year = ((string)value).Trim(); string oldYear = (string)(getValueAt(row, col)); if (year.Equals(oldYear)) { return; } gn.setYrAve(year); if (row == 0) { if (year.Trim().Equals("")) { setCellAttributes(row, col, true); } else { setCellAttributes(row, col, false); } } break; case COL_ID: string id = (string)value; string oldID = (string)(getValueAt(row, col)); if (id.Equals(oldID)) { return; } /* * int index = id.indexOf("("); * if (index > -1) { * id = id.substring(0, index); * } * id = id.trim(); */ gn.setID(id); if (id.Trim().Equals("")) { setCellAttributes(row, col, true); } else { setCellAttributes(row, col, false); } break; } base.setValueAt(value, row, col); }