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/CreateUMLModelWizard.java (-8 / +14 lines)
Lines 14-22 Link Here
14
package org.eclipse.papyrus.diagram.common.wizards;
14
package org.eclipse.papyrus.diagram.common.wizards;
15
15
16
import org.eclipse.emf.common.util.URI;
16
import org.eclipse.emf.common.util.URI;
17
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.emf.ecore.resource.Resource;
17
import org.eclipse.emf.ecore.resource.Resource;
18
import org.eclipse.papyrus.wizards.Activator;
19
import org.eclipse.papyrus.wizards.CreateModelWizard;
19
import org.eclipse.papyrus.wizards.CreateModelWizard;
20
import org.eclipse.papyrus.wizards.SelectTemplateWizardPage;
20
import org.eclipse.uml2.uml.Model;
21
import org.eclipse.uml2.uml.Model;
21
import org.eclipse.uml2.uml.UMLFactory;
22
import org.eclipse.uml2.uml.UMLFactory;
22
import org.eclipse.uml2.uml.UMLPackage;
23
import org.eclipse.uml2.uml.UMLPackage;
Lines 48-60 Link Here
48
		return "uml";
49
		return "uml";
49
	}
50
	}
50
51
51
	/**
52
	protected SelectTemplateWizardPage getSelectTemplateWizardPage() {
52
	 * This method is invoked for creation of a model 
53
		return new SelectTemplateWizardPage(Activator.PLUGIN_ID, null, null) {
53
	 */
54
			/**
54
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
55
			 * This method is invoked for creation of a model 
55
		Model model = UMLFactory.eINSTANCE.createModel();
56
			 */
56
		model.setName(rootElementName);
57
			protected void initializeEmptyModel(Resource resource, String rootElementName) {
57
		resource.getContents().add(model);
58
				Model model = UMLFactory.eINSTANCE.createModel();
59
				model.setName(rootElementName);
60
				resource.getContents().add(model);
61
			}
62
		}; 
58
	}
63
	}
59
64
65
60
}
66
}
(-)src/org/eclipse/papyrus/wizards/CreateModelWizard.java (-162 / +42 lines)
Lines 7-38 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     Obeo - initial API and implementation
9
 *     Obeo - initial API and implementation
10
 *     Tatiana Fesenko(CEA) - [313179] Refactor CreateModelWizard
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.papyrus.wizards;
12
package org.eclipse.papyrus.wizards;
12
13
13
import java.io.IOException;
14
import static org.eclipse.papyrus.wizards.Activator.log;
14
import java.util.ArrayList;
15
import java.util.List;
16
15
17
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.emf.common.util.URI;
17
import org.eclipse.emf.common.util.URI;
23
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.resource.Resource;
19
import org.eclipse.emf.ecore.resource.Resource;
25
import org.eclipse.emf.ecore.resource.ResourceSet;
26
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
27
import org.eclipse.emf.ecore.util.EcoreUtil;
28
import org.eclipse.emf.transaction.RecordingCommand;
29
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.wizard.Wizard;
21
import org.eclipse.jface.wizard.Wizard;
31
import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
32
import org.eclipse.papyrus.core.utils.DiResourceSet;
22
import org.eclipse.papyrus.core.utils.DiResourceSet;
33
import org.eclipse.papyrus.core.utils.EditorUtils;
34
import org.eclipse.papyrus.core.utils.PapyrusTrace;
35
import org.eclipse.papyrus.resource.uml.UmlModel;
36
import org.eclipse.ui.INewWizard;
23
import org.eclipse.ui.INewWizard;
37
import org.eclipse.ui.IWorkbench;
24
import org.eclipse.ui.IWorkbench;
38
import org.eclipse.ui.IWorkbenchPage;
25
import org.eclipse.ui.IWorkbenchPage;
Lines 138-174 Link Here
138
		}
125
		}
139
		selectDiagramKindPage = new SelectDiagramKindPage("Select kind of diagram");
126
		selectDiagramKindPage = new SelectDiagramKindPage("Select kind of diagram");
140
		// fjcano #293135 :: support model templates
127
		// fjcano #293135 :: support model templates
141
		selectTemplateWizardPage = new SelectTemplateWizardPage(Activator.PLUGIN_ID, null, null);
128
		selectTemplateWizardPage = getSelectTemplateWizardPage();
142
	}
129
	}
143
	
130
	
