简体   繁体   English

数据模型与BeanNode表示对象的双向同步

[英]Two-way syncing of data model with BeanNode presentation objects

I am interested in porting an app to the netbeans platform, but I am having difficulty understanding how to keep the connection between Nodes and the objects that they wrap up to date. 我有兴趣将应用程序移植到netbeans平台,但是我很难理解如何保持Nodes和它们包装的对象之间的联系。

A main component of the existing app is a data model that is a hierarchical group of pojo/javabean objects. 现有应用程序的主要组件是一个数据模型,该数据模型是pojo / javabean对象的分层组。 Some of the objects are containers used for grouping, and others are leaf node types. 一些对象是用于分组的容器,而另一些是叶节点类型。 The model would typically have several hundred objects, with the deepest nesting being about 5 - 6 objects deep. 该模型通常会包含数百个对象,最深的嵌套约为5-6个对象。

I understand how to take my data model and instantiate a tree of BeanNode objects: create ChildFactory classes that will walk through the data model and create a comparable tree of BeanNodes. 我了解如何获取数据模型并实例化BeanNode对象树:创建将遍历数据模型并创建可比较的BeanNode树的ChildFactory类。 So far so good. 到现在为止还挺好。 Once I have the Node structure then I can add an explorer to visualize the data, and then add actions to modify the Nodes (Add/Delete/Move). 一旦有了Node结构,就可以添加一个资源管理器以可视化数据,然后添加操作以修改Node(添加/删除/移动)。

Changes to the Nodes have to propagate back to the data model. 对节点的更改必须传播回数据模型。 The model can also be changed by events within the app that are not related to the netbeans platform, and these changes have to be propagated to the Node hierarchy. 还可以通过应用程序中与netbeans平台无关的事件来更改模型,并且必须将这些更改传播到Node层次结构。

Is there a standard idiom or Netbean features that can be used to manage the synchronization between a tree of Nodes and the data model? 是否存在可用于管理节点树和数据模型之间的同步的标准惯用法或Netbean功能?

Here are my thoughts so far: To keep the Nodes up to date with the data model I will have to let the Nodes listen to changes on the data model, and the data model will fire change events. 到目前为止,我的想法是:为了使节点与数据模型保持最新,我将不得不让节点侦听数据模型上的更改,然后数据模型将触发更改事件。 Each Node object will listen for changes to the bean that is is wrapping, and react accordingly. 每个Node对象将侦听对正在包装的Bean的更改,并做出相应的反应。

To have the data model keep up with changes to the Node presentation I can call methods on the data model during the actionPerformed methods that implement the Add/Delete/Move/etc actions. 为了使数据模型跟上对Node表示的更改,我可以在actionPerformed方法期间调用数据模型上的方法,这些方法实现Add / Delete / Move / etc操作。

How do I prevent echoing, where the change notifications keep bouncing back and forth between the two data structures? 我如何防止回显,而更改通知在两个数据结构之间不断来回反弹?

Netbeans seems to be all about conventions on how to put the app together. Netbeans似乎都是关于如何将应用程序组合在一起的约定。 Is there a convention for this data modeling problem? 是否有关于此数据建模问题的约定?

"Changes to the Nodes have to propagate back to the data model. The model can also be changed by events within the app that are not related to the netbeans platform, and these changes have to be propagated to the Node hierarchy." “对节点的更改必须传播回数据模型。还可以通过应用程序中与netbeans平台无关的事件来更改模型,并且这些更改必须传播到节点层次结构。”

For the changes propagate back to your data model you just pass the data model to the node when creating it, and make all the changes to this same instance. 为了使更改传播回您的数据模型,您只需在创建数据模型时将其传递给节点,然后对同一实例进行所有更改。

Changes made directly to the data model that need to be propagated to the note will require that you recreate the nodes passing the ChildrenFactory with your list of elements or that you work with a LookupListener. 直接对需要传播到注释的数据模型所做的更改将要求您重新创建通过带有元素列表的ChildrenFactory的节点,或者使用LookupListener。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM