Skip to content

Commit

Permalink
Add API for properties and actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mypsycho committed Jun 11, 2024
1 parent 5af18e2 commit d6cf1b8
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import org.eclipse.sirius.viewpoint.description.tool.InitialNodeCreationOperatio
import org.eclipse.sirius.viewpoint.description.tool.ModelOperation

import static extension org.mypsycho.modit.emf.sirius.api.SiriusDesigns.*
import org.eclipse.sirius.viewpoint.description.DecorationDescriptionsSet

/**
* Adaptation of Sirius model into Java and EClass reflections API
Expand Down Expand Up @@ -447,6 +448,14 @@ abstract class AbstractDiagramPart<T extends EObject> extends AbstractTypedEditi
customization.vsmElementCustomizations
}

/** Gets decorations of a layer. */
def getDecorationDescriptions(Layer it) {
if (decorationDescriptionsSet === null) {
decorationDescriptionsSet = DecorationDescriptionsSet.create
}
decorationDescriptionsSet.decorationDescriptions
}

/**
* Add customization on assembly.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ import org.eclipse.sirius.viewpoint.description.validation.ValidationFix

import static extension org.mypsycho.modit.emf.sirius.api.SiriusDesigns.*
import org.eclipse.sirius.properties.PageDescription
import org.eclipse.sirius.properties.GroupOverrideDescription
import org.eclipse.sirius.properties.PageOverrideDescription

/**
* Adaptation of Sirius model into Java and EClass reflections API
Expand Down Expand Up @@ -138,7 +140,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
*
* @param expression to evaluate
*/
protected def toOperation(String expression) {
def toOperation(String expression) {
ChangeContext.create[ browseExpression = expression ]
}

Expand All @@ -147,7 +149,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
*
* @param expression to evaluate
*/
protected def toContext(String expression, ModelOperation... subOperations) {
def toContext(String expression, ModelOperation... subOperations) {
expression.toOperation.andThen [
subModelOperations += subOperations
]
Expand All @@ -166,7 +168,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
expression.toContext(subOperations)
}

protected def toTool(ModelOperation operation) {
def toTool(ModelOperation operation) {
InitialOperation.create[
firstModelOperations = operation
]
Expand All @@ -179,7 +181,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param expression of value
* @return a new SetValue
*/
protected def setter(String featureExpr, String value) {
def setter(String featureExpr, String value) {
SetValue.create[
featureName = featureExpr
valueExpression = value
Expand All @@ -193,7 +195,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param expression of value
* @return a new SetValue
*/
protected def SetValue setter(EStructuralFeature feature, String expression) {
def SetValue setter(EStructuralFeature feature, String expression) {
feature.name.setter(expression)
}

Expand All @@ -203,7 +205,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param feature to set
* @return a new SetValue
*/
protected def SetValue setter(EStructuralFeature feature) {
def SetValue setter(EStructuralFeature feature) {
feature.setter(SiriusDesigns.PROP_VALUE)
}

Expand All @@ -214,7 +216,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param expr expression of value
* @return a new SetValue
*/
protected def <T> SetValue setter(EStructuralFeature feature,
def <T> SetValue setter(EStructuralFeature feature,
Functions.Function1<? extends EObject, ?> expr) {
SetValue.create[
featureName = feature.name
Expand All @@ -224,18 +226,18 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {


/** Creates a 'CreateIntance' operation. */
protected def creator(EReference ref, Class<? extends EObject> instanceType) {
def creator(EReference ref, Class<? extends EObject> instanceType) {
ref.name.creator(instanceType)
}

/** Creates a 'CreateIntance' operation. */
protected def creator(String refName, Class<? extends EObject> instanceType) {
def creator(String refName, Class<? extends EObject> instanceType) {
refName.creator(instanceType.asDomainClass)
}

/** Deprecated: use typed signature. */
// for reverse template only
protected def creator(String refName, String instanceType) {
def creator(String refName, String instanceType) {
CreateInstance.create [
referenceName = refName
typeName = instanceType
Expand All @@ -248,7 +250,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param expression of value
* @return a new RemoveElement
*/
protected def remover(String expression) {
def remover(String expression) {
expression.toOperation.chain(RemoveElement.create)
}

Expand All @@ -259,7 +261,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param expression of element
* @return a new Unset
*/
protected def unsetter(String feature, String expression) {
def unsetter(String feature, String expression) {
Unset.create [
featureName = feature
elementExpression = expression
Expand All @@ -273,7 +275,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param expression of element
* @return a new Unset
*/
protected def unsetter(EStructuralFeature feature, String expression) {
def unsetter(EStructuralFeature feature, String expression) {
expression.unsetter(feature.name)
}

Expand All @@ -284,7 +286,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param expression of element
* @return a new Unset
*/
protected def letDo(String expression, String varName, ModelOperation... operations) {
def letDo(String expression, String varName, ModelOperation... operations) {
Let.create [
variableName = varName
valueExpression = expression
Expand All @@ -299,7 +301,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
}

/** Creates a 'switch' operation. */
protected def switchDo(Pair<String, ? extends ModelOperation>... subCases) {
def switchDo(Pair<String, ? extends ModelOperation>... subCases) {
Switch.create[
cases += subCases.map[ descr |
Case.create [
Expand All @@ -313,7 +315,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
}

/** Sets a default case to a 'Switch' operation. */
protected def setByDefault(Switch it, ModelOperation operation) {
def setByDefault(Switch it, ModelOperation operation) {
andThen[
// must be performed after original empty default
^default = Default.create[
Expand All @@ -323,26 +325,26 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
}

/** Creates a 'If' operation. */
protected def ifThenDo(String expression, ModelOperation... operations) {
expression.thenDo(operations)
}

/** Creates a 'If' operation. Use ifThenDo */
@Deprecated
protected def thenDo(String expression, ModelOperation... operations) {
def ifThenDo(String expression, ModelOperation... operations) {
If.create [
conditionExpression = expression
subModelOperations += operations
]
}

/** Creates a 'If' operation. Use 'ifThenDo' ! */
@Deprecated
def thenDo(String expression, ModelOperation... operations) {
expression.ifThenDo(operations)
}

/**
* Creates a 'For' operation.
*
* @param it 'iterator' -&gt; 'collection'
* @param operations to perform
*/
protected def forDo(Pair<String, String> it, ModelOperation... operations) {
def forDo(Pair<String, String> it, ModelOperation... operations) {
value.forDo(key, operations)
}

Expand All @@ -353,7 +355,7 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
* @param iter iterator name
* @param operations to perform
*/
protected def forDo(String valuesExpression, String iter, ModelOperation... operations) {
def forDo(String valuesExpression, String iter, ModelOperation... operations) {
For.create [
expression = valuesExpression
iteratorName = iter
Expand Down Expand Up @@ -389,48 +391,39 @@ abstract class AbstractEdition extends AbstractIdentifiableElement {
]
}

/** Creates an external java action. */
def javaDo(Class<?> actionId, String name, Pair<String, String>... params) {
actionId.name.javaDo(name, params)
}

/** Creates an external java action. */
def javaDo(String actionId, String name, Pair<String, String>... params) {
ExternalJavaAction.create(name) [
id = actionId
parameters += params.map[ key.jparam(value) ]
]
}

/**
* Sets the operation for provided widget.
* <p>
* Widget may be used in wizard operation of all views.
* </p>
* <p>
* This class unifies the initialOperation declaration of sub-class tool.
* </p>
* @param it tool to set
* @param value operation to perform
*/
/** Adds an action to a group. */
def action(GroupDescription owner, String label, String icon, ModelOperation operation) {
label.createToolAction(icon, operation) => [ owner.actions += it ]
}

/**
* Sets the operation for provided widget.
* <p>
* Widget may be used in wizard operation of all views.
* </p>
* <p>
* This class unifies the initialOperation declaration of sub-class tool.
* </p>
* @param it tool to set
* @param value operation to perform
*/
/** Adds an action to a page. */
def action(PageDescription owner, String label, String icon, ModelOperation operation) {
label.createToolAction(icon, operation) => [ owner.actions += it ]
}


/** Adds an action to a group. */
def action(GroupOverrideDescription owner, String label, String icon, ModelOperation operation) {
label.createToolAction(icon, operation) => [ owner.actions += it ]
}

/** Adds an action to a page. */
def action(PageOverrideDescription owner, String label, String icon, ModelOperation operation) {
label.createToolAction(icon, operation) => [ owner.actions += it ]
}

/**
* Sets the operation for provided widget.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@
*******************************************************************************/
package org.mypsycho.modit.emf.sirius.api

import java.util.Collections
import java.util.HashMap
import java.util.Iterator
import java.util.Map
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.sirius.diagram.description.AbstractNodeMapping
import org.eclipse.sirius.diagram.description.DiagramDescription
import org.eclipse.sirius.diagram.description.EdgeMapping
import org.eclipse.sirius.properties.PageDescription
import org.eclipse.sirius.properties.ViewExtensionDescription
import org.eclipse.sirius.viewpoint.description.Group
import org.eclipse.sirius.viewpoint.description.IdentifiedElement
import org.eclipse.sirius.viewpoint.description.RepresentationDescription
import org.eclipse.sirius.viewpoint.description.UserColor
import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription
import org.eclipse.sirius.viewpoint.description.tool.ExternalJavaAction
import java.util.Collections
import java.util.Iterator
import org.eclipse.sirius.properties.GroupDescription
import org.eclipse.sirius.properties.PageOverrideDescription
import org.eclipse.sirius.properties.GroupOverrideDescription

/**
* Convenient methods and constants to handle dependencies between Sirius designs.
Expand Down Expand Up @@ -85,6 +89,10 @@ class SiriusDependencies {
RepresentationDescription: aliasBase + toClassname.apply(it)
ViewExtensionDescription: aliasBase + toClassname.apply(it)

PageDescription: '''page:«aliasBase»«name»'''
GroupDescription: '''group:«aliasBase»«name»'''
PageOverrideDescription: '''page+:«aliasBase»«name»'''
GroupOverrideDescription: '''group+:«aliasBase»«name»'''
}
}

Expand All @@ -105,9 +113,10 @@ class SiriusDependencies {
}

static def getDependencyExtras(
String designId, ResourceSet rs, String resourcePath
String designId, ResourceSet rs,
String resourcePath
) {
designId.getDependencyExtras(rs, resourcePath, [ SiriusDesigns.toClassname(it) ])
designId.getDependencyExtras(rs, resourcePath) [ SiriusDesigns.toClassname(it) ]
}

static def getDependencyExtras(
Expand Down Expand Up @@ -136,7 +145,6 @@ class SiriusDependencies {
DiagramDescription it, String aliasBase, (EObject)=>String toClassname
) {
val result = new HashMap<EObject, String>

result += #{ it as EObject -> getExtraAlias(aliasBase, toClassname) }

val representationAlias = aliasBase + toClassname.apply(it) + "#"
Expand All @@ -145,6 +153,30 @@ class SiriusDependencies {
result
}

private static def dispatch Map<EObject, String> mapDependencyExtras(
ViewExtensionDescription it, String aliasBase, (EObject)=>String toClassname
) {
val result = new HashMap<EObject, String>
result += #{ it as EObject -> getExtraAlias(aliasBase, toClassname) }

val uniqueExt = (eContainer as Group)
.extensions
.filter(ViewExtensionDescription)
.size == 1
val extAlias = aliasBase + (uniqueExt ? "" : name)

val uniqueCat = categories.size > 1
categories.forEach[
val categoryAlias = uniqueExt && uniqueCat
? aliasBase
: '''«extAlias»«uniqueCat ? '_' + name : ""»#'''
result += pages.toDependencyExtras(categoryAlias, toClassname)
result += groups.toDependencyExtras(categoryAlias, toClassname)
]

result
}

private static def dispatch Map<EObject, String> mapDependencyExtras(
Group it, String aliasBase, (EObject)=>String toClassname
) {
Expand All @@ -155,15 +187,22 @@ class SiriusDependencies {
.flatMap[ ownedRepresentations + ownedRepresentationExtensions ]
.forEach [ result += mapDependencyExtras(aliasBase, toClassname) ]

ownedViewpoints
extensions
.filter(ViewExtensionDescription)
.forEach [ result += mapDependencyExtras(aliasBase, toClassname) ]

result += paletteColors.iterator().toDependencyExtras(aliasBase, toClassname)
result += paletteColors.toDependencyExtras(aliasBase, toClassname)

result
}

static def toDependencyExtras(
Iterable<? extends EObject> values, String aliasBase,
(EObject)=>String toClassname
) {
values.iterator.toDependencyExtras(aliasBase, toClassname)
}

static def toDependencyExtras(
Iterator<? extends EObject> values, String aliasBase,
(EObject)=>String toClassname
Expand Down
Loading

0 comments on commit d6cf1b8

Please sign in to comment.