1 | package de.uka.ipd.sdq.featureinstance; |
2 | |
3 | import org.eclipse.core.runtime.IPath; |
4 | import org.eclipse.core.runtime.Path; |
5 | import org.eclipse.emf.common.util.URI; |
6 | import org.eclipse.jface.viewers.IStructuredSelection; |
7 | import org.eclipse.jface.wizard.Wizard; |
8 | import org.eclipse.swt.SWT; |
9 | import org.eclipse.swt.widgets.Composite; |
10 | import org.eclipse.swt.widgets.Label; |
11 | import org.eclipse.ui.INewWizard; |
12 | import org.eclipse.ui.IWorkbench; |
13 | import org.eclipse.ui.dialogs.WizardNewFileCreationPage; |
14 | |
15 | class FeatureConfigCreationWizardPage extends WizardNewFileCreationPage { |
16 | |
17 | @Override |
18 | protected void createAdvancedControls(Composite parent) { |
19 | Label label = new Label(parent, SWT.BORDER); |
20 | label.setText(message); |
21 | super.createAdvancedControls(parent); |
22 | } |
23 | |
24 | /** |
25 | * Override to create files with this extension. |
26 | * |
27 | * @generated |
28 | */ |
29 | protected String getExtension() { |
30 | return fileExtension; |
31 | } |
32 | |
33 | /** |
34 | * @generated |
35 | */ |
36 | public URI getURI() { |
37 | return URI.createPlatformResourceURI(getFilePath().toString(), false); |
38 | } |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | private final String fileExtension; |
44 | protected String fileName; |
45 | protected String message; |
46 | |
47 | /** |
48 | * @generated |
49 | */ |
50 | public FeatureConfigCreationWizardPage(String pageName, IStructuredSelection selection, String fileExtension, String fileName, String message) { |
51 | super(pageName, selection); |
52 | this.fileExtension = fileExtension; |
53 | this.fileName = fileName; |
54 | this.message = message; |
55 | } |
56 | |
57 | /** |
58 | * @generated |
59 | */ |
60 | protected IPath getFilePath() { |
61 | IPath path = getContainerFullPath(); |
62 | if (path == null) { |
63 | path = new Path(""); //$NON-NLS-1$ |
64 | } |
65 | String fileName = getFileName(); |
66 | if (fileName != null) { |
67 | path = path.append(fileName); |
68 | } |
69 | return path; |
70 | } |
71 | |
72 | /** |
73 | * @generated |
74 | */ |
75 | @Override |
76 | public void createControl(Composite parent) { |
77 | super.createControl(parent); |
78 | setFileName(fileName + ".featureconfig"); |
79 | setPageComplete(true); |
80 | } |
81 | } |
82 | |
83 | public class FeatureConfigCreationWizard extends Wizard implements INewWizard { |
84 | |
85 | protected URI resourceURI; |
86 | protected IWorkbench workbench; |
87 | protected IStructuredSelection selection; |
88 | protected FeatureConfigCreationWizardPage page; |
89 | protected String fileName; |
90 | protected String message; |
91 | |
92 | @Override |
93 | public void addPages() { |
94 | page = new FeatureConfigCreationWizardPage("Resource selection page", selection, "", fileName, message); |
95 | addPage(page); |
96 | super.addPages(); |
97 | } |
98 | |
99 | public URI getNewResource () { |
100 | return resourceURI; |
101 | } |
102 | |
103 | public boolean performFinish() { |
104 | try { |
105 | resourceURI = page.getURI(); |
106 | } |
107 | catch (Exception e) { |
108 | return false; |
109 | } |
110 | return true; |
111 | } |
112 | |
113 | public FeatureConfigCreationWizard (String fileName, String message) { |
114 | this.fileName = fileName; |
115 | this.message = message; |
116 | } |
117 | |
118 | public void init(IWorkbench workbench, IStructuredSelection selection) { |
119 | this.workbench = workbench; |
120 | this.selection = selection; |
121 | setWindowTitle("FeatureConfig creation wizard"); |
122 | } |
123 | |
124 | } |