@doc alias="elem" hierarchy="GMLDOM">
The Element is the basic building block from which %GML% units are composed.
A %GML% unit is always made of a collection of one or more %GML% elements, referenced by unique identifiers.
Depending on its type, a %GML% element may contain a collection of one or more child elements, referenced by unique identifiers.
Elements can be nested in this way to any arbitrary depth.
(c) SAP AG 2003-2006. All rights reserved.
///////////////////////////////////////////////////////////////////////
// CLASS HEADER
Class Element inherit TransObject;
metadata title = '#TEXT[XTIT_ELEMENT]';
metadata descr = '#TEXT[XTOL_ELEMENT]';
metadata namestem = '';
///////////////////////////////////////////////////////////////////////
// PROPERTIES
<@doc>Gets the containing unit
virtual readonly property unit = ^Unit;
<@doc>Gets the parent object
virtual readonly property parent = ^GmlObject;
<@doc>Gets the state that contains this object, if any
virtual readonly property state = ^CompositeState;
<@doc>Reference to a collection of configuration items configuring this element
virtual property config_item = ^ConfigurationItem[id];
virtual property canContain = [];
///////////////////////////////////////////////////////////////////////
// METHODS
<@doc>
Gets the tooltip text to display for the element
The scale at the which the element's text is currently displayed, relative to the reference coordinates system (1=actual size).
The tooltip text to display, or ~null if there is no tooltip
The tooltip text can contain any valid HTML markup.
The ~textScale parameter can be used as a condition for displaying the tooltip only when the scale is too small to render legible text.
method getTooltip(textScale)
return (textScale < 0.65 ? this.name : null);
end
<@doc>
Gets the UI Configuration by calling the rule defineUIConfiguration
The list of UI Configuration definitions - in the structure {key1:value1, key2:value2, ...}, where:
key is a concatenation of the name-spaced-command and the name-of-the-button-attribute.
For example, to disable the FieldSelector button, command is '#NS[OPEN_FIELDS_SELECTOR]' and attribute is "disable".
The key, in that case, will be UPPER('#NS[OPEN_FIELDS_SELECTOR]_disable');
The value is typically boolean, and depends on the attribute logic. For disable false means the button will work.
Note - since the command ID is kept in upper-case, the key must also be entered in UPPER case mode.
Note - since IDs in VC Core are upper-case, the key must be also entered in UPPER case mode.
method getUiConfiguration()
return RULE('defineUIConfiguration',this.unit, this);
end
override method onCreate()
if (!this.name) this.name = this.Class.metadata.namestem || '';
this.supercall();
end
override method setDirty(isSVGChange)
var d=this.unit;
if (d) d.setDirty(isSVGChange);
end
override method onRemoveMe(parent, trans)
this.supercall();
// if child belongs to a state, update the state's members collection
if (this.state) {
delete this.state.members[this.id];
}
//clear the related ConfigurationItem
//note: if an element is moved between diagrams, its configuration item will be cleared.
if (this.config_item)
for (var x in this.config_item) {
var item = this.config_item[x];
if (!item.parent) continue;
item.parent.removeItem(item);
}
end
///////////////////////////////////////////////////////////////////////
// TRANSLATION METHODS
<@doc>
Used for creating a new Text instance and an entry in the translation table
The translation type
The text to be translated
The newly genenrated key
override method insertTranslation(theType, value)
if(ISA(this.unit, 'gml:Scenario'))
{
// Call the scenarion function:
return this.unit.insertTranslation(theType, value, this);
}
end
<@doc>
Used for retrieving Text from the translation table
The key of the Text to retrieve
Whether called from DE engine or not
The translated text (and type in case of DE)
override method getTranslation(key, isDE)
if(ISA(this.unit, 'gml:Scenario'))
{
// Call the scenarion function:
return this.unit.getTranslation(key, isDE);
}
end
<@doc>
Used for updating Text instance and an entry in the translation table
The new text to be translated
The key of the Text object to update
Optional. Needed when the type is to be replaced
The updated key
override method updateTranslation(value, key, type)
if(ISA(this.unit, 'gml:Scenario'))
{
// Call the scenario function:
return this.unit.updateTranslation(value, key, type);
}
end
<@doc>
Used for removing Texts from the translation table
One or more (array) of Texts to remove
override method removeTranslation(key)
if(ISA(this.unit, 'gml:Scenario'))
{
// Call the scenario function:
this.unit.removeTranslation(key);
}
end
<@doc>
Check if the object or its children have translation implications - currently this means if it has links to Gml:Text objects
~true if it does have translation implications, ~false otherwise
override method hasTranslation(deep)
var table = this.unit && this.unit.translationTable;
if (table)
for (var i in table.items) {
if (table.items[i].objID==this.id) return(true);
}
//check children
if (deep && this.hasChildTranslation())
return(true);
return(false); //nothing found
end
//////////////////////////////////////////////////////////////////////
// TRANSACTIONS
transaction doInsertElement(unit, parent, child, prop_name, before,subType)
do, redo:
// insert the child element
setunit(child, unit);
child.parent = parent;
parent.children[child.id] = child; //update virtual property
parent.assignChild(child, prop_name,before);
// notify that the child element has been inserted
var evt = document.createEventObject();
evt.type = 'onInsertElement';
evt.object = parent;
evt.child = child;
evt.prop_name = prop_name;
evt.unit = unit;
evt.subType=subType;
$ENV.fireModelEvent(evt);
unit.setDirty();
// TODO: bubble this event to all parents instead of the two callbacks
if (parent.onInsert) parent.onInsert(child, this);
if (child.onInsertMe) child.onInsertMe(parent, this);
function setunit(e, d) {
e.unit = d;
d.all_elements[e.id] = e;
for (var k in e.children) setunit(e.children[k], d);
}
undo:
// remove the child element
if (parent.onRemove) parent.onRemove(child, this);
if (child.onRemoveMe) child.onRemoveMe(parent, this);
delete parent.children[child.id];
parent.clearChild(child, prop_name);
child.parent = null;
clrunit(child);
// notify that the child element has been removed
var evt = document.createEventObject();
evt.type = 'onRemoveElement';
evt.object = parent;
evt.child = child;
evt.unit = unit;
evt.prop_name = prop_name;
evt.subType=subType;
$ENV.fireModelEvent(evt);
unit.setDirty();
function clrunit(e) {
if (e.unit) {
delete e.unit.all_elements[e.id];
e.unit = null;
}
for (var k in e.children) clrunit(e.children[k]);
}
end
transaction doRemoveElement(unit, parent, child, prop_name,index,subType)
do, redo:
// remove the child element
if (parent.onRemove) parent.onRemove(child, this);
if (child.onRemoveMe) child.onRemoveMe(parent, this);
index = parent.clearChild(child, prop_name);
delete parent.children[child.id];
// notify that the child element has been removed
var evt = document.createEventObject();
evt.type = 'onRemoveElement';
evt.object = parent;
evt.child = child;
evt.unit = unit;
evt.subType=subType;
evt.prop_name = prop_name;
$ENV.fireModelEvent(evt);
// clear parent and unit properties after event was handled
child.parent = null;
clrunit(child);
unit.setDirty();
function clrunit(e) {
if (e.unit) {
delete e.unit.all_elements[e.id];
e.unit = null;
}
for (var k in e.children) clrunit(e.children[k]);
}
undo:
// insert the child element
setunit(child, unit);
child.parent = parent;
parent.children[child.id] = child;
parent.assignChild(child, prop_name,index);
// notify that the element has been inserted
var evt = document.createEventObject();
evt.type = 'onInsertElement';
evt.object = parent;
evt.child = child;
evt.unit = unit;
evt.subType = subType;
evt.prop_name = prop_name;
$ENV.fireModelEvent(evt);
unit.setDirty();
if (parent.onInsert) parent.onInsert(child, this);
if (child.onInsertMe) child.onInsertMe(parent, this);
function setunit(e, d) {
e.unit = d;
d.all_elements[e.id] = e;
for (var k in e.children) setunit(e.children[k], d);
}
end
method modifySVGProperty(svgproperty,color)
this[svgproperty]=color;
var evt = document.createEventObject();
evt.type = 'onUpdateObject';
evt.object = this;
evt.name = svgproperty;
evt.value = "";
$ENV.fireModelEvent(evt);
end
///////////////////////////////////////////////////////////////////////
// RULES
Configure RULES
$ENV.extendRule('definePropertyGroups', {
constraint:'(object isa gml:Element)',
behavior: function() {
groups.push({id: 'Behavior', type:'group', title:'Behavior', toggle:'off', inner:4, priority:400,
visible: 'ISA(data, "core.gml:ScenarioUsage", "core.gml:Interactor", "core.gml:EventLink")', sortBy:'label'});
},
comments:'⇒ [Behavior]'
});