Skip to content

Commit efa5ce9

Browse files
committed
message : mediator to mediator added.
1 parent b900531 commit efa5ce9

File tree

10 files changed

+210
-28
lines changed

10 files changed

+210
-28
lines changed

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/screens/MvcExpressVisualizerScreen.as

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mindscriptact.mvcExpressLogger.screens {
22
import com.bit101.components.Label;
3+
import flash.display.Shape;
34
import flash.display.Sprite;
4-
import flash.utils.getQualifiedClassName;
55
import flash.utils.setTimeout;
66

77
/**
@@ -103,8 +103,53 @@ public class MvcExpressVisualizerScreen extends Sprite {
103103
mediatorLabel.graphics.lineTo(proxies[i].view.x - mediatorLabel.x, proxies[i].view.y - mediatorLabel.y + 5);
104104
mediatorLabel.graphics.moveTo(mediatorLabel.width, 5);
105105
mediatorLabel.graphics.lineTo(mediatorLabel.width + 5, 5 - 2);
106-
mediatorLabel.graphics.moveTo(mediatorLabel.width, 5);
107106
mediatorLabel.graphics.lineTo(mediatorLabel.width + 5, 5 + 2);
107+
mediatorLabel.graphics.lineTo(mediatorLabel.width, 5);
108+
}
109+
}
110+
}
111+
112+
public function drawMessageToMediator(messageLogObj:Object, possition:int):void {
113+
var messageShape:Shape;
114+
if (mediators[possition]) {
115+
var mediatorLabel:Label = mediators[possition].view;
116+
if (mediatorLabel) {
117+
// handle message from mediator
118+
var messageFromObject:Object = messageLogObj.messageFromMediator;
119+
if (messageFromObject) {
120+
for (var j:int = 0; j < mediators.length; j++) {
121+
if (mediators[j].mediatorObject == messageFromObject) {
122+
var sourceMediatorLabel:Label = mediators[j].view;
123+
if (sourceMediatorLabel) {
124+
125+
messageShape = new Shape();
126+
messageShape.graphics.lineStyle(2, 0xD9FFD9, 0.3);
127+
messageShape.graphics.lineTo(50, (sourceMediatorLabel.y - mediatorLabel.y) * 0.2);
128+
messageShape.graphics.lineTo(0, sourceMediatorLabel.y - mediatorLabel.y);
129+
130+
messageShape.graphics.moveTo(0, 0);
131+
messageShape.graphics.lineTo(10, -2);
132+
messageShape.graphics.lineTo(10, 2);
133+
messageShape.graphics.lineTo(0, 0);
134+
135+
messageShape.x = mediatorLabel.width;
136+
messageShape.y = 10;
137+
mediatorLabel.addChild(messageShape);
138+
139+
setTimeout(hideShape, 1500, messageShape);
140+
}
141+
break;
142+
}
143+
}
144+
}
145+
}
146+
}
147+
}
148+
149+
private function hideShape(shape:Shape):void {
150+
if (shape.parent) {
151+
if (shape.parent.contains(shape)) {
152+
shape.parent.removeChild(shape);
108153
}
109154
}
110155
}
@@ -175,11 +220,11 @@ public class MvcExpressVisualizerScreen extends Sprite {
175220
var proxyLabel:Label = (proxyObject.view as Label);
176221
proxyLabel.graphics.lineStyle(1, 0xFF00FF, 0.5);
177222
proxyLabel.graphics.moveTo(0, 15);
178-
proxyLabel.graphics.curveTo(-50, 15, proxies[i].view.x - proxyLabel.x, proxies[i].view.y - proxyLabel.y + 17);
223+
proxyLabel.graphics.curveTo(-100, 15, proxies[i].view.x - proxyLabel.x, proxies[i].view.y - proxyLabel.y + 17);
179224
proxyLabel.graphics.moveTo(0, 15);
180225
proxyLabel.graphics.lineTo(-5, 15 - 2);
181-
proxyLabel.graphics.moveTo(0, 15);
182226
proxyLabel.graphics.lineTo(-5, 15 + 2);
227+
proxyLabel.graphics.lineTo(0, 15);
183228
}
184229
}
185230
}
@@ -223,18 +268,17 @@ public class MvcExpressVisualizerScreen extends Sprite {
223268
if (mediators[j].mediatorObject == messageFromObject) {
224269
var mediatorLabel:Label = mediators[j].view;
225270
if (mediatorLabel) {
226-
commandLabel.graphics.lineStyle(2, 0xFFFFD9, 0.5);
271+
commandLabel.graphics.lineStyle(2, 0xFFFFD9, 0.3);
227272
commandLabel.graphics.moveTo(0, 10);
228273
commandLabel.graphics.lineTo(-commandLabel.x + mediatorLabel.x + mediatorLabel.width, -commandLabel.y + mediatorLabel.y + mediatorLabel.height - 10);
229274
commandLabel.graphics.moveTo(0, 10);
230275
commandLabel.graphics.lineTo(-10, 10 - 2);
231-
commandLabel.graphics.moveTo(0, 10);
232276
commandLabel.graphics.lineTo(-10, 10 + 2);
277+
commandLabel.graphics.lineTo(0, 10);
233278
}
234279
break;
235280
}
236281
}
237-
//mediators.
238282
}
239283

240284
setTimeout(removeObject, 1500, commandPosition, commandLogObj);
@@ -285,8 +329,8 @@ public class MvcExpressVisualizerScreen extends Sprite {
285329
commandLabel.graphics.lineTo(proxyLabel.x - commandLabel.x, proxyLabel.y - commandLabel.y + 17);
286330
commandLabel.graphics.moveTo(commandLabel.width, 5);
287331
commandLabel.graphics.lineTo(commandLabel.width + 5, 5 - 2);
288-
commandLabel.graphics.moveTo(commandLabel.width, 5);
289332
commandLabel.graphics.lineTo(commandLabel.width + 5, 5 + 2);
333+
commandLabel.graphics.lineTo(commandLabel.width, 5);
290334
}
291335
}
292336
}

mvcExpressLogger/com/mindscriptact/mvcExpressLogger/visualizer/VisualizerManager.as

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mindscriptact.mvcExpressLogger.visualizer {
22
import com.mindscriptact.mvcExpressLogger.screens.MvcExpressVisualizerScreen;
33
import flash.utils.Dictionary;
4+
import org.flexunit.async.AsyncNativeTestResponder;
45
import org.mvcexpress.core.CommandMap;
56
import org.mvcexpress.mvc.Command;
67
import org.mvcexpress.mvc.Mediator;
@@ -149,9 +150,35 @@ public class VisualizerManager {
149150
}
150151
}
151152
break;
153+
case "Mediator.addHandler":
154+
// add handler to mediator
155+
mediators = getModuleMediators(logObj.moduleName);
156+
for (var k:int = 0; k < mediators.length; k++) {
157+
if (mediators[k].mediatorObject == logObj.mediatorObject) {
158+
if (!mediators[k].handleObjects) {
159+
mediators[k].handleObjects = new Vector.<Object>();
160+
}
161+
mediators[k].handleObjects.push(logObj);
162+
}
163+
}
164+
break;
152165
case "Mediator.sendMessage":
153166
sendMessageStack.push(logObj);
154167
break;
168+
case "Mediator.sendMessage.CLEAN":
169+
topObject = sendMessageStack.pop();
170+
if (logObj.type != topObject.type) {
171+
CONFIG::debug {
172+
throw Error("NOT HANDLED:" + logObj);
173+
}
174+
} else {
175+
if (logObj.params != topObject.params) {
176+
CONFIG::debug {
177+
throw Error("NOT HANDLED:" + logObj);
178+
}
179+
}
180+
}
181+
break;
155182
case "Messenger.send":
156183
topObject = sendMessageStack[sendMessageStack.length - 1];
157184
if (topObject) {
@@ -184,7 +211,59 @@ public class VisualizerManager {
184211
}
185212
}
186213
break;
187-
214+
case "Messenger.send.HANDLER":
215+
if (mvcExpressVisualizerScreen) {
216+
if (currentModuleName == logObj.moduleName) {
217+
//
218+
topObject = sendMessageStack[sendMessageStack.length - 1];
219+
if (topObject) {
220+
if (logObj.type == topObject.type) {
221+
if (logObj.params == topObject.params) {
222+
if (topObject.moduleName == logObj.moduleName) {
223+
// ALL IS GOOD...
224+
// find mediator with handler function.
225+
mediators = getModuleMediators(logObj.moduleName);
226+
for (var l:int = 0; l < mediators.length; l++) {
227+
if (mediators[l].mediatorClassName == logObj.handlerClassName) {
228+
var handlerObjects:Vector.<Object> = mediators[l].handleObjects;
229+
if (handlerObjects) {
230+
for (var m:int = 0; m < handlerObjects.length; m++) {
231+
if (handlerObjects[m].handler == logObj.handler) {
232+
if (topObject.moduleName == logObj.moduleName && topObject.type == logObj.type && topObject.params == logObj.params) {
233+
if (topObject.mediatorObject) {
234+
logObj.messageFromMediator = topObject.mediatorObject;
235+
}
236+
}
237+
this.mvcExpressVisualizerScreen.drawMessageToMediator(logObj, l);
238+
}
239+
}
240+
}
241+
}
242+
}
243+
244+
} else {
245+
CONFIG::debug {
246+
throw Error("NOT HANDLED:" + logObj);
247+
}
248+
}
249+
} else {
250+
CONFIG::debug {
251+
throw Error("NOT HANDLED:" + logObj);
252+
}
253+
}
254+
} else {
255+
CONFIG::debug {
256+
throw Error("NOT HANDLED:" + logObj);
257+
}
258+
}
259+
} else {
260+
CONFIG::debug {
261+
throw Error("NOT HANDLED:" + logObj);
262+
}
263+
}
264+
}
265+
}
266+
break;
188267
default:
189268
CONFIG::debug {
190269
throw Error("NOT HANDLED:" + logObj);
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.mindScriptAct.mvcExpressVisualizer.controller {
22
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyA;
33
import org.mvcexpress.mvc.Command;
4-
4+
55
/**
66
* TODO:CLASS COMMENT
77
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
88
*/
9-
public class TestCommandA extends Command{
10-
9+
public class TestCommandA extends Command {
1110

1211
[Inject]
1312
public var testProxyA:TestProxyA;
1413

15-
public function execute(testText:String):void{
16-
17-
}
14+
public function execute(testText:String):void {
1815

16+
}
17+
1918
}
2019
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package com.mindScriptAct.mvcExpressVisualizer.controller {
2+
import com.mindScriptAct.mvcExpressVisualizer.model.ITestProxyB;
23
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyA;
4+
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyB;
35
import flash.geom.Point;
46
import org.mvcexpress.mvc.Command;
5-
7+
68
/**
79
* TODO:CLASS COMMENT
810
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
911
*/
10-
public class TestCommandB extends Command{
11-
12+
public class TestCommandB extends Command {
1213

1314
[Inject]
1415
public var testProxyA:TestProxyA;
1516

16-
public function execute(testPoint:Point):void{
17-
18-
}
17+
[Inject(name="BProxyName")]
18+
public var testProxyB:ITestProxyB;
1919

20+
public function execute(testPoint:Point):void {
21+
22+
}
23+
2024
}
2125
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/messages/Message.as

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class Message {
88
static public const TEST_COMMAND_B:String = "testCommandB";
99
static public const TEST_MEDIATOR_A_COMMAND:String = "testMediatorACommand";
1010
static public const TEST_MEDIATOR_B_COMMAND:String = "testMediatorBCommand";
11+
static public const TEST_MESSAGE_TO_MEDIATORS_B:String = "testMessageToMediatorsB";
12+
static public const TEST_MESSAGE_TO_MEDIATORS_A:String = "testMessageToMediatorsA";
1113

1214

1315
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/view/testA/TestViewAMediator.as

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,33 @@ public class TestViewAMediator extends Mediator {
1818
public var testProxyA:TestProxyA;
1919

2020
override public function onRegister():void {
21-
var pushButton:PushButton = new PushButton(view, 20, 50, "Send A mediator message", handleSendTestMessage);
21+
var pushButton:PushButton;
22+
pushButton = new PushButton(view, 15, 50, "Send command message", handleSendCommandMessage);
2223
pushButton.width = 150;
24+
pushButton = new PushButton(view, 15, 75, "Send mediator message", handleSendMediatorMessage);
25+
pushButton.width = 150;
26+
pushButton = new PushButton(view, 15, 100, "Triger proxy", handleSendProxyMessage);
27+
pushButton.width = 150;
28+
29+
addHandler(Message.TEST_MESSAGE_TO_MEDIATORS_A, handleMediatorTest);
30+
}
31+
32+
private function handleMediatorTest(blank:Object):void {
33+
2334
}
2435

25-
private function handleSendTestMessage(event:Event):void {
36+
private function handleSendCommandMessage(event:Event):void {
2637
sendMessage(Message.TEST_MEDIATOR_A_COMMAND, "A params..");
2738
}
2839

40+
private function handleSendMediatorMessage(event:Event):void {
41+
sendMessage(Message.TEST_MESSAGE_TO_MEDIATORS_B);
42+
}
43+
44+
private function handleSendProxyMessage(event:Event):void {
45+
46+
}
47+
2948
override public function onRemove():void {
3049

3150
}

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/view/testB/TestViewBMediator.as

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,33 @@ public class TestViewBMediator extends Mediator {
1919
public var testProxyB:ITestProxyB;
2020

2121
override public function onRegister():void {
22-
var pushButton:PushButton = new PushButton(view, 20, 50, "Send B mediator message", handleSendTestMessage);
22+
var pushButton:PushButton;
23+
pushButton = new PushButton(view, 15, 50, "Send command message", handleSendCommandMessage);
2324
pushButton.width = 150;
25+
pushButton = new PushButton(view, 15, 75, "Send mediator message", handleSendMediatorMessage);
26+
pushButton.width = 150;
27+
pushButton = new PushButton(view, 15, 100, "Triger proxy", handleSendProxyMessage);
28+
pushButton.width = 150;
29+
30+
addHandler(Message.TEST_MESSAGE_TO_MEDIATORS_B, handleMediatorTest);
31+
}
32+
33+
private function handleMediatorTest(blank:Object):void {
34+
2435
}
2536

26-
private function handleSendTestMessage(event:Event):void {
37+
private function handleSendCommandMessage(event:Event):void {
2738
sendMessage(Message.TEST_MEDIATOR_B_COMMAND, new Point(11, 22));
2839
}
2940

41+
private function handleSendMediatorMessage(event:Event):void {
42+
sendMessage(Message.TEST_MESSAGE_TO_MEDIATORS_A);
43+
}
44+
45+
private function handleSendProxyMessage(event:Event):void {
46+
47+
}
48+
3049
override public function onRemove():void {
3150

3251
}

src/org/mvcexpress/core/MediatorMap.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public class MediatorMap implements IMediatorMap {
106106
MvcExpress.debugFunction("§*+ MediatorMap.mediate > viewObject : " + viewObject + " (viewClass:" + viewClass + ")" + " WITH > mediatorClass : " + mediatorClass);
107107
}
108108
if (MvcExpress.loggerFunction != null) {
109-
MvcExpress.loggerFunction({action: "MediatorMap.mediate", moduleName: moduleName, viewObject: viewObject, mediatorObject: mediator, viewClass: viewClass, mediatorClass: mediatorClass});
109+
MvcExpress.loggerFunction({action: "MediatorMap.mediate", moduleName: moduleName, viewObject: viewObject, mediatorObject: mediator, viewClass: viewClass, mediatorClass: mediatorClass, mediatorClassName: getQualifiedClassName(mediatorClass)});
110110
}
111111
}
112112

src/org/mvcexpress/core/messenger/Messenger.as

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public class Messenger {
142142
type
143143
/* Failed handler class: */
144144
handlerVo.handlerClassName
145+
//
146+
if (MvcExpress.loggerFunction != null) {
147+
MvcExpress.loggerFunction({action: "Messenger.send.HANDLER", moduleName: moduleName, type: type, params: params, handler: handlerVo.handler, handlerClassName: handlerVo.handlerClassName});
148+
}
145149
}
146150
handlerVo.handler(params);
147151
}

0 commit comments

Comments
 (0)