Change color of UML element [message #1374802] |
Thu, 22 May 2014 20:18 |
Vinicius Pereira Messages: 50 Registered: March 2014 |
Member |
|
|
Hi everyone,
I can find and access a UML element in Model Explorer and Editor, using ID (from "XML schema") to find it.
ModelSet papyrusModelSet = registry.getService(ModelSet.class);
UmlModel umlModel = (UmlModel)papyrusModelSet.getModel(UmlModel.MODEL_ID);
EObject modelRoot = umlModel.lookupRoot();
Resource umlResource = modelRoot.eResource();
EObject umlElement = umlResource.getEObject(elementID.trim());
This UML element can be a State, a Transition, a Parameter, a Message...
In the case of State, the umlElement is a EObject/StateImpl. I know that I need to change the color in Shape#setFillColor(), but how I go from EObject/StateImpl to Shape/ShapeImpl?
I'm using Papyrus 1.0 in Eclipse Luna.
thank you
[Updated on: Mon, 14 July 2014 23:43] Report message to a moderator
|
|
|
|
Re: Change color of UML element [message #1401270 is a reply to message #1374802] |
Tue, 15 July 2014 11:22 |
|
Hi,
To get the View that visualizes your model element in a particular
diagram (this view may be a Shape or Edge of some kind), you can use
the org.eclipse.papyrus.uml.diagram.common.util.CrossReferenceUtil API.
Once you have the view, you can set colours and other visual attributes
in the notation model styles, yes, but you can also use CSS to specify
the same visual attributes. With a CSS stylesheet you can apply these
attributes more broadly for a diagram or all of the diagrams in a
project, using selectors to apply them automatically to views of
elements matching some criteria. See the on-line help for details.
HTH,
Christian
On 2014-05-22 20:18:35 +0000, Vinicius Pereira said:
> Hi everyone,
>
> I can find and access a UML element in Model Explorer and Editor, using
> ID (from "XML schema") to find it.
>
>
> ModelSet papyrusModelSet = registry.getService(ModelSet.class);
> UmlModel umlModel = (UmlModel)papyrusModelSet.getModel(UmlModel.MODEL_ID);
> EObject modelRoot = umlModel.lookupRoot();
>
> Resource umlResource = modelRoot.eResource();
> EObject umlElement = umlResource.getEObject(elementID.trim());
>
>
> This UML element can be a State, a Transition, a Parameter, a Message...
>
> In the case of State, the umlElement is a EObject/StateImpl. I know
> that I need to change the color in Shape#setFillColor(), but how I go
> from EObject/StateImpl to Shape/ShapeImpl?
>
>
> Another thing: for State I need Shape, for Transition I need Connector
> and Message I need Edge... but why I cannot change edge's color?
>
> I'm using Papyrus 1.0 in Eclipse Luna M7.
>
> thank you
|
|
|
Re: Change color of UML element [message #1402158 is a reply to message #1401270] |
Wed, 16 July 2014 15:58 |
Vinicius Pereira Messages: 50 Registered: March 2014 |
Member |
|
|
Christian W. Damus wrote on Tue, 15 July 2014 07:22Hi,
To get the View that visualizes your model element in a particular
diagram (this view may be a Shape or Edge of some kind), you can use
the org.eclipse.papyrus.uml.diagram.common.util.CrossReferenceUtil API.
Thanks for the tip! I will try.
Christian W. Damus wrote on Tue, 15 July 2014 07:22
Once you have the view, you can set colours and other visual attributes
in the notation model styles, yes, but you can also use CSS to specify
the same visual attributes. With a CSS stylesheet you can apply these
attributes more broadly for a diagram or all of the diagrams in a
project, using selectors to apply them automatically to views of
elements matching some criteria. See the on-line help for details.
For the CSS I saw that I cannot apply styles for each element. For example, State A with Blue and State B with Green.
But if I manage to get to Shape and use setFillColor() I will be happy
Thanks
|
|
|
Re: Change color of UML element [message #1402201 is a reply to message #1402158] |
Wed, 16 July 2014 17:25 |
|
Hi,
I suppose it depends on what the colours and other styling
characteristics are intended to signify. If they are meant to indicate
some kind of abstract properties of your model elements, then likely
you can devise selector criteria in your CSS rules based on the
attributes of those elements (including stereotypes applied to them):
the selector language pretty much has full access to the UML metamodel
(and applied profiles).
If it's just a matter of colour-coding specific elements using
arbitrary, then yes, the basic GMF notation styles should be sufficient.
Cheers,
Christian
On 2014-07-16 15:58:21 +0000, Vinicius Pereira said:
> Christian W. Damus wrote on Tue, 15 July 2014 07:22
>> Hi,
>>
>> To get the View that visualizes your model element in a particular
>> diagram (this view may be a Shape or Edge of some kind), you can use
>> the org.eclipse.papyrus.uml.diagram.common.util.CrossReferenceUtil API.
>
>
> Thanks for the tip! I will try.
>
> Christian W. Damus wrote on Tue, 15 July 2014 07:22
>> Once you have the view, you can set colours and other visual attributes
>> in the notation model styles, yes, but you can also use CSS to specify
>> the same visual attributes. With a CSS stylesheet you can apply these
>> attributes more broadly for a diagram or all of the diagrams in a
>> project, using selectors to apply them automatically to views of
>> elements matching some criteria. See the on-line help for details.
>
>
> For the CSS I saw that I cannot apply styles for each element. For
> example, State A with Blue and State B with Green.
>
> But if I manage to get to Shape and use setFillColor() I will be happy :)
>
> Thanks
|
|
|
|
|
|
|
Re: Change color of UML element [message #1730458 is a reply to message #1714989] |
Mon, 25 April 2016 23:53 |
Da Mist Messages: 9 Registered: November 2015 |
Junior Member |
|
|
Hi Vinicius,
Could you please tell me, how to get CSSShapeImpl without selecting any object in the editor?
I got the vertex of the region of a particular shatemachine by using region.getSubvertex(stateName).
This is giving me a org.eclipse.uml2.uml type vertex.
But I am not able to convert it CSSShapeImpl.
Could you please help me in this regard?
Thanks!
[Updated on: Mon, 25 April 2016 23:54] Report message to a moderator
|
|
|
|
Re: Change color of UML element [message #1730467 is a reply to message #1730459] |
Tue, 26 April 2016 05:31 |
Da Mist Messages: 9 Registered: November 2015 |
Junior Member |
|
|
Hi Vinicius,
Thank you so much for your reply.
Right now I am able to get EObject. But I am not getting the view.
What is the type of the view? And how to get it from EObject?
Here is how I have tried to do it:
State st = (State) region.getSubvertex(stateName);
EObject eobj = st;
if(eobj instanceof State) {
View view = (View)((State) eobj).getModel();
if(view instanceof CSSShapeImpl) {
CSSShapeImpl spI = (CSSShapeImpl) view;
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(spI);
domain.getCommandStack().execute(new RecordingCommand(domain) {
@Override
protected void doExecute() {
// TODO Auto-generated method stub
spI.setFillColor(432718);
}
});
}
But it is giving this error:
org.eclipse.uml2.uml.internal.impl.ModelImpl cannot be cast to org.eclipse.gmf.runtime.notation.View
Please help me!
Thanks!
[Updated on: Tue, 26 April 2016 05:59] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04789 seconds