144
	/**
131
	protected SelectTemplateWizardPage getSelectTemplateWizardPage() {
145
	 * Suggests a name of diagram file for the domain model file 
132
		return new SelectTemplateWizardPage(Activator.PLUGIN_ID, null, null); 
146
	 */
147
	protected String getDiagramFileName(IFile domainModel) {
148
		String diModelFileName = (domainModel.getLocation().removeFileExtension().lastSegment());
149
		diModelFileName += ".di";
150
		return diModelFileName;
151
	}
152
153
	/**
154
	 * Returns the first file from the given selection 
155
	 */
156
	private IFile getSelectedFile(IStructuredSelection selection) {
157
		if(selection != null && !selection.isEmpty() && selection.getFirstElement() instanceof IFile) {
158
			return (IFile)selection.getFirstElement();
159
		}
160
		return null;
161
	}
133
	}
162
134
163
	/**
135
	/**
164
	 * Returns true is the file can be served as a model model for the diagram
165
	 */
166
	protected boolean isSupportedDomainModelFile(IFile file) {
167
		return file != null && getModelFileExtension().equals(file.getFileExtension());
168
	}
169
170
171
	/**
172
	 * This method will be invoked, when the "Finish" button is pressed.
136
	 * This method will be invoked, when the "Finish" button is pressed.
173
	 * 
137
	 * 
174
	 * @return <code>true</code> if everything runs without problems, <code>false</code> if an exception must be caught.
138
	 * @return <code>true</code> if everything runs without problems, <code>false</code> if an exception must be caught.
Lines 176-326 Link Here
176
	 */
140
	 */
177
	@Override
141
	@Override
178
	public boolean performFinish() {
142
	public boolean performFinish() {
179
		try {
143
		// create a new file, result != null if successful
180
			// create a new file, result != null if successful
144
		final IFile newFile = newModelFilePage.createNewFile();
181
			final IFile newFile = newModelFilePage.createNewFile();
145
		selectTemplateWizardPage.initializeModelResource(diResourceSet, newFile, getModelContentType(), getModelFileExtension());
182
146
		if(newFile == null) {
183
			RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
147
			return false;
184
148
		}
185
				@Override
186
				protected void doExecute() {
187
					// Create Model Resource, Notation Resource, DI Resource
188
					diResourceSet.createModelResources(newFile, getModelContentType(), getModelFileExtension());
189
190
					// Initialize Model Resource
191
					Resource modelResource = diResourceSet.getModelResource();
192
					if(modelResource != null) {
193
						IPath path = new Path(newFile.getName());
194
						initializeModelResource(modelResource, path.removeFileExtension().toString());
195
					}
196
				}
197
			};
198
			diResourceSet.getTransactionalEditingDomain().getCommandStack().execute(command);
199
200
			// WorkspaceModifyOperation operation = new
201
			// WorkspaceModifyOperation() {
202
			// @Override
203
			// protected void execute(IProgressMonitor progressMonitor) {
204
			//			
205
			// }
206
			// };
207
			//		
208
			// getContainer().run(false, false, operation);
209
210
			// open newly created file in the editor
211
			IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
212
			if((newFile != null) && (page != null)) {
213
214
				String diagramName = selectDiagramKindPage.getDiagramName();
215
				ICreationCommand creationCommand = selectDiagramKindPage.getCreationCommand();
216
149
217
				if(creationCommand == null) {
150
		EObject root = domainModelURI != null ? selectRootElementPage.getModelElement() : null;
218
					// Create an empty editor (no diagrams opened)
151
		selectDiagramKindPage.createDiagram(diResourceSet, root);
219
					// Geting an IPageMngr is enough to initialize the
220
					// SashSystem.
221
					EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain());
222
				} else {
223
					EObject root = domainModelURI != null ? selectRootElementPage.getModelElement() : null;
224
					creationCommand.createDiagram(diResourceSet, root, diagramName);
225
				}
226
				try {
227
					diResourceSet.save(new NullProgressMonitor());
228
				} catch (IOException e) {
229
					PapyrusTrace.log(e);
230
					return false;
231
				}
232
152
233
				try {
153
		IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
234
					IDE.openEditor(page, newFile, true);
154
		if(page != null) {
235
				} catch (PartInitException e) {
155
			try {
236
					PapyrusTrace.log(e);
156
				IDE.openEditor(page, newFile, true);
237
					return false;
157
			} catch (PartInitException e) {
238
				}
158
				log.error(e);
159
				return false;
239
			}
160
			}
240
		} catch (Exception e) {
241
			e.printStackTrace();
242
			return false;
243
		}
161
		}
