Custom Figure Implementation

Hello,

I want to implement a custom figure implementation to customize the rendering of diagram nodes.

For that purpose, I found a section in the book "The MPS Language Workbench" by Fabien Camagne. (Page 221)

So, I created a baseLanguage Class in the sandbox.solution 

@Figure

public class NewFigure extends View {

}

and now I attempt to do a property field as described in the book:

@FigureParameter

public Property<Integer> width = new ValueProperty<Integer>(100);

but the "Property<PrimitiveType>" as well as "@FigureParameter" is not found in the scope, although I think, I added all necessary models and languages. 

Thanks in advance and kindly regards!

Volker

1 comment
Comment actions Permalink

I have no idea about the diagram-stuff you are trying to do, but in situations like the ones you describe, what I usually do is I search for instances of the nodes I need within the Project Scope and then copy/paste an instance into my root.

So, in your case, I searched for "FigureParameterAttribute" by means of Ctrl/Cmd+N (2x). ThereI opened the find-usages dialog (Ctrl/Cmd+Alt+Shift+F7) and searched like so:

I found a usage in MovableContentView, and upon pasting it into my file, MPS asks me to import the following:

Notice that you seem to can toggle the FigureParameterAttribute only by means of a intention:

This intention only applies for public static fields and if the extended classifiers contain ViewPropertySpec, apparently:

error intention : false 
available in child nodes : true
child filter : <all child nodes>

description(node, editorContext)->string {
return node.@figureParameterPropertySpecification == null ? "Add figure parameter attribute" : "Remove figure parameter attribute";

}

isApplicable(editorContext, node)->boolean {
if (!node.visibility.isInstanceOf(PublicVisibility)) { return false; }
node<ClassifierType> classifierType = node.type as ClassifierType;
if (classifierType == null && classifierType.classifier == null) { return false; }

set<node<Classifier>> allExtendedClassifiers = classifierType.classifier.getAllExtendedClassifiers();
return allExtendedClassifiers.contains(node/ViewPropertySpec/);
}

execute(node, editorContext)->void {
if (node.@figureParameterPropertySpecification != null) {
node.@figureParameterPropertySpecification = null;
} else {
node.@figureParameterPropertySpecification = new node<FigureParameterAttributeViewProperty>();
}
}
0

Please sign in to leave a comment.