@doc hierarchy="GMLDOM">
The Component is a reusable model unit.
(c) SAP AG 2003-2006. All rights reserved.
///////////////////////////////////////////////////////////////////////
// CLASS HEADER
Class Component inherit Unit;
metadata title = '#TEXT[XTIT_COMPONENT]';
metadata descr = '#TEXT[XTOL_COMPONENT]';
metadata usageElement = 'core.gml:ComponentUsage';
metadata configurationType = 'core.gml:Configuration';
///////////////////////////////////////////////////////////////////////
// PROPERTIES
<@doc>A collection of @gml:ConfigurationItem elements that represent this component's
specific features
strong readonly property configuration = ^Configuration;
<@doc>
Gets the configuration related to the object
The object's configuration
method getConfiguration()
return this.configuration;
end
<@method name="getConfigurationClassName">
Returns the class name of the configuration object that is created with the creation of this component.
The default implementation returns the class name that appears in the ~configurationType metadata.
Override this method to provide another (more dynamic) way to decide on the configuration class name.
The class name of a subclass of @gml:Configuration that should be created for this component, or ~'' to create no configuration.
method getConfigurationClassName()
return this.Class.metadata.configurationType || '';
end
<@method name="getConfigurationItemType">
A method that is returns the type of configuration item that should be created per child element of this component.
Override this method to provide
The child element that was inserted to this component
The subclass of @gml:ConfigurationItem that should be created for this element, or ~''
method getConfigurationItemType(element)
return '';
end
override method onCreate()
this.supercall();
var config_class = this.getConfigurationClassName();
if (config_class)
this.createElement(config_class, 'configuration');
end
listen onShapeMenu for core.gml:ComponentUsage
var target = object.getTarget()
target.appendExternalEditorsToMenu(target, menu);
end
listen onDiagramMenu for core.gml:Component
object.appendExternalEditorsToMenu(object, menu);
end
///////////////////////////////////////////////////////////////////////
// METHODS
<@doc>
Returns an array representing all the events published or consumed by this component
Specify incoming or outgoing events
An array of event names
method getEvents(dir)
var evts = [];
var evtClass = (dir == #[DIR_IN]) ? 'core.gml:EventInport' : (dir == #[DIR_OUT] ? 'core.gml:EventOutport' : 'core.gml:EventPort');
var ports = this.getCollection(evtClass);
for (var p in ports)
if (ports[p].name) //do not add events with empty names
evts.push(ports[p].name);
return evts;
end
override method getConnectablePlugs(paramPlug)
//TODO: either optimize or rewrite more simply
if (!ISA(paramPlug, 'core.gml:Plug'))
return null;
var srcElem = paramPlug.parent;
var A = {};
var B = this.getCollection('core.gml:Connectable');
var is_in_plug = (paramPlug.dir == #[DIR_IN]);
var is_io_plug = (paramPlug.dir == #[DIR_IO]);
for (var k in B)
{
var C; //holds all plugs opposite to paramPlug
if (is_io_plug)
{
C = B[k].getPlugsByClass('core.gml:DirectPlug');
}
else if (is_in_plug)
{
C = B[k].getPlugsByClass('core.gml:Outplug');
}
else
{
C = B[k].getPlugsByClass('core.gml:Inplug');
}
if (!C) continue;
for (var k2 in C)
{
if (is_in_plug)
{
//paramPlug is inPlug, thus it is the target in a potential link
//to test if this is possible, we need to call canConnect on the object that is the parent of paramPlug
if (!paramPlug.parent.canConnect(C[k2], paramPlug))
continue;
}
else //io plug, out_plug
{
//C[k2] is in plug, thus a target Plug. call canConnect on its parent object which is B[k]
if (!B[k].canConnect(paramPlug, C[k2]))
continue;
}
A[k2] = C[k2];
}
}
return A;
end
method getExternalEditors()
return null;
end
method getExternalEditorParams(editorId)
return "";
end
method getExternalEditorFeatures(editorId)
return "";
end
method appendExternalEditorsToMenu(component, menu)
var editors = component.getExternalEditors();
if (!editors) return;
for (var k in editors) {
var editor = editors[k];
var id = editor.id;
var name = editor.name;
var url = editor.url;
var icon = editor.icon;
if (!id || !name || !url || !icon) return;
// Check whether a command for the specified editor already exists
var command = $ENV.getCommand(id);
id = UPPER(id);
if (!command) {
$ENV.defineCommand({
id: id,
signal: 'CONTEXT->openExternalEditor("' + url + '", "' + id + '")',
text: '#TEXT[XMIT_EDIT_USING] ' + name,
icon: icon,
category: 'STANDARD'
});
}
menu.append({button:id});
}
end
method openExternalEditor(url, id)
var params = this.getExternalEditorParams(id);
if (!params) params = "";
var features = this.getExternalEditorFeatures(id);
if (!features) features= "";
var returnValue = window.showModalDialog(url, params, features);
var evt = document.createEventObject();
evt.type = 'onExternalEditorClose';
evt.object = this;
evt.editorId = id;
evt.returnValue = returnValue;
$ENV.fireModelEvent(evt);
end