Class ResourceTree

All Implemented Interfaces:
Styleable, Event­Target, Skinnable

public class ResourceTree extends TreeView<Resource>
A view of data store resources organized in a tree. This view can be used for showing the content of one or many Data­Stores. A resource can be added by a call to add­Resource(Resource) or loaded from a file by load­Resource(Object).

Resource­Tree registers the necessarily handlers for making this view a target of "drag and drop" events. Users can drop files or URLs for opening data files.

Limitations

  • The root­Property should be considered read-only. For changing content, use the set­Resource(Resource) instead.
  • If the user selects "close" in the contextual menu, the resource is unconditionally closed (if it is an instance of Data­Store). There is not yet a mechanism for keeping it open if the resource is shared by another Resource­Tree instance.
Since:
1.1
"TODO:"
We should remove automatically the Data­Store instances that are closed externally.
  • Field Details

    • onResourceLoaded

      public final ObjectProperty<EventHandler<ResourceEvent>> onResourceLoaded
      Function to be called after a resource has been loaded from a file or URL. The default value is null.
      See Also:
    • onResourceClosed

      public final ObjectProperty<EventHandler<ResourceEvent>> onResourceClosed
      Function to be called after a resource has been closed and removed from this tree view. This event happens when the remove­And­Close(Resource) method has been invoked, which happens for example when the user selected the "close" item from the contextual menu. The default value is null.
      Since:
      1.2
      See Also:
    • windows

      protected final MapWindows windows
      The manager of windows where to show the resources, or null if none. If non-null, the contextual menu will contain a "Show in mosaic" item.
      Since:
      1.7
  • Constructor Details

    • ResourceTree

      public ResourceTree()
      Creates a new tree of resources with initially no resource to show. For showing a resource, invoke set­Resource(Resource), add­Resource(Resource) or load­Resource(Object) after construction.
    • ResourceTree

      public ResourceTree(MapWindows windows)
      Creates a new tree of resources which can show the resources using the given manager of windows. If windows is non-null, the contextual menu will contain a "Show in mosaic" menu item.
      Parameters:
      windows - manager of windows for map canvases, or null if none.
      Since:
      1.7
  • Method Details

    • getResource

      public Resource getResource()
      Returns the root data store Resource of this tree. The returned value depends on how the resource was set:
      Returns:
      root Resource, or null if none.
    • setResource

      public void setResource(Resource resource)
      Sets the root data store Resource of this tree. The root resource is typically, but not necessarily, a Data­Store instance. If another root resource existed before this method call, it is discarded without being closed. Closing the previous resource is caller's responsibility.

      Modified tree view properties

      This method updates the root and show­Root properties of Tree­View in an implementation-dependent way.
      Parameters:
      resource - the root resource to show, or null if none.
      See Also:
    • addResource

      public boolean addResource(Resource resource)
      Adds a resource in this tree below previously added resources. This method does nothing if the given resource is already present in this tree.

      Modified tree view properties

      This method updates the root and show­Root properties of Tree­View in an implementation-dependent way.
      Parameters:
      resource - the root resource to add, or null if none.
      Returns:
      true if the given resource has been added, or false if it was already presents or if the given resource is null.
      See Also:
    • loadResource

      public void loadResource(Object source)
      Loads in a background thread the resources from the given source, then adds the resource to this tree. If the resource has already been loaded, then this method will use the existing instance instead of loading the data again.

      Notifications

      If on­Resource­Loaded has a non-null value, the Event­Handler will be notified in JavaFX thread after the background thread finished to open the resource. If an exception occurs while opening the resource, then Event­Handler is not notified and the error is reported in a dialog box instead.
      Parameters:
      source - the source of the resource to load. This is usually a File or Path.
      See Also:
    • removeAndClose

      public void removeAndClose(Resource resource)
      Removes the given resource from this tree and closes the resource if it is a Data­Store instance. It is caller's responsibility to ensure that the given resource is not used anymore.

      Only the "root" resources (such as the resources given to set­Resource(Resource) or add­Resource(Resource) methods) can be removed. Children of Aggregate resource are not scanned. If the given resource cannot be removed, then this method does nothing.

      Notifications

      If on­Resource­Closed has a non-null value, the Event­Handler will be notified. The notification may happen in same time that the resource is closing in a background thread. If an exception occurs while closing the resource, the error is reported in a dialog box.
      Parameters:
      resource - the resource to remove. Null values are ignored.
      See Also: