/// <summary> /// Constructor. This builds the model for displaying the given component data. </summary> /// <param name="dataset"> StateMod_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 StateMod_DataSetComponent_TableModel(StateMod_DataSet dataset, RTi.Util.IO.DataSetComponent comp) throws Exception public StateMod_DataSetComponent_TableModel(StateMod_DataSet dataset, DataSetComponent comp) { System.Collections.IList data = null; string routine = "StateMod_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 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. }