1 | /* |
2 | *Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.part; |
5 | |
6 | import org.eclipse.core.runtime.IPath; |
7 | import org.eclipse.core.runtime.Path; |
8 | import org.eclipse.emf.common.util.URI; |
9 | import org.eclipse.jface.viewers.IStructuredSelection; |
10 | import org.eclipse.osgi.util.NLS; |
11 | import org.eclipse.swt.widgets.Composite; |
12 | import org.eclipse.ui.dialogs.WizardNewFileCreationPage; |
13 | |
14 | /** |
15 | * @generated |
16 | */ |
17 | public class PalladioComponentModelCreationWizardPage extends |
18 | WizardNewFileCreationPage { |
19 | |
20 | /** |
21 | * @generated |
22 | */ |
23 | private final String fileExtension; |
24 | |
25 | /** |
26 | * @generated |
27 | */ |
28 | public PalladioComponentModelCreationWizardPage(String pageName, |
29 | IStructuredSelection selection, String fileExtension) { |
30 | super(pageName, selection); |
31 | this.fileExtension = fileExtension; |
32 | } |
33 | |
34 | /** |
35 | * Override to create files with this extension. |
36 | * |
37 | * @generated |
38 | */ |
39 | protected String getExtension() { |
40 | return fileExtension; |
41 | } |
42 | |
43 | /** |
44 | * @generated |
45 | */ |
46 | public URI getURI() { |
47 | return URI.createPlatformResourceURI(getFilePath().toString(), false); |
48 | } |
49 | |
50 | /** |
51 | * @generated |
52 | */ |
53 | protected IPath getFilePath() { |
54 | IPath path = getContainerFullPath(); |
55 | if (path == null) { |
56 | path = new Path(""); //$NON-NLS-1$ |
57 | } |
58 | String fileName = getFileName(); |
59 | if (fileName != null) { |
60 | path = path.append(fileName); |
61 | } |
62 | return path; |
63 | } |
64 | |
65 | /** |
66 | * @generated |
67 | */ |
68 | public void createControl(Composite parent) { |
69 | super.createControl(parent); |
70 | setFileName(PalladioComponentModelDiagramEditorUtil.getUniqueFileName( |
71 | getContainerFullPath(), getFileName(), getExtension())); |
72 | setPageComplete(validatePage()); |
73 | } |
74 | |
75 | /** |
76 | * @generated |
77 | */ |
78 | protected boolean validatePage() { |
79 | if (!super.validatePage()) { |
80 | return false; |
81 | } |
82 | String extension = getExtension(); |
83 | if (extension != null |
84 | && !getFilePath().toString().endsWith("." + extension)) { |
85 | setErrorMessage(NLS |
86 | .bind( |
87 | Messages.PalladioComponentModelCreationWizardPageExtensionError, |
88 | extension)); |
89 | return false; |
90 | } |
91 | return true; |
92 | } |
93 | } |