/** @generated */
  public StateMachine_MAVONewDiagramFileWizard(
      URI domainModelURI, EObject diagramRoot, TransactionalEditingDomain editingDomain) {
    assert domainModelURI != null : "Domain model uri must be specified"; // $NON-NLS-1$
    assert diagramRoot != null : "Doagram root element must be specified"; // $NON-NLS-1$
    assert editingDomain != null : "Editing domain must be specified"; // $NON-NLS-1$

    myFileCreationPage =
        new WizardNewFileCreationPage(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_CreationPageName,
            StructuredSelection.EMPTY);
    myFileCreationPage.setTitle(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_CreationPageTitle);
    myFileCreationPage.setDescription(
        NLS.bind(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_CreationPageDescription,
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts.StateMachineEditPart
                .MODEL_ID));
    IPath filePath;
    String fileName = URI.decode(domainModelURI.trimFileExtension().lastSegment());
    if (domainModelURI.isPlatformResource()) {
      filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true));
    } else if (domainModelURI.isFile()) {
      filePath = new Path(domainModelURI.trimSegments(1).toFileString());
    } else {
      // TODO : use some default path
      throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); // $NON-NLS-1$
    }
    myFileCreationPage.setContainerFullPath(filePath);
    myFileCreationPage.setFileName(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
            .StateMachine_MAVODiagramEditorUtil.getUniqueFileName(
            filePath, fileName, "statemachinediag_mavo")); // $NON-NLS-1$

    diagramRootElementSelectionPage =
        new DiagramRootElementSelectionPage(
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageName);
    diagramRootElementSelectionPage.setTitle(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageTitle);
    diagramRootElementSelectionPage.setDescription(
        edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
            .StateMachine_MAVONewDiagramFileWizard_RootSelectionPageDescription);
    diagramRootElementSelectionPage.setModelElement(diagramRoot);

    myEditingDomain = editingDomain;
  }
  /** @generated */
  public boolean performFinish() {
    LinkedList<IFile> affectedFiles = new LinkedList<IFile>();
    IFile diagramFile = myFileCreationPage.createNewFile();
    edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.StateMachine_MAVODiagramEditorUtil
        .setCharset(diagramFile);
    affectedFiles.add(diagramFile);
    URI diagramModelURI = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
    ResourceSet resourceSet = myEditingDomain.getResourceSet();
    final Resource diagramResource = resourceSet.createResource(diagramModelURI);
    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(
            myEditingDomain,
            edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                .StateMachine_MAVONewDiagramFileWizard_InitDiagramCommand,
            affectedFiles) {

          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {
            int diagramVID =
                edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
                    .StateMachine_MAVOVisualIDRegistry.getDiagramVisualID(
                    diagramRootElementSelectionPage.getModelElement());
            if (diagramVID
                != edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts
                    .StateMachineEditPart.VISUAL_ID) {
              return CommandResult.newErrorCommandResult(
                  edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part.Messages
                      .StateMachine_MAVONewDiagramFileWizard_IncorrectRootError);
            }
            Diagram diagram =
                ViewService.createDiagram(
                    diagramRootElementSelectionPage.getModelElement(),
                    edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.edit.parts
                        .StateMachineEditPart.MODEL_ID,
                    edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
                        .StateMachine_MAVODiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            diagramResource.getContents().add(diagram);
            return CommandResult.newOKCommandResult();
          }
        };
    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new NullProgressMonitor(), null);
      diagramResource.save(
          edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
              .StateMachine_MAVODiagramEditorUtil.getSaveOptions());
      edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
          .StateMachine_MAVODiagramEditorUtil.openDiagram(diagramResource);
    } catch (ExecutionException e) {
      edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
          .StateMachine_MAVODiagramEditorPlugin.getInstance()
          .logError("Unable to create model and diagram", e); // $NON-NLS-1$
    } catch (IOException ex) {
      edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
          .StateMachine_MAVODiagramEditorPlugin.getInstance()
          .logError("Save operation failed for: " + diagramModelURI, ex); // $NON-NLS-1$
    } catch (PartInitException ex) {
      edu.toronto.cs.se.modelepedia.statemachine_mavo.diagram.part
          .StateMachine_MAVODiagramEditorPlugin.getInstance()
          .logError("Unable to open editor", ex); // $NON-NLS-1$
    }
    return true;
  }