Skip to content

Commit b900531

Browse files
committed
Message sending : mediator to execute command.
1 parent cb251dc commit b900531

File tree

12 files changed

+147
-33
lines changed

12 files changed

+147
-33
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,27 @@ public class MvcExpressVisualizerScreen extends Sprite {
216216
commandLabel.y = commandPosition * 20 + 60;
217217
this.addChild(commandLabel);
218218

219+
// handle message from mediator
220+
var messageFromObject:Object = commandLogObj.messageFromMediator;
221+
if (messageFromObject) {
222+
for (var j:int = 0; j < mediators.length; j++) {
223+
if (mediators[j].mediatorObject == messageFromObject) {
224+
var mediatorLabel:Label = mediators[j].view;
225+
if (mediatorLabel) {
226+
commandLabel.graphics.lineStyle(2, 0xFFFFD9, 0.5);
227+
commandLabel.graphics.moveTo(0, 10);
228+
commandLabel.graphics.lineTo(-commandLabel.x + mediatorLabel.x + mediatorLabel.width, -commandLabel.y + mediatorLabel.y + mediatorLabel.height - 10);
229+
commandLabel.graphics.moveTo(0, 10);
230+
commandLabel.graphics.lineTo(-10, 10 - 2);
231+
commandLabel.graphics.moveTo(0, 10);
232+
commandLabel.graphics.lineTo(-10, 10 + 2);
233+
}
234+
break;
235+
}
236+
}
237+
//mediators.
238+
}
239+
219240
setTimeout(removeObject, 1500, commandPosition, commandLogObj);
220241
}
221242

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

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ public class VisualizerManager {
1717
private var moduleMediators:Dictionary = new Dictionary();
1818
private var moduleProxies:Dictionary = new Dictionary();
1919
private var currentModuleName:String;
20+
private var sendMessageStack:Vector.<Object> = new Vector.<Object>();
2021

2122
public function logMvcExpress(logObj:Object):void {
23+
var topObject:Object;
2224
var mediators:Vector.<Object>;
2325
var proxies:Vector.<Object>;
2426
var i:int;
@@ -137,22 +139,69 @@ public class VisualizerManager {
137139
case "CommandMap.handleCommandExecute":
138140
if (this.mvcExpressVisualizerScreen) {
139141
if (currentModuleName == logObj.moduleName) {
142+
topObject = sendMessageStack[sendMessageStack.length - 1];
143+
if (topObject.moduleName == logObj.moduleName && topObject.type == logObj.type && topObject.params == logObj.params) {
144+
if (topObject.mediatorObject) {
145+
logObj.messageFromMediator = topObject.mediatorObject;
146+
}
147+
}
140148
this.mvcExpressVisualizerScreen.addCommand(logObj);
141149
}
142150
}
143151
break;
152+
case "Mediator.sendMessage":
153+
sendMessageStack.push(logObj);
154+
break;
155+
case "Messenger.send":
156+
topObject = sendMessageStack[sendMessageStack.length - 1];
157+
if (topObject) {
158+
if (logObj.type == topObject.type) {
159+
if (logObj.params == topObject.params) {
160+
if (topObject.moduleName == null) {
161+
topObject.moduleName = logObj.moduleName;
162+
} else {
163+
if (topObject.moduleName == logObj.moduleName) {
164+
// ALL IS GOOD...
165+
} else {
166+
CONFIG::debug {
167+
throw Error("NOT HANDLED:" + logObj);
168+
}
169+
}
170+
}
171+
} else {
172+
CONFIG::debug {
173+
throw Error("NOT HANDLED:" + logObj);
174+
}
175+
}
176+
} else {
177+
CONFIG::debug {
178+
throw Error("NOT HANDLED:" + logObj);
179+
}
180+
}
181+
} else {
182+
CONFIG::debug {
183+
throw Error("NOT HANDLED:" + logObj);
184+
}
185+
}
186+
break;
187+
144188
default:
189+
CONFIG::debug {
145190
throw Error("NOT HANDLED:" + logObj);
191+
}
192+
break;
146193
}
147194
}
148195

149196
public function manageThisScreen(currentModuleName:String, mvcExpressVisualizerScreen:MvcExpressVisualizerScreen):void {
150197
this.currentModuleName = currentModuleName;
151-
this.mvcExpressVisualizerScreen = mvcExpressVisualizerScreen;
152-
//
153-
this.mvcExpressVisualizerScreen.addProxies(moduleProxies[currentModuleName]);
154-
this.mvcExpressVisualizerScreen.addMediators(moduleMediators[currentModuleName]);
155-
this.mvcExpressVisualizerScreen.clearCommands();
198+
if (mvcExpressVisualizerScreen) {
199+
this.mvcExpressVisualizerScreen = mvcExpressVisualizerScreen;
200+
//
201+
this.mvcExpressVisualizerScreen.addProxies(moduleProxies[currentModuleName]);
202+
this.mvcExpressVisualizerScreen.addMediators(moduleMediators[currentModuleName]);
203+
this.mvcExpressVisualizerScreen.clearCommands();
204+
}
156205
}
157206

158207
public function manageNothing():void {

sampleProjects/com/mindScriptAct/mvcExpressVisualizer/VisualLoggerTestModule.as

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mindScriptAct.mvcExpressVisualizer {
22
import com.bit101.components.PushButton;
3-
import com.mindScriptAct.circularDependenciesTest.controller.TestCommand;
43
import com.mindScriptAct.modules.console.Console;
54
import com.mindScriptAct.modules.ModuleNames;
65
import com.mindscriptact.mvcExpressLogger.MvcExpressLogger;
@@ -58,6 +57,8 @@ public class VisualLoggerTestModule extends ModuleSprite {
5857

5958
// set up controller
6059
commandMap.map(Message.TEST_COMMAND_B, TestCommandB);
60+
commandMap.map(Message.TEST_MEDIATOR_A_COMMAND, TestCommandA);
61+
commandMap.map(Message.TEST_MEDIATOR_B_COMMAND, TestCommandB);
6162

6263
// set up data
6364
proxyMap.map(new TestProxyA());
@@ -78,14 +79,16 @@ public class VisualLoggerTestModule extends ModuleSprite {
7879
testViewB1Button = new PushButton(this, 10, 530, "Add TestViewB 1", handleAddMediatorB1);
7980
testViewB2Button = new PushButton(this, 150, 530, "Add TestViewB 2", handleAddMediatorB2);
8081

81-
testViewB1Button = new PushButton(this, 300, 500, "Execute Command A", handleCommandA);
82-
testViewB2Button = new PushButton(this, 300, 530, "Execute Command B", handleCommandB);
82+
testViewB1Button = new PushButton(this, 300, 500, "Module:Execute CommandA", handleCommandA);
83+
testViewB1Button.width = 150;
84+
testViewB2Button = new PushButton(this, 300, 530, "Module:Send message", handleCommandB);
85+
testViewB2Button.width = 150;
8386

8487
testProxyCButton = new PushButton(this, 180, 570, "Add TestProxyC", handleAddProxyC);
8588

8689
var console:Console = new Console();
8790
this.addChild(console);
88-
console.x = 500;
91+
console.x = 600;
8992
console.y = 450;
9093
}
9194

@@ -141,7 +144,7 @@ public class VisualLoggerTestModule extends ModuleSprite {
141144
this.addChild(testViewB1);
142145
mediatorMap.mediate(testViewB1);
143146
testViewB1Button.label = "Remove TestViewB 1";
144-
testViewB1.y = 250;
147+
testViewB1.y = 200;
145148
}
146149
}
147150

@@ -157,7 +160,7 @@ public class VisualLoggerTestModule extends ModuleSprite {
157160
mediatorMap.mediate(testViewB2);
158161
testViewB2Button.label = "Remove TestViewB 2";
159162
testViewB2.x = 300;
160-
testViewB2.y = 250;
163+
testViewB2.y = 200;
161164
}
162165
}
163166

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package com.mindScriptAct.mvcExpressVisualizer.messages {
66
*/
77
public class Message {
88
static public const TEST_COMMAND_B:String = "testCommandB";
9+
static public const TEST_MEDIATOR_A_COMMAND:String = "testMediatorACommand";
10+
static public const TEST_MEDIATOR_B_COMMAND:String = "testMediatorBCommand";
911

1012

1113
}
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
package com.mindScriptAct.mvcExpressVisualizer.view {
2+
import com.bit101.components.PushButton;
3+
import com.mindScriptAct.mvcExpressVisualizer.controller.TestCommandA;
4+
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
25
import com.mindScriptAct.mvcExpressVisualizer.VisualLoggerTestModule;
6+
import flash.events.Event;
7+
import flash.geom.Point;
38
import org.mvcexpress.mvc.Mediator;
49

510
/**
611
* TODO:CLASS COMMENT
712
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
813
*/
9-
public class VisualLoggerTestModuleMediator extends Mediator{
14+
public class VisualLoggerTestModuleMediator extends Mediator {
15+
private var testViewB1Button:PushButton;
16+
private var testViewB2Button:PushButton;
1017

1118
[Inject]
1219
public var view:VisualLoggerTestModule;
1320

1421
//[Inject]
1522
//public var myProxy:MyProxy;
1623

17-
override public function onRegister():void{
18-
24+
override public function onRegister():void {
25+
testViewB2Button = new PushButton(view, 320, 560, "Mediator:Send Message", handleCommandB);
26+
testViewB2Button.width = 150
1927
}
2028

21-
override public function onRemove():void{
22-
29+
override public function onRemove():void {
30+
2331
}
2432

33+
private function handleCommandB(event:Event):void {
34+
sendMessage(Message.TEST_COMMAND_B, new Point(123, 321));
35+
}
2536
}
2637
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
package com.mindScriptAct.mvcExpressVisualizer.view.testA {
2+
import com.bit101.components.PushButton;
23
import flash.display.Shape;
34
import flash.display.Sprite;
45

@@ -11,11 +12,12 @@ public class TestViewA extends Sprite {
1112

1213
public function TestViewA() {
1314
var rectangle:Shape = new Shape();
14-
rectangle.graphics.lineStyle(0.1, 0xFF0000);
15-
rectangle.graphics.beginFill(0x0000FF);
16-
rectangle.graphics.drawRect(0, 0, 100, 100);
15+
rectangle.graphics.lineStyle(2, 0xFFFF00);
16+
rectangle.graphics.beginFill(0xCEFFCE);
17+
rectangle.graphics.drawRect(5, 5, 250, 150);
1718
rectangle.graphics.endFill();
1819
this.addChild(rectangle);
20+
1921
}
2022

2123
}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
package com.mindScriptAct.mvcExpressVisualizer.view.testA {
2+
import com.bit101.components.PushButton;
3+
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
24
import com.mindScriptAct.mvcExpressVisualizer.model.TestProxyA;
5+
import flash.events.Event;
36
import org.mvcexpress.mvc.Mediator;
47

58
/**
69
* TODO:CLASS COMMENT
710
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
811
*/
9-
public class TestViewAMediator extends Mediator{
12+
public class TestViewAMediator extends Mediator {
1013

1114
[Inject]
1215
public var view:TestViewA;
1316

1417
[Inject]
1518
public var testProxyA:TestProxyA;
1619

17-
override public function onRegister():void{
18-
20+
override public function onRegister():void {
21+
var pushButton:PushButton = new PushButton(view, 20, 50, "Send A mediator message", handleSendTestMessage);
22+
pushButton.width = 150;
1923
}
2024

21-
override public function onRemove():void{
22-
25+
private function handleSendTestMessage(event:Event):void {
26+
sendMessage(Message.TEST_MEDIATOR_A_COMMAND, "A params..");
2327
}
2428

29+
override public function onRemove():void {
30+
31+
}
32+
2533
}
2634
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ public class TestViewB extends Sprite {
1111

1212
public function TestViewB() {
1313
var rectangle:Shape = new Shape();
14-
rectangle.graphics.lineStyle(0.1, 0xFF0000);
15-
rectangle.graphics.beginFill(0x00FF40);
16-
rectangle.graphics.drawRect(0, 0, 100, 100);
14+
rectangle.graphics.lineStyle(2, 0x00FF00);
15+
rectangle.graphics.beginFill(0xCEFFCE);
16+
rectangle.graphics.drawRect(5, 5, 250, 150);
1717
rectangle.graphics.endFill();
1818
this.addChild(rectangle);
1919
}
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
package com.mindScriptAct.mvcExpressVisualizer.view.testB {
2+
import com.bit101.components.PushButton;
3+
import com.mindScriptAct.mvcExpressVisualizer.messages.Message;
24
import com.mindScriptAct.mvcExpressVisualizer.model.ITestProxyB;
5+
import flash.events.Event;
6+
import flash.geom.Point;
37
import org.mvcexpress.mvc.Mediator;
48

59
/**
610
* TODO:CLASS COMMENT
711
* @author Raimundas Banevicius (http://www.mindscriptact.com/)
812
*/
9-
public class TestViewBMediator extends Mediator{
13+
public class TestViewBMediator extends Mediator {
1014

1115
[Inject]
1216
public var view:TestViewB;
1317

1418
[Inject(name="BProxyName")]
1519
public var testProxyB:ITestProxyB;
1620

17-
override public function onRegister():void{
18-
21+
override public function onRegister():void {
22+
var pushButton:PushButton = new PushButton(view, 20, 50, "Send B mediator message", handleSendTestMessage);
23+
pushButton.width = 150;
1924
}
2025

21-
override public function onRemove():void{
22-
26+
private function handleSendTestMessage(event:Event):void {
27+
sendMessage(Message.TEST_MEDIATOR_B_COMMAND, new Point(11, 22));
2328
}
2429

30+
override public function onRemove():void {
31+
32+
}
33+
2534
}
2635
}

src/org/mvcexpress/core/CommandMap.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public class CommandMap {
162162
MvcExpress.debugFunction("©* CommandMap.handleCommandExecute > messageType : " + messageType + ", params : " + params + " Executed with : " + commandList[i]);
163163
}
164164
if (MvcExpress.loggerFunction != null) {
165-
MvcExpress.loggerFunction({action: "CommandMap.handleCommandExecute", moduleName: moduleName, commandObject: command, commandClass: commandList[i], params: params});
165+
MvcExpress.loggerFunction( { action: "CommandMap.handleCommandExecute", moduleName: moduleName, commandObject: command, commandClass: commandList[i], type:messageType, params: params } );
166166
}
167167
}
168168

0 commit comments

Comments
 (0)