| /******************************************************************************* |
| * Copyright (c) 2015 THALES GLOBAL SERVICES. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Obeo - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.sirius.business.internal.migration; |
| |
| import java.util.List; |
| |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.sirius.business.api.metamodel.helper.FontFormatHelper; |
| import org.eclipse.sirius.business.api.migration.AbstractMigrationParticipant; |
| import org.eclipse.sirius.viewpoint.FontFormat; |
| import org.eclipse.sirius.viewpoint.ViewpointPackage; |
| import org.osgi.framework.Version; |
| |
| import com.google.common.collect.Lists; |
| |
| /** |
| * Remove the old font format attribute values used before the multi valued |
| * label font format attribute. |
| * |
| * @author mbats |
| */ |
| public class FontFormatMigrationParticipant extends AbstractMigrationParticipant { |
| |
| private static final Version MIGRATION_VERSION = new Version("10.0.0.201505222000"); |
| |
| private static final String ITALIC = "italic"; |
| |
| private static final String BOLD = "bold"; |
| |
| @Override |
| public Version getMigrationVersion() { |
| return MIGRATION_VERSION; |
| } |
| |
| @Override |
| public Object getValue(EObject object, EStructuralFeature feature, Object value, String loadedVersion) { |
| List<FontFormat> labelFormat = Lists.newArrayList(); |
| // All features typed by FontFormat have been modified: the cardinality |
| // has been changed from [0..1] to [0..n], the value, which was a |
| // FontFormat, now has to be a list of FontFormat. |
| // The previous "normal" value correspond to an empty list. |
| if (feature.getEType() == ViewpointPackage.Literals.FONT_FORMAT && value instanceof String) { |
| String oldFontFormat = (String) value; |
| if (oldFontFormat.contains(ITALIC)) { |
| FontFormatHelper.setFontFormat(labelFormat, FontFormat.ITALIC_LITERAL); |
| } |
| // The previous "bold_italic" value is treated by the two |
| // "if contains" blocks. |
| if (oldFontFormat.contains(BOLD)) { |
| FontFormatHelper.setFontFormat(labelFormat, FontFormat.BOLD_LITERAL); |
| } |
| } |
| |
| if (labelFormat.isEmpty()) { |
| return null; |
| } |
| return labelFormat.toString().replaceAll(",", "").replace("[", "").replace("]", ""); |
| } |
| } |