244
162
245
		return true;
163
		return true;
246
	}
164
	}
247
165
248
	/**
166
	/**
249
	 * Gets the model content type.
167
	 * Suggests a name of diagram file for the domain model file
250
	 *
251
	 * @return the model content type
252
	 */
168
	 */
253
	protected abstract String getModelContentType();
169
	protected String getDiagramFileName(IFile domainModel) {
254
170
		String diModelFileName = (domainModel.getLocation().removeFileExtension().lastSegment());
255
	/**
171
		diModelFileName += ".di";
256
	 * Gets the model file extension.
172
		return diModelFileName;
257
	 *
173
	}
258
	 * @return the model file extension
259
	 */
260
	protected abstract String getModelFileExtension();
261
174
262
	// fjcano #293135 :: support model templates
263
	/**
175
	/**
264
	 * Initialize model resource.
176
	 * Returns true is the file can be served as a model model for the diagram
265
	 *
266
	 * @param resource the resource
267
	 * @param rootElementName the root element name
268
	 */
177
	 */
269
	private void initializeModelResource(Resource resource, String rootElementName) {
178
	protected boolean isSupportedDomainModelFile(IFile file) {
270
		String templatePath = selectTemplateWizardPage.getTemplatePath();
179
		return file != null && getModelFileExtension().equals(file.getFileExtension());
271
		boolean initializeFromTemplate = templatePath != null;
272
		if(initializeFromTemplate) {
273
			initializeFromTemplate(resource, rootElementName, templatePath);
274
		} else {
275
			initializeEmptyModel(resource, rootElementName);
276
		}
277
	}
180
	}
278
181
279
	/**
182
	/**
280
	 * Initialize from template.
183
	 * Returns the first file from the given selection
281
	 *
282
	 * @param resource the resource
283
	 * @param rootElementName the root element name
284
	 * @param templatePath the template path
285
	 */
184
	 */
286
	protected void initializeFromTemplate(Resource resource, String rootElementName, String templatePath) {
185
	private IFile getSelectedFile(IStructuredSelection selection) {
287
		Resource templateResource = loadTemplateResource(templatePath);
186
		if(selection != null && !selection.isEmpty() && selection.getFirstElement() instanceof IFile) {
288
		List<EObject> eObjectsToAdd = new ArrayList<EObject>();
187
			return (IFile)selection.getFirstElement();
289
		for(EObject eObject : templateResource.getContents()) {
290
			eObjectsToAdd.add(EcoreUtil.copy(eObject));
291
		}
292
		for(EObject eObject : eObjectsToAdd) {
293
			resource.getContents().add(eObject);
294
		}
188
		}
189
		return null;
295
	}
190
	}
296
191
297
	/**
192
	/**
298
	 * Initialize empty model.
193
	 * Gets the model content type.
299
	 *
194
	 * 
300
	 * @param resource the resource
195
	 * @return the model content type
301
	 * @param rootElementName the root element name
302
	 */
196
	 */
303
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
197
	protected abstract String getModelContentType();
304
	}
305
198
306
	/**
199
	/**
307
	 * Load template resource.
200
	 * Gets the model file extension.
308
	 *
201
	 * 
309
	 * @param templatePath the template path
202
	 * @return the model file extension
310
	 * @return the resource
311
	 */
203
	 */
312
	private Resource loadTemplateResource(String templatePath) {
204
	protected abstract String getModelFileExtension();
313
		String templatePluginID = selectTemplateWizardPage.getTemplatePluginId();
314
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
315
		String fullUri = templateURL.getPath();
316
		URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
317
		ResourceSet resourceSet = new ResourceSetImpl();
318
		Resource resource = resourceSet.getResource(uri, true);
319
		if(resource.isLoaded()) {
320
			return resource;
321
		}
322
		return null;
323
	}
