|
Added
Link Here
|
| 1 |
/* |
| 2 |
* Copyright (c) 2007 Borland Software Corporation |
| 3 |
* |
| 4 |
* All rights reserved. This program and the accompanying materials |
| 5 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 6 |
* which accompanies this distribution, and is available at |
| 7 |
* http://www.eclipse.org/legal/epl-v10.html |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* Alexander Shatalin (Borland) - initial API and implementation |
| 11 |
* Dmitry Stadnik (Borland) - rewritten in xpand |
| 12 |
* Tatiana Fesenko (Borland) - fix for bugzilla #230873 'Make diagram file extension shorter' |
| 13 |
*/ |
| 14 |
|
| 15 |
«IMPORT "http://www.eclipse.org/gmf/2006/GenModel"» |
| 16 |
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"» |
| 17 |
|
| 18 |
«EXTENSION xpt::editor::Utils» |
| 19 |
«EXTENSION aspects::xpt::FileExtensionUtils» |
| 20 |
|
| 21 |
«AROUND NewDiagramFileWizard FOR gmfgen::GenDiagram-» |
| 22 |
«EXPAND xpt::Common::copyright FOR editorGen-» |
| 23 |
package «editorGen.editor.packageName»; |
| 24 |
|
| 25 |
«EXPAND xpt::Common::generatedClassComment» |
| 26 |
public class «EXPAND xpt::editor::NewDiagramFileWizard::className» extends org.eclipse.jface.wizard.Wizard { |
| 27 |
|
| 28 |
«EXPAND xpt::Common::generatedMemberComment» |
| 29 |
private «EXPAND xpt::editor::NewDiagramFileWizard::creationPage» myFileCreationPage; |
| 30 |
|
| 31 |
«EXPAND xpt::Common::generatedMemberComment» |
| 32 |
private «EXPAND xpt::editor::ModelElementSelectionPage::qualifiedClassName» diagramRootElementSelectionPage; |
| 33 |
|
| 34 |
«EXPAND xpt::Common::generatedMemberComment» |
| 35 |
private org.eclipse.emf.transaction.TransactionalEditingDomain myEditingDomain; |
| 36 |
|
| 37 |
«EXPAND xpt::Common::generatedMemberComment» |
| 38 |
public «EXPAND xpt::editor::NewDiagramFileWizard::className»(org.eclipse.emf.common.util.URI domainModelURI, |
| 39 |
org.eclipse.emf.ecore.EObject diagramRoot, |
| 40 |
org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain) { |
| 41 |
assert domainModelURI != null : "Domain model uri must be specified"; «EXPAND xpt::Common::nonNLS» |
| 42 |
assert diagramRoot != null : "Doagram root element must be specified"; «EXPAND xpt::Common::nonNLS» |
| 43 |
assert editingDomain != null : "Editing domain must be specified"; «EXPAND xpt::Common::nonNLS» |
| 44 |
|
| 45 |
myFileCreationPage = new «EXPAND xpt::editor::NewDiagramFileWizard::creationPage»(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardCreationPage().nameKey()) FOR editorGen», org.eclipse.jface.viewers.StructuredSelection.EMPTY); |
| 46 |
myFileCreationPage.setTitle(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardCreationPage().titleKey()) FOR editorGen»); |
| 47 |
myFileCreationPage.setDescription(org.eclipse.osgi.util.NLS.bind( |
| 48 |
«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardCreationPage().descriptionKey()) FOR editorGen», |
| 49 |
«EXPAND xpt::editor::VisualIDRegistry::modelID»)); |
| 50 |
org.eclipse.core.runtime.IPath filePath; |
| 51 |
String fileName = domainModelURI.trimFileExtension().lastSegment(); |
| 52 |
if (domainModelURI.isPlatformResource()) { |
| 53 |
filePath = new org.eclipse.core.runtime.Path(domainModelURI.trimSegments(1).toPlatformString(true)); |
| 54 |
} else if (domainModelURI.isFile()) { |
| 55 |
filePath = new org.eclipse.core.runtime.Path(domainModelURI.trimSegments(1).toFileString()); |
| 56 |
} else { |
| 57 |
// TODO : use some default path |
| 58 |
throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); «EXPAND xpt::Common::nonNLS» |
| 59 |
} |
| 60 |
myFileCreationPage.setContainerFullPath(filePath); |
| 61 |
«REM» #230873 'Make diagram file extension shorter' |
| 62 |
The only change is here. We take the first extension from the comma-separated list«ENDREM-» |
| 63 |
myFileCreationPage.setFileName(«getDiagramEditorUtilQualifiedClassName()».getUniqueFileName( |
| 64 |
filePath, fileName, "«editorGen.getDefaultDiagramExtension()»")); «EXPAND xpt::Common::nonNLS» |
| 65 |
«REM»End of the only change«ENDREM-» |
| 66 |
diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPage().nameKey()) FOR editorGen»); |
| 67 |
diagramRootElementSelectionPage.setTitle(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPage().titleKey()) FOR editorGen»); |
| 68 |
diagramRootElementSelectionPage.setDescription(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPage().descriptionKey()) FOR editorGen»); |
| 69 |
diagramRootElementSelectionPage.setModelElement(diagramRoot); |
| 70 |
|
| 71 |
myEditingDomain = editingDomain; |
| 72 |
} |
| 73 |
|
| 74 |
«EXPAND xpt::Common::generatedMemberComment» |
| 75 |
public void addPages() { |
| 76 |
addPage(myFileCreationPage); |
| 77 |
addPage(diagramRootElementSelectionPage); |
| 78 |
} |
| 79 |
|
| 80 |
«EXPAND xpt::Common::generatedMemberComment» |
| 81 |
public boolean performFinish() { |
| 82 |
java.util.List affectedFiles = new java.util.LinkedList(); |
| 83 |
«IF null == editorGen.application-» |
| 84 |
org.eclipse.core.resources.IFile diagramFile = myFileCreationPage.createNewFile(); |
| 85 |
«EXPAND xpt::Common::setCharset("diagramFile")-» |
| 86 |
affectedFiles.add(diagramFile); |
| 87 |
org.eclipse.emf.common.util.URI diagramModelURI = org.eclipse.emf.common.util.URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true); |
| 88 |
«ELSE-» |
| 89 |
org.eclipse.core.runtime.IPath diagramModelPath = myFileCreationPage.getContainerFullPath().append(myFileCreationPage.getFileName()); |
| 90 |
org.eclipse.emf.common.util.URI diagramModelURI = org.eclipse.emf.common.util.URI.createFileURI(diagramModelPath.toString()); |
| 91 |
«ENDIF-» |
| 92 |
org.eclipse.emf.ecore.resource.ResourceSet resourceSet = myEditingDomain.getResourceSet(); |
| 93 |
final org.eclipse.emf.ecore.resource.Resource diagramResource = resourceSet.createResource(diagramModelURI); |
| 94 |
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand command = |
| 95 |
new org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand( |
| 96 |
myEditingDomain, «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardInitDiagramCommand()) FOR editorGen», affectedFiles) { |
| 97 |
|
| 98 |
protected org.eclipse.gmf.runtime.common.core.command.CommandResult doExecuteWithResult( |
| 99 |
org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info) |
| 100 |
throws org.eclipse.core.commands.ExecutionException { |
| 101 |
int diagramVID = «EXPAND xpt::editor::VisualIDRegistry::getDiagramVisualIDMethodCall»(diagramRootElementSelectionPage.getModelElement()); |
| 102 |
if (diagramVID != «EXPAND xpt::editor::VisualIDRegistry::visualID») { |
| 103 |
return org.eclipse.gmf.runtime.common.core.command.CommandResult.newErrorCommandResult( |
| 104 |
«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardIncorrectRootError()) FOR editorGen»); |
| 105 |
} |
| 106 |
org.eclipse.gmf.runtime.notation.Diagram diagram = |
| 107 |
org.eclipse.gmf.runtime.diagram.core.services.ViewService.createDiagram( |
| 108 |
diagramRootElementSelectionPage.getModelElement(), «EXPAND xpt::editor::VisualIDRegistry::modelID», |
| 109 |
«editorGen.plugin.getActivatorQualifiedClassName()».DIAGRAM_PREFERENCES_HINT); |
| 110 |
diagramResource.getContents().add(diagram); |
| 111 |
«IF editorGen.sameFileForDiagramAndModel-» |
| 112 |
diagramResource.getContents().add(diagram.getElement()); |
| 113 |
«ENDIF-» |
| 114 |
«IF !synchronized-» |
| 115 |
new «getDiagramContentInitializerQualifiedClassName()»().initDiagramContent(diagram); |
| 116 |
«ENDIF-» |
| 117 |
return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult(); |
| 118 |
} |
| 119 |
}; |
| 120 |
try { |
| 121 |
org.eclipse.core.commands.operations.OperationHistoryFactory.getOperationHistory().execute( |
| 122 |
command, new org.eclipse.core.runtime.NullProgressMonitor(), null); |
| 123 |
diagramResource.save(«EXPAND xpt::Common::getSaveOptions»); |
| 124 |
«getDiagramEditorUtilQualifiedClassName()».openDiagram(diagramResource); |
| 125 |
} catch (org.eclipse.core.commands.ExecutionException e) { |
| 126 |
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError( |
| 127 |
"Unable to create model and diagram", e); «EXPAND xpt::Common::nonNLS» |
| 128 |
} catch (java.io.IOException ex) { |
| 129 |
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError( |
| 130 |
"Save operation failed for: " + diagramModelURI, ex); «EXPAND xpt::Common::nonNLS» |
| 131 |
} catch (org.eclipse.ui.PartInitException ex) { |
| 132 |
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError( |
| 133 |
"Unable to open editor", ex); «EXPAND xpt::Common::nonNLS» |
| 134 |
} |
| 135 |
return true; |
| 136 |
} |
| 137 |
|
| 138 |
«EXPAND xpt::Common::generatedClassComment» |
| 139 |
private static class DiagramRootElementSelectionPage extends «EXPAND xpt::editor::ModelElementSelectionPage::qualifiedClassName» { |
| 140 |
|
| 141 |
«EXPAND xpt::Common::generatedMemberComment» |
| 142 |
protected DiagramRootElementSelectionPage(String pageName) { |
| 143 |
super(pageName); |
| 144 |
} |
| 145 |
|
| 146 |
«EXPAND xpt::Common::generatedMemberComment» |
| 147 |
protected String getSelectionTitle() { |
| 148 |
return «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageSelectionTitle()) FOR editorGen»; |
| 149 |
} |
| 150 |
|
| 151 |
«EXPAND xpt::Common::generatedMemberComment» |
| 152 |
protected boolean validatePage() { |
| 153 |
if (selectedModelElement == null) { |
| 154 |
setErrorMessage(«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageNoSelectionMessage()) FOR editorGen»); |
| 155 |
return false; |
| 156 |
} |
| 157 |
boolean result = org.eclipse.gmf.runtime.diagram.core.services.ViewService.getInstance().provides( |
| 158 |
new org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation( |
| 159 |
new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(selectedModelElement), |
| 160 |
«EXPAND xpt::editor::VisualIDRegistry::modelID», |
| 161 |
«editorGen.plugin.getActivatorQualifiedClassName()».DIAGRAM_PREFERENCES_HINT)); |
| 162 |
setErrorMessage(result ? null : «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageInvalidSelectionMessage()) FOR editorGen»); |
| 163 |
return result; |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
«ENDAROUND» |