Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Change colour of specific node from code
Change colour of specific node from code [message #1798850] Mon, 26 November 2018 15:29 Go to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
Hi all,

I would like to know, if it is possible to change the colour of specific nodes by code.
In my project I create a model with the help of sirius editor. Then I use the another Add-on (henshin) for graph pattern matching on the model file. In the final step I would like to change the colour of certain nodes.
I read, that I should use java services to achieve my goal but I can't get it to work. My two problems are, that I don't know how to change the style properties when I only have the Eobject instance and I don't know how to call the service from outside the sirius editor. In the sirius tutorial it is only shown how to start a service from within the editor.

Any help is appreciated.

Regards
Florian
Re: Change colour of specific node from code [message #1798908 is a reply to message #1798850] Tue, 27 November 2018 10:38 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
Hi Florian,

Regarding your context I suggest the following:


  • You create a Style customization https://www.eclipse.org/sirius/doc/specifier/diagrams/Diagrams.html#customization with a selection property customization on color property that will apply to all mappings that can have their color changed.

  • In the predicate expression you call a service with aql:self.doChangeColor('red'). In the service doChangeColor you test that you have a graph pattern matching result somewhere in a singleton for example. If so you check if the color provided as parameter must be applied and return true if so. False otherwise

  • You do a custom style for each color that can be used and call the service with the right color.

  • Then either you do a tool that will call the pattern matching from a service. In this case the color refresh will be done automatically. Or if your pattern matching algorithm is triggered outside of Sirius, either you do manual refresh of the diagram or you call a refresh from Sirius API directly at the end of the algorithm execution.


Is this solution ok for you?

Regards,



Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Tue, 27 November 2018 10:41]

Report message to a moderator

Re: Change colour of specific node from code [message #1798998 is a reply to message #1798908] Wed, 28 November 2018 13:34 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
Hi Pierre,

Thank you for your suggestions. Thanks to your answer I can change the color of nodes.

But I still struggle with executing a service from outside the sirius editor. Could you hep me with that too?

Regards,
Florian
Re: Change colour of specific node from code [message #1799040 is a reply to message #1798998] Thu, 29 November 2018 09:33 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
Hi,

I don't understand why you want to use a service from outside the Sirius Editor. You don't need to with the solution I propose.
What service do you want to call outside of Sirius editor?
Service is a concept specific to odesign that call be called in mappings and tools defined. If you are outside you just have to use java code and do what you want.
Do you mean you don't know how to set a java class containing services in the odesign? In this case you have to add a new java extension under your viewpoint item in the odesign with the qualified name of your class containing the service. Then you will have access to its services in interpreted expressions of your VSM

Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Thu, 29 November 2018 09:34]

Report message to a moderator

Re: Change colour of specific node from code [message #1799047 is a reply to message #1799040] Thu, 29 November 2018 11:46 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
Hi,

I followed the first two points of your suggestion and thus managed to change the colour of specific nodes. Since they shall only be changed from grey to red I think point three is not needed (right?). I used the automatically created service in the odesign.

The problem is, that the service is called every time a new node is placed. But I want to place all my nodes without changing their colour and later start the graph pattern matching and based on that change the colour.

What I need right now is a way to refresh the graph and give him the results from the graph pattern matching.

(I am new to sirius, so I apologise if this sounds stupid)

Regards,
Florian
Re: Change colour of specific node from code [message #1799089 is a reply to message #1799047] Thu, 29 November 2018 16:20 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
A question is never stupid ;)

The service changing color to red in the customization must be base on existing graph pattern matching result.
I.e your service mustRedColorBeAppliedToElement(EObject semanticElement) in the color customization expression will look like this:

public boolean mustRedColorBeAppliedToElement(EObject semanticElement){
if(PatternMathingResult.instance.getResults()!=null){
    //if semanticElement should be red regarding the results then return true else return false.
}

}


where PatternMathingResult is a singleton java instance where you put the result of your matching algorithm when executed.

If no results are present, then it will return false and the color will not be changed.

At the end of the execution you also must refresh your diagram with Sirius APIorg.eclipse.sirius.ui.business.api.dialect.DialectUIServices.refreshEditor(DialectEditor, IProgressMonitor)

Then your element will turn to red automatically. If you want to remove the red color you just have to clear the results in the singleton.

Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Thu, 29 November 2018 16:21]

Report message to a moderator

Re: Change colour of specific node from code [message #1799143 is a reply to message #1799089] Fri, 30 November 2018 12:41 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
Hi,

I didn't know about singletons, so I had to read up a little about the concept. It seems quite fitting for my purposes but there is a problem I couldn't solve. How can the editor and the external java class (which is looking for risk patterns) access this singleton class?

Right now I have two runtimes (like in the tutorial). In the first one I created the ecore model. The second one is started through running the .editor project as another eclipse instance. In the second instance is the sirius editor with the .odesign file. The singleton class is supposed to be in the same project as the pattern matching class in the first runtime, right?

For better understanding:
1. Runtime: Ecore model, .edit project, .editor project, pattern matching project
2. Runtime: Sirius editor project (with .odesign file), project with models for testing purposes

The problem is, that I can't place the singleton class in the sirius project nor in the pattern matching project because of the accessibility.

Regards,
Florian
Re: Change colour of specific node from code [message #1799244 is a reply to message #1799089] Mon, 03 December 2018 13:03 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
Has anyone an idea? I realy don't know how to proceede from here.
That is kind of frustrating since I am nearly done. The only thing missing is the exchange of information between the graph pattern project and the sirius editor.
Re: Change colour of specific node from code [message #1799246 is a reply to message #1799143] Mon, 03 December 2018 13:21 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
Hi Florian,

I don't understand why the singleton could not be in the pattern matching project?
For me you should have Sirius editor project depending on pattern matching project because you are using its results. Am I right?
If so, then you should put the result in the pattern matching project singleton that should already exists.
This is the plugin activator you can specify in the MANIFEST.MF of the plugin. If it does not exist you can create it. It is a singleton where you can put some information.
It will look like :
public class TestClass implements BundleActivator {
    public static  TestClass INSTANCE;
    @Override
    public void start(BundleContext context) throws Exception {
        INSTANCE = this;
    }

    @Override
    public void stop(BundleContext context) throws Exception {
    }

}


You can put the result here (TestClass.INSTANCE.setResults(...)). This is the easier option. Then it is accessible by using TestClass.INSTANCE.getResults() in odesign project and services.

Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Mon, 03 December 2018 13:22]

Report message to a moderator

Re: Change colour of specific node from code [message #1799255 is a reply to message #1799246] Mon, 03 December 2018 14:40 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
Hi Pierre,

sorry if this gets annoying.
I tried it the way you describe it. I created the TestClass and set it as activator in the Manifest.MF of the Pattern Matching project. Then I added the pattern matching project to the dependencies of the sirius editor project.
The TestClass can obviously get accessed by the pattern matching class (as it is in the same project) but the services class doesn't know the TestClass.
It seems to me, that i am missing something here. Do you have any idea where I went wrong?

Regards,
Florian
Re: Change colour of specific node from code [message #1799257 is a reply to message #1799255] Mon, 03 December 2018 14:49 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
Have you exported the package containing the activator in the manifest in runtime section so the plugin Sirius project can use it in the service class? If so you should be able to import the TestClass in the service class and use it.

Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Mon, 03 December 2018 14:52]

Report message to a moderator

Re: Change colour of specific node from code [message #1799260 is a reply to message #1799257] Mon, 03 December 2018 15:08 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
I added it to the list but that didn't change anything.
Do you think it is a problem, that the projects are in different workspaces? (As far as I know they have to, when you have two instances of eclipse running)
Re: Change colour of specific node from code [message #1799261 is a reply to message #1799260] Mon, 03 December 2018 15:26 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
When you say " the services class doesn't know the TestClass" what do you mean exactly?
You should be able to import the class before being able to use it.

What is in your dev workspace is loaded in your launched runtime by default. If you were able to find the project in the dependencies of the odseign project then that means it is loaded.


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Mon, 03 December 2018 15:31]

Report message to a moderator

Re: Change colour of specific node from code [message #1799262 is a reply to message #1799261] Mon, 03 December 2018 15:35 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
I mean normally you start writing the class name and Eclipse suggests the right import. But in this case it doesn't.

When I try importing it manually, only projects from the same workspace can be imported.
Re: Change colour of specific node from code [message #1799263 is a reply to message #1799262] Mon, 03 December 2018 16:17 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
The steps to use a class C from a project A in a class C2 in a project B are the following:
- In A export package containing the class and make it visible to all plugins
- In B add a dependency to A
- Import C in C2

If all previous are done and the class cannot be found it means the plugin containing it is not loaded either because it is not selected in the runtime configuration to be launched. Or because the plugin had an error while loading (you will see this kind of information in the console of your first eclipse that had launched the runtime where sirius project is).
Check the section" plug-ins" of your launched Eclipse application to see if either "all" option is selected or the plugin pattern matching is checked.




Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

[Updated on: Mon, 03 December 2018 16:18]

Report message to a moderator

Re: Change colour of specific node from code [message #1799265 is a reply to message #1799263] Mon, 03 December 2018 17:27 Go to previous messageGo to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
You are completely right. All I had to do was restart eclipse and I could finally import the singleton class. But as you might have guessed already I have a follow up question : )
While it is possible to call the class from both sides, the INSTANCE is always null. Even when I try something like:
TestClass.INSTANCE.setResult("Test");
in the pattern matching project (where the singleton class is).
Re: Change colour of specific node from code [message #1799294 is a reply to message #1799265] Tue, 04 December 2018 10:28 Go to previous messageGo to next message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 249
Registered: June 2017
Senior Member
Is your singleton correctly defined in the manifest in the activator text field with full qualified name?

If not the start(BundleContext context) method will not be called and thus the instance will not be initialized. You can put a breakpoint to see if it is called.

Otherwise you can use

private TestClass instance=new TestClass()

But it should work.


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Change colour of specific node from code [message #1799769 is a reply to message #1799294] Thu, 13 December 2018 11:22 Go to previous message
Florian Kunz is currently offline Florian KunzFriend
Messages: 17
Registered: September 2018
Junior Member
Sorry for the delayed reply but I had to finalize the project or rather I had to get it working. In the end it didn't work out the way I wanted because I couldn't get the singleton to work properly.

The reason it wasn't initialized was a check missing in the manifest of the project containing the project. ("Activate this plug-in when one of its classes is loaded"). With this check the sirius project was able to access the singleton instance properly but the Graph-Pattern Matching class in the project containing the singleton couldn't. It was always null.
In the end I created an xml File witch contained the findings of the Graph-Pattern Matching and let both projects access it. The path had to be hard coded so it's far from optimal but it works for now.
The current problem is rather me not knowing enough about plug-in development and singletons. So I will dig deeper into that. Thanks to you I know where I have to look.

Thanks a lot for all your help. I greatly appreciate it.
Previous Topic:How to represent CData,Text,comment,ProcessingInstruction in eclipse sirius
Next Topic:conditionally hiding a visual element
Goto Forum:
  


Current Time: Thu Aug 22 18:12:59 GMT 2019

Powered by FUDForum. Page generated in 0.02457 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top