324
325
205
326
}
206
}
(-)src/org/eclipse/papyrus/wizards/Activator.java (+5 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.papyrus.wizards;
11
package org.eclipse.papyrus.wizards;
12
12
13
import org.eclipse.papyrus.log.LogHelper;
13
import org.eclipse.ui.plugin.AbstractUIPlugin;
14
import org.eclipse.ui.plugin.AbstractUIPlugin;
14
import org.osgi.framework.BundleContext;
15
import org.osgi.framework.BundleContext;
15
16
Lines 25-30 Link Here
25
26
26
	// The shared instance
27
	// The shared instance
27
	private static Activator plugin;
28
	private static Activator plugin;
29
	
30
	/** Logging helper */
31
    public static LogHelper log;
28
32
29
	/**
33
	/**
30
	 * The constructor
34
	 * The constructor
Lines 40-45 Link Here
40
	public void start(BundleContext context) throws Exception {
44
	public void start(BundleContext context) throws Exception {
41
		super.start(context);
45
		super.start(context);
42
		plugin = this;
46
		plugin = this;
47
		log = new LogHelper(plugin);
43
	}
48
	}
44
49
45
	/*
50
	/*
(-)src/org/eclipse/papyrus/wizards/SelectTemplateWizardPage.java (-28 / +115 lines)
Lines 15-24 Link Here
15
import java.util.Collection;
15
import java.util.Collection;
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IExtension;
20
import org.eclipse.core.runtime.IExtension;
20
import org.eclipse.core.runtime.IExtensionRegistry;
21
import org.eclipse.core.runtime.IExtensionRegistry;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Platform;
25
import org.eclipse.emf.common.util.URI;
26
import org.eclipse.emf.ecore.EObject;
27
import org.eclipse.emf.ecore.resource.Resource;
28
import org.eclipse.emf.ecore.resource.ResourceSet;
29
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
30
import org.eclipse.emf.ecore.util.EcoreUtil;
31
import org.eclipse.emf.transaction.RecordingCommand;
22
import org.eclipse.jface.viewers.ILabelProviderListener;
32
import org.eclipse.jface.viewers.ILabelProviderListener;
23
import org.eclipse.jface.viewers.IStructuredContentProvider;
33
import org.eclipse.jface.viewers.IStructuredContentProvider;
24
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 27-32 Link Here
27
import org.eclipse.jface.viewers.TableViewer;
37
import org.eclipse.jface.viewers.TableViewer;
28
import org.eclipse.jface.viewers.Viewer;
38
import org.eclipse.jface.viewers.Viewer;
29
import org.eclipse.jface.wizard.WizardPage;
39
import org.eclipse.jface.wizard.WizardPage;
40
import org.eclipse.papyrus.core.utils.DiResourceSet;
30
import org.eclipse.swt.SWT;
41
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.events.SelectionEvent;
42
import org.eclipse.swt.events.SelectionEvent;
32
import org.eclipse.swt.events.SelectionListener;
43
import org.eclipse.swt.events.SelectionListener;
Lines 60-79 Link Here
60
		// TODO Auto-generated constructor stub
71
		// TODO Auto-generated constructor stub
61
	}
72
	}
62
73
63
	public SelectTemplateWizardPage(String editorId, WizardPage nextPage,
74
	public SelectTemplateWizardPage(String editorId, WizardPage nextPage, WizardPage templatePage) {
64
			WizardPage templatePage) {
65
		super("Select creation approach");
75
		super("Select creation approach");
66
		this.setTitle("Select creation approach");
76
		this.setTitle("Select creation approach");
67
		this
77
		this.setDescription("Diagrams can be created from scratch or from a template");
68
				.setDescription("Diagrams can be created from scratch or from a template");
69
		this.editorId = editorId;
78
		this.editorId = editorId;
70
	}
79
	}
71
80
72
	public String getTemplatePath() {
81
	public String getTemplatePath() {
73
		if(this.useTemplateButton.getSelection()) {
82
		if(this.useTemplateButton.getSelection()) {
74
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
83
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
75
				Object first = ((IStructuredSelection)this.templateTableViewer
84
				Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement();
76
						.getSelection()).getFirstElement();
77
				if(first instanceof ModelTemplateDescription) {
85
				if(first instanceof ModelTemplateDescription) {
78
					return ((ModelTemplateDescription)first).getPath();
86
					return ((ModelTemplateDescription)first).getPath();
79
				}
87
				}
Lines 86-93 Link Here
86
	public String getTemplatePluginId() {
94
	public String getTemplatePluginId() {
87
		if(this.useTemplateButton.getSelection()) {
95
		if(this.useTemplateButton.getSelection()) {
88
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
96
			if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) {
89
				Object first = ((IStructuredSelection)this.templateTableViewer
97
				Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement();
90
						.getSelection()).getFirstElement();
91
				if(first instanceof ModelTemplateDescription) {
98
				if(first instanceof ModelTemplateDescription) {
92
					return ((ModelTemplateDescription)first).getPluginId();
99
					return ((ModelTemplateDescription)first).getPluginId();
93
				}
100
				}
Lines 125-137 Link Here
125
		templateTableViewer = new TableViewer(composite);
132
		templateTableViewer = new TableViewer(composite);
126
		templateTableViewer.getTable().setLayoutData(data);
133
		templateTableViewer.getTable().setLayoutData(data);
127
134
128
		templateTableViewer
135
		templateTableViewer.setContentProvider(new ModelTemplatesContentProvider());
129
				.setContentProvider(new ModelTemplatesContentProvider());
130
		templateTableViewer.setLabelProvider(new ModelTemplatesLabelProvider());
136
		templateTableViewer.setLabelProvider(new ModelTemplatesLabelProvider());
131
		templateTableViewer.setInput(0);
137
		templateTableViewer.setInput(0);
132
		if(templateTableViewer.getTable().getItemCount() > 0) {
138
		if(templateTableViewer.getTable().getItemCount() > 0) {
133
			IStructuredSelection ss = new StructuredSelection(
139
			IStructuredSelection ss = new StructuredSelection(templateTableViewer.getElementAt(0));
134
					templateTableViewer.getElementAt(0));
135
			templateTableViewer.setSelection(ss);
140
			templateTableViewer.setSelection(ss);
136
		} else {
141
		} else {
137
			useTemplateButton.setEnabled(false);
142
			useTemplateButton.setEnabled(false);
Lines 171-178 Link Here
171
176
172
	}
177
	}
173
178
174
	private class ModelTemplatesContentProvider implements
179
	public void initializeModelResource(final DiResourceSet diResourceSet, final IFile newFile, final String modelContentType, final String modelFileExtension) {
175
			IStructuredContentProvider {
180
		RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
181
182
			@Override
183
			protected void doExecute() {
184
				// Create Model Resource, Notation Resource, DI Resource
185
				diResourceSet.createModelResources(newFile, modelContentType, modelFileExtension);
186
187
				// Initialize Model Resource
188
				Resource modelResource = diResourceSet.getModelResource();
189
				if(modelResource != null) {
190
					IPath path = new Path(newFile.getName());
191
					initializeModelResource(modelResource, path.removeFileExtension().toString());
192
				}
193
			}
194
		};
195
		diResourceSet.getTransactionalEditingDomain().getCommandStack().execute(command);
196
197
	}
198
199
	/**
200
	 * Initialize model resource.
201
	 * 
202
	 * @param resource
203
	 *        the resource
204
	 * @param rootElementName
205
	 *        the root element name
206
	 */
207
	protected void initializeModelResource(Resource resource, String rootElementName) {
208
		String templatePath = getTemplatePath();
209
		boolean initializeFromTemplate = templatePath != null;
210
		if(initializeFromTemplate) {
211
			initializeFromTemplate(resource, rootElementName, templatePath);
212
		} else {
213
			initializeEmptyModel(resource, rootElementName);
214
		}
215
	}
216
217
	/**
218
	 * Initialize from template.
219
	 * 
220
	 * @param resource
221
	 *        the resource
222
	 * @param rootElementName
223
	 *        the root element name
224
	 * @param templatePath
225
	 *        the template path
226
	 */
227
	protected void initializeFromTemplate(Resource resource, String rootElementName, String templatePath) {
228
		Resource templateResource = loadTemplateResource(templatePath);
229
		List<EObject> eObjectsToAdd = new ArrayList<EObject>();
230
		for(EObject eObject : templateResource.getContents()) {
231
			eObjectsToAdd.add(EcoreUtil.copy(eObject));
232
		}
233
		for(EObject eObject : eObjectsToAdd) {
234
			resource.getContents().add(eObject);
235
		}
236
	}
237
238
	/**
239
	 * Initialize empty model.
240
	 * 
241
	 * @param resource
242
	 *        the resource
243
	 * @param rootElementName
244
	 *        the root element name
245
	 */
246
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
247
	}
