Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 05cbcd2f220261bea3614ddfb0380d905c1d0c69 (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
/*****************************************************************************
 * Copyright (c) 2017 CEA LIST,ALL4TEC and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
 *   Etienne Allogo (ARTAL) - etienne.allogo@artal.fr - Bug 569174 : Remove reference to xpand/qvto
 *****************************************************************************/

package org.eclipse.papyrus.codegen;

import java.io.File;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.gmf.codegen.gmfgen.GenEditorGenerator;
import org.eclipse.papyrus.gmf.codegen.util.GeneratorWithXtend2;
import org.eclipse.papyrus.gmf.common.UnexpectedBehaviourException;

/**
 * Papyrus gmf generator.
 */
public class PapyrusGenerator extends GeneratorWithXtend2 {

	/**
	 * The Papyrus codegen Emitters.
	 */
	private final PapyrusCodegenEmitters emitters;

	/**
	 * The editor gen model.
	 */
	private GenEditorGenerator editorGen;

	/**
	 * Constructor.
	 */
	public PapyrusGenerator(final GenEditorGenerator genModel, final PapyrusCodegenEmitters codegenEmitters) {
		super(genModel, codegenEmitters);
		editorGen = genModel;
		emitters = codegenEmitters;
	}

	/**
	 * @see org.eclipse.papyrus.gmf.codegen.xtend.ui.handlers.GeneratorWithXtend2#customRun()
	 *
	 * @throws InterruptedException
	 * @throws UnexpectedBehaviourException
	 */
	@Override
	protected void customRun() throws InterruptedException, UnexpectedBehaviourException {
		super.customRun();
		// generatePaletteConfiguration(); // commented to disable paletteConfiguration model generation
	}

	/**
	 * Generate palette configuration model.
	 *
	 * @throws UnexpectedBehaviourException
	 * @throws InterruptedException
	 */
	@SuppressWarnings("restriction")
	protected void generatePaletteConfiguration() throws UnexpectedBehaviourException, InterruptedException {
		if (null == editorGen.getDiagram().getPalette()) {
			return;
		}
		doGenerateFile(emitters.getPaletteConfigurationEmitter(), new Path(getRelativePath() + File.separator + editorGen.getModelID() + ".paletteconfiguration"), editorGen); //$NON-NLS-1$
	}

	/**
	 * @return The relative path of the model's resource.
	 */
	protected String getRelativePath() {
		String path = null;

		URI resourceURI = editorGen.eResource().getURI();
		if (resourceURI.isPlatformResource()) {
			String platformString = resourceURI.toPlatformString(true);
			IPath workspacePath = new Path(platformString);
			workspacePath = workspacePath.removeFirstSegments(1);
			workspacePath = workspacePath.removeLastSegments(1);
			path = workspacePath.toString();
		} else {
			path = "model";//$NON-NLS-1$
		}
		return path;
	}

}

Back to the top