/// <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> /// Clear all data from the tree. /// </summary> public virtual void clear() { string routine = "StateMod_DataSet_JTree.clear"; SimpleJTree_Node node = getRoot(); System.Collections.IList v = getChildrenList(node); int size = 0; if (v != null) { size = v.Count; } for (int i = 0; i < size; i++) { try { removeNode((SimpleJTree_Node)v[i], false); } catch (Exception e) { Message.printWarning(2, routine, "Cannot remove node " + node.ToString()); Message.printWarning(2, routine, e); } } }
/// <summary> /// Checks to see if the mouse event would trigger display of the popup menu. /// The popup menu does not display if it is null. </summary> /// <param name="e"> the MouseEvent that happened. </param> private void showPopupMenu(MouseEvent e) { string routine = "StateMod_DataSet_JTree.showPopupMenu"; if (!e.isPopupTrigger() || !__display_data_objects) { // Do not do anything... return; } TreePath path = getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } __popup_Node = (SimpleJTree_Node)path.getLastPathComponent(); // First remove the menu items that are currently in the menu... __popup_JPopupMenu.removeAll(); object data = null; // Data object associated with the node DataSetComponent comp2; // Used to check components in groups. // Now reset the popup menu based on the selected node... if (__display_data_objects) { // Get the data for the node. If the node is a data object, // the type can be checked to know what to display. // The tree is displaying data objects so the popup will show // specific JFrames for each data group. If the group folder // was selected, then display the JFrame showing the first item // selected. If a specific data item in the group was selected, // then show the specific data item. JMenuItem item; data = __popup_Node.getData(); if (data is DataSetComponent) { // Specific checks need to be done to identify the component group... DataSetComponent comp = (DataSetComponent)data; int comp_type = comp.getComponentType(); if (comp_type == StateMod_DataSet.COMP_CONTROL_GROUP) { // For now display the control file information only... comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_CONTROL); if (comp2.hasData()) { item = new SimpleJMenuItem("Control Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_STREAMGAGE_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_STREAMGAGE_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Stream Gage Station Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_DELAY_TABLE_MONTHLY_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Delay Table Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_DELAY_TABLE_DAILY_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DELAY_TABLES_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Delay Table Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_DIVERSION_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DIVERSION_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Diversion Properties", this); __popup_JPopupMenu.add(item); } } else if ((comp_type == StateMod_DataSet.COMP_PRECIPITATION_GROUP)) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_PRECIPITATION_TS_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Precipitation Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_EVAPORATION_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_EVAPORATION_TS_MONTHLY); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Evaporation Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_RESERVOIR_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_RESERVOIR_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Reservoir Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_INSTREAM_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_INSTREAM_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Instream Flow Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_WELL_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_WELL_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Well Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_PLAN_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_PLANS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Plan Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_STREAMESTIMATE_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_STREAMESTIMATE_STATIONS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Stream Estimate Station Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_RIVER_NETWORK_GROUP) { // Only add if data are available... comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_RIVER_NETWORK); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("River Network Properties", this); __popup_JPopupMenu.add(item); } } else if (comp_type == StateMod_DataSet.COMP_OPERATION_GROUP) { comp2 = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_OPERATION_RIGHTS); if ((comp2 != null) && comp2.hasData()) { item = new SimpleJMenuItem("Operation Rights Properties", this); __popup_JPopupMenu.add(item); } } } // The data are a specific data instance so display the // properties for the specific item if a primary data item. // Control... nothing for now. else if (data is StateMod_StreamGage) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_DelayTable) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_Diversion) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); __popup_JPopupMenu.add(new SimpleJMenuItem(__SUMMARIZE_HOW1 + "\"" + __popup_Node.getText() + "\"" + __SUMMARIZE_HOW2, this)); } else if (data is MonthTS) { // Precipitation or evaporation time series... __popup_JPopupMenu.add(new SimpleJMenuItem(__popup_Node.getText() + __PROPERTIES, this)); __popup_JPopupMenu.add(new SimpleJMenuItem(__SUMMARIZE_HOW1 + "\"" + __popup_Node.getText() + "\"" + __SUMMARIZE_HOW2, this)); } else if (data is StateMod_Reservoir) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_InstreamFlow) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_Well) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_Plan) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_StreamEstimate) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_OperationalRight) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_RiverNetworkNode) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } // Others (e.g., San Juan Sediment) supported later.... else { Message.printWarning(2, routine, "Node data is not recognized"); return; } } // Now display the popup so that the user can select the appropriate menu item... Point pt = JGUIUtil.computeOptimalPosition(e.getPoint(), e.getComponent(), __popup_JPopupMenu); __popup_JPopupMenu.show(e.getComponent(), pt.x, pt.y); }
/// <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> /// Checks to see if the mouse event would trigger display of the popup menu. /// The popup menu does not display if it is null. </summary> /// <param name="e"> the MouseEvent that happened. </param> private void showPopupMenu(MouseEvent e) { if (!e.isPopupTrigger() || !__display_data_objects) { // Do not do anything... return; } // Figure out which node is selected... TreePath path = getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } __popup_Node = (SimpleJTree_Node)path.getLastPathComponent(); // First remove the menu items that are currently in the menu... __popup_JPopupMenu.removeAll(); object data = null; // Data object associated with the node // Now reset the popup menu based on the selected node... if (__display_data_objects) { // Get the data for the node. If the node is a data object, // the type can be checked to know what to display. // The tree is displaying data objects so the popup will show // specific JFrames for each data group. If the group folder // was selected, then display the JFrame showing the first item // selected. If a specific data item in the group was selected, // then show the specific data item. JMenuItem item; data = __popup_Node.getData(); if (data is DataSetComponent) { // Specific checks need to be done to identify the // component... DataSetComponent comp = (DataSetComponent)data; int comp_type = comp.getComponentType(); if (comp_type == StateCU_DataSet.COMP_CLIMATE_STATIONS_GROUP) { item = new SimpleJMenuItem("Climate Stations Properties", "Climate Stations Properties", this); __popup_JPopupMenu.add(item); } else if (comp_type == StateCU_DataSet.COMP_CROP_CHARACTERISTICS_GROUP) { item = new SimpleJMenuItem("Crop Properties", "Crop Properties", this); __popup_JPopupMenu.add(item); } else if (comp_type == StateCU_DataSet.COMP_DELAY_TABLES_GROUP) { item = new SimpleJMenuItem("Delay Tables Properties", "Delay Tables Properties", this); __popup_JPopupMenu.add(item); } else if (comp_type == StateCU_DataSet.COMP_CU_LOCATIONS_GROUP) { item = new SimpleJMenuItem("CU Locations Properties", "CU Locations Properties", this); __popup_JPopupMenu.add(item); } } // Check specific instances of the primary data object... else if (data is StateCU_ClimateStation) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateCU_CropCharacteristics) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateMod_DelayTable) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else if (data is StateCU_Location) { item = new SimpleJMenuItem(__popup_Node.getText() + " Properties", __popup_Node.getText() + " Properties", this); __popup_JPopupMenu.add(item); } else { return; } } // Now display the popup so that the user can select the appropriate // menu item... __popup_JPopupMenu.show(e.getComponent(), e.getX(), e.getY()); }
/// <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); }