blob: b6bc3efcb1933c6b6a4137ac252293e6c97d417f [file] [log] [blame]
/*
* Copyright (c) 2007, 2010 Borland Software Corporation and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Alexander Shatalin (Borland) - initial API and implementation
* Dmitry Stadnik (Borland) - rewritten in xpand
*/
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel'»
«EXTENSION xpt::editor::Utils»
«DEFINE className FOR gmfgen::GenDiagram»«newDiagramFileWizardClassName»«ENDDEFINE»
«DEFINE qualifiedClassName FOR gmfgen::GenDiagram»«editorGen.editor.packageName».«EXPAND className»«ENDDEFINE»
«DEFINE NewDiagramFileWizard FOR gmfgen::GenDiagram
«EXPAND xpt::Common::copyright FOR editorGen
package «editorGen.editor.packageName»;
«EXPAND xpt::Common::generatedClassComment»
public class «EXPAND className» extends org.eclipse.jface.wizard.Wizard {
«EXPAND xpt::Common::generatedMemberComment»
private «EXPAND creationPage» myFileCreationPage;
«EXPAND xpt::Common::generatedMemberComment»
private «EXPAND xpt::editor::ModelElementSelectionPage::qualifiedClassName» diagramRootElementSelectionPage;
«EXPAND xpt::Common::generatedMemberComment»
private org.eclipse.emf.transaction.TransactionalEditingDomain myEditingDomain;
«EXPAND xpt::Common::generatedMemberComment»
public «EXPAND className»(org.eclipse.emf.common.util.URI domainModelURI,
org.eclipse.emf.ecore.EObject diagramRoot,
org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain) {
«EXPAND xpt::Common::_assert('domainModelURI != null : \"Domain model uri must be specified\"')-»
«EXPAND xpt::Common::_assert('diagramRoot != null : \"Doagram root element must be specified\"')-»
«EXPAND xpt::Common::_assert('editingDomain != null : \"Editing domain must be specified\"')-»
myFileCreationPage = new «EXPAND creationPage»(«EXPAND xpt::Externalizer::accessorCall(nameKey(i18nKeyForNewDiagramFileWizardCreationPage(self))) FOR editorGen», org.eclipse.jface.viewers.StructuredSelection.EMPTY);
myFileCreationPage.setTitleEXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForNewDiagramFileWizardCreationPage(self))) FOR editorGen»);
myFileCreationPage.setDescription(org.eclipse.osgi.util.NLS.bind(
«EXPAND xpt::Externalizer::accessorCall(descriptionKey(i18nKeyForNewDiagramFileWizardCreationPage(self))) FOR editorGen»,
«EXPAND xpt::editor::VisualIDRegistry::modelID»));
org.eclipse.core.runtime.IPath filePath;
String fileName = org.eclipse.emf.common.util.URI.decode(domainModelURI.trimFileExtension().lastSegment());
if (domainModelURI.isPlatformResource()) {
filePath = new org.eclipse.core.runtime.Path(domainModelURI.trimSegments(1).toPlatformString(true));
} else if (domainModelURI.isFile()) {
filePath = new org.eclipse.core.runtime.Path(domainModelURI.trimSegments(1).toFileString());
} else {
// TODO : use some default path
throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); «EXPAND xpt::Common::nonNLS»
}
myFileCreationPage.setContainerFullPath(filePath);
myFileCreationPage.setFileNamegetDiagramEditorUtilQualifiedClassName()».getUniqueFileName(
filePath, fileName, "«editorGen.diagramFileExtension»")); «EXPAND xpt::Common::nonNLS»
diagramRootElementSelectionPage = new DiagramRootElementSelectionPageEXPAND xpt::Externalizer::accessorCall(nameKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self))) FOR editorGen»);
diagramRootElementSelectionPage.setTitleEXPAND xpt::Externalizer::accessorCall(titleKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self))) FOR editorGen»);
diagramRootElementSelectionPage.setDescriptionEXPAND xpt::Externalizer::accessorCall(descriptionKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self))) FOR editorGen»);
diagramRootElementSelectionPage.setModelElement(diagramRoot);
myEditingDomain = editingDomain;
}
«EXPAND xpt::Common::generatedMemberComment»
public void addPages() {
addPage(myFileCreationPage);
addPage(diagramRootElementSelectionPage);
}
«EXPAND xpt::Common::generatedMemberComment»
public boolean performFinish() {
«EXPAND CodeStyle::newGenericInstance('affectedFiles', 'java.util.LinkedList', 'org.eclipse.core.resources.IFile')»();
«IF null = editorGen.application
org.eclipse.core.resources.IFile diagramFile = myFileCreationPage.createNewFile();
«EXPAND xpt::Common::setCharset('diagramFile')-»
affectedFiles.add(diagramFile);
org.eclipse.emf.common.util.URI diagramModelURI = org.eclipse.emf.common.util.URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
«ELSE
org.eclipse.core.runtime.IPath diagramModelPath = myFileCreationPage.getContainerFullPath().append(myFileCreationPage.getFileName());
org.eclipse.emf.common.util.URI diagramModelURI = org.eclipse.emf.common.util.URI.createFileURI(diagramModelPath.toString());
«ENDIF
org.eclipse.emf.ecore.resource.ResourceSet resourceSet = myEditingDomain.getResourceSet();
final org.eclipse.emf.ecore.resource.Resource diagramResource = resourceSet.createResource(diagramModelURI);
org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand command =
new org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand(
myEditingDomain, «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardInitDiagramCommand(self)) FOR editorGen», affectedFiles) {
protected org.eclipse.gmf.runtime.common.core.command.CommandResult doExecuteWithResult(
org.eclipse.core.runtime.IProgressMonitor monitor, org.eclipse.core.runtime.IAdaptable info)
throws org.eclipse.core.commands.ExecutionException {
int diagramVID = «EXPAND xpt::editor::VisualIDRegistry::getDiagramVisualIDMethodCall»(diagramRootElementSelectionPage.getModelElement());
if (diagramVID != «EXPAND xpt::editor::VisualIDRegistry::visualID») {
return org.eclipse.gmf.runtime.common.core.command.CommandResult.newErrorCommandResult(
«EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardIncorrectRootError(self)) FOR editorGen»);
}
org.eclipse.gmf.runtime.notation.Diagram diagram =
org.eclipse.gmf.runtime.diagram.core.services.ViewService.createDiagram(
diagramRootElementSelectionPage.getModelElement(), «EXPAND xpt::editor::VisualIDRegistry::modelID»,
«EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»);
diagramResource.getContents().add(diagram);
«IF editorGen.sameFileForDiagramAndModel
diagramResource.getContents().add(diagram.getElement());
«ENDIF
«IF not synchronized
new «getDiagramContentInitializerQualifiedClassName()»().initDiagramContent(diagram);
«ENDIF
return org.eclipse.gmf.runtime.common.core.command.CommandResult.newOKCommandResult();
}
};
try {
org.eclipse.core.commands.operations.OperationHistoryFactory.getOperationHistory().execute(
command, new org.eclipse.core.runtime.NullProgressMonitor(), null);
diagramResource.saveEXPAND xpt::Common::getSaveOptions»);
«getDiagramEditorUtilQualifiedClassName()».openDiagram(diagramResource);
} catch (org.eclipse.core.commands.ExecutionException e) {
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
"Unable to create model and diagram", e); «EXPAND xpt::Common::nonNLS»
} catch (java.io.IOException ex) {
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
"Save operation failed for: " + diagramModelURI, ex); «EXPAND xpt::Common::nonNLS»
} catch (org.eclipse.ui.PartInitException ex) {
«editorGen.plugin.getActivatorQualifiedClassName()».getInstance().logError(
"Unable to open editor", ex); «EXPAND xpt::Common::nonNLS»
}
return true;
}
«EXPAND xpt::Common::generatedClassComment»
private static class DiagramRootElementSelectionPage extends «EXPAND xpt::editor::ModelElementSelectionPage::qualifiedClassName» {
«EXPAND xpt::Common::generatedMemberComment»
protected DiagramRootElementSelectionPage(String pageName) {
super(pageName);
}
«EXPAND xpt::Common::generatedMemberComment»
protected String getSelectionTitle() {
return «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageSelectionTitle(self)) FOR editorGen»;
}
«EXPAND xpt::Common::generatedMemberComment»
protected boolean validatePage() {
if (getModelElement() == null) {
setErrorMessageEXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageNoSelectionMessage(self)) FOR editorGen»);
return false;
}
boolean result = org.eclipse.gmf.runtime.diagram.core.services.ViewService.getInstance().provides(
new org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation(
new org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter(getModelElement()),
«EXPAND xpt::editor::VisualIDRegistry::modelID», «EXPAND xpt::plugin::Activator::preferenceHintAccess FOR editorGen»));
setErrorMessage(result ? null : «EXPAND xpt::Externalizer::accessorCall(i18nKeyForNewDiagramFileWizardRootSelectionPageInvalidSelectionMessage(self)) FOR editorGen»);
return result;
}
}
}
«ENDDEFINE»
«DEFINE creationPage FOR gmfgen::GenDiagram»
«IF null = editorGen.application
org.eclipse.ui.dialogs.WizardNewFileCreationPage«ELSE
«editorGen.application.packageName».WizardNewFileCreationPage«ENDIF
«ENDDEFINE»
«DEFINE i18nAccessors FOR gmfgen::GenDiagram
«EXPAND xpt::Externalizer::accessorField(nameKey(i18nKeyForNewDiagramFileWizardCreationPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForNewDiagramFileWizardCreationPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(descriptionKey(i18nKeyForNewDiagramFileWizardCreationPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(nameKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(titleKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(descriptionKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardRootSelectionPageSelectionTitle(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardRootSelectionPageNoSelectionMessage(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardRootSelectionPageInvalidSelectionMessage(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardInitDiagramCommand(self))-»
«EXPAND xpt::Externalizer::accessorField(i18nKeyForNewDiagramFileWizardIncorrectRootError(self))-»
«ENDDEFINE»
«DEFINE i18nValues FOR gmfgen::GenDiagram
«EXPAND xpt::Externalizer::messageEntry(nameKey(i18nKeyForNewDiagramFileWizardCreationPage(self)), 'Initialize new diagram file')-»
«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForNewDiagramFileWizardCreationPage(self)), 'Diagram file')-»
«EXPAND xpt::Externalizer::messageEntry(descriptionKey(i18nKeyForNewDiagramFileWizardCreationPage(self)), 'Create new diagram based on {0} model content')-»
«EXPAND xpt::Externalizer::messageEntry(nameKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)), 'Select diagram root element')-»
«EXPAND xpt::Externalizer::messageEntry(titleKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)), 'Diagram root element')-»
«EXPAND xpt::Externalizer::messageEntry(descriptionKey(i18nKeyForNewDiagramFileWizardRootSelectionPage(self)), 'Select semantic model element to be depicted on diagram')-»"Select diagram root element:"
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardRootSelectionPageSelectionTitle(self), 'Select diagram root element:')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardRootSelectionPageNoSelectionMessage(self), 'Diagram root element is not selected')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardRootSelectionPageInvalidSelectionMessage(self), 'Invalid diagram root element is selected')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardInitDiagramCommand(self), 'Initializing diagram contents')-»
«EXPAND xpt::Externalizer::messageEntry(i18nKeyForNewDiagramFileWizardIncorrectRootError(self), 'Incorrect model object stored as a root resource object')-»
«ENDDEFINE»