Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/CreationWizardGenerator.java19
-rw-r--r--plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/DiagramEditorUtilGenerator.java296
-rw-r--r--plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/NewDiagramFileWizardGenerator.java2
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/editor/CreationWizard.javajet21
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/editor/DiagramEditorUtil.javajet130
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet2
6 files changed, 184 insertions, 286 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/CreationWizardGenerator.java b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/CreationWizardGenerator.java
index 6be8b34e3..26973418c 100644
--- a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/CreationWizardGenerator.java
+++ b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/CreationWizardGenerator.java
@@ -18,10 +18,10 @@ public class CreationWizardGenerator
protected final String TEXT_1 = "";
protected final String TEXT_2 = NL + "/*" + NL + " *";
protected final String TEXT_3 = NL + " */";
- protected final String TEXT_4 = NL + NL + "import java.lang.reflect.InvocationTargetException;" + NL + "" + NL + "import org.eclipse.core.runtime.CoreException;" + NL + "import org.eclipse.core.runtime.IProgressMonitor;" + NL + "import org.eclipse.emf.common.util.URI;" + NL + "import org.eclipse.jface.dialogs.ErrorDialog;" + NL + "import org.eclipse.jface.operation.IRunnableWithProgress;" + NL + "import org.eclipse.jface.viewers.IStructuredSelection;" + NL + "import org.eclipse.jface.wizard.Wizard;" + NL + "import org.eclipse.ui.INewWizard;" + NL + "import org.eclipse.ui.IWorkbench;";
+ protected final String TEXT_4 = NL + NL + "import java.lang.reflect.InvocationTargetException;" + NL + "" + NL + "import org.eclipse.core.runtime.CoreException;" + NL + "import org.eclipse.core.runtime.IProgressMonitor;" + NL + "import org.eclipse.emf.ecore.resource.Resource;" + NL + "import org.eclipse.jface.dialogs.ErrorDialog;" + NL + "import org.eclipse.jface.operation.IRunnableWithProgress;" + NL + "import org.eclipse.jface.viewers.IStructuredSelection;" + NL + "import org.eclipse.jface.wizard.Wizard;" + NL + "import org.eclipse.ui.INewWizard;" + NL + "import org.eclipse.ui.IWorkbench;";
protected final String TEXT_5 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
protected final String TEXT_6 = " extends Wizard implements INewWizard {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate IWorkbench workbench;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + " protected IStructuredSelection selection;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected ";
- protected final String TEXT_7 = " page;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected URI diagramURI;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean openNewlyCreatedDiagramEditor = true;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + " public IWorkbench getWorkbench() {" + NL + " return workbench;" + NL + " }" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IStructuredSelection getSelection() {" + NL + " return selection;" + NL + " }" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic final URI getDiagramURI() {" + NL + "\t\treturn diagramURI;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic final boolean isOpenNewlyCreatedDiagramEditor() {" + NL + "\t\treturn openNewlyCreatedDiagramEditor;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setOpenNewlyCreatedDiagramEditor(boolean openNewlyCreatedDiagramEditor) {" + NL + "\t\tthis.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void init(IWorkbench workbench, IStructuredSelection selection) {" + NL + " this.workbench = workbench;" + NL + " this.selection = selection;" + NL + "\t\tsetWindowTitle(\"New ";
+ protected final String TEXT_7 = " page;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Resource diagram;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate boolean openNewlyCreatedDiagramEditor = true;" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + " public IWorkbench getWorkbench() {" + NL + " return workbench;" + NL + " }" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic IStructuredSelection getSelection() {" + NL + " return selection;" + NL + " }" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic final Resource getDiagram() {" + NL + "\t\treturn diagram;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic final boolean isOpenNewlyCreatedDiagramEditor() {" + NL + "\t\treturn openNewlyCreatedDiagramEditor;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setOpenNewlyCreatedDiagramEditor(boolean openNewlyCreatedDiagramEditor) {" + NL + "\t\tthis.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void init(IWorkbench workbench, IStructuredSelection selection) {" + NL + " this.workbench = workbench;" + NL + " this.selection = selection;" + NL + "\t\tsetWindowTitle(\"New ";
protected final String TEXT_8 = " Diagram\");";
protected final String TEXT_9 = NL + "\t\tsetDefaultPageImageDescriptor(";
protected final String TEXT_10 = ".getBundledImageDescriptor(\"icons/wizban/New";
@@ -32,10 +32,11 @@ public class CreationWizardGenerator
protected final String TEXT_15 = NL + "\t\t\t\tnew ";
protected final String TEXT_16 = "(null) {" + NL + "" + NL + "\t\t\tprotected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException {";
protected final String TEXT_17 = NL + "\t\t\t\tnew IRunnableWithProgress() {" + NL + "" + NL + "\t\t\tpublic void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {";
- protected final String TEXT_18 = NL + "\t\t\t\tdiagramURI = ";
- protected final String TEXT_19 = ".createAndOpenDiagram(" + NL + "\t\t\t\t\t\tpage.getContainerFullPath()," + NL + "\t\t\t\t\t\tpage.getFileName()," + NL + "\t\t\t\t\t\tgetWorkbench().getActiveWorkbenchWindow()," + NL + "\t\t\t\t\t\tmonitor," + NL + "\t\t\t\t\t\tisOpenNewlyCreatedDiagramEditor()," + NL + "\t\t\t\t\t\ttrue);" + NL + "\t\t\t}" + NL + "\t\t};" + NL + "\t\ttry {" + NL + "\t\t\tgetContainer().run(false, true, op);" + NL + "\t\t} catch (InterruptedException e) {" + NL + "\t\t\treturn false;" + NL + "\t\t} catch (InvocationTargetException e) {" + NL + "\t\t\tif (e.getTargetException() instanceof CoreException) {" + NL + "\t\t\t\tErrorDialog.openError(getContainer().getShell(), \"Creation Problems\", null, ((CoreException) e.getTargetException()).getStatus());" + NL + "\t\t\t} else {" + NL + "\t\t\t\t";
- protected final String TEXT_20 = ".getInstance().logError(\"Error creating diagram\", e.getTargetException()); //$NON-NLS-1$" + NL + "\t\t\t}" + NL + "\t\t\treturn false;" + NL + "\t\t}" + NL + "\t\treturn diagramURI != null;" + NL + "\t}" + NL + "}";
- protected final String TEXT_21 = NL;
+ protected final String TEXT_18 = NL + "\t\t\t\tdiagram = ";
+ protected final String TEXT_19 = ".createDiagram(page.getContainerFullPath(), page.getFileName(), monitor);" + NL + "\t\t\t\tif (isOpenNewlyCreatedDiagramEditor() && diagram != null) {" + NL + "\t\t\t\t\t";
+ protected final String TEXT_20 = ".openDiagram(diagram);" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t};" + NL + "\t\ttry {" + NL + "\t\t\tgetContainer().run(false, true, op);" + NL + "\t\t} catch (InterruptedException e) {" + NL + "\t\t\treturn false;" + NL + "\t\t} catch (InvocationTargetException e) {" + NL + "\t\t\tif (e.getTargetException() instanceof CoreException) {" + NL + "\t\t\t\tErrorDialog.openError(getContainer().getShell(), \"Creation Problems\", null, ((CoreException) e.getTargetException()).getStatus());" + NL + "\t\t\t} else {" + NL + "\t\t\t\t";
+ protected final String TEXT_21 = ".getInstance().logError(\"Error creating diagram\", e.getTargetException()); //$NON-NLS-1$" + NL + "\t\t\t}" + NL + "\t\t\treturn false;" + NL + "\t\t}" + NL + "\t\treturn diagram != null;" + NL + "\t}" + NL + "}";
+ protected final String TEXT_22 = NL;
public String generate(Object argument)
{
@@ -94,10 +95,12 @@ final String pluginClassName = importManager.getImportedName(genDiagram.getEdito
stringBuffer.append(TEXT_18);
stringBuffer.append(importManager.getImportedName(genDiagram.getDiagramEditorUtilQualifiedClassName()));
stringBuffer.append(TEXT_19);
- stringBuffer.append(pluginClassName);
+ stringBuffer.append(importManager.getImportedName(genDiagram.getDiagramEditorUtilQualifiedClassName()));
stringBuffer.append(TEXT_20);
- importManager.emitSortedImports();
+ stringBuffer.append(pluginClassName);
stringBuffer.append(TEXT_21);
+ importManager.emitSortedImports();
+ stringBuffer.append(TEXT_22);
return stringBuffer.toString();
}
}
diff --git a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/DiagramEditorUtilGenerator.java b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/DiagramEditorUtilGenerator.java
index c6cb16b2d..3e944f8da 100644
--- a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/DiagramEditorUtilGenerator.java
+++ b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/DiagramEditorUtilGenerator.java
@@ -20,83 +20,73 @@ public class DiagramEditorUtilGenerator
protected final String TEXT_1 = "";
protected final String TEXT_2 = NL + "/*" + NL + " *";
protected final String TEXT_3 = NL + " */";
- protected final String TEXT_4 = NL + NL + "import java.io.IOException;" + NL + "import java.util.ArrayList;" + NL + "import java.util.Collections;" + NL + "import java.util.List;" + NL + "" + NL + "import org.eclipse.core.commands.ExecutionException;" + NL + "import org.eclipse.core.commands.operations.OperationHistoryFactory;" + NL + "import org.eclipse.core.resources.IFile;" + NL + "import org.eclipse.core.resources.IResource;" + NL + "import org.eclipse.core.runtime.IAdaptable;" + NL + "import org.eclipse.core.runtime.IPath;" + NL + "import org.eclipse.core.runtime.IProgressMonitor;" + NL + "import org.eclipse.core.runtime.SubProgressMonitor;" + NL + "import org.eclipse.emf.common.util.URI;" + NL + "import org.eclipse.emf.ecore.resource.Resource;" + NL + "import org.eclipse.emf.ecore.resource.ResourceSet;" + NL + "import org.eclipse.gmf.runtime.common.core.command.CommandResult;" + NL + "import org.eclipse.gmf.runtime.diagram.core.services.ViewService;" + NL + "import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;" + NL + "import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;" + NL + "import org.eclipse.gmf.runtime.notation.Diagram;" + NL + "import org.eclipse.swt.widgets.Shell;" + NL + "import org.eclipse.ui.IEditorPart;" + NL + "import org.eclipse.ui.IWorkbenchPage;" + NL + "import org.eclipse.ui.IWorkbenchWindow;" + NL + "import org.eclipse.ui.PartInitException;" + NL + "import org.eclipse.emf.transaction.TransactionalEditingDomain;";
+ protected final String TEXT_4 = NL + NL + "import java.io.IOException;" + NL + "import java.util.Collections;" + NL + "" + NL + "import org.eclipse.core.commands.ExecutionException;" + NL + "import org.eclipse.core.commands.operations.OperationHistoryFactory;" + NL + "import org.eclipse.core.resources.IFile;" + NL + "import org.eclipse.core.runtime.IAdaptable;" + NL + "import org.eclipse.core.runtime.IPath;" + NL + "import org.eclipse.core.runtime.IProgressMonitor;" + NL + "import org.eclipse.core.runtime.SubProgressMonitor;" + NL + "import org.eclipse.emf.common.util.URI;" + NL + "import org.eclipse.emf.ecore.resource.Resource;" + NL + "import org.eclipse.gmf.runtime.common.core.command.CommandResult;" + NL + "import org.eclipse.gmf.runtime.diagram.core.services.ViewService;" + NL + "import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;" + NL + "import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;" + NL + "import org.eclipse.gmf.runtime.notation.Diagram;" + NL + "import org.eclipse.ui.PartInitException;" + NL + "import org.eclipse.emf.transaction.TransactionalEditingDomain;";
protected final String TEXT_5 = NL + NL + "/**" + NL + " * @generated" + NL + " */" + NL + "public class ";
- protected final String TEXT_6 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final URI createAndOpenDiagram(IPath containerPath, String fileName, IWorkbenchWindow window, IProgressMonitor progressMonitor, boolean openEditor, boolean saveDiagram) {" + NL + "\t\tIFile diagramFile = createNewDiagramFile(containerPath, fileName, window.getShell(), progressMonitor);" + NL + "\t\tif (diagramFile != null && openEditor) {" + NL + "\t\t\topenDiagramEditor(window, diagramFile, saveDiagram, progressMonitor);" + NL + "\t\t}" + NL + "\t\treturn URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final IEditorPart openDiagramEditor(IWorkbenchWindow window, IFile file, boolean saveDiagram, IProgressMonitor progressMonitor) {" + NL + "\t\tIEditorPart editorPart = null;" + NL + "\t\ttry {" + NL + "\t\t\tIWorkbenchPage page = window.getActivePage();" + NL + "\t\t\tif (page != null) {" + NL + "\t\t\t\teditorPart = openDiagramEditor(page, file);" + NL + "\t\t\t\tif (saveDiagram) {" + NL + "\t\t\t\t\teditorPart.doSave(progressMonitor);" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t\tfile.refreshLocal(IResource.DEPTH_ZERO, null);" + NL + "\t\t\treturn editorPart;" + NL + "\t\t} catch (Exception e) {" + NL + "\t\t\t";
- protected final String TEXT_7 = ".getInstance().logError(\"Error opening diagram\", e);" + NL + "\t\t}" + NL + "\t\treturn null;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final IEditorPart openDiagramEditor(IWorkbenchPage page, IFile file) throws PartInitException {";
- protected final String TEXT_8 = NL + "\t\treturn ";
- protected final String TEXT_9 = ".openEditor(page, file);";
- protected final String TEXT_10 = NL + "\t\tURI fileURI = URI.createFileURI(file.getLocation().toString());" + NL + "\t\t";
- protected final String TEXT_11 = " editorDescriptor = page.getWorkbenchWindow().getWorkbench().getEditorRegistry().getDefaultEditor(fileURI.toFileString());" + NL + "\t\tif (editorDescriptor == null) {" + NL + "\t\t\t";
- protected final String TEXT_12 = ".openError(page.getWorkbenchWindow().getShell(), \"Error\"," + NL + "\t\t\t\t\t";
- protected final String TEXT_13 = ".bind(\"There is no editor registered for the file ''{0}''.\", fileURI.toFileString()));" + NL + "\t\t\treturn null;" + NL + "\t\t}" + NL + "\t\treturn page.openEditor(new ";
- protected final String TEXT_14 = "(fileURI), editorDescriptor.getId());";
- protected final String TEXT_15 = NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * <p>" + NL + "\t * This method should be called within a workspace modify operation since it creates resources." + NL + "\t * </p>" + NL + "\t * @generated" + NL + "\t * @return the created file resource, or <code>null</code> if the file was not created" + NL + "\t */" + NL + "\tpublic static final IFile createNewDiagramFile(IPath containerFullPath, String fileName, Shell shell, IProgressMonitor progressMonitor) {" + NL + "\t\tTransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();" + NL + "\t\tResourceSet resourceSet = editingDomain.getResourceSet();" + NL + "\t\tprogressMonitor.beginTask(\"Creating diagram and model files\", 3); //$NON-NLS-1$" + NL + "\t\tfinal IFile diagramFile = createNewFile(containerFullPath, fileName, shell);" + NL + "\t\tfinal Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true));" + NL + "\t\tList affectedFiles = new ArrayList();" + NL + "\t\taffectedFiles.add(diagramFile);";
- protected final String TEXT_16 = NL + "\t\tIPath modelFileRelativePath = diagramFile.getFullPath().removeFileExtension().addFileExtension(\"";
- protected final String TEXT_17 = "\"); //$NON-NLS-1$" + NL + "\t\tIFile modelFile = diagramFile.getParent().getFile(new ";
- protected final String TEXT_18 = "(modelFileRelativePath.lastSegment()));" + NL + "\t\tfinal Resource modelResource = resourceSet.createResource(URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true));" + NL + "\t\taffectedFiles.add(modelFile);";
- protected final String TEXT_19 = NL + "\t\tAbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, \"Creating diagram and model\", affectedFiles) { //$NON-NLS-1$" + NL + "\t\t\tprotected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {";
- protected final String TEXT_20 = NL + "\t\t\t\t";
- protected final String TEXT_21 = " model = createInitialModel();";
- protected final String TEXT_22 = NL + "\t\t\t\tmodelResource.getContents().add(createInitialRoot(model));";
- protected final String TEXT_23 = NL + "\t\t\t\tdiagramResource.getContents().add(model);";
- protected final String TEXT_24 = NL + "\t\t\t\tDiagram diagram = ViewService.createDiagram(";
- protected final String TEXT_25 = NL + "\t\t\t\t";
- protected final String TEXT_26 = "(";
- protected final String TEXT_27 = ") ";
- protected final String TEXT_28 = "model, ";
- protected final String TEXT_29 = NL + "\t\t\t\t\t";
- protected final String TEXT_30 = ".MODEL_ID," + NL + "\t\t\t\t\t";
- protected final String TEXT_31 = ".DIAGRAM_PREFERENCES_HINT);" + NL + "\t\t\t\tif (diagram != null) {" + NL + "\t\t\t\t\tdiagramResource.getContents().add(diagram);" + NL + "\t\t\t\t\tdiagram.setName(diagramFile.getName());";
- protected final String TEXT_32 = NL + "\t\t\t\t\tdiagram.setElement(";
- protected final String TEXT_33 = "(";
- protected final String TEXT_34 = ") ";
- protected final String TEXT_35 = "model);";
- protected final String TEXT_36 = NL + "\t\t\t\t}" + NL + "\t\t\ttry {";
- protected final String TEXT_37 = NL + "\t\t\t\t";
- protected final String TEXT_38 = " options = new ";
- protected final String TEXT_39 = "();" + NL + "\t\t\t\toptions.put(";
- protected final String TEXT_40 = ".OPTION_ENCODING, \"UTF-8\"); //$NON-NLS-1$" + NL + "\t\t\t\tmodelResource.save(options);";
- protected final String TEXT_41 = NL + "\t\t\t\tdiagramResource.save(Collections.EMPTY_MAP);" + NL + "\t\t\t} catch (IOException e) {" + NL + "\t\t\t\t";
- protected final String TEXT_42 = NL + "\t\t\t\t";
- protected final String TEXT_43 = ".getInstance().logError(\"Unable to store model and diagram resources\", e); //$NON-NLS-1$" + NL + "\t\t\t}" + NL + "\t\t\t\treturn CommandResult.newOKCommandResult();" + NL + "\t\t\t}" + NL + "\t\t};" + NL + "\t\t" + NL + "\t\ttry {" + NL + "\t\t\tOperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);" + NL + "\t\t} catch (ExecutionException e) {" + NL + "\t\t\t";
- protected final String TEXT_44 = ".getInstance().logError(\"Unable to create model and diagram\", e); //$NON-NLS-1$" + NL + "\t\t}" + NL + "\t\t";
- protected final String TEXT_45 = NL + "\t\ttry {" + NL + "\t\t\tmodelFile.setCharset(\"UTF-8\", new SubProgressMonitor(progressMonitor, 1)); //$NON-NLS-1$" + NL + "\t\t} catch (";
- protected final String TEXT_46 = " e) {" + NL + "\t\t\t";
- protected final String TEXT_47 = ".getInstance().logError(\"Unable to set charset for model file\", e); //$NON-NLS-1$" + NL + "\t\t}";
- protected final String TEXT_48 = NL + "\t\ttry {" + NL + "\t\t\tdiagramFile.setCharset(\"UTF-8\", new SubProgressMonitor(progressMonitor, 1)); //$NON-NLS-1$" + NL + "\t\t} catch (";
- protected final String TEXT_49 = " e) {" + NL + "\t\t\t";
- protected final String TEXT_50 = ".getInstance().logError(\"Unable to set charset for diagram file\", e); //$NON-NLS-1$" + NL + "\t\t}" + NL + "\t\t" + NL + "\t\treturn diagramFile;" + NL + "\t}";
- protected final String TEXT_51 = NL + "\t/**" + NL + "\t * Create a new instance of domain element associated with canvas." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static ";
- protected final String TEXT_52 = " createInitialModel() {" + NL + "\t\treturn ";
- protected final String TEXT_53 = ".";
- protected final String TEXT_54 = ".create";
- protected final String TEXT_55 = "();" + NL + "\t}" + NL;
- protected final String TEXT_56 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static ";
- protected final String TEXT_57 = " createInitialRoot(";
- protected final String TEXT_58 = " model) {";
- protected final String TEXT_59 = NL + "\t\treturn ";
- protected final String TEXT_60 = "(";
- protected final String TEXT_61 = ") ";
- protected final String TEXT_62 = "model;";
- protected final String TEXT_63 = NL + "\t\t";
- protected final String TEXT_64 = " docRoot =" + NL + "\t\t\t\t";
- protected final String TEXT_65 = ".";
- protected final String TEXT_66 = ".create";
- protected final String TEXT_67 = "();" + NL + "\t\tdocRoot.set";
- protected final String TEXT_68 = "(model);" + NL + "\t\treturn docRoot;";
- protected final String TEXT_69 = NL + "\t}";
- protected final String TEXT_70 = NL + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static IFile createNewFile(IPath containerPath, String fileName, Shell shell) {" + NL + "\t\tIPath newFilePath = containerPath.append(fileName);" + NL + "\t\tIFile newFileHandle = ";
- protected final String TEXT_71 = ".getWorkspace().getRoot().getFile(newFilePath);" + NL + "\t\ttry {" + NL + "\t\t\tcreateFile(newFileHandle);" + NL + "\t\t} catch (";
- protected final String TEXT_72 = " e) {" + NL + "\t\t\t";
- protected final String TEXT_73 = ".openError(shell, \"Creation Problems\", null, e.getStatus());" + NL + "\t\t\treturn null;" + NL + "\t\t}" + NL + "\t\treturn newFileHandle;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected static void createFile(IFile fileHandle) throws ";
- protected final String TEXT_74 = " {" + NL + "\t\ttry {" + NL + "\t\t\tfileHandle.create(new ";
- protected final String TEXT_75 = "(new byte[0])," + NL + "\t\t\t\t\tfalse, new ";
- protected final String TEXT_76 = "());" + NL + "\t\t} catch (";
- protected final String TEXT_77 = " e) {" + NL + "\t\t\t// If the file already existed locally, just refresh to get contents" + NL + "\t\t\tif (e.getStatus().getCode() == ";
- protected final String TEXT_78 = ".PATH_OCCUPIED) {" + NL + "\t\t\t\tfileHandle.refreshLocal(";
- protected final String TEXT_79 = ".DEPTH_ZERO, null);" + NL + "\t\t\t} else {" + NL + "\t\t\t\tthrow e;" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t}" + NL + "}";
- protected final String TEXT_80 = NL;
+ protected final String TEXT_6 = " {" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static boolean openDiagram(Resource diagram) throws PartInitException {";
+ protected final String TEXT_7 = NL + "\t\treturn ";
+ protected final String TEXT_8 = ".openEditor((EObject) diagram.getContents().get(0));";
+ protected final String TEXT_9 = NL + "\t\tURI fileURI = URI.createFileURI(file.getLocation().toString());" + NL + "\t\t";
+ protected final String TEXT_10 = " editorDescriptor = page.getWorkbenchWindow().getWorkbench().getEditorRegistry().getDefaultEditor(fileURI.toFileString());" + NL + "\t\tif (editorDescriptor == null) {" + NL + "\t\t\t";
+ protected final String TEXT_11 = ".openError(page.getWorkbenchWindow().getShell(), \"Error\"," + NL + "\t\t\t\t\t";
+ protected final String TEXT_12 = ".bind(\"There is no editor registered for the file ''{0}''.\", fileURI.toFileString()));" + NL + "\t\t\treturn null;" + NL + "\t\t}" + NL + "\t\treturn page.openEditor(new ";
+ protected final String TEXT_13 = "(fileURI), editorDescriptor.getId());";
+ protected final String TEXT_14 = NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static void setCharset(IPath path) {" + NL + "\t\tIFile file = ";
+ protected final String TEXT_15 = ".getWorkspace().getRoot().getFile(path);" + NL + "\t\ttry {" + NL + "\t\t\tfile.setCharset(\"UTF-8\", new ";
+ protected final String TEXT_16 = "()); //$NON-NLS-1$" + NL + "\t\t} catch (";
+ protected final String TEXT_17 = " e) {" + NL + "\t\t\t";
+ protected final String TEXT_18 = ".getInstance().logError(\"Unable to set charset for file \" + path, e); //$NON-NLS-1$" + NL + "\t\t}" + NL + "\t}" + NL + "" + NL + "\t/**";
+ protected final String TEXT_19 = NL + "\t * <p>" + NL + "\t * This method should be called within a workspace modify operation since it creates resources." + NL + "\t * </p>";
+ protected final String TEXT_20 = NL + "\t * @generated" + NL + "\t * @return the created resource, or <code>null</code> if the resource was not created" + NL + "\t */" + NL + "\tpublic static final Resource createDiagram(IPath containerFullPath, final String fileName, IProgressMonitor progressMonitor) {" + NL + "\t\tTransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();" + NL + "\t\tprogressMonitor.beginTask(\"Creating diagram and model files\", 3); //$NON-NLS-1$" + NL + "\t\tIPath diagramPath = containerFullPath.append(fileName);" + NL + "\t\tfinal Resource diagramResource = editingDomain.getResourceSet().createResource(URI.createPlatformResourceURI(diagramPath.toString()));";
+ protected final String TEXT_21 = NL + "\t\tIPath modelPath = diagramPath.removeFileExtension().addFileExtension(\"taipan\"); //$NON-NLS-1$" + NL + "\t\tfinal Resource modelResource = editingDomain.getResourceSet().createResource(URI.createPlatformResourceURI(modelPath.toString()));";
+ protected final String TEXT_22 = NL + "\t\tAbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, \"Creating diagram and model\", Collections.EMPTY_LIST) { //$NON-NLS-1$" + NL + "\t\t\tprotected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {";
+ protected final String TEXT_23 = NL + "\t\t\t\t";
+ protected final String TEXT_24 = " model = createInitialModel();";
+ protected final String TEXT_25 = NL + "\t\t\t\tmodelResource.getContents().add(createInitialRoot(model));";
+ protected final String TEXT_26 = NL + "\t\t\t\tdiagramResource.getContents().add(model);";
+ protected final String TEXT_27 = NL + "\t\t\t\tDiagram diagram = ViewService.createDiagram(";
+ protected final String TEXT_28 = NL + "\t\t\t\t";
+ protected final String TEXT_29 = "(";
+ protected final String TEXT_30 = ") ";
+ protected final String TEXT_31 = "model, ";
+ protected final String TEXT_32 = NL + "\t\t\t\t\t";
+ protected final String TEXT_33 = ".MODEL_ID," + NL + "\t\t\t\t\t";
+ protected final String TEXT_34 = ".DIAGRAM_PREFERENCES_HINT);" + NL + "\t\t\t\tif (diagram != null) {" + NL + "\t\t\t\t\tdiagramResource.getContents().add(diagram);" + NL + "\t\t\t\t\tdiagram.setName(fileName);";
+ protected final String TEXT_35 = NL + "\t\t\t\t\tdiagram.setElement(";
+ protected final String TEXT_36 = "(";
+ protected final String TEXT_37 = ") ";
+ protected final String TEXT_38 = "model);";
+ protected final String TEXT_39 = NL + "\t\t\t\t}" + NL + "\t\t\ttry {" + NL + "\t\t\t\t";
+ protected final String TEXT_40 = " options = new ";
+ protected final String TEXT_41 = "();" + NL + "\t\t\t\toptions.put(";
+ protected final String TEXT_42 = ".OPTION_ENCODING, \"UTF-8\"); //$NON-NLS-1$";
+ protected final String TEXT_43 = NL + "\t\t\t\tmodelResource.save(options);";
+ protected final String TEXT_44 = NL + "\t\t\t\tdiagramResource.save(options);" + NL + "\t\t\t} catch (IOException e) {" + NL + "\t\t\t\t";
+ protected final String TEXT_45 = NL + "\t\t\t\t";
+ protected final String TEXT_46 = ".getInstance().logError(\"Unable to store model and diagram resources\", e); //$NON-NLS-1$" + NL + "\t\t\t}" + NL + "\t\t\t\treturn CommandResult.newOKCommandResult();" + NL + "\t\t\t}" + NL + "\t\t};" + NL + "\t\t" + NL + "\t\ttry {" + NL + "\t\t\tOperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);" + NL + "\t\t} catch (ExecutionException e) {" + NL + "\t\t\t";
+ protected final String TEXT_47 = ".getInstance().logError(\"Unable to create model and diagram\", e); //$NON-NLS-1$" + NL + "\t\t}" + NL + "\t\t";
+ protected final String TEXT_48 = NL + "\t\tsetCharset(modelPath);";
+ protected final String TEXT_49 = NL + "\t\tsetCharset(diagramPath);" + NL + "\t\treturn diagramResource;" + NL + "\t}";
+ protected final String TEXT_50 = NL + "\t/**" + NL + "\t * Create a new instance of domain element associated with canvas." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static ";
+ protected final String TEXT_51 = " createInitialModel() {" + NL + "\t\treturn ";
+ protected final String TEXT_52 = ".";
+ protected final String TEXT_53 = ".create";
+ protected final String TEXT_54 = "();" + NL + "\t}" + NL;
+ protected final String TEXT_55 = NL + "\t/**" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprivate static ";
+ protected final String TEXT_56 = " createInitialRoot(";
+ protected final String TEXT_57 = " model) {";
+ protected final String TEXT_58 = NL + "\t\treturn ";
+ protected final String TEXT_59 = "(";
+ protected final String TEXT_60 = ") ";
+ protected final String TEXT_61 = "model;";
+ protected final String TEXT_62 = NL + "\t\t";
+ protected final String TEXT_63 = " docRoot =" + NL + "\t\t\t\t";
+ protected final String TEXT_64 = ".";
+ protected final String TEXT_65 = ".create";
+ protected final String TEXT_66 = "();" + NL + "\t\tdocRoot.set";
+ protected final String TEXT_67 = "(model);" + NL + "\t\treturn docRoot;";
+ protected final String TEXT_68 = NL + "\t}";
+ protected final String TEXT_69 = NL + "}";
+ protected final String TEXT_70 = NL;
public String generate(Object argument)
{
@@ -121,128 +111,126 @@ if (copyrightText != null && copyrightText.trim().length() > 0) {
stringBuffer.append(TEXT_5);
stringBuffer.append(importManager.getCompilationUnitName());
stringBuffer.append(TEXT_6);
- stringBuffer.append(importManager.getImportedName(editorGen.getPlugin().getActivatorQualifiedClassName()));
- stringBuffer.append(TEXT_7);
if (editorGen.getApplication() == null) {
+ stringBuffer.append(TEXT_7);
+ stringBuffer.append(importManager.getImportedName("org.eclipse.emf.edit.ui.util.EditUIUtil"));
stringBuffer.append(TEXT_8);
- stringBuffer.append(importManager.getImportedName("org.eclipse.ui.ide.IDE"));
- stringBuffer.append(TEXT_9);
} else {
- stringBuffer.append(TEXT_10);
+ stringBuffer.append(TEXT_9);
stringBuffer.append(importManager.getImportedName("org.eclipse.ui.IEditorDescriptor"));
- stringBuffer.append(TEXT_11);
+ stringBuffer.append(TEXT_10);
stringBuffer.append(importManager.getImportedName("org.eclipse.jface.dialogs.MessageDialog"));
- stringBuffer.append(TEXT_12);
+ stringBuffer.append(TEXT_11);
stringBuffer.append(importManager.getImportedName("org.eclipse.osgi.util.NLS"));
- stringBuffer.append(TEXT_13);
+ stringBuffer.append(TEXT_12);
stringBuffer.append(importManager.getImportedName("org.eclipse.emf.common.ui.URIEditorInput"));
- stringBuffer.append(TEXT_14);
+ stringBuffer.append(TEXT_13);
}
+ stringBuffer.append(TEXT_14);
+ stringBuffer.append(importManager.getImportedName("org.eclipse.core.resources.ResourcesPlugin"));
stringBuffer.append(TEXT_15);
+ stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.NullProgressMonitor"));
+ stringBuffer.append(TEXT_16);
+ stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.CoreException"));
+ stringBuffer.append(TEXT_17);
+ stringBuffer.append(importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName()));
+ stringBuffer.append(TEXT_18);
+ if (editorGen.getApplication() == null) {
+ stringBuffer.append(TEXT_19);
+ }
+ stringBuffer.append(TEXT_20);
final boolean standaloneDomainModel = !editorGen.isSameFileForDiagramAndModel() && genDiagram.getDomainDiagramElement() != null;
if (standaloneDomainModel) {
- stringBuffer.append(TEXT_16);
- stringBuffer.append(editorGen.getDomainFileExtension());
- stringBuffer.append(TEXT_17);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.Path"));
- stringBuffer.append(TEXT_18);
+ stringBuffer.append(TEXT_21);
}
- stringBuffer.append(TEXT_19);
+ stringBuffer.append(TEXT_22);
if (genDiagram.getDomainDiagramElement() != null) {
- stringBuffer.append(TEXT_20);
+ stringBuffer.append(TEXT_23);
stringBuffer.append(importManager.getImportedName(genDiagram.getDomainDiagramElement().getQualifiedInterfaceName()));
- stringBuffer.append(TEXT_21);
+ stringBuffer.append(TEXT_24);
if (standaloneDomainModel) {
- stringBuffer.append(TEXT_22);
+ stringBuffer.append(TEXT_25);
} else {
- stringBuffer.append(TEXT_23);
+ stringBuffer.append(TEXT_26);
}
}
- stringBuffer.append(TEXT_24);
- if (genDiagram.getDomainDiagramElement() != null) {
- stringBuffer.append(TEXT_25);
- if (genDiagram.getDomainDiagramElement().isExternalInterface()) {
- stringBuffer.append(TEXT_26);
- stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
stringBuffer.append(TEXT_27);
- }
+ if (genDiagram.getDomainDiagramElement() != null) {
stringBuffer.append(TEXT_28);
- }
+ if (genDiagram.getDomainDiagramElement().isExternalInterface()) {
stringBuffer.append(TEXT_29);
- stringBuffer.append(importManager.getImportedName(genDiagram.getEditPartQualifiedClassName()));
+ stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
stringBuffer.append(TEXT_30);
- stringBuffer.append(genDiagram.getEditorGen().getPlugin().getActivatorClassName());
+ }
stringBuffer.append(TEXT_31);
- if (genDiagram.getDomainDiagramElement() != null) {
+ }
stringBuffer.append(TEXT_32);
- if (genDiagram.getDomainDiagramElement().isExternalInterface()) {
+ stringBuffer.append(importManager.getImportedName(genDiagram.getEditPartQualifiedClassName()));
stringBuffer.append(TEXT_33);
- stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
+ stringBuffer.append(genDiagram.getEditorGen().getPlugin().getActivatorClassName());
stringBuffer.append(TEXT_34);
- }
+ if (genDiagram.getDomainDiagramElement() != null) {
stringBuffer.append(TEXT_35);
- }
+ if (genDiagram.getDomainDiagramElement().isExternalInterface()) {
stringBuffer.append(TEXT_36);
- if (standaloneDomainModel) {
+ stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
stringBuffer.append(TEXT_37);
- stringBuffer.append(importManager.getImportedName("java.util.Map"));
+ }
stringBuffer.append(TEXT_38);
- stringBuffer.append(importManager.getImportedName("java.util.HashMap"));
+ }
stringBuffer.append(TEXT_39);
- stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.xmi.XMIResource"));
+ stringBuffer.append(importManager.getImportedName("java.util.Map"));
stringBuffer.append(TEXT_40);
- }
+ stringBuffer.append(importManager.getImportedName("java.util.HashMap"));
stringBuffer.append(TEXT_41);
- // TODO CommandResult.newErrorCommandResult(e) would be better?
+ stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.xmi.XMIResource"));
stringBuffer.append(TEXT_42);
- stringBuffer.append(importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName()));
+ if (standaloneDomainModel) {
stringBuffer.append(TEXT_43);
- stringBuffer.append(importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName()));
+ }
stringBuffer.append(TEXT_44);
- if (standaloneDomainModel) {
+ // TODO CommandResult.newErrorCommandResult(e) would be better?
stringBuffer.append(TEXT_45);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.CoreException"));
+ stringBuffer.append(importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName()));
stringBuffer.append(TEXT_46);
stringBuffer.append(importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName()));
stringBuffer.append(TEXT_47);
- }
+ if (standaloneDomainModel) {
stringBuffer.append(TEXT_48);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.CoreException"));
+ }
stringBuffer.append(TEXT_49);
- stringBuffer.append(importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName()));
- stringBuffer.append(TEXT_50);
if (genDiagram.getDomainDiagramElement() != null) {
final String diagramElementImportedName = importManager.getImportedName(genDiagram.getDomainDiagramElement().getQualifiedInterfaceName());
final GenPackage domainGenPackage = genDiagram.getDomainDiagramElement().getGenPackage();
- stringBuffer.append(TEXT_51);
+ stringBuffer.append(TEXT_50);
stringBuffer.append(diagramElementImportedName);
- stringBuffer.append(TEXT_52);
+ stringBuffer.append(TEXT_51);
stringBuffer.append(importManager.getImportedName(domainGenPackage.getQualifiedFactoryInterfaceName()));
- stringBuffer.append(TEXT_53);
+ stringBuffer.append(TEXT_52);
stringBuffer.append(domainGenPackage.getFactoryInstanceName());
- stringBuffer.append(TEXT_54);
+ stringBuffer.append(TEXT_53);
stringBuffer.append(genDiagram.getDomainDiagramElement().getName());
- stringBuffer.append(TEXT_55);
+ stringBuffer.append(TEXT_54);
if (standaloneDomainModel /*may need docRoot only if separate file for domain model*/) {
- stringBuffer.append(TEXT_56);
+ stringBuffer.append(TEXT_55);
stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
- stringBuffer.append(TEXT_57);
+ stringBuffer.append(TEXT_56);
stringBuffer.append(diagramElementImportedName);
- stringBuffer.append(TEXT_58);
+ stringBuffer.append(TEXT_57);
if (!domainGenPackage.hasDocumentRoot()) {
- stringBuffer.append(TEXT_59);
+ stringBuffer.append(TEXT_58);
if (genDiagram.getDomainDiagramElement().isExternalInterface()) {
- stringBuffer.append(TEXT_60);
+ stringBuffer.append(TEXT_59);
stringBuffer.append(importManager.getImportedName("org.eclipse.emf.ecore.EObject"));
- stringBuffer.append(TEXT_61);
+ stringBuffer.append(TEXT_60);
}
- stringBuffer.append(TEXT_62);
+ stringBuffer.append(TEXT_61);
} else {
// would be better to get GenClass for docRoot and directly use setter
GenClass docRoot = domainGenPackage.getDocumentRoot();
@@ -257,42 +245,24 @@ for (java.util.Iterator it = docRoot.getGenFeatures().iterator(); it.hasNext();
}
} /*for*/
- stringBuffer.append(TEXT_63);
+ stringBuffer.append(TEXT_62);
stringBuffer.append(importManager.getImportedName(docRoot.getQualifiedInterfaceName()));
- stringBuffer.append(TEXT_64);
+ stringBuffer.append(TEXT_63);
stringBuffer.append(importManager.getImportedName(domainGenPackage.getQualifiedFactoryInterfaceName()));
- stringBuffer.append(TEXT_65);
+ stringBuffer.append(TEXT_64);
stringBuffer.append(domainGenPackage.getFactoryInstanceName());
- stringBuffer.append(TEXT_66);
+ stringBuffer.append(TEXT_65);
stringBuffer.append(docRoot.getName());
- stringBuffer.append(TEXT_67);
+ stringBuffer.append(TEXT_66);
stringBuffer.append(featureAccessor);
- stringBuffer.append(TEXT_68);
+ stringBuffer.append(TEXT_67);
}
- stringBuffer.append(TEXT_69);
+ stringBuffer.append(TEXT_68);
} /*if standaloneDomainModel*/
} /* domainDiagramElement != null */
- stringBuffer.append(TEXT_70);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.resources.ResourcesPlugin"));
- stringBuffer.append(TEXT_71);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.CoreException"));
- stringBuffer.append(TEXT_72);
- stringBuffer.append(importManager.getImportedName("org.eclipse.jface.dialogs.ErrorDialog"));
- stringBuffer.append(TEXT_73);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.CoreException"));
- stringBuffer.append(TEXT_74);
- stringBuffer.append(importManager.getImportedName("java.io.ByteArrayInputStream"));
- stringBuffer.append(TEXT_75);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.NullProgressMonitor"));
- stringBuffer.append(TEXT_76);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.runtime.CoreException"));
- stringBuffer.append(TEXT_77);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.resources.IResourceStatus"));
- stringBuffer.append(TEXT_78);
- stringBuffer.append(importManager.getImportedName("org.eclipse.core.resources.IResource"));
- stringBuffer.append(TEXT_79);
+ stringBuffer.append(TEXT_69);
importManager.emitSortedImports();
- stringBuffer.append(TEXT_80);
+ stringBuffer.append(TEXT_70);
return stringBuffer.toString();
}
}
diff --git a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/NewDiagramFileWizardGenerator.java b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/NewDiagramFileWizardGenerator.java
index 0669268fe..69940d249 100644
--- a/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/NewDiagramFileWizardGenerator.java
+++ b/plugins/org.eclipse.gmf.codegen/src-templates/org/eclipse/gmf/codegen/templates/editor/NewDiagramFileWizardGenerator.java
@@ -39,7 +39,7 @@ public class NewDiagramFileWizardGenerator {
protected final String TEXT_20 = NL + "\t\t\t\tdiagramResource.getContents().add(diagram.getElement());";
protected final String TEXT_21 = NL + "\t\t\t\tinitDiagramContents(diagram, myDiagramRoot);";
protected final String TEXT_22 = NL + "\t\t\t\treturn CommandResult.newOKCommandResult();" + NL + "\t\t\t}" + NL + "\t\t};" + NL + "\t\t\t" + NL + "\t\ttry {" + NL + "\t\t\tOperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);" + NL + "\t\t\tdiagramResource.save(Collections.EMPTY_MAP);" + NL + "\t\t\t";
- protected final String TEXT_23 = ".openDiagramEditor(myWorkbenchPage, diagramFile);" + NL + "\t\t} catch (ExecutionException e) {" + NL + "\t\t\t";
+ protected final String TEXT_23 = ".openDiagram(diagramResource);" + NL + "\t\t} catch (ExecutionException e) {" + NL + "\t\t\t";
protected final String TEXT_24 = ".getInstance().logError(\"Unable to create model and diagram\", e); //$NON-NLS-1$" + NL + "\t\t} catch (IOException ex) {" + NL + "\t\t\t";
protected final String TEXT_25 = ".getInstance().logError(\"Save operation failed for: \" + diagramFile.getFullPath().toString(), ex); //$NON-NLS-1$" + NL + "\t\t} catch (PartInitException ex) {" + NL + "\t\t\t";
protected final String TEXT_26 = ".getInstance().logError(\"Unable to open editor\", ex); //$NON-NLS-1$" + NL + "\t\t}\t\t\t" + NL + "\t\treturn true;" + NL + "\t}" + NL + "\t\t";
diff --git a/plugins/org.eclipse.gmf.codegen/templates/editor/CreationWizard.javajet b/plugins/org.eclipse.gmf.codegen/templates/editor/CreationWizard.javajet
index 26a00dbc7..86050f52d 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/editor/CreationWizard.javajet
+++ b/plugins/org.eclipse.gmf.codegen/templates/editor/CreationWizard.javajet
@@ -11,7 +11,7 @@ import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -43,7 +43,7 @@ public class <%=importManager.getCompilationUnitName()%> extends Wizard implemen
/**
* @generated
*/
- protected URI diagramURI;
+ protected Resource diagram;
/**
* @generated
@@ -67,8 +67,8 @@ public class <%=importManager.getCompilationUnitName()%> extends Wizard implemen
/**
* @generated
*/
- public final URI getDiagramURI() {
- return diagramURI;
+ public final Resource getDiagram() {
+ return diagram;
}
/**
@@ -130,13 +130,10 @@ final String pluginClassName = importManager.getImportedName(genDiagram.getEdito
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
<%}%>
- diagramURI = <%=importManager.getImportedName(genDiagram.getDiagramEditorUtilQualifiedClassName())%>.createAndOpenDiagram(
- page.getContainerFullPath(),
- page.getFileName(),
- getWorkbench().getActiveWorkbenchWindow(),
- monitor,
- isOpenNewlyCreatedDiagramEditor(),
- true);
+ diagram = <%=importManager.getImportedName(genDiagram.getDiagramEditorUtilQualifiedClassName())%>.createDiagram(page.getContainerFullPath(), page.getFileName(), monitor);
+ if (isOpenNewlyCreatedDiagramEditor() && diagram != null) {
+ <%=importManager.getImportedName(genDiagram.getDiagramEditorUtilQualifiedClassName())%>.openDiagram(diagram);
+ }
}
};
try {
@@ -151,7 +148,7 @@ final String pluginClassName = importManager.getImportedName(genDiagram.getEdito
}
return false;
}
- return diagramURI != null;
+ return diagram != null;
}
}
<%importManager.emitSortedImports();%>
diff --git a/plugins/org.eclipse.gmf.codegen/templates/editor/DiagramEditorUtil.javajet b/plugins/org.eclipse.gmf.codegen/templates/editor/DiagramEditorUtil.javajet
index 93dd63232..7f0c4016f 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/editor/DiagramEditorUtil.javajet
+++ b/plugins/org.eclipse.gmf.codegen/templates/editor/DiagramEditorUtil.javajet
@@ -9,30 +9,22 @@ final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1]
<%importManager.emitPackageStatement(stringBuffer);%>
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
<%importManager.markImportLocation(stringBuffer);%>
@@ -45,41 +37,9 @@ public class <%=importManager.getCompilationUnitName()%> {
/**
* @generated
*/
- public static final URI createAndOpenDiagram(IPath containerPath, String fileName, IWorkbenchWindow window, IProgressMonitor progressMonitor, boolean openEditor, boolean saveDiagram) {
- IFile diagramFile = createNewDiagramFile(containerPath, fileName, window.getShell(), progressMonitor);
- if (diagramFile != null && openEditor) {
- openDiagramEditor(window, diagramFile, saveDiagram, progressMonitor);
- }
- return URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
- }
-
- /**
- * @generated
- */
- public static final IEditorPart openDiagramEditor(IWorkbenchWindow window, IFile file, boolean saveDiagram, IProgressMonitor progressMonitor) {
- IEditorPart editorPart = null;
- try {
- IWorkbenchPage page = window.getActivePage();
- if (page != null) {
- editorPart = openDiagramEditor(page, file);
- if (saveDiagram) {
- editorPart.doSave(progressMonitor);
- }
- }
- file.refreshLocal(IResource.DEPTH_ZERO, null);
- return editorPart;
- } catch (Exception e) {
- <%=importManager.getImportedName(editorGen.getPlugin().getActivatorQualifiedClassName())%>.getInstance().logError("Error opening diagram", e);
- }
- return null;
- }
-
- /**
- * @generated
- */
- public static final IEditorPart openDiagramEditor(IWorkbenchPage page, IFile file) throws PartInitException {
+ public static boolean openDiagram(Resource diagram) throws PartInitException {
<%if (editorGen.getApplication() == null) {%>
- return <%=importManager.getImportedName("org.eclipse.ui.ide.IDE")%>.openEditor(page, file);
+ return <%=importManager.getImportedName("org.eclipse.emf.edit.ui.util.EditUIUtil")%>.openEditor((EObject) diagram.getContents().get(0));
<%} else {%>
URI fileURI = URI.createFileURI(file.getLocation().toString());
<%=importManager.getImportedName("org.eclipse.ui.IEditorDescriptor")%> editorDescriptor = page.getWorkbenchWindow().getWorkbench().getEditorRegistry().getDefaultEditor(fileURI.toFileString());
@@ -93,30 +53,39 @@ public class <%=importManager.getCompilationUnitName()%> {
}
/**
+ * @generated
+ */
+ private static void setCharset(IPath path) {
+ IFile file = <%=importManager.getImportedName("org.eclipse.core.resources.ResourcesPlugin")%>.getWorkspace().getRoot().getFile(path);
+ try {
+ file.setCharset("UTF-8", new <%=importManager.getImportedName("org.eclipse.core.runtime.NullProgressMonitor")%>()); //$NON-NLS-1$
+ } catch (<%=importManager.getImportedName("org.eclipse.core.runtime.CoreException")%> e) {
+ <%=importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName())%>.getInstance().logError("Unable to set charset for file " + path, e); //$NON-NLS-1$
+ }
+ }
+
+ /**
+<%if (editorGen.getApplication() == null) {%>
* <p>
* This method should be called within a workspace modify operation since it creates resources.
* </p>
+<%}%>
* @generated
- * @return the created file resource, or <code>null</code> if the file was not created
+ * @return the created resource, or <code>null</code> if the resource was not created
*/
- public static final IFile createNewDiagramFile(IPath containerFullPath, String fileName, Shell shell, IProgressMonitor progressMonitor) {
+ public static final Resource createDiagram(IPath containerFullPath, final String fileName, IProgressMonitor progressMonitor) {
TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
- ResourceSet resourceSet = editingDomain.getResourceSet();
progressMonitor.beginTask("Creating diagram and model files", 3); //$NON-NLS-1$
- final IFile diagramFile = createNewFile(containerFullPath, fileName, shell);
- final Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true));
- List affectedFiles = new ArrayList();
- affectedFiles.add(diagramFile);
+ IPath diagramPath = containerFullPath.append(fileName);
+ final Resource diagramResource = editingDomain.getResourceSet().createResource(URI.createPlatformResourceURI(diagramPath.toString()));
<%
final boolean standaloneDomainModel = !editorGen.isSameFileForDiagramAndModel() && genDiagram.getDomainDiagramElement() != null;
if (standaloneDomainModel) {
%>
- IPath modelFileRelativePath = diagramFile.getFullPath().removeFileExtension().addFileExtension("<%=editorGen.getDomainFileExtension()%>"); //$NON-NLS-1$
- IFile modelFile = diagramFile.getParent().getFile(new <%=importManager.getImportedName("org.eclipse.core.runtime.Path")%>(modelFileRelativePath.lastSegment()));
- final Resource modelResource = resourceSet.createResource(URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true));
- affectedFiles.add(modelFile);
+ IPath modelPath = diagramPath.removeFileExtension().addFileExtension("taipan"); //$NON-NLS-1$
+ final Resource modelResource = editingDomain.getResourceSet().createResource(URI.createPlatformResourceURI(modelPath.toString()));
<%}%>
- AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, "Creating diagram and model", affectedFiles) { //$NON-NLS-1$
+ AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, "Creating diagram and model", Collections.EMPTY_LIST) { //$NON-NLS-1$
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
<%
if (genDiagram.getDomainDiagramElement() != null) {%>
@@ -137,18 +106,18 @@ if (genDiagram.getDomainDiagramElement() != null) {%>
<%=genDiagram.getEditorGen().getPlugin().getActivatorClassName()%>.DIAGRAM_PREFERENCES_HINT);
if (diagram != null) {
diagramResource.getContents().add(diagram);
- diagram.setName(diagramFile.getName());
+ diagram.setName(fileName);
<%if (genDiagram.getDomainDiagramElement() != null) {%>
diagram.setElement(<%if (genDiagram.getDomainDiagramElement().isExternalInterface()) {%>(<%=importManager.getImportedName("org.eclipse.emf.ecore.EObject")%>) <%}%>model);
<%}%>
}
try {
-<%if (standaloneDomainModel) {%>
<%=importManager.getImportedName("java.util.Map")%> options = new <%=importManager.getImportedName("java.util.HashMap")%>();
options.put(<%=importManager.getImportedName("org.eclipse.emf.ecore.xmi.XMIResource")%>.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
+<%if (standaloneDomainModel) {%>
modelResource.save(options);
<%}%>
- diagramResource.save(Collections.EMPTY_MAP);
+ diagramResource.save(options);
} catch (IOException e) {
<%// TODO CommandResult.newErrorCommandResult(e) would be better? %>
<%=importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName())%>.getInstance().logError("Unable to store model and diagram resources", e); //$NON-NLS-1$
@@ -164,19 +133,10 @@ if (genDiagram.getDomainDiagramElement() != null) {%>
}
<%if (standaloneDomainModel) {%>
- try {
- modelFile.setCharset("UTF-8", new SubProgressMonitor(progressMonitor, 1)); //$NON-NLS-1$
- } catch (<%=importManager.getImportedName("org.eclipse.core.runtime.CoreException")%> e) {
- <%=importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName())%>.getInstance().logError("Unable to set charset for model file", e); //$NON-NLS-1$
- }
+ setCharset(modelPath);
<%}%>
- try {
- diagramFile.setCharset("UTF-8", new SubProgressMonitor(progressMonitor, 1)); //$NON-NLS-1$
- } catch (<%=importManager.getImportedName("org.eclipse.core.runtime.CoreException")%> e) {
- <%=importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName())%>.getInstance().logError("Unable to set charset for diagram file", e); //$NON-NLS-1$
- }
-
- return diagramFile;
+ setCharset(diagramPath);
+ return diagramResource;
}
<%if (genDiagram.getDomainDiagramElement() != null) {
final String diagramElementImportedName = importManager.getImportedName(genDiagram.getDomainDiagramElement().getQualifiedInterfaceName());
@@ -221,37 +181,5 @@ for (java.util.Iterator it = docRoot.getGenFeatures().iterator(); it.hasNext();
}
<%} /*if standaloneDomainModel*/
} /* domainDiagramElement != null */%>
-
- /**
- * @generated
- */
- public static IFile createNewFile(IPath containerPath, String fileName, Shell shell) {
- IPath newFilePath = containerPath.append(fileName);
- IFile newFileHandle = <%=importManager.getImportedName("org.eclipse.core.resources.ResourcesPlugin")%>.getWorkspace().getRoot().getFile(newFilePath);
- try {
- createFile(newFileHandle);
- } catch (<%=importManager.getImportedName("org.eclipse.core.runtime.CoreException")%> e) {
- <%=importManager.getImportedName("org.eclipse.jface.dialogs.ErrorDialog")%>.openError(shell, "Creation Problems", null, e.getStatus());
- return null;
- }
- return newFileHandle;
- }
-
- /**
- * @generated
- */
- protected static void createFile(IFile fileHandle) throws <%=importManager.getImportedName("org.eclipse.core.runtime.CoreException")%> {
- try {
- fileHandle.create(new <%=importManager.getImportedName("java.io.ByteArrayInputStream")%>(new byte[0]),
- false, new <%=importManager.getImportedName("org.eclipse.core.runtime.NullProgressMonitor")%>());
- } catch (<%=importManager.getImportedName("org.eclipse.core.runtime.CoreException")%> e) {
- // If the file already existed locally, just refresh to get contents
- if (e.getStatus().getCode() == <%=importManager.getImportedName("org.eclipse.core.resources.IResourceStatus")%>.PATH_OCCUPIED) {
- fileHandle.refreshLocal(<%=importManager.getImportedName("org.eclipse.core.resources.IResource")%>.DEPTH_ZERO, null);
- } else {
- throw e;
- }
- }
- }
}
<%importManager.emitSortedImports();%>
diff --git a/plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet b/plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet
index 776d0c00b..2e22c3d64 100644
--- a/plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet
+++ b/plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet
@@ -161,7 +161,7 @@ if (!genDiagram.isSynchronized()) {
try {
OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
diagramResource.save(Collections.EMPTY_MAP);
- <%=importManager.getImportedName(genDiagram.getDiagramEditorUtilQualifiedClassName())%>.openDiagramEditor(myWorkbenchPage, diagramFile);
+ <%=importManager.getImportedName(genDiagram.getDiagramEditorUtilQualifiedClassName())%>.openDiagram(diagramResource);
} catch (ExecutionException e) {
<%=pluginActivatorClass%>.getInstance().logError("Unable to create model and diagram", e); //$NON-NLS-1$
} catch (IOException ex) {

Back to the top