Search in sources :

Example 1 with UserFixedColor

use of org.eclipse.sirius.viewpoint.description.UserFixedColor in project InformationSystem by ObeoNetwork.

the class ClassDiagramGenerator method addPalette.

private void addPalette(Configuration configuration, Viewpoint viewpointFromTemplate) {
    if (configuration.getColors().isEmpty() == false) {
        // Get Group from template
        Group groupFromTemplate = null;
        if (viewpointFromTemplate.eContainer() instanceof Group) {
            groupFromTemplate = (Group) viewpointFromTemplate.eContainer();
        }
        // get group
        EObject eContainer = configuration.getViewpoint().eContainer();
        if (eContainer instanceof Group) {
            Group group = (Group) eContainer;
            UserColorsPalette palette = null;
            if (group.getUserColorsPalettes().isEmpty()) {
                // We have to create a user color palette
                palette = DescriptionFactory.eINSTANCE.createUserColorsPalette();
                palette.setName("Palette");
                AddCommand addCommand = new AddCommand(editingDomain, group, DescriptionPackage.Literals.GROUP__USER_COLORS_PALETTES, palette);
                editingDomain.getCommandStack().execute(addCommand);
            } else {
                // use the first palette
                palette = group.getUserColorsPalettes().get(0);
            }
            for (ColorInfo colorInfo : configuration.getColors()) {
                // Check if color exists
                UserFixedColor newColor = null;
                for (UserColor userColor : palette.getEntries()) {
                    if (userColor instanceof UserFixedColor && userColor.getName().equals(colorInfo.getName())) {
                        newColor = (UserFixedColor) userColor;
                        break;
                    }
                }
                if (newColor == null) {
                    newColor = DescriptionFactory.eINSTANCE.createUserFixedColor();
                    AddCommand addCommand = new AddCommand(editingDomain, palette, DescriptionPackage.Literals.USER_COLORS_PALETTE__ENTRIES, newColor);
                    editingDomain.getCommandStack().execute(addCommand);
                }
                newColor.setName(colorInfo.getName());
                newColor.setRed(colorInfo.getRed());
                newColor.setGreen(colorInfo.getGreen());
                newColor.setBlue(colorInfo.getBlue());
            }
            // representation descriptions must reference the new palette
            if (palette != null) {
                replaceColorReferences(groupFromTemplate, group, configuration.getColors(), palette);
            }
        }
    }
}
Also used : Group(org.eclipse.sirius.viewpoint.description.Group) UserColorsPalette(org.eclipse.sirius.viewpoint.description.UserColorsPalette) UserFixedColor(org.eclipse.sirius.viewpoint.description.UserFixedColor) EObject(org.eclipse.emf.ecore.EObject) UserColor(org.eclipse.sirius.viewpoint.description.UserColor) ColorInfo(org.obeonetwork.tools.classdiagramconfiguration.ColorInfo) AddCommand(org.eclipse.emf.edit.command.AddCommand)

Example 2 with UserFixedColor

use of org.eclipse.sirius.viewpoint.description.UserFixedColor in project InformationSystem by ObeoNetwork.

the class ClassDiagramGenerator method replaceColorReferences.

private void replaceColorReferences(Group groupFromTemplate, Group newGroup, Collection<ColorInfo> generationColors, UserColorsPalette palette) {
    // Retrieve colors in the odesign templates
    Collection<UserColor> defaultUserColors = new ArrayList<UserColor>();
    for (ColorInfo generationColor : generationColors) {
        for (UserColorsPalette defaultPalette : groupFromTemplate.getUserColorsPalettes()) {
            for (UserColor defaultColor : defaultPalette.getEntries()) {
                if (defaultColor instanceof UserFixedColor && defaultColor.getName().equals(generationColor.getName())) {
                    defaultUserColors.add(defaultColor);
                }
            }
        }
    }
    // we have to change references to these colors to the corresponding ones in the new palette
    Map<UserColor, UserColor> colorCorrespondances = new HashMap<UserColor, UserColor>();
    for (UserColor userColor : defaultUserColors) {
        for (UserColor newColor : palette.getEntries()) {
            if (newColor instanceof UserFixedColor && userColor.getName().equals(newColor.getName())) {
                colorCorrespondances.put(userColor, newColor);
            }
        }
    }
    // find references to the default color
    for (Entry<UserColor, UserColor> entry : colorCorrespondances.entrySet()) {
        Collection<Setting> settings = EcoreUtil.UsageCrossReferencer.find(entry.getKey(), newGroup.eResource().getResourceSet());
        for (Setting setting : settings) {
            EcoreUtil.replace(setting.getEObject(), setting.getEStructuralFeature(), entry.getKey(), entry.getValue());
        }
    }
}
Also used : UserColorsPalette(org.eclipse.sirius.viewpoint.description.UserColorsPalette) UserFixedColor(org.eclipse.sirius.viewpoint.description.UserFixedColor) HashMap(java.util.HashMap) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) ArrayList(java.util.ArrayList) UserColor(org.eclipse.sirius.viewpoint.description.UserColor) ColorInfo(org.obeonetwork.tools.classdiagramconfiguration.ColorInfo)

Aggregations

UserColor (org.eclipse.sirius.viewpoint.description.UserColor)2 UserColorsPalette (org.eclipse.sirius.viewpoint.description.UserColorsPalette)2 UserFixedColor (org.eclipse.sirius.viewpoint.description.UserFixedColor)2 ColorInfo (org.obeonetwork.tools.classdiagramconfiguration.ColorInfo)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EObject (org.eclipse.emf.ecore.EObject)1 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)1 AddCommand (org.eclipse.emf.edit.command.AddCommand)1 Group (org.eclipse.sirius.viewpoint.description.Group)1