248
	
249
	/**
250
	 * Load template resource.
251
	 * 
252
	 * @param templatePath
253
	 *        the template path
254
	 * @return the resource
255
	 */
256
	private Resource loadTemplateResource(String templatePath) {
257
		String templatePluginID = getTemplatePluginId();
258
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
259
		String fullUri = templateURL.getPath();
260
		URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
261
		ResourceSet resourceSet = new ResourceSetImpl();
262
		Resource resource = resourceSet.getResource(uri, true);
263
		if(resource.isLoaded()) {
264
			return resource;
265
		}
266
		return null;
267
	}
268
269
270
	private class ModelTemplatesContentProvider implements IStructuredContentProvider {
176
271
177
		private static final String extensionPointId = "org.eclipse.papyrus.wizards.templates";
272
		private static final String extensionPointId = "org.eclipse.papyrus.wizards.templates";
178
273
Lines 189-196 Link Here
189
			List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
284
			List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
190
285
191
			IExtensionRegistry registry = Platform.getExtensionRegistry();
286
			IExtensionRegistry registry = Platform.getExtensionRegistry();
192
			IExtension[] extensions = registry.getExtensionPoint(
287
			IExtension[] extensions = registry.getExtensionPoint(extensionPointId).getExtensions();
193
					extensionPointId).getExtensions();
194
288
195
			for(IExtension extension : extensions) {
289
			for(IExtension extension : extensions) {
196
				templates.addAll(processExtension(extension));
290
				templates.addAll(processExtension(extension));
Lines 199-213 Link Here
199
			return templates.toArray();
293
			return templates.toArray();
200
		}
294
		}
201
295
202
		private Collection<ModelTemplateDescription> processExtension(
296
		private Collection<ModelTemplateDescription> processExtension(IExtension extension) {
203
				IExtension extension) {
204
			List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
297
			List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>();
205
			for(IConfigurationElement configElement : extension
298
			for(IConfigurationElement configElement : extension.getConfigurationElements()) {
206
					.getConfigurationElements()) {
299
				templates.add(new ModelTemplateDescription(configElement.getAttribute(ATTRIBUTE_NAME), extension.getContributor().getName(), configElement.getAttribute(ATTRIBUTE_FILE)));
207
				templates.add(new ModelTemplateDescription(configElement
208
						.getAttribute(ATTRIBUTE_NAME), extension
209
						.getContributor().getName(), configElement
210
						.getAttribute(ATTRIBUTE_FILE)));
211
			}
300
			}
212
			return templates;
301
			return templates;
213
		}
302
		}
Lines 233-240 Link Here
233
322
234
		private String pluginId;
323
		private String pluginId;
235
324
236
		public ModelTemplateDescription(String name, String pluginId,
325
		public ModelTemplateDescription(String name, String pluginId, String path) {
237
				String path) {
238
			super();
326
			super();
239
			this.name = name;
327
			this.name = name;
240
			// this.e = metamodelURI;
328
			// this.e = metamodelURI;
Lines 283-290 Link Here
283
		public String getColumnText(Object element, int columnIndex) {
371
		public String getColumnText(Object element, int columnIndex) {
284
			if(element instanceof ModelTemplateDescription) {
372
			if(element instanceof ModelTemplateDescription) {
285
				ModelTemplateDescription modelTemplate = (ModelTemplateDescription)element;
373
				ModelTemplateDescription modelTemplate = (ModelTemplateDescription)element;
286
				return modelTemplate.getName() + " ("
374
				return modelTemplate.getName() + " (" + modelTemplate.getFileName() + ")";
287
						+ modelTemplate.getFileName() + ")";
288
			}
375
			}
289
			return null;
376
			return null;
290
		}
377
		}
(-)src/org/eclipse/papyrus/wizards/SelectDiagramKindPage.java (-13 / +39 lines)
Lines 11-25 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.papyrus.wizards;
12
package org.eclipse.papyrus.wizards;
13
13
14
import java.io.IOException;
14
import java.util.ArrayList;
15
import java.util.ArrayList;
15
import java.util.List;
16
import java.util.List;
16
17
18
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.jface.wizard.WizardPage;
20
import org.eclipse.jface.wizard.WizardPage;
18
import org.eclipse.papyrus.core.extension.NotFoundException;
21
import org.eclipse.papyrus.core.extension.NotFoundException;
19
import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
22
import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
20
import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
23
import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
21
import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
24
import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
22
import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
25
import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
26
import org.eclipse.papyrus.core.utils.DiResourceSet;
27
import org.eclipse.papyrus.core.utils.EditorUtils;
23
import org.eclipse.papyrus.core.utils.PapyrusTrace;
28
import org.eclipse.papyrus.core.utils.PapyrusTrace;
24
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.ModifyEvent;
30
import org.eclipse.swt.events.ModifyEvent;
Lines 73-86 Link Here
73
	public ICreationCommand getCreationCommand() {
78
	public ICreationCommand getCreationCommand() {
74
		return creationCommand;
79
		return creationCommand;
75
	}
80
	}
76
	
81
77
	public SelectDiagramKindPage(String pageName) {
82
	public SelectDiagramKindPage(String pageName) {
78
		super(pageName);
83
		super(pageName);
79
		setPageComplete(false);
84
		setPageComplete(false);
80
		setTitle("Initialization information");
85
		setTitle("Initialization information");
81
		setDescription("Select name and kind of the diagram");
86
		setDescription("Select name and kind of the diagram");
82
	}
87
	}
83
	
88
84
	/**
89
	/**
85
	 * {@inheritDoc}
90
	 * {@inheritDoc}
86
	 */
91
	 */
Lines 94-104 Link Here
94
99
95
		createNameForm(plate);
100
		createNameForm(plate);
96
		createDiagramKindForm(plate);
101
		createDiagramKindForm(plate);
97
		
102
98
//		if(!myDiagramKindButtons.isEmpty()) {
103
		//		if(!myDiagramKindButtons.isEmpty()) {
99
//			Button defaultKind = myDiagramKindButtons.get(0);
104
		//			Button defaultKind = myDiagramKindButtons.get(0);
100
//			setDefaultDiagramKind((String)defaultKind.getData());
105
		//			setDefaultDiagramKind((String)defaultKind.getData());
101
//		}
106
		//		}
102
		setPageComplete(validatePage());
107
		setPageComplete(validatePage());
103
108
104
	}
109
	}
Lines 128-139 Link Here
128
			button.setData(desc.getCommandId());
133
			button.setData(desc.getCommandId());
129
			myDiagramKindButtons.add(button);
134
			myDiagramKindButtons.add(button);
130
		}
