Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1f1da509c57877c7eb4e881173a39056b86ca166 (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
/*****************************************************************************
 * 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.invariantsemantictypeconfiguration;

import java.util.Arrays;
import java.util.Collections;

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.edithelper.IEditHelperAdvice;
import org.eclipse.papyrus.infra.extendedtypes.AbstractConfigurableElementTypeFactory;
import org.eclipse.papyrus.infra.extendedtypes.ComposedElementMatcher;
import org.eclipse.papyrus.infra.extendedtypes.ICreationElementValidator;

/**
 * Factory used to create ElementType from a {@link InvariantSemanticTypeConfiguration}.
 */
public class InvariantElementTypeFactory extends AbstractConfigurableElementTypeFactory<InvariantSemanticTypeConfiguration> {

	/**
	 * {@inheritDoc}
	 */
	public ICreationElementValidator createElementCreationValidator(InvariantSemanticTypeConfiguration configuration) {
		return RuleConfigurationFactoryRegistry.getInstance().createCreationElementValidator(configuration.getInvariantRuleConfiguration());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected String getSemanticHint(InvariantSemanticTypeConfiguration configuration) {
		return configuration.getHint();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected IEditHelperAdvice createEditHelperAdvice(InvariantSemanticTypeConfiguration configuration) {
		return RuleConfigurationFactoryRegistry.getInstance().createEditHelperAdvice(configuration.getInvariantRuleConfiguration());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected IContainerDescriptor createContainerDescriptor(InvariantSemanticTypeConfiguration configuration) {
		return  RuleConfigurationFactoryRegistry.getInstance().createContainerDescriptor(configuration.getInvariantRuleConfiguration());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected IElementMatcher createElementMatcher(InvariantSemanticTypeConfiguration configuration) {
		IElementMatcher superMatcher = super.createElementMatcher(configuration);
		if(superMatcher !=null)  {
			// create a composed matcher to have the matcher described by the model configuration element type and the one for the specific invariants
			IElementMatcher invariantMatcher = RuleConfigurationFactoryRegistry.getInstance().createMatcher(configuration.getInvariantRuleConfiguration());
			ComposedElementMatcher composedMatcher = new ComposedElementMatcher(Arrays.asList(superMatcher, invariantMatcher));
			return composedMatcher;
		}
		// no configured matcher. Return the invariant one
		return RuleConfigurationFactoryRegistry.getInstance().createMatcher(configuration.getInvariantRuleConfiguration());
	}
	
}

Back to the top