<@doc hierarchy="GMLDOM" also="@Link, @Plug"> Represents an element that can be connected to other elements in the same unit. (c) SAP AG 2003-2006. All rights reserved. /////////////////////////////////////////////////////////////////////// // CLASS HEADER Class Connectable inherit Element; metadata title = '#TEXT[XTIT_CONNECTABLE]'; metadata descr = '#TEXT[XTOL_CONNECTABLE]'; /////////////////////////////////////////////////////////////////////// // PROPERTIES <@doc>The collection of plugs owned by this element. Use @getPlugs to retrieve them. strong readonly property plugs = ^core.gml:Plug[id]; /////////////////////////////////////////////////////////////////////// // METHODS override method onCreate() this.supercall(); end <@doc> Queries whether a given source plug can be connected to a target plug under this element The source plug (belonging to another element) The target plug (belonging to this element) A whitespace-separated list of all valid link types that can be connected between the source and target plugs, or ~null in case the source and target plugs cannot be connected. method canConnect(srcPlug, trgPlug) return ''; end <@doc> Get the collection of plugs owned by the object The requested plugs collection method getPlugs() return this.plugs; end <@doc> Get a collection of plugs owned by the object The direction of the plugs to retrieve The requested plugs collection method getPlugsByDir(dir) var A={}, C=this.plugs; for (var k in C) { if (C[k].isa('core.gml:Plug') && (C[k].dir & dir)) A[k]=C[k]; } return A; end <@doc> Get a collection of plugs of a specific class type The full class name of the plugs to retrieve The requested plugs collection method getPlugsByClass(classname) var A={}, C=this.plugs; for (var k in C) { if (C[k].isa(classname)) A[k]=C[k]; } return A; end <@doc> Get the single object plug in the specified direction (assuming there is exactly one such plug) The direction of the plugs to retrieve The requested plug, if found method getSinglePlug(dir) var C=this.plugs; for (var k in C) { if (C[k].isa('core.gml:Plug') && (C[k].dir == dir)) return C[k]; } return null; end <@doc> Get all incoming/outcomming Link objects pointed to/out the object The links direction Collection of all incoming/outcomming Link objects method getLinks(dir) var dirIn = (dir & #[DIR_IN]) ? true : false; var dirOut = (dir & #[DIR_OUT]) ? true : false; //TODO: consider optimization // Recalculate the connecotor's collection var result_links = {}; if (this.unit) { var links = this.unit.getCollection('core.gml:Link', false); for (var i in links) { //we search for in/out plugs which parents identical to this if(dirIn && (links[i].target.parent.id == this.id)) { result_links[links[i].id] = links[i]; continue; } if(dirOut && (links[i].source.parent.id == this.id)) { result_links[links[i].id] = links[i]; continue; } } } return result_links; end <@doc> Get all incoming/outcomming Link objects pointed to/out a given plug in this object. A plug, one of the plugs of this objects Collection of all incoming/outcomming Link objects that connect to the given plug. method getLinksByPlug(plug) #DEVTIME[ //TODO: verify that this plug indeed related to this object ] if (!this.unit) return {}; var links = this.unit.getCollection('core.gml:Link', false); var results = {}; for (var l in links) { var link = links[l]; if (link.source == plug || link.target == plug) results[link.id] = link; } return results; end /////////////////////////////////////////////////////////////////////// // EVENT LISTENERS listen onShapeMenu for core.gml:Connectable menu.append({button:'EDIT_PROPERTIES'}); menu.append(); menu.append({button:'EDIT_RENAME'}); menu.append({button:'EDIT_DELETE'}); if ($ENV.context.object && $ENV.context.element && $ENV.context.unit && $ENV.triggerEvent('canRemoveElement',$ENV.context.object,$ENV.context.element,$ENV.context.unit,"elements","cutEvent")){ menu.append({button:'CUT_ELEMENT'}); menu.append(); } end