Skip to content

Commit cd35eb4

Browse files
committed
Refactoring code to fix problem where combobox lost event to populate its data.
1 parent 30e4656 commit cd35eb4

File tree

5 files changed

+56
-68
lines changed

5 files changed

+56
-68
lines changed

bigbluebutton-client/src/org/bigbluebutton/modules/layout/events/LayoutsLoadedEvent.as

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ package org.bigbluebutton.modules.layout.events
2525
public class LayoutsLoadedEvent extends Event
2626
{
2727
public static const LAYOUTS_LOADED_EVENT:String = "LAYOUTS_LOADED_EVENT";
28+
public static const SEND_LAYOUTS_LOADED_EVENT:String = "SEND_LAYOUTS_LOADED_EVENT";
2829
public var layouts:LayoutDefinitionFile = null;
2930
public var success:Boolean = false;
3031
public var error:TypeError = null;

bigbluebutton-client/src/org/bigbluebutton/modules/layout/events/PopulateComboboxEvent.as

Lines changed: 0 additions & 36 deletions
This file was deleted.

bigbluebutton-client/src/org/bigbluebutton/modules/layout/managers/LayoutManager.as

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ package org.bigbluebutton.modules.layout.managers
6262
private var _containerDeactivated:Boolean = false;
6363
private var _sendCurrentLayoutUpdateTimer:Timer = new Timer(500,1);
6464
private var _applyCurrentLayoutTimer:Timer = new Timer(150,1);
65+
private var _delayToSendLayoutsToCombobox:Timer = new Timer(60,0);
6566
private var _customLayoutsCount:int = 0;
66-
private var sendToCombobox:Boolean = false;
67+
private var comboboxIsInitialized:Boolean = false;
6768
private var _eventsToDelay:Array = new Array(MDIManagerEvent.WINDOW_RESTORE,
6869
MDIManagerEvent.WINDOW_MINIMIZE,
6970
MDIManagerEvent.WINDOW_MAXIMIZE);
@@ -76,6 +77,31 @@ package org.bigbluebutton.modules.layout.managers
7677
_sendCurrentLayoutUpdateTimer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
7778
sendLayoutUpdate(updateCurrentLayout());
7879
});
80+
81+
_delayToSendLayoutsToCombobox.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void {
82+
checkIfCanSendLayoutToCombobox();
83+
});
84+
}
85+
86+
87+
public function sendPopulateComboboxEvent():void {
88+
var sendLayoutsLoaded:LayoutsLoadedEvent = new LayoutsLoadedEvent(LayoutsLoadedEvent.SEND_LAYOUTS_LOADED_EVENT );
89+
sendLayoutsLoaded.layouts = _layouts;
90+
_globalDispatcher.dispatchEvent(sendLayoutsLoaded);
91+
}
92+
93+
94+
public function initDelayTimerUntilComboboxIsInitialized():void {
95+
_delayToSendLayoutsToCombobox.start();
96+
}
97+
98+
99+
public function checkIfCanSendLayoutToCombobox():void {
100+
LogUtil.debug("Estou tentando");
101+
if(comboboxIsInitialized) {
102+
_delayToSendLayoutsToCombobox.stop();
103+
sendPopulateComboboxEvent();
104+
}
79105
}
80106

81107
public function loadServerLayouts(layoutUrl:String):void {
@@ -84,21 +110,23 @@ package org.bigbluebutton.modules.layout.managers
84110
loader.addEventListener(LayoutsLoadedEvent.LAYOUTS_LOADED_EVENT, function(e:LayoutsLoadedEvent):void {
85111
if (e.success) {
86112
_layouts = e.layouts;
113+
if(comboboxIsInitialized) {
114+
sendPopulateComboboxEvent();
115+
}
116+
else {
117+
initDelayTimerUntilComboboxIsInitialized();
118+
}
87119
LogUtil.debug("LayoutManager: layouts loaded successfully");
120+
88121
} else {
89122
LogUtil.error("LayoutManager: layouts not loaded (" + e.error.message + ")");
90123
}
91124
});
92125
loader.loadFromUrl(layoutUrl);
93126
}
94127

