source: java/main/src/main/java/com/framsticks/gui/Browser.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: 7.1 KB
RevLine 
[77]1package com.framsticks.gui;
2
3import com.framsticks.core.*;
[97]4import com.framsticks.gui.console.Console;
5import com.framsticks.gui.console.TrackConsole;
[99]6import com.framsticks.gui.table.ColumnsConfig;
7import com.framsticks.gui.table.ListPanelProvider;
[88]8import com.framsticks.params.annotations.AutoAppendAnnotation;
9import com.framsticks.params.annotations.FramsClassAnnotation;
10import com.framsticks.params.annotations.ParamAnnotation;
[97]11import com.framsticks.remote.RemoteTree;
12import com.framsticks.util.FramsticksException;
[88]13import com.framsticks.util.dispatching.AbstractJoinable;
[84]14import com.framsticks.util.dispatching.Dispatcher;
[88]15import com.framsticks.util.dispatching.Dispatching;
[97]16import com.framsticks.util.dispatching.ExceptionResultHandler;
[84]17import com.framsticks.util.dispatching.Future;
[88]18import com.framsticks.util.dispatching.Joinable;
19import com.framsticks.util.dispatching.JoinableCollection;
20import com.framsticks.util.dispatching.JoinableParent;
21import com.framsticks.util.dispatching.JoinableState;
[84]22
[88]23import javax.swing.*;
24
[77]25import org.apache.log4j.Logger;
26
[84]27import java.awt.Dimension;
[97]28import java.awt.Toolkit;
29import java.awt.datatransfer.StringSelection;
30import java.awt.event.ActionEvent;
[84]31import java.util.ArrayList;
[97]32import java.util.LinkedList;
[84]33import java.util.List;
[85]34import com.framsticks.util.dispatching.RunAt;
[77]35
36/**
37 * @author Piotr Sniegowski
38 */
[88]39@FramsClassAnnotation
[97]40public class Browser extends AbstractJoinable implements Dispatcher<Browser>, JoinableParent, ExceptionResultHandler {
[77]41
[97]42        private static final Logger log = Logger.getLogger(Browser.class);
[77]43
[97]44        protected final JoinableCollection<Frame> frames = new JoinableCollection<Frame>().setObservableName("frames");
45        protected final JoinableCollection<Tree> trees = new JoinableCollection<Tree>().setObservableName("trees");
46        protected final JoinableCollection<Console> consoles = new JoinableCollection<Console>().setObservableName("consoles");
[88]47
[97]48        protected final List<PopupMenuEntryProvider> popupMenuEntryProviders = new LinkedList<>();
[98]49        // protected final SwingDispatcher
[97]50
51        protected final MainFrame mainFrame;
52        protected final List<PanelProvider> panelProviders = new ArrayList<PanelProvider>();
[84]53        protected Dimension defaultFrameDimension;
[77]54
[88]55        String name;
56
[84]57        public void addFrame(Frame frame) {
58                frames.add(frame);
59        }
[77]60
[99]61        protected final StandardPanelProvider standardPanelProvider;
62        protected final ListPanelProvider listPanelProvider;
63
[84]64        public Browser() {
[88]65                setName("browser");
[84]66                JPopupMenu.setDefaultLightWeightPopupEnabled(false);
[99]67                addPanelProvider(standardPanelProvider = new StandardPanelProvider());
68                addPanelProvider(listPanelProvider = new ListPanelProvider());
[77]69
[88]70                mainFrame = new MainFrame(Browser.this);
[98]71
72                // mainFrame.getStatusBar().setExceptionHandler(ThrowExceptionHandler.getInstance());
73
[88]74                addFrame(mainFrame);
[97]75
76                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
77                        @Override
78                        public void provide(JPopupMenu menu, Path path) {
79                                menu.add(new JMenuItem(path.getFullTextual()));
80                                menu.addSeparator();
81                        }
82                });
83
84                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
85                        @SuppressWarnings("serial")
86                        @Override
87                        public void provide(JPopupMenu menu, final Path path) {
88                                menu.add(new AbstractAction("Copy path to clipboard") {
89                                        @Override
90                                        public void actionPerformed(ActionEvent e) {
91                                                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(path.getFullTextual()), null);
92                                        }
93                                });
94                        }
95                });
96
97                addPopupMenuEntryProvider(new PopupMenuEntryProvider() {
98                        @SuppressWarnings("serial")
99                        @Override
100                        public void provide(JPopupMenu menu, final Path path) {
101                                if (!(path.getTree() instanceof RemoteTree)) {
102                                        return;
103                                }
104                                final RemoteTree remoteTree = (RemoteTree) path.getTree();
105                                menu.add(new AbstractAction("Open tracking console") {
106                                        @Override
107                                        public void actionPerformed(ActionEvent e) {
108                                                consoles.add(new TrackConsole().setConnection(remoteTree.getConnection()));
109                                        }
110                                });
111                        }
112                });
113                // addNodeActionToTreePopupMenu("", new NodeAction() )
114
[77]115        }
116
[88]117        @AutoAppendAnnotation
[84]118        public void addPanelProvider(PanelProvider panelProvider) {
119                log.debug("added panel provider of type: " + panelProvider.getClass().getCanonicalName());
120                panelProviders.add(panelProvider);
121        }
122
[88]123        @AutoAppendAnnotation
[99]124        public void addColumnsConfig(ColumnsConfig columnsConfig) {
125                listPanelProvider.addColumnsConfig(columnsConfig);
126        }
127
128        @AutoAppendAnnotation
[97]129        public void addPopupMenuEntryProvider(PopupMenuEntryProvider popupMenuEntryProvider) {
130                popupMenuEntryProviders.add(popupMenuEntryProvider);
[88]131        }
132
[97]133        @AutoAppendAnnotation
134        public void addTree(Tree tree) {
[99]135                log.debug("adding tree: " + tree);
[98]136                tree.setDispatcher(new SwingDispatcher<Tree>());
[97]137                trees.add(tree);
138        }
139
[84]140        public void autoResolvePath(final String path, final Future<Path> future) {
[98]141                // final Tree i = trees.get("localhost");
142                // i.dispatch(new RunAt<Tree>(future) {
143                //      @Override
144                //      protected void runAt() {
145                //              TreeOperations.tryGet(i, path, new FutureHandler<Path>(future) {
146                //                      @Override
147                //                      protected void result(final Path p) {
148                //                              future.pass(p);
149                //                              mainFrame.dispatch(new RunAt<Frame>(future) {
150                //                                      @Override
151                //                                      protected void runAt() {
152                //                                              mainFrame.goTo(p);
153                //                                      }
154                //                              });
155                //                      }
156                //              });
157                //      }
158                // });
[84]159        }
160
[77]161        public void clear() {
[84]162                assert isActive();
163                for (Frame f : frames) {
164                        f.clear();
165                }
[77]166        }
167
[88]168        @Override
169        protected void joinableStart() {
170                Dispatching.use(frames, this);
[97]171                Dispatching.use(trees, this);
172                Dispatching.use(consoles, this);
[88]173
[97]174                dispatch(new RunAt<Browser>(this) {
[84]175                        @Override
[97]176                        protected void runAt() {
177
178                                for (final Tree i : trees) {
179                                        i.dispatch(new RunAt<Tree>(this) {
180                                                @Override
181                                                protected void runAt() {
182                                                        final Path p = Path.to(i, "/");
183                                                        dispatch(new RunAt<Browser>(this) {
184                                                                @Override
185                                                                protected void runAt() {
186                                                                        mainFrame.addRootPath(p);
187                                                                }
188                                                        });
189                                                }
190                                        });
191                                }
[84]192                        }
193                });
[77]194        }
195
[88]196        /**
[97]197         * @return the tree
[88]198         */
[97]199        public JoinableCollection<Tree> getTrees() {
200                return trees;
[84]201        }
[77]202
[84]203        /**
204         * @return the mainFrame
205         */
206        public MainFrame getMainFrame() {
207                return mainFrame;
208        }
209
[88]210        /**
211         * @return the name
212         */
213        @ParamAnnotation
214        public String getName() {
215                return name;
216        }
217
218        /**
219         * @param name the name to set
220         */
221        @ParamAnnotation
222        public void setName(String name) {
223                this.name = name;
224        }
225
226        @Override
227        public boolean isActive() {
228                return SwingDispatcher.getInstance().isActive();
229        }
230
231        @Override
[90]232        public void dispatch(RunAt<? extends Browser> runnable) {
233                SwingDispatcher.getInstance().dispatch(runnable);
[88]234        }
235
236        @Override
237        protected void joinableJoin() throws InterruptedException {
238                Dispatching.join(frames);
[97]239                Dispatching.join(trees);
240                Dispatching.join(consoles);
[88]241                // super.join();
242        }
243
244        @Override
245        protected void joinableInterrupt() {
[97]246                Dispatching.drop(consoles, this);
[88]247                Dispatching.drop(frames, this);
[97]248                Dispatching.drop(trees, this);
[88]249        }
250
251        @Override
252        public void childChangedState(Joinable joinable, JoinableState state) {
253                if (joinable == frames) {
254                        proceedToState(state);
255                }
256
257        }
258
259        @Override
260        protected void joinableFinish() {
261
262        }
263
264        @Override
265        public String toString() {
266                return getName();
267        }
268
[97]269        @Override
270        public void handle(FramsticksException exception) {
271                mainFrame.handle(exception);
272        }
[88]273
[77]274}
Note: See TracBrowser for help on using the repository browser.