Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7fbbc0387dbbc66b5ea0a62570b042641aa308e4 (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
/*****************************************************************************
 * 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:
 *  Ansgar Radermacher  ansgar.radermacher@cea.fr
 *
 *****************************************************************************/

package org.eclipse.papyrus.qompass.designer.core.templates;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.FCM.BindingHelper;
import org.eclipse.papyrus.FCM.Template;
import org.eclipse.papyrus.qompass.designer.core.extensions.BindingHelperExt;
import org.eclipse.papyrus.qompass.designer.core.listeners.PostCopyListener;
import org.eclipse.papyrus.qompass.designer.core.transformations.LazyCopier;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.TemplateBinding;
import org.eclipse.uml2.uml.util.UMLUtil;

/**
 * Specific tweaking of template instantiation is implemented by means of a PostCopyListener that
 * evaluates the template stereotype.
 * Chiefly used for text templates
 */
public class PostTemplateInstantiationListener implements PostCopyListener {

	public static PostTemplateInstantiationListener getInstance() {
		if (postTemplateInstantiationListener == null) {
			postTemplateInstantiationListener = new PostTemplateInstantiationListener();
		}
		return postTemplateInstantiationListener;
	}

	public void init(LazyCopier copy, TemplateBinding binding) {
		this.binding = binding;
	}

	private TemplateBinding binding;

	private static PostTemplateInstantiationListener postTemplateInstantiationListener;

	@Override
	public void postCopyEObject(LazyCopier copy, EObject targetEObj) {
		if (targetEObj instanceof Element) {

			Template template = UMLUtil.getStereotypeApplication((Element) targetEObj, Template.class);
			if ((template != null)) {
				BindingHelper helper = template.getHelper();
				if (helper != null) {
					BindingHelperExt.applyPostHelper(helper, copy, binding, targetEObj);
				}
			}
		}
	}
}

Back to the top