extensions.Customization.ext Maven / Gradle / Ivy
import pom;
extension org::openxma::xmadsl::Extensions;
extension org::openxma::dsl::common::extensions::LogUtil;
emf::EObject getCustomModelElement(emf::EObject targetNode, emf::EObject sourceNode,emf::EObject objectToFind):
let path = getRelativModelObjectPath(objectToFind,sourceNode):
let foundElement = targetNode.findElementByRelativePath(path):
/*
log("Source node: "+sourceNode)->
log("Target node: "+targetNode)->
logListElements("Path element: ",path)->
log("Object to find: "+objectToFind)->
log("Object found: "+foundElement)->
*/
foundElement;
/**
* Call of add customizations default implementation
*/
Void addCustomization(CustomizationOfGuiElement customization, Component component, Component customComponent):
error("Default implementation called for addCustomization")->
null;
/**
* Add customizations of IComposite
*/
Void addCustomization(CustomizationOfComposite customization, Component component, Component customComponent):
let customComposite = (IComposite)customComponent.getCustomModelElement(component,customization.composite):
customComposite.addCustomContent(customization.addedWidgetSetItems,customization.addedElements)->
null;
/**
* Add customizations of ITabFolder
*/
Void addCustomization(CustomizationOfTabFolder customization, Component component, Component customComponent):
let customTabFolder = (ITabFolder)customComponent.getCustomModelElement(component,customization.tabFolder):
customTabFolder.addCustomTabPages(customization.addedTabItems)->
null;
/**
* Add custom content
*/
Void addCustomContent(ComplexElement complexElement, List[SetOfGuiElements] simpleElementSetItems, List[ComposedElement] complexElementItems):
error("Default implementation called for addCustomContent")->
null;
Void addCustomContent(IComposite composite, List[SetOfGuiElements] simpleElementSetItems, List[ComposedElement] complexElementItems):
composite.content.widgetSetItems.addAll(simpleElementSetItems)->
composite.content.elements.addAll(complexElementItems)->
null;
/**
* Add custom tabPage
*/
Void addCustomTabPages(ITabFolder tabFolder, List[TabPage] tabPages):
tabFolder.tabItems.addAll(tabPages)->
null;
/**
* Create a model-object-path starting from a defined container-node in the model.
*/
List[emf::EObject] getRelativModelObjectPath(emf::EObject obj, emf::EObject containerNode):
(obj.eContainer != containerNode)
? obj.eContainer.getRelativModelObjectPath(containerNode).add(obj)
: createEObjectList().add(obj);
/**
*
*/
List[emf::EObject] createEObjectList():
let list = (List[emf::EObject]){}:
list;
/**
* Try to find a model element described by the path. The search is
* started from a model element which (direct or indirect=nested) contains
* the element to be found.
*
* The path is a list of model elements beginning with the top level model
* element used for the search.
*
* This method can for example be used to find a corrsponding model-element
* in a copied model.
*
**/
emf::EObject findElementByRelativePath(emf::EObject startContainerNode, List[emf::EObject] path):
let currentChildren = startContainerNode.eContents:
let matchingChild = (currentChildren.size>0)
? currentChildren.selectFirst(e|e.equalsObject(path.get(0)))
: null:
(matchingChild != null)
? findXMAPathElement(matchingChild,path)
: null;
/**
* Compare objects by id
*
* Maybe it is not necessary to write this method and just compare 2 objects with operator '=='.
*/
boolean equalsObject(emf::EObject e1, emf::EObject e2):
(e1.metaType != e2.metaType)
? false
: ( let id1 = e1.id():
let id2 = e2.id():
(id1 != null && id2 != null)
? id1 == id2
: ( if (id1==null) then log("!! Id not found: e1= "+e1.metaType+", id= "+id1)->
if (id2==null) then log("!! Id not found: e2= "+e2.metaType+", id= "+id2)->
false)
);
emf::EObject findXMAPathElement(emf::EObject currentElement, List[emf::EObject] path):
JAVA org.openxma.xmadsl.LinkerUtil.findXMAPathElement(org.eclipse.emf.ecore.EObject, java.util.List);