Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordstadnik2007-03-01 13:05:35 +0000
committerdstadnik2007-03-01 13:05:35 +0000
commitec7ac396062ee1b5219f0e47892dd6d347eae23d (patch)
tree50deedd3df3eb62aa20fcc310444ca223f2385fc /plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet
parent27e85ef3d01df00341ce8bbc81ef133fa58016fb (diff)
downloadorg.eclipse.gmf-tooling-ec7ac396062ee1b5219f0e47892dd6d347eae23d.tar.gz
org.eclipse.gmf-tooling-ec7ac396062ee1b5219f0e47892dd6d347eae23d.tar.xz
org.eclipse.gmf-tooling-ec7ac396062ee1b5219f0e47892dd6d347eae23d.zip
rewrite NewDiagramFileWizard in xpand
Diffstat (limited to 'plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet')
-rw-r--r--plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet271
1 files changed, 0 insertions, 271 deletions
diff --git a/plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet b/plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet
deleted file mode 100644
index 2e22c3d64..000000000
--- a/plugins/org.eclipse.gmf.codegen/templates/editor/NewDiagramFileWizard.javajet
+++ /dev/null
@@ -1,271 +0,0 @@
-<%@ jet package="org.eclipse.gmf.codegen.templates.editor" class="NewDiagramFileWizardGenerator"
- imports="org.eclipse.gmf.codegen.gmfgen.* org.eclipse.emf.codegen.ecore.genmodel.* java.util.* org.eclipse.gmf.common.codegen.*"
- skeleton="../common.skeleton"%>
-<%
-final GenDiagram genDiagram = (GenDiagram) ((Object[]) argument)[0];
-final ImportAssistant importManager = (ImportAssistant) ((Object[]) argument)[1];
-final GenEditorGenerator editorGen = genDiagram.getEditorGen();
-final String pluginActivatorClass = importManager.getImportedName(editorGen.getPlugin().getActivatorQualifiedClassName());
-%>
-<%@ include file="../copyright4java.jetinc"%>
-<%
-importManager.emitPackageStatement(stringBuffer);
-
-importManager.addImport("java.io.IOException");
-importManager.addImport("java.util.Collections");
-importManager.addImport("java.util.List");
-importManager.addImport("java.util.LinkedList");
-importManager.addImport("org.eclipse.core.commands.ExecutionException");
-importManager.addImport("org.eclipse.core.commands.operations.OperationHistoryFactory");
-importManager.addImport("org.eclipse.core.resources.IContainer");
-importManager.addImport("org.eclipse.core.resources.IFile");
-importManager.addImport("org.eclipse.core.runtime.IProgressMonitor");
-importManager.addImport("org.eclipse.core.runtime.IAdaptable");
-importManager.addImport("org.eclipse.core.runtime.NullProgressMonitor");
-importManager.addImport("org.eclipse.core.runtime.Path");
-importManager.addImport("org.eclipse.emf.common.util.URI");
-importManager.addImport("org.eclipse.emf.ecore.EObject");
-importManager.addImport("org.eclipse.emf.ecore.resource.Resource");
-importManager.addImport("org.eclipse.emf.ecore.resource.ResourceSet");
-importManager.addImport("org.eclipse.gmf.runtime.common.core.command.CommandResult");
-importManager.addImport("org.eclipse.gmf.runtime.notation.Diagram");
-importManager.addImport("org.eclipse.gmf.runtime.diagram.core.services.ViewService");
-importManager.addImport("org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand");
-importManager.addImport("org.eclipse.emf.transaction.TransactionalEditingDomain");
-importManager.addImport("org.eclipse.jface.viewers.IStructuredSelection");
-importManager.addImport("org.eclipse.jface.wizard.Wizard");
-importManager.addImport("org.eclipse.swt.widgets.Composite");
-importManager.addImport("org.eclipse.ui.PartInitException");
-importManager.addImport("org.eclipse.ui.dialogs.WizardNewFileCreationPage");
-importManager.addImport("org.eclipse.ui.IWorkbenchPage");
-
-importManager.markImportLocation(stringBuffer);
-%>
-
-/**
- * @generated
- */
-public class <%=genDiagram.getNewDiagramFileWizardClassName()%> extends Wizard {
-
- /**
- * @generated
- */
- private TransactionalEditingDomain myEditingDomain;
-
- /**
- * @generated
- */
- private WizardNewFileCreationPage myFileCreationPage;
-
- /**
- * @generated
- */
- private IFile mySelectedModelFile;
-
- /**
- * @generated
- */
- private IWorkbenchPage myWorkbenchPage;
-
- /**
- * @generated
- */
- private IStructuredSelection mySelection;
-
- /**
- * @generated
- */
- private EObject myDiagramRoot;
-
- /**
- * @generated
- */
- public <%=genDiagram.getNewDiagramFileWizardClassName()%>(IFile selectedModelFile, IWorkbenchPage workbenchPage, IStructuredSelection selection, EObject diagramRoot, TransactionalEditingDomain editingDomain) {
- assert selectedModelFile != null : "Null selectedModelFile in <%=genDiagram.getNewDiagramFileWizardClassName()%> constructor"; //$NON-NLS-1$
- assert workbenchPage != null : "Null workbenchPage in <%=genDiagram.getNewDiagramFileWizardClassName()%> constructor"; //$NON-NLS-1$
- assert selection != null : "Null selection in <%=genDiagram.getNewDiagramFileWizardClassName()%> constructor"; //$NON-NLS-1$
- assert diagramRoot != null : "Null diagramRoot in <%=genDiagram.getNewDiagramFileWizardClassName()%> constructor"; //$NON-NLS-1$
- assert editingDomain != null : "Null editingDomain in <%=genDiagram.getNewDiagramFileWizardClassName()%> constructor"; //$NON-NLS-1$
-
- mySelectedModelFile = selectedModelFile;
- myWorkbenchPage = workbenchPage;
- mySelection = selection;
- myDiagramRoot = diagramRoot;
- myEditingDomain = editingDomain;
- }
-
- /**
- * @generated
- */
- public void addPages() {
- myFileCreationPage = new WizardNewFileCreationPage("Initialize new Ecore diagram file", mySelection) {
-
- public void createControl(Composite parent) {
- super.createControl(parent);
-
- IContainer parentContainer = mySelectedModelFile.getParent();
- String originalFileName = mySelectedModelFile.getProjectRelativePath().removeFileExtension().lastSegment();
- String fileExtension = ".<%=editorGen.getDiagramFileExtension()%>"; //$NON-NLS-1$
- String fileName = originalFileName + fileExtension;
- for (int i = 1; parentContainer.getFile(new Path(fileName)).exists(); i++) {
- fileName = originalFileName + i + fileExtension;
- }
- setFileName(fileName);
- }
-
- };
- myFileCreationPage.setTitle("Diagram file");
- myFileCreationPage.setDescription("Create new diagram based on " + <%=importManager.getImportedName(genDiagram.getEditPartQualifiedClassName())%>.MODEL_ID + " model content");
- addPage(myFileCreationPage);
- addPage(new RootElementSelectorPage());
- }
-
- /**
- * @generated
- */
- public boolean performFinish() {
- IFile diagramFile = myFileCreationPage.createNewFile();
- try {
- diagramFile.setCharset("UTF-8", new 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 diagram file", e); //$NON-NLS-1$
- }
-
- ResourceSet resourceSet = myEditingDomain.getResourceSet();
- final Resource diagramResource = resourceSet.createResource(URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true));
-
- List affectedFiles = new LinkedList();
- affectedFiles.add(mySelectedModelFile);
- affectedFiles.add(diagramFile);
-
- AbstractTransactionalCommand command = new AbstractTransactionalCommand(myEditingDomain, "Initializing diagram contents", affectedFiles) { //$NON-NLS-1$
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- int diagramVID = <%=importManager.getImportedName(genDiagram.getVisualIDRegistryQualifiedClassName())%>.getDiagramVisualID(myDiagramRoot);
- if (diagramVID != <%=importManager.getImportedName(genDiagram.getEditPartQualifiedClassName())%>.VISUAL_ID) {
- return CommandResult.newErrorCommandResult("Incorrect model object stored as a root resource object"); //$NON-NLS-1$
- }
- Diagram diagram = ViewService.createDiagram(myDiagramRoot, <%=importManager.getImportedName(genDiagram.getEditPartQualifiedClassName())%>.MODEL_ID, <%=pluginActivatorClass%>.DIAGRAM_PREFERENCES_HINT);
- diagramResource.getContents().add(diagram);
-<%if (editorGen.isSameFileForDiagramAndModel()) {%>
- diagramResource.getContents().add(diagram.getElement());
-<%
-}
-if (!genDiagram.isSynchronized()) {
-%>
- initDiagramContents(diagram, myDiagramRoot);
-<%}%>
- return CommandResult.newOKCommandResult();
- }
- };
-
- try {
- OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
- diagramResource.save(Collections.EMPTY_MAP);
- <%=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) {
- <%=pluginActivatorClass%>.getInstance().logError("Save operation failed for: " + diagramFile.getFullPath().toString(), ex); //$NON-NLS-1$
- } catch (PartInitException ex) {
- <%=pluginActivatorClass%>.getInstance().logError("Unable to open editor", ex); //$NON-NLS-1$
- }
- return true;
- }
-
-<%if (!genDiagram.isSynchronized()) {%>
-<%@ include file="../semanticSync.jetinc/initDiagramContents.jetinc"%>
-<%}%>
-
- /**
- * @generated
- */
- private class RootElementSelectorPage extends <%=importManager.getImportedName("org.eclipse.jface.wizard.WizardPage")%> implements <%=importManager.getImportedName("org.eclipse.jface.viewers.ISelectionChangedListener")%> {
-
- /**
- * @generated
- */
- protected RootElementSelectorPage() {
- super("Select diagram root element");
- setTitle("Diagram root element");
- setDescription("Select semantic model element to be depicted on diagram");
- }
-
- /**
- * @generated
- */
- public void createControl(<%=importManager.getImportedName("org.eclipse.swt.widgets.Composite")%> parent) {
- initializeDialogUnits(parent);
- <%=importManager.getImportedName("org.eclipse.swt.widgets.Composite")%> topLevel = new <%=importManager.getImportedName("org.eclipse.swt.widgets.Composite")%>(parent, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.NONE);
- topLevel.setLayout(new <%=importManager.getImportedName("org.eclipse.swt.layout.GridLayout")%>());
- topLevel.setLayoutData(new <%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>(<%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>.VERTICAL_ALIGN_FILL | <%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>.HORIZONTAL_ALIGN_FILL));
- topLevel.setFont(parent.getFont());
- setControl(topLevel);
- createModelBrowser(topLevel);
- setPageComplete(validatePage());
- }
-
- /**
- * @generated
- */
- private void createModelBrowser(<%=importManager.getImportedName("org.eclipse.swt.widgets.Composite")%> parent) {
- <%=importManager.getImportedName("org.eclipse.swt.widgets.Composite")%> panel = new <%=importManager.getImportedName("org.eclipse.swt.widgets.Composite")%>(parent, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.NONE);
- panel.setLayoutData(new <%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>(<%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>.FILL_BOTH));
- <%=importManager.getImportedName("org.eclipse.swt.layout.GridLayout")%> layout = new <%=importManager.getImportedName("org.eclipse.swt.layout.GridLayout")%>();
- layout.marginWidth = 0;
- panel.setLayout(layout);
-
- <%=importManager.getImportedName("org.eclipse.swt.widgets.Label")%> label = new <%=importManager.getImportedName("org.eclipse.swt.widgets.Label")%>(panel, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.NONE);
- label.setText("Select diagram root element:");
- label.setLayoutData(new <%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>(<%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>.HORIZONTAL_ALIGN_BEGINNING));
-
- <%=importManager.getImportedName("org.eclipse.jface.viewers.TreeViewer")%> treeViewer = new <%=importManager.getImportedName("org.eclipse.jface.viewers.TreeViewer")%>(panel, <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.SINGLE | <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.H_SCROLL | <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.V_SCROLL | <%=importManager.getImportedName("org.eclipse.swt.SWT")%>.BORDER);
- <%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%> layoutData = new <%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>(<%=importManager.getImportedName("org.eclipse.swt.layout.GridData")%>.FILL_BOTH);
- layoutData.heightHint = 300;
- layoutData.widthHint = 300;
- treeViewer.getTree().setLayoutData(layoutData);
- treeViewer.setContentProvider(new <%=importManager.getImportedName("org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider")%>(<%=importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName())%>.getInstance().getItemProvidersAdapterFactory()));
- treeViewer.setLabelProvider(new <%=importManager.getImportedName("org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider")%>(<%=importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName())%>.getInstance().getItemProvidersAdapterFactory()));
- treeViewer.setInput(myDiagramRoot.eResource());
- treeViewer.setSelection(new <%=importManager.getImportedName("org.eclipse.jface.viewers.StructuredSelection")%>(myDiagramRoot));
- treeViewer.addSelectionChangedListener(this);
- }
-
- /**
- * @generated
- */
- public void selectionChanged(<%=importManager.getImportedName("org.eclipse.jface.viewers.SelectionChangedEvent")%> event) {
- myDiagramRoot = null;
- if (event.getSelection() instanceof <%=importManager.getImportedName("org.eclipse.jface.viewers.IStructuredSelection")%>) {
- <%=importManager.getImportedName("org.eclipse.jface.viewers.IStructuredSelection")%> selection = (<%=importManager.getImportedName("org.eclipse.jface.viewers.IStructuredSelection")%>) event.getSelection();
- if (selection.size() == 1) {
- Object selectedElement = selection.getFirstElement();
- if (selectedElement instanceof <%=importManager.getImportedName("org.eclipse.emf.edit.provider.IWrapperItemProvider")%>) {
- selectedElement = ((<%=importManager.getImportedName("org.eclipse.emf.edit.provider.IWrapperItemProvider")%>) selectedElement).getValue();
- }
- if (selectedElement instanceof <%=importManager.getImportedName("org.eclipse.emf.ecore.util.FeatureMap")%>.Entry) {
- selectedElement = ((<%=importManager.getImportedName("org.eclipse.emf.ecore.util.FeatureMap")%>.Entry) selectedElement).getValue();
- }
- if (selectedElement instanceof EObject) {
- myDiagramRoot = (EObject) selectedElement;
- }
- }
- }
- setPageComplete(validatePage());
- }
-
- /**
- * @generated
- */
- private boolean validatePage() {
- if (myDiagramRoot == null) {
- setErrorMessage("No diagram root element selected");
- return false;
- }
- boolean result = ViewService.getInstance().provides(new <%=importManager.getImportedName("org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation")%>(new <%=importManager.getImportedName("org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter")%>(myDiagramRoot), <%=importManager.getImportedName(genDiagram.getEditPartQualifiedClassName())%>.MODEL_ID, <%=importManager.getImportedName(genDiagram.getEditorGen().getPlugin().getActivatorQualifiedClassName())%>.DIAGRAM_PREFERENCES_HINT));
- setErrorMessage(result ? null : "Invalid diagram root element was selected");
- return result;
- }
-
- }
-}
-<%importManager.emitSortedImports();%> \ No newline at end of file

Back to the top