Coder Social home page Coder Social logo

Comments (2)

stuarta0 avatar stuarta0 commented on July 1, 2024

From written notes (2014):

To abstract the UI, we need to represent our own tree structure & have an adapter at the end which converts into the concrete UI implementation.

So we use the current query builder class. It gets us the data we want in a data table. We sort this data by each sort field in order. Then we group the data : first group followed by second group hierarchicaly below, followed by third etc. In the end we have a tree structure (either 1 deep i.e. a list, or N deep) that we give to the tree.

TreeControl will perform actions such as expand/collapse node and select node. Do we care? Maybe we only care about GetChildren(node). Back up, what about the whole "can I expand or not?" i.e. has children logic? OK so we have our base adapter<T> where T is the tree node type. We have our WinForms implementation which is adapter<TreeNode>. If we provide an Expand(T) we can do our query logic here as well as load in advance (and we can decide if we want to add children to detect load on demand or whether we've already supplied the data).

Let's think overall - we want to swap our UI implementation with a minimum of effort. Therefore we want to be determining our nodes hierarchy & then hand this off to a class to create the UI nodes - like how the PresetAdapter calls its abstract method to create its concrete PresetPart<T>. The difference here is that we need to know what nodes hierarchy to make & that requires querying the database. Since we abstract the database implementation this would probably fall to the inherited class to determine. But then we're miing concerns of getting data with displaying data...

How do we handle custom behaviours? e.g. if we wanted our implementation to handle determining whether a node has children when it hasn't been loaded yet? This kind of behaviour is not related to the UI, so is it the application that provides the implementation of this & couples it with the existing UI code? Yes. So if the concrete implementation of TreeNode creation inherits, then we need to supply this behaviour to the adapter, not inherit. So this is where the adapter needs to ask something for the nodes. We could supply a default implementation (or two) that does the "get node data up until next dynamic node" or the "get nodes & their immediate children so we know if we can expand" logic. So this probably means separating the whole node creation sub-tree logic into this class - which actually means the whole "group by" logic can be swapped out too.

1432072865600-612282390

The adapter will need to notify on nodes added/removed and also expanded/contracted so the UI can update accordingly. Also the UI TreeNodes need to be notified of changes somehow. Not just text but colours/styles or whatever the concrete node creation provides. This will allow us to update nodes (& their hierarchies) if live changes occur in our application. For example the state of an object changes to 'complete' from 'pending' & its colour changes from orange to green or it relocates the node to another subtree. If it relocates to another tree it implies the node provider will have knowledge of the existing tree structure implying that the relationship is actually from the provider to the adapter; i.e. the adapter fires an event to get nodes & the provider responds. Actually this is OK because the adapter will have events for expand/contract/add/delete s othe provider can respond to expand & calculate the child nodes to then add as necessary, then the flow would be:

  • UI node expanded (without expanding)
  • Adapter expanded
  • NodeProvider handles, add child nodes
  • Adapter nodes added
  • UI add nodes
  • UI actually expand node

from dbqf.

stuarta0 avatar stuarta0 commented on July 1, 2024

To save dumping my current brain, here's a similar thought process:
http://www.codeproject.com/Articles/26288/Simplifying-the-WPF-TreeView-by-Using-the-ViewMode

In a nutshell, provide a viewmodel/adapter Node object with all hierarchy bundled into it and mimic the object in the UI. This works in WPF as per the article above and would be possible to make it work (a little more manually as per previous comment) in WinForms. See 1b70963 for the basis of this behaviour.

from dbqf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.