135
		}
131
		
136
132
	}
137
	}
133
	
138
134
	private void setDefaultDiagramKind(String defaultKindCommandId) {
139
	private void setDefaultDiagramKind(String defaultKindCommandId) {
135
		for(Button button : myDiagramKindButtons) {
140
		for(Button button : myDiagramKindButtons) {
136
			if (defaultKindCommandId != null && defaultKindCommandId.equals(button.getData())) {
141
			if(defaultKindCommandId != null && defaultKindCommandId.equals(button.getData())) {
137
				button.setSelection(true);
142
				button.setSelection(true);
138
			} else {
143
			} else {
139
				button.setSelection(false);
144
				button.setSelection(false);
Lines 143-149 Link Here
143
	}
148
	}
144
149
145
	private void setDiagramCreationCommand(String commandId) {
150
	private void setDiagramCreationCommand(String commandId) {
146
		if (commandId == null) {
151
		if(commandId == null) {
147
			this.creationCommand = null;
152
			this.creationCommand = null;
148
			return;
153
			return;
149
		}
154
		}
Lines 210-218 Link Here
210
		setErrorMessage(message);
215
		setErrorMessage(message);
211
		setPageComplete(message == null);
216
		setPageComplete(message == null);
212
	}
217
	}
213
	
218
214
	protected boolean validatePage() {
219
	protected boolean validatePage() {
215
		return false == "".equals(getDiagramName()) && getCreationCommand() != null;
220
		return false == "".equals(getDiagramName()) && getCreationCommand() != null;
216
	}
221
	}
217
	
222
223
	public boolean createDiagram(DiResourceSet diResourceSet, EObject root) {
224
		String diagramName = getDiagramName();
225
		ICreationCommand creationCommand = getCreationCommand();
226
227
		if(creationCommand != null) {
228
			creationCommand.createDiagram(diResourceSet, root, diagramName);
229
		} else {
230
			// Create an empty editor (no diagrams opened)
231
			// Geting an IPageMngr is enough to initialize the
232
			// SashSystem.
233
			EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain());
234
		}
235
		try {
236
			diResourceSet.save(new NullProgressMonitor());
237
		} catch (IOException e) {
238
			PapyrusTrace.log(e);
239
			return false;
240
		}
241
		return true;
242
	}
243
218
}
244
}

Return to bug 313179