Ignore:
Timestamp:
07/08/13 23:04:56 (11 years ago)
Author:
psniegowski
Message:

HIGHLIGHTS:

CHANGELOG:
Get data also on tree expansion.

Use nice framstick icon for empty nodes.

Update panel after reload if it is current.

Add shallow reload procedure.

Cut Gui prefix from several tree classes.

Bring back counter of GuiTreeNode?.

Use IdentityHashMap? were it is more appriopriate.

Remove TreeListener?.

Do not use TreeListener? in GUI.

Minor change.

Done migration to GuiTreeModel?.

BrowserTest? in that version always crashes frams.linux.

Move rendering implementation into GuiAbstractNode?.

Use hand-crafted list in GuiTreeNode?.

Generally, it would be a great place for WeakIdentityHashMap?
(but there is none in Java Collection Framework).

Remove superfluous logging.

Fix bug in GuiTreeNode?.

Use IdentityHashMap? instead of HashMap?.

Improve structure update.

Filter out invalid uids in UniqueListAccess?.

Improve TreeCellRenderer?.

Add filtering in TrackConsole?.

Improve TreeModel?.

More changes.

More improvements.

More changes.

Remove TreeNode?.

Support MetaNode? in the GuiTreeModel?.

Implement more in GuiTreeModel?.

Add CompositeParam? interface to FramsClass? and AccessInterface?.

Allow access by number to UniqueList?.

Add UidComparator?.

Use TreeMap? as a default accessee in unique list.

It keeps order of keys.

Introduce classes to use with new TreeModel?.

Another step.

Migrate from TreeNode? to Node in many places.

Remove some uses of TreeNode? as DefaultMutableTreeNode?.

Remove Path from TreeNode? interface.

Remove Path from TreeNode?.

Add Path recration from node feature.

Reworking TreeCellRenderer?.

Minor change of TreeOperations? interface.

Remove last methods from TreeNode?.

Another minor step.

Do not store reference to TreeAtFrame? in TreeNode?.

Add proxy exceptionHandler to StatusBar?.

Move panels management to TreeAtFrame?.

Store localChanges in the NodeAtFrame?.

More cleanup.

Move name computing to TreeCellRenderer?.

Move tooltip and icon computations to TreeCellRenderer?.

More dispatches removed.

Remove most dispatching from TreeNode?.

TreeNode? does not actually redispatch tasks.

Make Tree embedded in Browser use SwingDispatcher?.

Make lazy binding of Tree with Dispatcher.

Minor changes.

Organizational change in AbstractTree?.

Make AbstractTree? compose from Thread instead of inherit from it.

Make SwingDispatcher? and AtOnceDispatcher? Joinable compatible.

Add ListPanelProvider?.

Improve Controls readonly and enabled handling.

Properly pass ExceptionHandlers? in more places.

Make Tree.get accept ValueParam?.

  • This is to allow access number of list elements.

Remove not needed get redirection in ClientAtServer?.

Rename tryResolve to tryGet.

Unify tryResolveAndGet into tryResolve.

Remove resolveTop from Tree interface.

Make Tree.get accept Future<Path>.

Use get to implement resolveTop also in ObjectTree?.

Unify resolveTop and get in RemoteTree?.

Another minor step.

More minor changes in tree operations.

Minor organizational changes.

In RemoteTree? first fetch info for root.

Reworking resolving.

Minor changes.

Make ListAccess? return proxy iterators (instead of creating temporary collection).

Let AccessInterface? return Iterable<Param>.

Improve resolving.

More improvements.

First working completion in ManagedConsole?.

Rename resolve to resolveTop.

This reflects the actuall functionality.

