source: java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java @ 96

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

HIGHLIGHTS:

  • cleanup Instance management
    • extract Instance interface
    • extract Instance common algorithms to InstanceUtils?
  • fix closing issues: Ctrl+C or window close button

properly shutdown whole program

by Java Framsticks framework

  • fix parsing and printing of all request types
  • hide exception passing in special handle method of closures
    • substantially improve readability of closures
    • basically enable use of exception in asynchronous closures

(thrown exception is transported back to the caller)

  • implement call request on both sides

CHANGELOG:
Further improve calling.

Improve instance calling.

Calling is working on both sides.

Improve exception handling in testing.

Waiters do not supercede other apllication exception being thrown.

Finished parsing and printing of all request types (with tests).

Move implementation and tests of request parsing to Request.

Add tests for Requests.

Improve waits in asynchronours tests.

Extract more algorithms to InstanceUtils?.

Extract Instance.resolve to InstanceUtils?.

Improve naming.

Improve passing exception in InstanceClient?.

Hide calling of passed functor in StateCallback?.

Hide Exception passing in asynchronous closures.

Hide exception passing in Future.

Make ResponseCallback? an abstract class.

Make Future an abstract class.

Minor change.

Move getPath to Path.to()

Move bindAccess to InstanceUtils?.

Extract common things to InstanceUtils?.

Fix synchronization bug in Connection.

Move resolve to InstanceUtils?.

Allow names of Joinable to be dynamic.

Add support for set request server side.

More fixes in communication.

Fix issues with parsing in connection.

Cut new line characters when reading.

More improvements.

Migrate closures to FramsticksException?.

Several changes.

Extract resolveAndFetch to InstanceUtils? algorithms.

Test resolving and fetching.

More fixes with function signature deduction.

Do not print default values in SimpleAbstractAccess?.

Add test of FramsClass? printing.

Improve FramsticksException? messages.

Add explicit dispatcher synchronization feature.

Rework assertions in tests.

Previous solution was not generic enough.

Allow addition of joinables to collection after start.

Extract SimulatorInstance? from RemoteInstance?.

Remove PrivateJoinableCollection?.

Improve connections.

Move shutdown hook to inside the Monitor.

It should work in TestNG tests, but it seems that
hooks are not called.

In ServerTest? client connects to testing server.

Move socket initialization to receiver thread.

Add proper closing on Ctrl+C (don't use signals).

Fix bugs with server accepting connections.

Merge Entity into Joinable.

Reworking ServerInstance?.

Extract more algorithm to InstanceUtils?.

Extract some common functionality from AbstractInstance?.

Functions were placed in InstanceUtils?.

Hide registry of Instance.

Use ValueParam? in Instance interface.

Minor change.

Extract Instance interface.

Old Instance is now AbstractInstance?.

File size: 2.7 KB
Line 
1package com.framsticks.gui.controls;
2
3import com.framsticks.core.Instance;
4import com.framsticks.core.Path;
5import com.framsticks.gui.Gui;
6import com.framsticks.gui.TreeNode;
7import com.framsticks.params.Param;
8import com.framsticks.params.ValueParam;
9import com.framsticks.params.types.ProcedureParam;
10import com.framsticks.util.FramsticksException;
11import com.framsticks.util.Logging;
12import com.framsticks.util.dispatching.Future;
13import com.framsticks.util.dispatching.RunAt;
14
15import javax.swing.*;
16import javax.swing.border.BevelBorder;
17
18import org.apache.log4j.Logger;
19
20import java.awt.event.ActionEvent;
21import java.awt.event.ActionListener;
22import java.util.HashMap;
23import java.util.LinkedList;
24import java.util.List;
25import java.util.Map;
26
27@SuppressWarnings("serial")
28public class ProcedureControl extends Control implements ControlOwner {
29
30        private static final Logger log = Logger.getLogger(ProcedureControl.class);
31
32        protected final JButton procedureButton;
33
34        final protected Map<ValueParam, ValueControl> components = new HashMap<>();
35
36        public ProcedureControl(ProcedureParam procedureParam) {
37                super(procedureParam);
38
39                procedureButton = new JButton("Call");
40                procedureButton.setName("call");
41
42                this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
43
44                Gui.fillWithControls(this, procedureParam.getArgumentsType(), components, ValueControl.class);
45
46                if (components.size() != procedureParam.getArgumentsType().size()) {
47                        procedureButton.setEnabled(false);
48                }
49                if (!components.isEmpty()) {
50                        this.setBorder(new BevelBorder(BevelBorder.RAISED));
51                }
52
53                procedureButton.addActionListener(new ActionListener() {
54                        @Override
55                        public void actionPerformed(ActionEvent e) {
56                                TreeNode treeNode = owner.getCurrentTreeNode();
57                                assert treeNode != null;
58
59                                log.debug("calling " + getParam() + " on " + treeNode);
60                                final Path path = treeNode.getInstancePath();
61
62                                final List<Object> arguments = new LinkedList<Object>();
63                                for (Param arg : getParam().getArgumentsType()) {
64                                        arguments.add(((ValueControl) components.get(arg)).getCurrentValue());
65                                }
66
67                                path.getInstance().dispatch(new RunAt<Instance>() {
68                                        @Override
69                                        public void run() {
70                                                path.getInstance().call(path, getParam(), arguments.toArray(), new Future<Object>() {
71
72                                                        @Override
73                                                        public void handle(FramsticksException e) {
74                                                                Logging.log(log, "call procedure", path, e);
75                                                        }
76
77                                                        @Override
78                                                        public void result(Object result) {
79
80                                                        }
81                                                });
82                                        }
83                                });
84                        }
85                });
86                this.add(procedureButton);
87
88        }
89
90        @Override
91        public JPanel getPanel() {
92                return this;
93        }
94
95        @Override
96        public TreeNode getCurrentTreeNode() {
97                return owner.getCurrentTreeNode();
98        }
99
100        @Override
101        public ProcedureParam getParam() {
102                return (ProcedureParam) param;
103        }
104
105}
Note: See TracBrowser for help on using the repository browser.