Colorize Eclasses and EReferenzes in .ecore_diagram (GMF)

27 Views Asked by At

Is there a "normal" way to Colorize the Nodes and Edges in the .ecore_diagram programaticaly?

My Code so far:

private static void saveDiagram(ResourceSet resourceSet,
        EPackage epackage, String path) {
    URI uri= URI.createFileURI(path);
    Resource overlapResource = resourceSet.createResource(uri, "ecore");


    overlapResource.getContents().add(epackage);
    Diagram d = createDiagram(epackage);

    URI diagUri = URI.createFileURI(path + "_diagram");
    Resource diagramResource = resourceSet.createResource(diagUri, "ecore");
    d.setName(diagUri.lastSegment());
    diagramResource.getContents().add(d);

    diagramResource.save(null); //In try catch block
    overlapResource.save(null); //In try catch block
}

public static Diagram createDiagram(EObject object) {
    Diagram diagram = NotationFactory.eINSTANCE.createDiagram();
    diagram.setMeasurementUnit(MeasurementUnit.PIXEL_LITERAL);
    diagram.setElement(object);
    diagram.setType("Ecore");
    return diagram;
}

I have the ecore file, ecore_diagram file and the EPackage... I dont know.. should I go throw all EClasses and EReferences and ... what?

Thx for Help!

2

There are 2 best solutions below

0
Banoffee On

"ecore_diagram" files are no longer supported, you are probably on a very old version of Eclipse modeling...

My guess would be to first identify the feature you need to change in the ecore_diagram format. Open the file as a text file and find the node you want to modify, then find the property you need to change. Validate that it does what you want.

Then do the same, programatically. Navigate from your Diagram instance down to the elements holding the property you need to change, change that property's value and save the model.

0
sali333 On

Here is a way for doing it in the case of a node for example :

In someway get the group of my odesign :

Group group = odesign.getGroup()

You create first a UserColorPalette :

UserColorsPalette colorPallette = org.eclipse.sirius.viewpoint.description.DescriptionFactory.eINSTANCE
                .createUserColorsPalette();
group.getUserColorsPalettes().add(colorPallette);
UserFixedColor fixedColor = org.eclipse.sirius.viewpoint.description.DescriptionFactory.eINSTANCE
            .createUserFixedColor();
colorPallette.getEntries().add(fixedColor);
fixedColor.setBlue(226);
fixedColor.setGreen(189);
fixedColor.setRed(161);

Then you add you use your style in your Node.

 NodeMapping nmd = DescriptionFactory.eINSTANCE.createNodeMapping();
 SquareDescription sd = StyleFactory.eINSTANCE.createSquareDescription();
 sd.setColor(attributesFixedColor);
 nmd.setStyle(sd);