|
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 |
} |