|
Lines 155-161
Link Here
|
| 155 |
try { |
155 |
try { |
| 156 |
// create a new file, result != null if successful |
156 |
// create a new file, result != null if successful |
| 157 |
final IFile newFile = newModelFilePage.createNewFile(); |
157 |
final IFile newFile = newModelFilePage.createNewFile(); |
| 158 |
NewModelFilePage.fileCount++; |
|
|
| 159 |
|
158 |
|
| 160 |
RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) { |
159 |
RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) { |
| 161 |
|
160 |
|
|
Lines 197-208
Link Here
|
| 197 |
// SashSystem. |
196 |
// SashSystem. |
| 198 |
EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain()); |
197 |
EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain()); |
| 199 |
} else { |
198 |
} else { |
| 200 |
// Create requested diagram. |
199 |
EObject root = domainModelURI != null ? selectRootElementPage.getModelElement() : null; |
| 201 |
if(domainModelURI != null) { |
200 |
creationCommand.createDiagram(diResourceSet, root, diagramName); |
| 202 |
creationCommand.createDiagram(diResourceSet, selectRootElementPage.getModelElement(), diagramName); |
|
|
| 203 |
} else { |
| 204 |
creationCommand.createDiagram(diResourceSet, null, diagramName); |
| 205 |
} |
| 206 |
} |
201 |
} |
| 207 |
try { |
202 |
try { |
| 208 |
diResourceSet.save(new NullProgressMonitor()); |
203 |
diResourceSet.save(new NullProgressMonitor()); |
|
Lines 231-277
Link Here
|
| 231 |
protected abstract String getModelFileExtension(); |
226 |
protected abstract String getModelFileExtension(); |
| 232 |
|
227 |
|
| 233 |
// fjcano #293135 :: support model templates |
228 |
// fjcano #293135 :: support model templates |
| 234 |
protected void initializeModelResource(Resource resource, String rootElementName) { |
229 |
private void initializeModelResource(Resource resource, String rootElementName) { |
| 235 |
if(isInitializeFromTemplate()) { |
230 |
String templatePath = selectTemplateWizardPage.getTemplatePath(); |
| 236 |
Resource templateResource = loadTemplateResource(); |
231 |
boolean initializeFromTemplate = templatePath != null; |
| 237 |
List<EObject> eObjectsToAdd = new ArrayList<EObject>(); |
232 |
if(initializeFromTemplate) { |
| 238 |
for(EObject eObject : templateResource.getContents()) { |
233 |
initializeFromTemplate(resource, rootElementName, templatePath); |
| 239 |
eObjectsToAdd.add(EcoreUtil.copy(eObject)); |
|
|
| 240 |
} |
| 241 |
for(EObject eObject : eObjectsToAdd) { |
| 242 |
resource.getContents().add(eObject); |
| 243 |
} |
| 244 |
} else { |
234 |
} else { |
| 245 |
// nothing |
235 |
initializeEmptyModel(resource, rootElementName); |
| 246 |
return; |
|
|
| 247 |
} |
236 |
} |
| 248 |
} |
237 |
} |
| 249 |
|
238 |
|
| 250 |
// fjcano #293135 :: support model templates |
239 |
protected void initializeFromTemplate(Resource resource, String rootElementName,String templatePath) { |
| 251 |
protected boolean isInitializeFromTemplate() { |
240 |
Resource templateResource = loadTemplateResource(templatePath); |
| 252 |
return getTemplatePath() != null; |
241 |
List<EObject> eObjectsToAdd = new ArrayList<EObject>(); |
|
|
242 |
for(EObject eObject : templateResource.getContents()) { |
| 243 |
eObjectsToAdd.add(EcoreUtil.copy(eObject)); |
| 244 |
} |
| 245 |
for(EObject eObject : eObjectsToAdd) { |
| 246 |
resource.getContents().add(eObject); |
| 247 |
} |
| 253 |
} |
248 |
} |
| 254 |
|
249 |
protected void initializeEmptyModel(Resource resource, String rootElementName) { |
| 255 |
// fjcano #293135 :: support model templates |
|
|
| 256 |
protected String getTemplatePath() { |
| 257 |
String templatePath = selectTemplateWizardPage.getTemplatePath(); |
| 258 |
return templatePath; |
| 259 |
} |
250 |
} |
| 260 |
|
251 |
|
| 261 |
// fjcano #293135 :: support model templates |
252 |
private Resource loadTemplateResource(String templatePath) { |
| 262 |
protected Resource loadTemplateResource() { |
|
|
| 263 |
String templatePluginID = selectTemplateWizardPage.getTemplatePluginId(); |
253 |
String templatePluginID = selectTemplateWizardPage.getTemplatePluginId(); |
| 264 |
String templatePath = getTemplatePath(); |
|
|
| 265 |
java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath); |
254 |
java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath); |
| 266 |
if(templatePath != null) { |
255 |
String fullUri = templateURL.getPath(); |
| 267 |
String fullUri = templateURL.getPath(); |
256 |
URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true); |
| 268 |
URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true); |
257 |
ResourceSet resourceSet = new ResourceSetImpl(); |
| 269 |
ResourceSet resourceSet = new ResourceSetImpl(); |
258 |
Resource resource = resourceSet.getResource(uri, true); |
| 270 |
Resource resource = resourceSet.getResource(uri, true); |
259 |
if(resource.isLoaded()) { |
| 271 |
if(resource.isLoaded()) { |
260 |
return resource; |
| 272 |
return resource; |
|
|
| 273 |
} |
| 274 |
} |
261 |
} |
| 275 |
return null; |
262 |
return null; |
| 276 |
} |
263 |
} |
|
|
264 |
|
| 265 |
|
| 277 |
} |
266 |
} |