95-
public function sendLayoutToComboboxWhenReceived():void {
96-
if(_layouts != null) {
97-
var populateComboboxEvent:PopulateComboboxEvent = new PopulateComboboxEvent();
98-
populateComboboxEvent.layouts = _layouts;
99-
_globalDispatcher.dispatchEvent(populateComboboxEvent);
100-
101-
}
128+
public function comboboxInitialized():void {
129+
comboboxIsInitialized = true;
102130
}
103131

104132
public function saveLayoutsToFile():void {
@@ -118,13 +146,15 @@ package org.bigbluebutton.modules.layout.managers
118146
/*
119147
* \TODO why do I need to create a new Event for this?
120148
*/
121-
var layoutsLoaded:LayoutsLoadedEvent = new LayoutsLoadedEvent();
122-
layoutsLoaded.layouts = _layouts;
123-
_globalDispatcher.dispatchEvent(layoutsLoaded);
149+
//var layoutsLoaded:LayoutsLoadedEvent = new LayoutsLoadedEvent();
150+
//layoutsLoaded.layouts = _layouts;
151+
//_globalDispatcher.dispatchEvent(layoutsLoaded);
124152
/*
125153
* it will update the ComboBox label, and will go back to this class
126154
* to apply the default layout
127155
*/
156+
157+
sendPopulateComboboxEvent();
128158
_globalDispatcher.dispatchEvent(new LayoutEvent(LayoutEvent.APPLY_DEFAULT_LAYOUT_EVENT));
129159

130160
Alert.show(ResourceUtil.getInstance().getString('bbb.layout.load.complete'), "", Alert.OK, _canvas);

bigbluebutton-client/src/org/bigbluebutton/modules/layout/maps/LayoutEventMap.mxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
</EventHandlers>
5656

5757
<EventHandlers type="{ComboBoxCreatedEvent.COMBOBOX_CREATED_EVENT}">
58-
<MethodInvoker generator="{LayoutManager}" method="sendLayoutToComboboxWhenReceived"/>
58+
<MethodInvoker generator="{LayoutManager}" method="comboboxInitialized"/>
5959
</EventHandlers>
6060

6161

bigbluebutton-client/src/org/bigbluebutton/modules/layout/views/LayoutsCombo.mxml

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@
3333
<mate:Listener type="{LayoutEvent.REMOTE_LOCK_LAYOUT_EVENT}" receive="{enabled=false || UserManager.getInstance().getConference().amIModerator()}" />
3434
<mate:Listener type="{LayoutEvent.REMOTE_UNLOCK_LAYOUT_EVENT}" receive="{enabled=true}" />
3535
<mate:Listener type="{LayoutEvent.INVALIDATE_LAYOUT_EVENT}" method="invalidadeLayout" />
36-
<mate:Listener type="{LayoutsLoadedEvent.LAYOUTS_LOADED_EVENT}" method="populateLayoutsList" />
3736
<mate:Listener type="{RedefineLayoutEvent.REDEFINE_LAYOUT_EVENT}" method="onRedefineLayout" />
38-
<mate:Listener type="{PopulateComboboxEvent.POPULATE_COMBOBOX_EVENT}" method="repopulateLayoutsList"/>
37+
<mate:Listener type="{LayoutsLoadedEvent.SEND_LAYOUTS_LOADED_EVENT}" method="populateLayoutsList"/>
3938

4039

4140
<mx:Script>
@@ -82,31 +81,16 @@
8281
private var _dispatcher:Dispatcher = new Dispatcher();
8382
8483
private var _defaultLayout:Object = null;
84+
private var shouldSelectedItemGoToDefaultBecauseTheEventWasLost:Boolean = false;
85+
8586
8687
private function init():void {
8788
LogUtil.debug("LayoutsCombo: view initialized");
8889
var comboBoxCreated:ComboBoxCreatedEvent = new ComboBoxCreatedEvent();
8990
_dispatcher.dispatchEvent(comboBoxCreated);
9091
}
9192
92-
private function repopulateLayoutsList(e:PopulateComboboxEvent):void {
93-
if(populated == false) {
94-
LogUtil.debug("LayoutsCombo: repopulating list because previous layout list was missed");
95-
_defaultLayout = null;
96-
dataProvider.removeAll();
97-
var idx:int = 0;
98-
for each (var value:LayoutDefinition in e.layouts.list) {
99-
var item:Object = {index:idx, label:value.name, layout:value};
100-
if (value.defaultLayout)
101-
_defaultLayout = item;
102-
dataProvider.addItem(item);
103-
idx++;
104-
}
105-
invalidateDisplayList();
106-
}
107-
}
10893
private function populateLayoutsList(e:LayoutsLoadedEvent):void {
109-
populated = true;
11094
LogUtil.debug("LayoutsCombo: populating list");
11195
_defaultLayout = null;
11296
dataProvider.removeAll();
@@ -119,11 +103,20 @@
119103
idx++;
120104
}
121105
invalidateDisplayList();
106+
107+
if(shouldSelectedItemGoToDefaultBecauseTheEventWasLost) {
108+
onApplyDefaultLayout();
109+
}
110+
else {
111+
houldSelectedItemGoToDefaultBecauseTheEventWasLost = false;
112+
}
122113
}
123114
124-
private function onApplyDefaultLayout(e:Event):void {
115+
private function onApplyDefaultLayout(e:Event = null):void {
125116
if (_defaultLayout != null)
126117
selectedItem = _defaultLayout;
118+
else
119+
shouldSelectedItemGoToDefaultBecauseTheEventWasLost = true;
127120
}
128121
129122
private function onRedefineLayout(e:RedefineLayoutEvent):void {

0 commit comments

Comments
 (0)