use of org.eclipse.sirius.viewpoint.description.UserColor 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);
}
}
}
}
use of org.eclipse.sirius.viewpoint.description.UserColor 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());
}
}
}
Aggregations