Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 313179 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/papyrus/diagram/common/wizards/NewPapyrusProjectWizard.java (-13 / +66 lines)
Lines 41-62 Link Here
41
import org.eclipse.uml2.uml.UMLPackage;
41
import org.eclipse.uml2.uml.UMLPackage;
42
42
43
/**
43
/**
44
 * The Wizard creates a Papyrus Project and a Papyrus Model inside it
44
 * The Wizard creates a Papyrus Project and a Papyrus Model inside it.
45
 */
45
 */
46
47
public class NewPapyrusProjectWizard extends BasicNewProjectResourceWizard {
46
public class NewPapyrusProjectWizard extends BasicNewProjectResourceWizard {
48
47
48
	/** The new project page. */
49
	private WizardNewProjectCreationPage myNewProjectPage;
49
	private WizardNewProjectCreationPage myNewProjectPage;
50
50
51
	/** The diagram kind page. */
51
	private SelectDiagramKindPage myDiagramKindPage;
52
	private SelectDiagramKindPage myDiagramKindPage;
52
53
54
	/** The initial project name. */
53
	private String initialProjectName;
55
	private String initialProjectName;
54
56
57
	/**
58
	 * @see org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard#init(org.eclipse.ui.IWorkbench,
59
	 *      org.eclipse.jface.viewers.IStructuredSelection)
60
	 * 
61
	 * @param workbench
62
	 * @param selection
63
	 */
55
	public void init(IWorkbench workbench, IStructuredSelection selection) {
64
	public void init(IWorkbench workbench, IStructuredSelection selection) {
56
		super.init(workbench, selection);
65
		super.init(workbench, selection);
57
		setWindowTitle("New Papyrus Project");
66
		setWindowTitle("New Papyrus Project");
58
	}
67
	}
59
68
69
	/**
70
	 * @see org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard#addPages()
71
	 * 
72
	 */
60
	public void addPages() {
73
	public void addPages() {
61
		super.addPages();
74
		super.addPages();
62
		myNewProjectPage = (WizardNewProjectCreationPage)getPage("basicNewProjectPage"); //$NON-NLS-1$
75
		myNewProjectPage = (WizardNewProjectCreationPage)getPage("basicNewProjectPage"); //$NON-NLS-1$
Lines 67-72 Link Here
67
		}
80
		}
68
81
69
		myDiagramKindPage = new SelectDiagramKindPage("Select kind of diagram") {
82
		myDiagramKindPage = new SelectDiagramKindPage("Select kind of diagram") {
83
70
			protected boolean validatePage() {
84
			protected boolean validatePage() {
71
				return true;
85
				return true;
72
			};
86
			};
Lines 74-96 Link Here
74
		addPage(myDiagramKindPage);
88
		addPage(myDiagramKindPage);
75
	}
89
	}
76
90
91
	/**
92
	 * Creates the file.
93
	 * 
94
	 * @return the file
95
	 */
77
	private IFile createFile() {
96
	private IFile createFile() {
78
		IPath newFilePath = myNewProjectPage.getProjectHandle().getFullPath().append(NewModelFilePage.DEFAULT_NAME + "." + NewModelFilePage.DIAGRAM_EXTENSION);
97
		IPath newFilePath = myNewProjectPage.getProjectHandle().getFullPath().append(NewModelFilePage.DEFAULT_NAME + "." + NewModelFilePage.DIAGRAM_EXTENSION);
79
		return ResourcesPlugin.getWorkspace().getRoot().getFile(newFilePath);
98
		return ResourcesPlugin.getWorkspace().getRoot().getFile(newFilePath);
80
	}
99
	}
81
100
101
	/**
102
	 * @see org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard#performFinish()
103
	 * 
104
	 * @return
105
	 */
82
	public boolean performFinish() {
106
	public boolean performFinish() {
83
		boolean created = super.performFinish();
107
		boolean created = super.performFinish();
84
		if (!created) {
108
		if(!created) {
85
			return false;
109
			return false;
86
		}
110
		}
87
		// if the user wants to create a diagram
111
		// if the user wants to create a diagram
88
		if (myDiagramKindPage.getCreationCommand() != null) {
112
		if(myDiagramKindPage.getCreationCommand() != null) {
89
			return createPapyrusModel();
113
			return createPapyrusModel();
90
		}
114
		}
91
		return true;
115
		return true;
92
	}
116
	}
93
	
117
118
	/**
119
	 * Creates the papyrus model.
120
	 * 
121
	 * @return true, if successful
122
	 */
94
	private boolean createPapyrusModel() {
123
	private boolean createPapyrusModel() {
95
		final DiResourceSet diResourceSet = new DiResourceSet();
124
		final DiResourceSet diResourceSet = new DiResourceSet();
96
		try {
125
		try {
Lines 147-171 Link Here
147
		return true;
176
		return true;
148
	}
177
	}
149
178
179
	/**
180
	 * Initialize model resource.
181
	 * 
182
	 * @param resource
183
	 *        the domain model resource
184
	 * @param rootElementName
185
	 *        the root element name
186
	 */
150
	private void initializeModelResource(Resource resource, String rootElementName) {
187
	private void initializeModelResource(Resource resource, String rootElementName) {
151
//		// fjcano #293135 :: support model templates
188
		//		// fjcano #293135 :: support model templates
152
//		if(!isInitializeFromTemplate()) {
189
		//		if(!isInitializeFromTemplate()) {
153
			Model model = UMLFactory.eINSTANCE.createModel();
190
		Model model = UMLFactory.eINSTANCE.createModel();
154
			model.setName(rootElementName);
191
		model.setName(rootElementName);
155
			resource.getContents().add(model);
192
		resource.getContents().add(model);
156
//		} else {
193
		//		} else {
157
//			super.initializeModelResource(resource, rootElementName);
194
		//			super.initializeModelResource(resource, rootElementName);
158
//		}
195
		//		}
159
	}
196
	}
160
197
198
	/**
199
	 * Sets the initial project name.
200
	 * 
201
	 * @param initialProjectName
202
	 *        the new initial project name
203
	 */
161
	public void setInitialProjectName(String initialProjectName) {
204
	public void setInitialProjectName(String initialProjectName) {
162
		this.initialProjectName = initialProjectName;
205
		this.initialProjectName = initialProjectName;
163
	}
206
	}
164
207
208
	/**
209
	 * Gets the model content type.
210
	 * 
211
	 * @return the model content type
212
	 */
165
	protected String getModelContentType() {
213
	protected String getModelContentType() {
166
		return UMLPackage.eCONTENT_TYPE;
214
		return UMLPackage.eCONTENT_TYPE;
167
	}
215
	}
168
216
217
	/**
218
	 * Gets the model file extension.
219
	 * 
220
	 * @return the model file extension
221
	 */
169
	protected String getModelFileExtension() {
222
	protected String getModelFileExtension() {
170
		return "uml";
223
		return "uml";
171
	}
224
	}
(-)src/org/eclipse/papyrus/wizards/CreateModelWizard.java (+35 lines)
Lines 245-255 Link Here
245
		return true;
245
		return true;
246
	}
246
	}
247
247
248
	/**
249
	 * Gets the model content type.
250
	 *
251
	 * @return the model content type
252
	 */
248
	protected abstract String getModelContentType();
253
	protected abstract String getModelContentType();
249
254
255
	/**
256
	 * Gets the model file extension.
257
	 *
258
	 * @return the model file extension
259
	 */
250
	protected abstract String getModelFileExtension();
260
	protected abstract String getModelFileExtension();
251
261
252
	// fjcano #293135 :: support model templates
262
	// fjcano #293135 :: support model templates
263
	/**
264
	 * Initialize model resource.
265
	 *
266
	 * @param resource the resource
267
	 * @param rootElementName the root element name
268
	 */
253
	private void initializeModelResource(Resource resource, String rootElementName) {
269
	private void initializeModelResource(Resource resource, String rootElementName) {
254
		String templatePath = selectTemplateWizardPage.getTemplatePath();
270
		String templatePath = selectTemplateWizardPage.getTemplatePath();
255
		boolean initializeFromTemplate = templatePath != null;
271
		boolean initializeFromTemplate = templatePath != null;
Lines 260-265 Link Here
260
		}
276
		}
261
	}
277
	}
