source: java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java @ 99

Last change on this file since 99 was 99, checked in by psniegowski, 11 years ago

HIGHLIGTS:

  • complete events implementation
  • add CLI in Java Framsticks server
  • add automatic registration for events in GUI
  • improve objects fetching (object are never overwritten with new instances)
  • properly react for ListChange? events
  • add ListPanel? with table view
    • columns to be shown may be statically specified in configuration
    • currently modyfying data through tables is not available
  • improve maven configuration
    • configuration file may be specified without touching pom.xml

CHANGELOG:
Extract constants from Flags into ParamFlags? and SetStateFlags?.

Extract flags I/O to FlagsUtils? class.

Configured maven to exec given resource configuration.

For example:
mvn exec:exec -Dframsticks.config=/configs/managed-console.xml

Cleanup pom.xml

Rename ObjectTree? to LocalTree? (also make LocalTree? and RemoteTree? final).

Minor change.

Add maximum number of columns in ListPanelProvider?.

Improve ColumnsConfig? interpretation.

Automatically fill FramsClass?.name if trying to construct empty.

Improve identitifer case mangling in XmlLoader?.

Introduce configurable ColumnsConfig?.

Draft working version of ListPanel?.

Table is being shown (although empty).

More improvements to table building.

Move some functionality from Frame to TreeModel?.

Move tree classes in gui to separate package.

Remove old table related classes.

Add draft implementation of TableModel?.

Redirect ParamBuilder?.forAccess to AccessInterface?.

Optimize ParamBuilder?.forAccess()

Do not clear list when loading.

Do not load fetched values directly.

Implement different AccessInterface? copying policy.

Optimize fetching values routine.

Remove Mode enum (work out get semantics).

Some improvements to ListChange? handling.

Improve UniqueListAccess?.

Add reaction for ListChanges? in the TreeNode?.

EventListeners? are being added in the TreeNode?.

Listeners for ListParams? are now very naive (they download
whole list).

Automatially register on events in GUI.

Events are working in RemoteTree? and Server.

Move listeners to the ClientSideManagedConnection?.

Remove old classes responsible for event subscriptions.

Improve event reading.

Improve events handling at server side.

Add register attribute in FramsClassAnnotation?
to automatically also register other classes.

Registering events works.

Setup for remote listeners registration.

More improvements.

Minor changes.

Add rootTree to the ClientAtServer?.

Moving CLI to the ClientAtServer?.

Fix bug: use Void.TYPE instead of Void.class

More development around CLI.

  • Improve Path resolving.

Add synthetic root to ObjectTree?.

It is needed to allow sybling for the original root
that would containg CLI.

Some work with registering events in RemoteTree?.

Draft implementation of listener registering in RemoteTree?.

Support events registration in the ObjectTree?.

Add events support to ReflectionAccess?.

EventParam? is recognized by ParamCandidate?.

Prepare interface for Events across project.

Add EventListener? and API for listeners in Tree.

