Class DataTree


public class DataTree extends DataSourceHolder
This class provides a JTree interface for a set of DataChoice-s and DataSource-s. It is used two ways:
  • To show the data choices in the DataSelector
  • To show all of the data sources and data choices when the user is selecting operands for formulas or when they are adding or changing the data choices in a display control
Version:
$Revision: 1.50 $Date: 2007/08/21 12:15:45 $
Author:
IDV development team
  • Constructor Details

    • DataTree

      public DataTree(IntegratedDataViewer idv, boolean showDataSourceNode, boolean treatFormulaDataSourceSpecial)
      Create a DataTree with the given idv reference.
      Parameters:
      idv - The idv
      showDataSourceNode - Should this DataTree display the DataSource-s in the tree
      treatFormulaDataSourceSpecial - If true we put the Formula data source (which represents the end-user formulas) at the top.
    • DataTree

      public DataTree(IntegratedDataViewer idv, DataSource formulaDataSource)
      Create a DataTree with the given idv reference and formula data source.
      Parameters:
      idv - The IDV
      formulaDataSource - The formula data source that holds the end-user formulas
    • DataTree

      public DataTree(IntegratedDataViewer idv, DataSource formulaDataSource, Dimension defaultSize)
      Create a DataTree with the given idv reference, formula data source and window size.
      Parameters:
      idv - The IDV
      formulaDataSource - The formula data source that holds the
      defaultSize - Default size of the window (if non-null)
    • DataTree

      public DataTree(IntegratedDataViewer idv, List sources, List categories)
      Create a DataTree with the given idv reference, list of DataSource-s and (potentially null) list of DataCategory-s If the categories list is non-null then this DataTree will only show data choices that are applicable to the categories.
      Parameters:
      idv - The IDV
      sources - List of data sources
      categories - List of data categories
    • DataTree

      public DataTree(IntegratedDataViewer idv, List sources, List categories, Dimension defaultSize)
      Create a DataTree with the given idv reference, list of DataSource-s, (potentially null) list of DataCategory-s and default window size. If the categories list is non-null then this DataTree will only show data choices that are applicable to the categories.
      Parameters:
      idv - The IDV
      sources - List of data sources
      categories - List of data categories
      defaultSize - Windwo size (if non-null)
    • DataTree

      public DataTree(IntegratedDataViewer idv, List sources, List categories, String initialSelectedFieldName, Dimension defaultSize)
      Create a DataTree with the given idv reference, list of DataSource-s, (potentially null) list of DataCategory-s and default window size. If the categories list is non-null then this DataTree will only show data choices that are applicable to the categories.
      Parameters:
      idv - The IDV
      sources - List of data sources
      categories - List of data categories
      initialSelectedFieldName - The name of the data choice we should select
      defaultSize - Window size (if non-null)
  • Method Details

    • sort

      public void sort()
      Turn on sorting
    • getName

      protected String getName()
      Overwrite the base class getName method.
      Overrides:
      getName in class DataSourceHolder
      Returns:
      The name of this class to be used in the gui
    • setDataSource

      public void setDataSource(DataSource dataSource)
      This does a removeAllDataSource/addDataSource resulting in a datatree that holds just the given datasource
      Parameters:
      dataSource - The data source to use
    • getContents

      public JComponent getContents()
      Get the main GUI contents
      Specified by:
      getContents in class DataSourceHolder
      Returns:
      The GUI
    • getTree

      public JTree getTree()
      Get the JTree we use
      Returns:
      The JTree
    • addAsAlias

      public void addAsAlias(Object[] pair)
      The pair contains a dataalias and a alias name Call AliasEditor.addAsAlias
      Parameters:
      pair - Holds a DataAlias and a alias name
    • clearSearchState

      public void clearSearchState()
      CLear the search state
    • doSearch

      public boolean doSearch(String searchString, JComponent near)
      Search the tree
      Parameters:
      searchString - search for
      near - component to show dialog near
      Returns:
      Success
    • selectChoices

      public void selectChoices(List choices)
      Have the JTree select the paths that lead to the DataChoice-s in the given list.
      Parameters:
      choices - List of data choices
    • selectChoices

      public void selectChoices(List choices, boolean shouldSet)
      Have the JTree select the paths that lead to the DataChoice-s in the given list.
      Parameters:
      choices - List of data choices
      shouldSet - Should we set the selection or add to the selection
    • setMultipleSelect

      public void setMultipleSelect(boolean v)
      Set the selection mode of the JTree
      Parameters:
      v - JTree is multiple or single select
    • getScroller

      public JScrollPane getScroller()
      Create (if needed) and return the JScrollPane around the JTree
      Returns:
      The tree scroller
    • addDisplayControl

      public void addDisplayControl(DisplayControl control, DataChoice choice)
      We have this here so we can display the DisplayControl-s in the DataTree. We display them under the tree node that represents the given DataChoice
      Overrides:
      addDisplayControl in class DataSourceHolder
      Parameters:
      control - The display control to represent
      choice - The data choice to show the display control under
    • removeDisplayControl

      public void removeDisplayControl(DisplayControl control)
      Remove the tree node that represents the given display control
      Overrides:
      removeDisplayControl in class DataSourceHolder
      Parameters:
      control - The control to remove from the tree
    • isValidData

      public boolean isValidData(Object data)
      Is the given object (either a data source or a data choice) represented in the JTree
      Parameters:
      data - The object to look for a tree node for
      Returns:
      Is object represented in tree
    • getTreeNode

      public DataTreeNode getTreeNode(Object data)
      Return the tree node that represents the given data object (e.g., data source, data choice)
      Parameters:
      data - The object to look for a tree node
      Returns:
      The tree node that represents the given object
    • createTreeNode

      public DataTreeNode createTreeNode(String label, Object data)
      Create a DataTreeNode with the given label that holds the given data object
      Parameters:
      label - The label
      data - The data
      Returns:
      The new DataTreeNode
    • createTreeNode

      public DataTreeNode createTreeNode(DataTreeNode parent, String label, Object data)
      Create a DataTreeNode with the given label that holds the given data object. Add it as a child if the given parent node.
      Parameters:
      parent - The parent node
      label - The label
      data - The data
      Returns:
      The new DataTreeNode
    • removeTreeNode

      public void removeTreeNode(DataTreeNode node)
      Remove the given DataTreeNode from the tree. Remove it from the dataToNode mapping. Jump through some hoops to fire the tree structure changed event and maintain the current expanded tree paths.
      Parameters:
      node - The node to remove
    • removeObject

      public void removeObject(Object dataObject)
      Find the DataTree node that represents the given data object and remove it from the tree
      Parameters:
      dataObject - The object whose tree node is to be removed
    • getPath

      public TreePath getPath(DefaultMutableTreeNode treeNode)
      Get the TreePath to the given treeNode
      Parameters:
      treeNode - The node to find the path to
      Returns:
      The path
    • getExpandedPaths

      public Hashtable getExpandedPaths()
      Get all expanded tree paths
      Returns:
      All expanded paths
    • dispose

      public void dispose()
      Remove all references to anything we may have. We do this because (stupid) Swing seems to keep around lots of different references to thei component and/or it's frame. So when we do a window.dispose () this DataTree does not get gc'ed.
      Overrides:
      dispose in class DataSourceHolder
    • removeAllDataSources

      public void removeAllDataSources()
      Remove all data sources from this tree
      Overrides:
      removeAllDataSources in class DataSourceHolder
    • removeDataSource

      public void removeDataSource(DataSource dataSource)
      Remove the specified data source only if it is not the formulaDataSource.
      Overrides:
      removeDataSource in class DataSourceHolder
      Parameters:
      dataSource - The data source to remove
    • removeDataSourceInner

      protected boolean removeDataSourceInner(DataSource dataSource)
      Remove the specified data source only if it is not the formulaDataSource.
      Overrides:
      removeDataSourceInner in class DataSourceHolder
      Parameters:
      dataSource - The data source to remove
      Returns:
      Was this removal successful
    • dataSourceChanged

      public void dataSourceChanged(DataSource source)
      Something changed about the given data source. Simply re-add it.
      Overrides:
      dataSourceChanged in class DataSourceHolder
      Parameters:
      source - The data source that changed.
    • addDataSource

      public void addDataSource(DataSource dataSource)
      Add the given DataSource and its DataChoice-s into the jtree.
      Overrides:
      addDataSource in class DataSourceHolder
      Parameters:
      dataSource - The data source to add
    • createSubtree

      protected void createSubtree(CompositeDataChoice choice, DataTreeNode treeNode)
      Recurse down the CompositeDataChoice hierarhcy of DataChoice-s, creating the JTree tree.
      Parameters:
      choice - The data choice to recurse down on
      treeNode - The tree node which represents the given composite data choice
    • openUp

      public void openUp()
      If the tree has a single path to a DataChoice then open up the tree to that data choice and select it.
    • getSelectedDataChoice

      public DataChoice getSelectedDataChoice()
      Find and return the first DataChoice that is selected.
      Returns:
      The first selected data choice
    • getSelectedDataChoice

      public DataChoice getSelectedDataChoice(ControlDescriptor descriptor)
      Find the first selected data choice that the given ControlDescriptor is applicable to.
      Parameters:
      descriptor - The descriptor to check for data choice applicability
      Returns:
      Selected DataChoice or null if none found
    • getSelectedDataChoicesRecursive

      public List<DataChoice> getSelectedDataChoicesRecursive()
      Get the list of selected data choices
      Returns:
      List of selected data choices
    • getSelectedDataChoices

      public List<DataChoice> getSelectedDataChoices()
      Get the list of selected data choices
      Returns:
      List of selected data choices
    • getObjectAt

      public Object getObjectAt(int x, int y)
      Find the data object that is contained by the tree node nearest to the given x/y position.
      Parameters:
      x - x position
      y - y position
      Returns:
      Nearest data object