Change semantic of tryResolve and tryResolveAndGet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java

    r97 r98  
    44
    55import com.framsticks.core.Tree;
    6 import com.framsticks.core.TreeListener;
    7 import com.framsticks.core.ListChange;
    86import com.framsticks.core.Node;
    97import com.framsticks.core.Path;
     8import com.framsticks.core.TreeOperations;
     9import com.framsticks.gui.controls.ValueControl;
    1010import com.framsticks.params.CompositeParam;
    1111import com.framsticks.params.FramsClass;
     
    1414
    1515import javax.swing.tree.TreePath;
    16 import com.framsticks.util.dispatching.RunAt;
     16
     17
     18import com.framsticks.util.dispatching.FutureHandler;
     19import com.framsticks.util.lang.Casting;
    1720
    1821/**
    1922 * @author Piotr Sniegowski
    2023 */
    21 public class TreeAtFrame implements TreeListener {
     24public class TreeAtFrame {
    2225
    2326        private static final Logger log = Logger.getLogger(TreeAtFrame.class);
     
    2629        protected final Tree tree;
    2730        protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>();
    28         protected TreeNode rootTreeNode;
     31        protected Node rootNode;
     32
     33        protected Map<TreeNode, NodeAtFrame> nodesStorage = new WeakHashMap<>();
    2934
    3035        public TreeAtFrame(Tree tree, Frame frame) {
     
    9095        }
    9196
    92         @Override
    93         public void onListChange(Path path, ListChange change) {
     97        public boolean hasLocalChanges(TreePath treePath) {
     98                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
     99                if (nodeAtFrame == null) {
     100                        return false;
     101                }
     102                return !nodeAtFrame.localChanges.isEmpty();
     103        }
     104
     105        public NodeAtFrame assureLocalInfo(TreePath treePath) {
     106                assert frame.isActive();
     107                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
     108
     109                if (nodeAtFrame == null) {
     110                        nodeAtFrame = new NodeAtFrame();
     111                        nodesStorage.put(Casting.throwCast(TreeNode.class, treePath.getLastPathComponent()), nodeAtFrame);
     112                }
     113                return nodeAtFrame;
     114        }
     115
     116        public NodeAtFrame getLocalInfo(TreePath treePath) {
     117                return nodesStorage.get(treePath.getLastPathComponent());
     118        }
     119
     120        public boolean changeValue(TreePath treePath, ValueControl component, Object newValue) {
     121                log.debug("changing value of " + component + " to '" + newValue + "'");
     122
     123                assureLocalInfo(treePath).localChanges.put(component, newValue);
     124
     125                return true;
     126        }
     127
     128        public void pushLocalChanges(TreePath treePath) {
     129                assert frame.isActive();
     130
     131                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
     132                if (nodeAtFrame == null) {
     133                        return;
     134                }
     135                Path path = frame.treeModel.convertToPath(treePath);
     136
     137                for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) {
     138                        TreeOperations.set(path, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(frame) {
     139                                @Override
     140                                protected void result(Integer flag) {
     141                                }
     142                        });
     143                }
     144        }
     145
     146        public void fillPanelWithValues(TreePath treePath) {
     147                NodeAtFrame nodeAtFrame = assureLocalInfo(treePath);
     148                if (nodeAtFrame == null) {
     149                        return;
     150                }
     151
     152                if (nodeAtFrame.panel == null) {
     153                        return;
     154                }
     155                Node node = TreeNode.tryGetNode(treePath);
     156                if (node == null) {
     157                        return;
     158                }
     159                nodeAtFrame.panel.setCurrentTreePath(treePath);
     160                nodeAtFrame.panel.pullValuesFromLocalToUser(TreeOperations.bindAccess(node));
     161
     162                frame.showPanel(nodeAtFrame.panel);
    94163
    95164        }
    96165
    97         public TreePath getTreePath(Path path, boolean create) {
    98                 assert frame.isActive();
    99                 TreeNode t = rootTreeNode;
    100                 TreePath result = new TreePath(frame.rootNode).pathByAddingChild(rootTreeNode);
    101                 List<Node> nodes = path.getNodes();
    102                 Iterator<Node> i = nodes.iterator();
    103                 i.next();
    104                 // Node first = i.next();
     166        public void useOrCreatePanel(TreePath treePath) {
     167                // node.assureResolved();
     168                Node node = TreeNode.tryGetNode(treePath);
    105169
    106                 // if (!t.path.isResolved()) {
    107                 //      t.path = new Path(path.getInstance(), nodes, first);
    108                 // }
    109                 while (i.hasNext()) {
    110                         Node n = i.next();
    111                         TreeNode r = null;
    112                         for (TreeNode c : t.childrenIterable()) {
    113                                 if (c.param.getId().equals(n.getParam().getId())) {
    114                                         r = c;
    115                                         break;
    116                                 }
     170                NodeAtFrame nodeAtFrame = assureLocalInfo(treePath);
     171
     172                if (nodeAtFrame.panel == null) {
     173                        CompositeParam param = node.getParam();
     174                        nodeAtFrame.panel = findPanel(param.computeAccessId());
     175                        if (nodeAtFrame.panel == null) {
     176                                FramsClass framsClass = node.getTree().getInfoFromCache(param.getContainedTypeName());
     177                                nodeAtFrame.panel = preparePanel(param, framsClass);
    117178                        }
    118                         if (r == null) {
    119                                 log.debug("missing " + n.getParam().getId() + " in " + t);
    120                                 if (!create) {
    121                                         return result;
    122                                 }
    123                                 Path p = Path.build().tree(path.getTree()).buildUpTo(nodes, n).finish();
    124 
    125 
    126                                 log.debug("forced resolution: creating treenode for " + p);
    127                                 TreeNode childNode = new TreeNode(TreeAtFrame.this, p);
    128 
    129                                 frame.addNode(childNode, t);
    130                                 // frame.treeModel.reload();
    131                                 // t.add(childNode);
    132                                 // frame.treeModel.nodeStructureChanged(t);
    133 
    134                                 r = childNode;
    135                         } else {
    136                                 // if (!r.path.isResolved()) {
    137                                 //      r.path = new Path(path.getInstance(), nodes, n);
    138                                 // }
    139                         }
    140                         result = result.pathByAddingChild(r);
    141                         t = r;
    142179                }
    143                 return result;
    144         }
    145 
    146         @Override
    147         public void onFetch(final Path path) {
    148                 assert tree.isActive();
    149                 log.trace("fetched " + path);
    150 
    151                 frame.dispatch(new RunAt<Frame>(frame) {
    152                         @Override
    153                         protected void runAt() {
    154 
    155                                 TreePath treePath = getTreePath(path, true);
    156                                 assert treePath.getPathCount() == path.size() + 1;
    157 
    158                                 final TreeNode result = (TreeNode) treePath.getLastPathComponent();
    159                                 // log.trace("found " + result + " == " + path);
    160                                 tree.dispatch(new RunAt<Tree>(frame) {
    161                                         @Override
    162                                         protected void runAt() {
    163                                                 result.reactForFetchResult(path, null);
    164                                         }
    165                                 });
    166                         }
    167                 });
    168         }
    169 
    170         @Override
    171         public void onRun(Exception e) {
    172 
    173         }
    174 
    175         @Override
    176         public void onStop(Exception e) {
    177 
     180                fillPanelWithValues(treePath);
    178181        }
    179182}
Note: See TracChangeset for help on using the changeset viewer.