File size: 4.7 KB
Line 
1package com.framsticks.gui;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.core.Tree;
6import com.framsticks.core.Node;
7import com.framsticks.core.Path;
8import com.framsticks.core.TreeOperations;
9import com.framsticks.gui.controls.ValueControl;
10import com.framsticks.gui.tree.TreeNode;
11import com.framsticks.params.CompositeParam;
12import com.framsticks.params.FramsClass;
13
14import java.util.*;
15
16import javax.swing.tree.TreePath;
17
18
19import com.framsticks.util.dispatching.FutureHandler;
20import com.framsticks.util.lang.Casting;
21
22/**
23 * @author Piotr Sniegowski
24 */
25public class TreeAtFrame {
26
27        private static final Logger log = Logger.getLogger(TreeAtFrame.class);
28
29        protected final Frame frame;
30        protected final Tree tree;
31        protected final Map<String, Panel> knownPanels = new HashMap<String, Panel>();
32        protected Node rootNode;
33
34        protected Map<TreeNode, NodeAtFrame> nodesStorage = new WeakHashMap<>();
35
36        public TreeAtFrame(Tree tree, Frame frame) {
37                this.frame = frame;
38                this.tree = tree;
39        }
40
41        public Frame getFrame() {
42                return frame;
43        }
44
45        /**
46         * @return the tree
47         */
48        public Tree getTree() {
49                return tree;
50        }
51
52        public void registerPanel(Panel panel) {
53        }
54
55        public Panel findPanel(String accessId) {
56                assert frame.isActive();
57                return (knownPanels.containsKey(accessId) ? knownPanels.get(accessId) : null);
58        }
59
60        public final String getName() {
61                return tree.getName();
62        }
63
64        public Panel preparePanel(CompositeParam param, FramsClass framsClass) {
65                assert frame.isActive();
66                Panel panel = preparePanelImpl(param, framsClass);
67                assert panel != null;
68                String accessId = param.computeAccessId();
69                panel.uniqueName = accessId + "@" + tree.getName();
70                knownPanels.put(accessId, panel);
71                frame.cardPanel.add(panel, panel.uniqueName);
72                log.debug("prepared panel for " + panel);
73                return panel;
74        }
75
76        protected Panel preparePanelImpl(CompositeParam param, FramsClass framsClass) {
77                assert frame.isActive();
78                List<Panel> panels = new ArrayList<Panel>();
79
80                Panel.Parameters parameters = new Panel.Parameters(this, param, framsClass);
81                for (PanelProvider pp : frame.browser.panelProviders) {
82                        Panel p = pp.providePanel(parameters);
83                        if (p != null) {
84                                panels.add(p);
85                        }
86                }
87
88                if (panels.isEmpty()) {
89                        return new EmptyPanel(parameters);
90                }
91                if (panels.size() == 1) {
92                        return panels.get(0);
93                }
94                return new MultiPanel(parameters, panels);
95
96        }
97
98        public boolean hasLocalChanges(TreePath treePath) {
99                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
100                if (nodeAtFrame == null) {
101                        return false;
102                }
103                return !nodeAtFrame.localChanges.isEmpty();
104        }
105
106        public NodeAtFrame assureLocalInfo(TreePath treePath) {
107                assert frame.isActive();
108                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
109
110                if (nodeAtFrame == null) {
111                        nodeAtFrame = new NodeAtFrame();
112                        nodesStorage.put(Casting.throwCast(TreeNode.class, treePath.getLastPathComponent()), nodeAtFrame);
113                }
114                return nodeAtFrame;
115        }
116
117        public NodeAtFrame getLocalInfo(TreePath treePath) {
118                return nodesStorage.get(treePath.getLastPathComponent());
119        }
120
121        public boolean changeValue(TreePath treePath, ValueControl component, Object newValue) {
122                log.debug("changing value of " + component + " to '" + newValue + "'");
123
124                assureLocalInfo(treePath).localChanges.put(component, newValue);
125
126                return true;
127        }
128
129        public void pushLocalChanges(TreePath treePath) {
130                assert frame.isActive();
131
132                NodeAtFrame nodeAtFrame = nodesStorage.get(treePath.getLastPathComponent());
133                if (nodeAtFrame == null) {
134                        return;
135                }
136                Path path = frame.treeModel.convertToPath(treePath);
137
138                for (Map.Entry<ValueControl, Object> e : nodeAtFrame.localChanges.entrySet()) {
139                        TreeOperations.set(path, e.getKey().getParam(), e.getValue(), new FutureHandler<Integer>(frame) {
140                                @Override
141                                protected void result(Integer flag) {
142                                }
143                        });
144                }
145        }
146
147        public void fillPanelWithValues(TreePath treePath) {
148                NodeAtFrame nodeAtFrame = assureLocalInfo(treePath);
149                if (nodeAtFrame == null) {
150                        return;
151                }
152
153                if (nodeAtFrame.panel == null) {
154                        return;
155                }
156                Node node = TreeNode.tryGetNode(treePath);
157                if (node == null) {
158                        return;
159                }
160                nodeAtFrame.panel.setCurrentTreePath(treePath);
161                nodeAtFrame.panel.pullValuesFromLocalToUser(TreeOperations.bindAccess(node));
162
163                frame.showPanel(nodeAtFrame.panel);
164
165        }
166
167        public void useOrCreatePanel(TreePath treePath) {
168                // node.assureResolved();
169                Node node = TreeNode.tryGetNode(treePath);
170
171                NodeAtFrame nodeAtFrame = assureLocalInfo(treePath);
172
173                if (nodeAtFrame.panel == null) {
174                        CompositeParam param = node.getParam();
175                        nodeAtFrame.panel = findPanel(param.computeAccessId());
176                        if (nodeAtFrame.panel == null) {
177                                FramsClass framsClass = node.getTree().getInfoFromCache(param.getContainedTypeName());
178                                nodeAtFrame.panel = preparePanel(param, framsClass);
179                        }
180                }
181                fillPanelWithValues(treePath);
182        }
183}
Note: See TracBrowser for help on using the repository browser.