Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 18e424c40ca6da18bbf19b4745b63d9ac4abf075 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
 * Copyright (c) 2006, 2009 Borland Software Corporation
 * 
 * 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:
 *    Dmitry Stadnik (Borland) - initial API and implementation
 */

«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«IMPORT 'http://www.eclipse.org/emf/2002/Ecore'»

«EXTENSION xpt::application::i18n»

«DEFINE WizardNewFileCreationPage FOR gmfgen::GenApplication-»
«EXPAND xpt::Common::copyright FOR editorGen-»
package «packageName»;

«EXPAND xpt::Common::generatedClassComment»
public class WizardNewFileCreationPage extends org.eclipse.jface.wizard.WizardPage {

	«EXPAND xpt::Common::generatedMemberComment»
	private final org.eclipse.jface.viewers.IStructuredSelection currentSelection;

	«EXPAND xpt::Common::generatedMemberComment»
	private String initialFileName;

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.core.runtime.IPath initialContainerFullPath;

	«EXPAND xpt::Common::generatedMemberComment»
	private org.eclipse.swt.widgets.Text fileNameEditor;

	«EXPAND xpt::Common::generatedMemberComment»
	public WizardNewFileCreationPage(String name, org.eclipse.jface.viewers.IStructuredSelection currentSelection) {
		super(name);
		this.currentSelection = currentSelection;
		String home = System.getProperty("user.home"); //$NON-NLS-1$
		if (home != null) {
			initialContainerFullPath = new org.eclipse.core.runtime.Path(home);
		}
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.jface.viewers.IStructuredSelection getSelection() {
		return currentSelection;
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public String getFileName() {
		if (fileNameEditor == null) {
			return initialFileName;
		}
		org.eclipse.core.runtime.IPath path = getFilePath();
		if (path == null || path.isEmpty() || path.hasTrailingSeparator()) {
			return null;
		}
		return path.lastSegment();
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public void setFileName(String fileName) {
		if (fileNameEditor == null) {
			initialFileName = fileName;
			return;
		}
		setFilePath(getContainerFullPath(), fileName);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public org.eclipse.core.runtime.IPath getContainerFullPath() {
		if (fileNameEditor == null) {
			return initialContainerFullPath;
		}
		org.eclipse.core.runtime.IPath path = getFilePath();
		if (path == null || path.isEmpty()) {
			return null;
		}
		if (path.hasTrailingSeparator()) {
			return path;
		}
		path = path.removeLastSegments(1);
		if (path.isEmpty()) {
			return null;
		}
		return path.addTrailingSeparator();
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public void setContainerFullPath(org.eclipse.core.runtime.IPath containerPath) {
		if (fileNameEditor == null) {
			initialContainerFullPath = containerPath;
			return;
		}
		setFilePath(containerPath, getFileName());
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected org.eclipse.core.runtime.IPath getFilePath() {
		String fileName = fileNameEditor.getText().trim();
		if (fileName.length() == 0) {
			return null;
		}
		return new org.eclipse.core.runtime.Path(fileNameEditor.getText());
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected void setFilePath(org.eclipse.core.runtime.IPath containerPath, String fileName) {
		if (fileName == null) {
			fileName = ""; //$NON-NLS-1$
		} else {
			fileName = fileName.trim();
		}
		if (containerPath == null) {
			fileNameEditor.setText(fileName);
		} else {
			if (!containerPath.hasTrailingSeparator()) {
				containerPath = containerPath.addTrailingSeparator();
			}
			org.eclipse.core.runtime.IPath path = fileName.length() == 0 ? containerPath : containerPath.append(fileName);
			fileNameEditor.setText(path.toOSString());
		}
		setPageComplete(validatePage());
	}

	«EXPAND xpt::Common::generatedMemberComment»
	public void createControl(org.eclipse.swt.widgets.Composite parent) {
		org.eclipse.swt.widgets.Composite plate = new org.eclipse.swt.widgets.Composite(parent, org.eclipse.swt.SWT.NONE);
		plate.setLayout(new org.eclipse.swt.layout.GridLayout(2, false));
		org.eclipse.swt.widgets.Label label = new org.eclipse.swt.widgets.Label(plate, org.eclipse.swt.SWT.NONE);
		label.setText(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewFileWizardFileLabel(self)) FOR editorGen»);
		label.setLayoutData(new org.eclipse.swt.layout.GridData(org.eclipse.swt.SWT.BEGINNING, org.eclipse.swt.SWT.CENTER, false, false, 2, 1));
		fileNameEditor = new org.eclipse.swt.widgets.Text(plate, org.eclipse.swt.SWT.SINGLE | org.eclipse.swt.SWT.BORDER);
		fileNameEditor.setLayoutData(new org.eclipse.swt.layout.GridData(org.eclipse.swt.SWT.FILL, org.eclipse.swt.SWT.CENTER, true, false));
		org.eclipse.swt.widgets.Button button = new org.eclipse.swt.widgets.Button(plate, org.eclipse.swt.SWT.PUSH);
		button.setText(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewFileWizardBrowseButton(self)) FOR editorGen»);
		button.setLayoutData(new org.eclipse.swt.layout.GridData(org.eclipse.swt.SWT.BEGINNING, org.eclipse.swt.SWT.CENTER, false, false));

		// logic
		fileNameEditor.addModifyListener(new org.eclipse.swt.events.ModifyListener() {

			public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
				setPageComplete(validatePage());
			}
		});
		button.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {

			public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
				org.eclipse.swt.widgets.FileDialog dialog = new org.eclipse.swt.widgets.FileDialog(getShell(), org.eclipse.swt.SWT.SAVE);
				dialog.setText(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewFileWizardSelectDialog(self)) FOR editorGen»);
				dialog.setFileName(getFileName());
				String fileName = dialog.open();
				if (fileName != null) {
					fileNameEditor.setText(fileName);
					setPageComplete(validatePage());
				}
			}

			public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
			}
		});

		// init
		setFilePath(initialContainerFullPath, initialFileName);
		setControl(plate);
	}

	«EXPAND xpt::Common::generatedMemberComment»
	protected boolean validatePage() {
		String fileName = fileNameEditor.getText().trim();
		if (fileName.length() == 0) {
			setErrorMessage(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewFileWizardEmpty(self)) FOR editorGen»);
			return false;
		}
		if (!new org.eclipse.core.runtime.Path("").isValidPath(fileName)) { //$NON-NLS-1$
			setErrorMessage(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewFileWizardInvalid(self)) FOR editorGen»);
			return false;
		}
		setErrorMessage(null);
		return true;
	}
	«EXPAND additions-»
}
«ENDDEFINE»

«DEFINE additions FOR gmfgen::GenApplication-»
«ENDDEFINE»

«DEFINE i18nValues FOR gmfgen::GenApplication-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewFileWizardFileLabel(self), 'File:')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewFileWizardBrowseButton(self), 'Browse')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewFileWizardSelectDialog(self), 'Select new file')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewFileWizardEmpty(self), 'Specify file name')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewFileWizardInvalid(self), 'Invalid file name')-»
«ENDDEFINE»

«DEFINE i18nAccessors FOR gmfgen::GenApplication-»
	«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewFileWizardFileLabel(self))-»
	«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewFileWizardBrowseButton(self))-»
	«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewFileWizardSelectDialog(self))-»
	«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewFileWizardEmpty(self))-»
	«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewFileWizardInvalid(self))-»
«ENDDEFINE»

Back to the top