conditional style

Hi,

is there a way to define a conditional style?

F.e.: if property "isSome" is set to true, underline the name of the node and give it a blue text-foreground-color.

Thx,

Mirko

11 comments
Comment actions Permalink

Hello Mirko,

You can set query style value. And write something like this:

underlined : (node, editorContext)->boolean {
  <condition>
}

text-foreground-color : (node, editorContext)->Color {
  if (<condition>) {
    return Color.BLUE;
  } else {
    return Color.BLACK;
  }
}

Regards,

Evgeny

0
Comment actions Permalink

Hi Evgeny,

where do i have to put this query-style value? Actually i'm editing within the Editor-Inspector of a Property-Cell:

mps_style.PNG

Within the "Style"-section i can't define such conditions... I guess that place is wrong :-\

Thank you,

Mirko



Attachment(s):
mps_style.PNG
0
Comment actions Permalink

Hello Mirko,

Try to press Ctrl + Space on the value of style. In completion menu should be value query.

Picture.png

Regards, Evgeny



Attachment(s):
Picture.png
0
Comment actions Permalink

Hi Evgeny,

thank you very much!

it works perfect.

Regards,

Mirko

0
Comment actions Permalink
Hey,

the way described above doesn't work for me...

/_persistent/style.PNG?file=29-3894&v=0&c=true

I get an error, which i don't understand:
"Abstract concept instance detected: Use on of sub-concepts instead. Concept: Expression"

Any ideas? :-)
0
Comment actions Permalink
We perhaps need to see more of your code to be able to help you.
0
Comment actions Permalink
Which code you mean? Can you see the screenshot?

It's a very simple example.. just a concept called "stereotype" implementing INamedConcept and the editor only contains {name}.

My purpose is to change the text color, if the concept ist named "Hardware"
0
Comment actions Permalink
OK, the screen-shot link was broken, so I ignored it. My mistake.

Now, seeing the code I suspect you may need to provide the colors. ATM you are returning an instance of Expression, which is an abstract concepts (cannot be instantiated, thus the error).
Import the java.awt.* model (Control + M) and type Color.xxx
0
Comment actions Permalink
Thank you very much, Vaclav!! :-)

Now I can select a color... but my code still does not work. Seems like something is wrong with the if-condition node.name == "Hardware". But returning a color without condition works fine.

Sorry, i'm very new to MPS and language workbenches... very hard at the beginning :-\
0
Comment actions Permalink
It's good to see you progressing. You need to use the equals() method to compare strings reliably. Or better use the MPS' :eq: operator, which is a null-safe variant of equals.
0
Comment actions Permalink
:-) works fine. Thanks for the quick help!!
0

Please sign in to leave a comment.