262
278
279
	/**
280
	 * Initialize from template.
281
	 *
282
	 * @param resource the resource
283
	 * @param rootElementName the root element name
284
	 * @param templatePath the template path
285
	 */
263
	protected void initializeFromTemplate(Resource resource, String rootElementName, String templatePath) {
286
	protected void initializeFromTemplate(Resource resource, String rootElementName, String templatePath) {
264
		Resource templateResource = loadTemplateResource(templatePath);
287
		Resource templateResource = loadTemplateResource(templatePath);
265
		List<EObject> eObjectsToAdd = new ArrayList<EObject>();
288
		List<EObject> eObjectsToAdd = new ArrayList<EObject>();
Lines 271-279 Link Here
271
		}
294
		}
272
	}
295
	}
273
296
297
	/**
298
	 * Initialize empty model.
299
	 *
300
	 * @param resource the resource
301
	 * @param rootElementName the root element name
302
	 */
274
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
303
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
275
	}
304
	}
276
305
306
	/**
307
	 * Load template resource.
308
	 *
309
	 * @param templatePath the template path
310
	 * @return the resource
311
	 */
277
	private Resource loadTemplateResource(String templatePath) {
312
	private Resource loadTemplateResource(String templatePath) {
278
		String templatePluginID = selectTemplateWizardPage.getTemplatePluginId();
313
		String templatePluginID = selectTemplateWizardPage.getTemplatePluginId();
279
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
314
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);

Return to bug 313179