Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a8b216736a9dbc7665609854c56d88bb6c5e55b7 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*******************************************************************************
 * Copyright (c) 2007, 2020 Borland Software Corporation, CEA LIST, Artal 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: 
 *    Dmitry Stadnik (Borland) - initial API and implementation
 *    Michael Golubev (Montages) - #386838 - migrate to Xtend2
 *    Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174
 *    Etienne Allogo (ARTAL) - etienne.allogo@artal.fr - Bug 569174 : L1.2 clean up + missing NLS
 *****************************************************************************/
package xpt.editor

import com.google.inject.Inject
import org.eclipse.papyrus.gmf.codegen.gmfgen.GenDiagram
import org.eclipse.papyrus.gmf.codegen.xtend.annotations.Localization
import xpt.Common
import xpt.Externalizer
import xpt.CodeStyle

@com.google.inject.Singleton class CreationWizardPage {

	@Inject extension CodeStyle;
	@Inject extension Common;

	@Inject Externalizer xptExternalizer;
	@Inject DiagramEditorUtil xptDiagramEditorUtil;

	def className(GenDiagram it) '''«creationWizardPageClassName»'''

	def packageName(GenDiagram it) '''«it.editorGen.editor.packageName»'''

	def qualifiedClassName(GenDiagram it) '''«packageName(it)».«className(it)»'''

	def fullPath(GenDiagram it) '''«qualifiedClassName(it)»'''

	def extendsList(GenDiagram it) '''extends « //
		IF editorGen.application === null »org.eclipse.ui.dialogs.WizardNewFileCreationPage« //
		ELSE»«editorGen.application.packageName».WizardNewFileCreationPage«ENDIF»'''

	def CreationWizardPage(GenDiagram it) '''
		«copyright(editorGen)»
		package «packageName(it)»;

		«generatedClassComment»
		public class «className(it)» «extendsList(it)» {

			«generatedMemberComment»
			private final String fileExtension;

			«generatedMemberComment»
			public «className(it)»(String pageName, org.eclipse.jface.viewers.IStructuredSelection selection, String fileExtension) {
			super(pageName, selection);
			this.fileExtension = fileExtension;
			}

			«generatedMemberComment('Override to create files with this extension.')» 
			protected String getExtension() {
				return fileExtension;
			}

			«generatedMemberComment»
			public org.eclipse.emf.common.util.URI getURI() {
			«IF editorGen.application === null »
				return org.eclipse.emf.common.util.URI.createPlatformResourceURI(getFilePath().toString(), false);
			«ELSE»
				return org.eclipse.emf.common.util.URI.createFileURI(getFilePath().toString());
			«ENDIF»
			}
			«IF editorGen.application === null »

				«generatedMemberComment»
				protected org.eclipse.core.runtime.IPath getFilePath() {
					org.eclipse.core.runtime.IPath path = getContainerFullPath();
					if (path == null) {
						path = new org.eclipse.core.runtime.Path(""); //$NON-NLS-1$
					}
					String fileName = getFileName();
					if (fileName != null) {
						path = path.append(fileName);
					}
					return path;
				}
			«ENDIF»

			«generatedMemberComment»
			«overrideC»
			public void createControl(org.eclipse.swt.widgets.Composite parent) {
				super.createControl(parent);
				setFileName(«xptDiagramEditorUtil.qualifiedClassName(it)».getUniqueFileName(getContainerFullPath(), getFileName(), getExtension()));
				setPageComplete(validatePage());
			}

			«generatedMemberComment»
			«overrideC»
			protected boolean validatePage() {
				if (!super.validatePage()) {
					return false;
				}
				String extension = getExtension();
				if (extension != null && !getFilePath().toString().endsWith("." + extension)) { «nonNLS»
					setErrorMessage(org.eclipse.osgi.util.NLS.bind(«xptExternalizer.accessorCall(editorGen, i18nKeyForCreationWizardPageExtensionError(it))», extension));
					return false;
				}
				return true;
			}
		}
	'''

	def i18nValues(GenDiagram it) '''
		«xptExternalizer.messageEntry(i18nKeyForCreationWizardPageExtensionError(it), 'File name should have {0} extension.')»
	'''

	def i18nAccessors(GenDiagram it) '''
		«xptExternalizer.accessorField(i18nKeyForCreationWizardPageExtensionError(it))»
	'''

	@Localization def String i18nKeyForCreationWizardPageExtensionError(GenDiagram diagram) {
		return className(diagram) + 'ExtensionError'
	}

}

Back to the top