Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1b7a086cf0f5b10fa45d8b00d15d86cc745cf089 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST.
 *
 *    
 * 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:
 *  Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.nattable.utils;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.infra.nattable.Activator;
import org.eclipse.papyrus.infra.nattable.messages.Messages;
import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.PasteEObjectConfiguration;


/**
 * Utils class for paste actions
 * 
 * @author VL222926
 * 
 */
public class PasteConfigurationUtils {


	private PasteConfigurationUtils() {
		//to prevent instanciation
	}

	/**
	 * 
	 * @param pasteConfiguration
	 *        a paste configuration
	 * @return
	 *         a status describing the consistence of the paste configuration
	 */
	public static IStatus hasConsistentPasteEObjectConfiguration(final PasteEObjectConfiguration pasteConfiguration) {
		Assert.isNotNull(pasteConfiguration);
		final String pluginId = Activator.PLUGIN_ID;
		final EStructuralFeature feature = pasteConfiguration.getPasteElementContainementFeature();
		if(feature == null) {
			return new Status(IStatus.ERROR, pluginId, Messages.PasteConfigurationUtils_ContainmentFeatureIsNull);
		} else if(feature instanceof EReference) {
			if(!((EReference)feature).isContainment()) {
				return new Status(IStatus.ERROR, pluginId, Messages.PasteConfigurationUtils_ContainmentFeatureIsNotAReferenceContainment);
			}
			final String elementId = pasteConfiguration.getPastedElementId();
			if(elementId != null && !elementId.equals("")) { //$NON-NLS-1$
				final IElementType elementType = ElementTypeRegistry.getInstance().getType(elementId);
				if(elementType != null) {
					final EClass elementTypeMetaclass = elementType.getEClass();
					final EClass containmentFeatureEClass = (EClass)feature.getEType();
					boolean knownFeature = elementTypeMetaclass == containmentFeatureEClass || containmentFeatureEClass.isSuperTypeOf(elementTypeMetaclass);
					if(knownFeature) {
						return new Status(IStatus.OK, pluginId, Messages.PasteConfigurationUtils_PasteConfigurationIsConsistent);
					} else {
						return new Status(IStatus.ERROR, pluginId, NLS.bind(Messages.PasteConfigurationUtils_CreatesElementsAreNotCompatibleWithContainmentFeature, elementId, containmentFeatureEClass.getName()));
					}
				} else {
					return new Status(IStatus.ERROR, pluginId, NLS.bind(Messages.PasteConfigurationUtils_ElementTypeCantBeFound, elementId));
				}
			} else {
				return new Status(IStatus.ERROR, pluginId, Messages.PasteConfigurationUtils_ElementIdNotDefined);
			}
		} else {
			return new Status(IStatus.ERROR, pluginId, Messages.PasteConfigurationUtils_ContainementFeatureIsNotAReference);
		}
	}
}

Back to the top