Skip to content

Commit

Permalink
Unify API usage for domain class.
Browse files Browse the repository at this point in the history
  • Loading branch information
mypsycho committed Jul 17, 2024
1 parent e5204af commit 5191b58
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ abstract class AbstractBaseDiagram<T extends DiagramDescription> extends Abstrac
* @param descrLabel displayed on representation groups
* @param domain class of diagram
*/
new(Class<T> type, SiriusVpGroup parent, String descrLabel, Class<? extends EObject> domain) {
super(type, parent, descrLabel)
new(Class<T> type, SiriusVpGroup parent, String label, Class<? extends EObject> domain) {
super(type, parent, label)

this.domain = domain
creationTasks.add[
domainClass = context.asDomainClass(domain)
domainClass = domain.asDomainClass
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
}

public static val STYLE = StylePackage.eINSTANCE
public static val DSTYLE = org.eclipse.sirius.diagram.description.style.StylePackage.eINSTANCE
public static val DSTYLE = org.eclipse.sirius.diagram.description.style
.StylePackage.eINSTANCE

/**
* Creates a factory for a diagram description
Expand Down Expand Up @@ -145,7 +146,7 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
* @param type of the description
*/
def void setDomainClass(AbstractNodeMapping it, Class<? extends EObject> type) {
domainClass = context.asEClass(type) as EClass
domainClass = type.asEClass
}

/**
Expand All @@ -161,7 +162,6 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
domainClass = SiriusDesigns.encode(type)
}


/**
* Sets the domain class of a mapping.
* <p>
Expand All @@ -172,7 +172,7 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
* @param type of the description
*/
def void setDomainClass(EdgeMapping it, Class<? extends EObject> type) {
domainClass = context.asEClass(type) as EClass
domainClass = type.asEClass
}

/**
Expand All @@ -189,7 +189,6 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
useDomainElement = true
}


/**
* Sets the candidates expression using a reference.
* <p>
Expand All @@ -208,12 +207,12 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
name = ref.name
}
if (it instanceof AbstractNodeMapping) {
if (domainClass === null || domainClass.empty) {
domainClass = SiriusDesigns.encode(ref.EType)
if (domainClass === null || domainClass.blank) {
domainClass = ref.EType as EClass
}
} else if (it instanceof EdgeMapping) {
if (domainClass === null || domainClass.empty) {
domainClass = SiriusDesigns.encode(ref.EType)
if (domainClass === null || domainClass.blank) {
domainClass = ref.EType as EClass
}
}
}
Expand Down Expand Up @@ -245,7 +244,8 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
// when using a image in node,
// we usually don't want icon on label
showIcon = false
(it as BorderedStyleDescription).borderSizeComputationExpression = "0" // hide border
// hide border
(it as BorderedStyleDescription).borderSizeComputationExpression = "0"
}

if (it instanceof BundledImageDescription) {
Expand All @@ -262,8 +262,8 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
* @param it mapping to set
* @param init initialization of the style
*/
def <T extends ContainerStyleDescription>
style(ContainerMapping it, Class<T> type, (T)=>void init
def <T extends ContainerStyleDescription> style(
ContainerMapping it, Class<T> type, (T)=>void init
) {
style = type.createStyle(init)
}
Expand All @@ -277,8 +277,8 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
* @param it mapping to set
* @param init initialization of the style
*/
def <T extends NodeStyleDescription>
style(NodeMapping it, Class<T> type, (T)=>void init
def <T extends NodeStyleDescription> style(
NodeMapping it, Class<T> type, (T)=>void init
) {
style = type.createStyle(init)
}
Expand All @@ -294,8 +294,9 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
* @param condition of style application
* @param init of created style (after default initialization)
*/
def <T extends ContainerStyleDescription>
styleIf(ContainerMapping owner, Class<T> type, String condition, (T)=>void init
def <T extends ContainerStyleDescription> styleIf(
ContainerMapping owner, Class<T> type,
String condition, (T)=>void init
) {
// Init is required as default styling make not sense
Objects.requireNonNull(init, "Conditional Style cannot have default properties")
Expand All @@ -319,8 +320,8 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
* @param condition of style application
* @param init of created style (after default initialization)
*/
def <T extends NodeStyleDescription>
styleIf(NodeMapping owner, Class<T> type, String condition, (T)=>void init
def <T extends NodeStyleDescription> styleIf(
NodeMapping owner, Class<T> type, String condition, (T)=>void init
) {
// Init is required as default styling make not sense
Objects.requireNonNull(init, "Conditional Style cannot have default properties")
Expand Down Expand Up @@ -520,42 +521,48 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi

/** Customizes a style reference with provided value. */
def customizeRef(
BasicLabelStyleDescription it, String condition, String styleReference, EObject value
BasicLabelStyleDescription it, String condition,
String styleReference, EObject value
) {
customizeFeatures(condition, styleReference.styleRef(value))
}

/** Customizes a style attribute with provided expression. */
def void customize(
BasicLabelStyleDescription it, String condition, String styleAttribute, String expression
BasicLabelStyleDescription it, String condition,
String styleAttribute, String expression
) {
customizeFeatures(condition, styleAttribute.styleAtt(expression))
}

/** Customizes a style reference with provided value. */
def customize(
BasicLabelStyleDescription it, String condition, EReference styleReference, EObject value
BasicLabelStyleDescription it, String condition,
EReference styleReference, EObject value
) {
customizeRef(condition, styleReference.name, value)
}

/** Customizes a style attribute with provided expression. */
def customize(
BasicLabelStyleDescription it, String condition, EAttribute styleAttribute, String expression
BasicLabelStyleDescription it, String condition,
EAttribute styleAttribute, String expression
) {
customize(condition, styleAttribute.name, expression)
}

/** Customizes style properties. */
def void customizeFeatures(
BasicLabelStyleDescription it, String condition, EStructuralFeatureCustomization... featCustoms
BasicLabelStyleDescription it, String condition,
EStructuralFeatureCustomization... featCustoms
) {
doCustoms(condition, featCustoms)
}

/** Customizes a style reference with provided value. */
def customizeRef(
EdgeStyleDescription it, String condition, String styleReference, EObject value
EdgeStyleDescription it, String condition,
String styleReference, EObject value
) {
customizeFeatures(condition, styleReference.styleRef(value))
}
Expand Down Expand Up @@ -583,7 +590,8 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi

/** Customizes style properties. */
def void customizeFeatures(
EdgeStyleDescription it, String condition, EStructuralFeatureCustomization... featCustoms
EdgeStyleDescription it, String condition,
EStructuralFeatureCustomization... featCustoms
) {
doCustoms(condition, featCustoms)
}
Expand Down Expand Up @@ -720,7 +728,9 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
}

/** Creates a delete description. */
protected def createElementDelete(String toolName, Enum<?> namespace, ModelOperation task) {
protected def createElementDelete(
String toolName, Enum<?> namespace, ModelOperation task
) {
Objects.requireNonNull(task)
// Alias is required as mapping declare drops
DeleteElementDescription.createAs(namespace, toolName) [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
labelSize = 10 // ODesign is provide 12, but eclipse default is Segoe:9
labelColor = SystemColor.extraRef("color:black")

labelExpression = context.itemProviderLabel
labelExpression = itemProviderLabel
}

/** Initializes variables of the tool. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ abstract class AbstractIdentifiableElement {
cat.name.id(path)
}


/**
* Creates an identification with provided category.
* <p>
Expand Down Expand Up @@ -181,7 +180,7 @@ abstract class AbstractIdentifiableElement {
* @param path of element
*/
protected def String id(String category, String root, String path) {
context.createId(category, root, path)
category.createId(root, path)
}

/**
Expand Down Expand Up @@ -250,7 +249,7 @@ abstract class AbstractIdentifiableElement {
Class<R> type, Class<? extends AbstractIdentifiableElement> container,
Enum<?> cat, String name
) {
type.ref(context.getContentAlias(container), cat, name)
type.ref(container.contentAlias, cat, name)
}

/**
Expand All @@ -267,7 +266,7 @@ abstract class AbstractIdentifiableElement {
Class<R> type, Class<? extends AbstractIdentifiableElement> container,
Enum<?> cat, String name, (IdentifiedElement)=> R path
) {
type.ref(context.getContentAlias(container), cat, name, path)
type.ref(container.contentAlias, cat, name, path)
}


Expand All @@ -279,7 +278,7 @@ abstract class AbstractIdentifiableElement {
* @param name of element
*/
protected def refId(Class<? extends AbstractIdentifiableElement> container, Enum<?> cat, String name) {
cat.id(context.getContentAlias(container), name)
cat.id(container.contentAlias, name)
}

/**
Expand Down Expand Up @@ -355,7 +354,7 @@ abstract class AbstractIdentifiableElement {
* @return aql expression
*/
def asAql(Class<? extends EObject> type) {
context.asEClass(type).asAql
type.asEClass().asAql
}

/** Aql shortcut to evaluate a type. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.eclipse.sirius.viewpoint.FontFormat
import org.eclipse.sirius.viewpoint.description.tool.ModelOperation

import static extension org.mypsycho.modit.emf.sirius.api.SiriusDesigns.*
import org.eclipse.emf.ecore.EClass

/**
* Adaptation of Sirius model into Java and EClass reflections API
Expand Down Expand Up @@ -87,15 +88,19 @@ abstract class AbstractPropertySet extends AbstractEdition {
this(parent, DEFAULT_NAME)
}

def void setDomainClass(GroupDescription it, Class<? extends EObject> value) {
domainClass = value.asDomainClass
def void setDomainClass(GroupDescription it, Class<? extends EObject> type) {
domainClass = type.asEClass
}

def void setDomainClass(GroupDescription it, EClass type) {
domainClass = SiriusDesigns.encode(type)
}

/** Creates the content of Property Description. */
def ViewExtensionDescription createContent() {
ViewExtensionDescription.createAs(Ns.view.id(extensionName)) [
name = extensionName
metamodels += context.businessPackages
metamodels += businessPackages
initCategories
]
}
Expand Down Expand Up @@ -280,11 +285,6 @@ abstract class AbstractPropertySet extends AbstractEdition {
def createAction(String label, ModelOperation operation) {
label.createAction(null, operation)
}

// ECore API has no constraint.
def String asDomainClass(Class<? extends EObject> type) {
context.asDomainClass(type)
}

def param(CustomDescription it, String key, String value) {
customExpressions += CustomExpression.create [
Expand All @@ -302,7 +302,7 @@ abstract class AbstractPropertySet extends AbstractEdition {
}

def page(Category owner, String name, Class<? extends EObject> domain, (PageDescription)=>void init) {
owner.page(name, domain.asAql, init)
owner.page(name, domain.asDomainClass, init)
}

def groups(PageDescription owner, String... names) {
Expand All @@ -320,7 +320,7 @@ abstract class AbstractPropertySet extends AbstractEdition {
}

def group(Category owner, String name, Class<? extends EObject> domain, (GroupDescription)=>void init) {
owner.group(name, domain.asAql, init)
owner.group(name, domain.asDomainClass, init)
}

def noTitle(GroupDescription it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ abstract class AbstractTable<T extends TableDescription> extends AbstractTypedEd
*
* @param parent of diagram
*/
new(Class<T> type, SiriusVpGroup parent, String dLabel, Class<? extends EObject> dClass) {
super(type, parent, dLabel)
new(Class<T> type, SiriusVpGroup parent, String label, Class<? extends EObject> domain) {
super(type, parent, label)
creationTasks.add [
domainClass = context.asDomainClass(dClass)
domainClass = domain.asDomainClass
]
}

Expand All @@ -97,7 +97,7 @@ abstract class AbstractTable<T extends TableDescription> extends AbstractTypedEd
* @param type of the description
*/
def void setDomainClass(LineMapping it, Class<? extends EObject> type) {
domainClass = context.asDomainClass(type)
domainClass = type.asEClass
}

/**
Expand Down Expand Up @@ -305,7 +305,7 @@ abstract class AbstractTable<T extends TableDescription> extends AbstractTypedEd
* @param action(root target, line target, line view)
*/
def setDelete(LineMapping it, Procedure2<EObject, EObject> action) {
delete = context.expression(LINE_DELETE_ARGS.params, action).toOperation
delete = LINE_DELETE_ARGS.params.expression(action).toOperation
}

/**
Expand Down Expand Up @@ -400,7 +400,7 @@ abstract class AbstractTable<T extends TableDescription> extends AbstractTypedEd
def createLine(String line, String role, String toolLabel,
Procedure3<EObject, EObject, EObject> action
) {
line.createLine(toolLabel, role, context.expression(CREATE_LINE_PARAMS, action).toOperation)
line.createLine(toolLabel, role, CREATE_LINE_PARAMS.expression(action).toOperation)
}

/**
Expand Down Expand Up @@ -434,7 +434,7 @@ abstract class AbstractTable<T extends TableDescription> extends AbstractTypedEd
def createAddLine(TableDescription owner, String line, String role, String toolLabel,
Procedure3<EObject, EObject, EObject> action
) {
val op = context.expression(CREATE_LINE_PARAMS, action).toOperation
val op = CREATE_LINE_PARAMS.expression(action).toOperation
line.createLine(toolLabel, role, op) => [
owner.ownedCreateLine += it
]
Expand Down Expand Up @@ -471,7 +471,7 @@ abstract class AbstractTable<T extends TableDescription> extends AbstractTypedEd
def createAddLine(LineMapping owner, String line, String role, String toolLabel,
Procedure3<EObject, EObject, EObject> action
) {
val op = context.expression(CREATE_LINE_PARAMS, action).toOperation
val op = CREATE_LINE_PARAMS.expression(action).toOperation
line.createLine(toolLabel, role, op) => [
owner.create += it
]
Expand Down
Loading

0 comments on commit 5191b58

Please sign in to comment.