Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Manager #522

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions support/client/lib/vwf.js
Expand Up @@ -363,6 +363,7 @@
active: false
},
{ library: "vwf/model/graphtool", active: false },
{ library: "vwf/model/eventManager", active: false },
{ library: "vwf/model/sound", active: false },
{ library: "vwf/model/object", active: true },
{ library: "vwf/model/stage/log", active: true },
Expand Down Expand Up @@ -439,6 +440,7 @@
{ library: "vwf/model/cesium", active: false },
{ library: "vwf/model/blockly", active: false },
{ library: "vwf/model/graphtool", active: false },
{ library: "vwf/model/eventManager", active: false },
{ library: "vwf/model/sound", active: false },
{ library: "vwf/model/kineticjs", active: false },
{ library: "vwf/model/mil-sym", active: false },
Expand Down
178 changes: 178 additions & 0 deletions support/client/lib/vwf/model/eventManager.js
@@ -0,0 +1,178 @@
"use strict";

define( [ "module", "vwf/model", "vwf/utility" ], function( module, model, utility ) {


return model.load( module, {

// == Module Definition ====================================================================

// -- initialize ---------------------------------------------------------------------------

initialize: function() {
this.state.nodes = {};
},

// == Model API ============================================================================

// -- creatingNode -------------------------------------------------------------------------

creatingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
childSource, childType, childIndex, childName, callback /* ( ready ) */ ) {

if ( isEventManager( childImplementsIDs ) ) {
this.state.nodes[ childID ] = {
"isBroadcasting": true,
"isListening": true,
"eventMap": {}
};
}

},

// -- initializingNode ---------------------------------------------------------------------

initializingNode: function( nodeID, childID, childExtendsID, childImplementsIDs,
childSource, childType, childIndex, childName ) {
},

// -- deletingNode -------------------------------------------------------------------------

deletingNode: function( nodeID ) {

if ( nodeID ) {
var childNode = this.state.nodes[ nodeID ];
if ( childNode ) {
var threeObject = childNode.threeObject;
if ( threeObject && threeObject.parent ) {
threeObject.parent.remove( threeObject );
}
delete this.state.nodes[ childNode ];
}
}

},

// -- creatingProperty ---------------------------------------------------------------------

creatingProperty: function( nodeID, propertyName, propertyValue ) {
return this.initializingProperty( nodeID, propertyName, propertyValue );
},

// -- initializingProperty -----------------------------------------------------------------

initializingProperty: function( nodeID, propertyName, propertyValue ) {
return this.settingProperty( nodeID, propertyName, propertyValue );
},

// -- settingProperty ----------------------------------------------------------------------

settingProperty: function( nodeID, propertyName, propertyValue ) {

var node = this.state.nodes[ nodeID ];
var value;
if ( node ) {
switch ( propertyName ) {
case "isBroadcasting":
value = propertyValue;
node.isBroadcasting = value;
break;
case "isListening":
value = propertyValue;
node.isListening = value;
break;
case "eventMap":
value = propertyValue;
node.eventMap = value;
break;
}
}
return value;

},

// -- gettingProperty ----------------------------------------------------------------------

gettingProperty: function( nodeID, propertyName, propertyValue ) {

var node = this.state.nodes[ nodeID ];
var value;
if ( node ) {
switch ( propertyName ) {
case "isBroadcasting":
value = node.isBroadcasting;
break;
case "isListening":
value = node.isListening;
break;
case "eventMap":
value = node.eventMap;
break;
}
}
return value;

},

// -- callingMethod ------------------------------------------------------------------------

callingMethod: function( nodeID, methodName, methodParameters, methodValue ) {
var node = this.state.nodes[ nodeID ];
var eventName, eventHandlerName;

if ( node ) {
switch ( methodName ) {
case "addListener":
eventName = methodParameters[ 0 ];
eventHandlerName = methodParameters[ 1 ];
node.eventMap[ eventName ] = eventHandlerName;
break;
case "removeListener":
eventName = methodParameters[ 0 ];
delete node.eventMap[ eventName ];
break;
}
}

},

// -- firingEvent --------------------------------------------------------------------------

firingEvent: function( nodeID, eventName, eventParameters ) {

var node = this.state.nodes[ nodeID ];
var listenerIDs, listenerNode;
if ( node && node.isBroadcasting ) {
listenerIDs = findListenerIDs( this.state.nodes, eventName );
for ( var i = 0; i < listenerIDs.length; i++ ) {
listenerNode = this.state.nodes[ listenerIDs[ i ] ];
this.kernel.callMethod(
listenerIDs[ i ],
listenerNode.eventMap[ eventName ],
eventParameters
);
}
}

},

} );

function isEventManager( implementsIDs ) {
return implementsIDs && implementsIDs.indexOf( "http-vwf-example-com-eventManager-vwf" ) !== -1;
}

function findListenerIDs( nodes, eventName ) {
var listenerIDs = [];
var keys = Object.keys( nodes );
var node;
for ( var i = 0; i < keys.length; i++ ) {
node = nodes[ keys[ i ] ]
if ( node.isListening && node.eventMap.hasOwnProperty( eventName ) ) {
listenerIDs.push( keys[ i ] );
}
}
return listenerIDs;
}

} );
22 changes: 22 additions & 0 deletions support/proxy/vwf.example.com/eventManager.vwf.yaml
@@ -0,0 +1,22 @@
# Copyright 2014 Lockheed Martin Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
properties:
isBroadcasting: true
isListening: true
eventMap: {}
methods:
addListener:
removeListener: