Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7971f03dfd28d79c3ce19400cb33388c188ea42b (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*****************************************************************************
 * 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:
 *  Remi Schnekenburger (CEA LIST) - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.infra.extendedtypes;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.gmf.runtime.emf.type.core.IContainerDescriptor;
import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
import org.eclipse.gmf.runtime.emf.type.core.NullElementMatcher;
import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;


/**
 * Factory to create Aspect Semantic Element Types from their {@link AspectSemanticTypeConfiguration}
 */
public class AspectSemanticTypeFactory extends AbstractConfigurableElementTypeFactory<AspectSemanticTypeConfiguration> {

	/**
	 * Default Constructor
	 */
	public AspectSemanticTypeFactory() {
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected IEditHelperAdvice createEditHelperAdvice(AspectSemanticTypeConfiguration configuration) {
		List<SemanticActionConfiguration> semanticActionConfigurations = configuration.getActionConfiguration();
		List<IEditHelperAdvice> actionAdvices = new ArrayList<IEditHelperAdvice>(semanticActionConfigurations.size()); 
		for(SemanticActionConfiguration actionConfiguration : semanticActionConfigurations) {
			IEditHelperAdvice advice = AspectConfigurationFactoryRegistry.getInstance().createEditHelperAdvice(actionConfiguration);
			if(advice!=null) {
				actionAdvices.add(advice);
			} else {
				Activator.log.error("Impossible to create an advice for :" + actionConfiguration, null);
			}
		}
		if(actionAdvices!=null && actionAdvices.size() > 0) {
			return new ComposedEditHelperAdvice(actionAdvices);
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected IContainerDescriptor createContainerDescriptor(AspectSemanticTypeConfiguration configuration) {
		List<SemanticActionConfiguration> semanticActionConfigurations = configuration.getActionConfiguration();
		List<IContainerDescriptor> containerDescriptors = new ArrayList<IContainerDescriptor>(semanticActionConfigurations.size()); 
		for(SemanticActionConfiguration actionConfiguration : semanticActionConfigurations) {
			IContainerDescriptor containerDescriptor = AspectConfigurationFactoryRegistry.getInstance().createContainerDescriptor(actionConfiguration);
			if(containerDescriptor!=null) {
				containerDescriptors.add(containerDescriptor);
			} else {
				Activator.log.error("Impossible to create an advice for :" + actionConfiguration, null);
			}
		}
		if(containerDescriptors!=null && containerDescriptors.size() > 0) {
			return new ComposedContainerDescriptor(containerDescriptors);
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ICreationElementValidator createElementCreationValidator(AspectSemanticTypeConfiguration configuration) {
		List<SemanticActionConfiguration> semanticActionConfigurations = configuration.getActionConfiguration();
		List<ICreationElementValidator> actionValidators = new ArrayList<ICreationElementValidator>(semanticActionConfigurations.size()); 
		for(SemanticActionConfiguration actionConfiguration : semanticActionConfigurations) {
			ICreationElementValidator validator = AspectConfigurationFactoryRegistry.getInstance().createCreationElementValidator(actionConfiguration);
			if(validator!=null) {
				actionValidators.add(validator);
			} else {
				Activator.log.error("Impossible to create an advice for :" + actionConfiguration, null);
			}
		}
		if(actionValidators!=null && actionValidators.size() > 0) {
			return new ComposedElementCreationValidator(actionValidators);
		}
		return null;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected IElementMatcher createElementMatcher(AspectSemanticTypeConfiguration configuration) {
		// these element types are there only for creation => it can not be match at any time
		return new NullElementMatcher();
	}
}

Back to the top