/** {@inheritDoc} */
 @Override
 public void dispose() {
   super.dispose();
   selectElementPage.dispose();
   representationWizardPage.dispose();
   airdFilePage.dispose();
 }
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.jface.wizard.Wizard#canFinish()
   */
  @Override
  public boolean canFinish() {
    if (existingSession != null && representationWizardPage.get() != null) {
      if (selectElementPage.getSelectedElement() != null) {
        return true;
      }
    }

    return super.canFinish();
  }
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.jface.wizard.Wizard#performFinish()
   */
  @Override
  public boolean performFinish() {
    EObject element = selectElementPage.getSelectedElement();
    if (element != null && representationWizardPage.get() != null) {

      try {
        final String representationName = selectElementPage.get();

        IRunnableWithProgress representationCreationRunnable =
            new IRunnableWithProgress() {

              public void run(IProgressMonitor monitor)
                  throws InvocationTargetException, InterruptedException {
                try {
                  monitor.beginTask(
                      org.eclipse.sirius.viewpoint.provider.Messages
                          .CreateRepresentationAction_creationTask,
                      5);
                  CreateRepresentationCommand createRepresentationCommand =
                      new CreateRepresentationCommand(
                          existingSession,
                          representationWizardPage.get(),
                          selectElementPage.getSelectedElement(),
                          representationName,
                          new SubProgressMonitor(monitor, 4));

                  IEditingSession editingSession =
                      SessionUIManager.INSTANCE.getUISession(existingSession);
                  editingSession.notify(
                      EditingSessionEvent.REPRESENTATION_ABOUT_TO_BE_CREATED_BEFORE_OPENING);
                  existingSession
                      .getTransactionalEditingDomain()
                      .getCommandStack()
                      .execute(createRepresentationCommand);
                  editingSession.notify(EditingSessionEvent.REPRESENTATION_CREATED_BEFORE_OPENING);
                  createdDRepresentation = createRepresentationCommand.getCreatedRepresentation();
                  monitor.worked(1);
                } finally {
                  monitor.done();
                }
              }
            };

        getContainer().run(true, false, representationCreationRunnable);
        IRunnableWithProgress runnable =
            new IRunnableWithProgress() {

              public void run(final IProgressMonitor monitor) {
                try {
                  monitor.beginTask(
                      org.eclipse.sirius.viewpoint.provider.Messages
                          .CreateRepresentationAction_openingTask,
                      1);
                  DialectUIManager.INSTANCE.openEditor(
                      existingSession, createdDRepresentation, new SubProgressMonitor(monitor, 1));
                } finally {
                  monitor.done();
                }
              }
            };
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        IRunnableContext context = new ProgressMonitorDialog(shell);
        PlatformUI.getWorkbench().getProgressService().runInUI(context, runnable, null);
      } catch (final InvocationTargetException e) {
        SiriusEditPlugin.getPlugin()
            .getLog()
            .log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
      } catch (final InterruptedException e) {
        SiriusEditPlugin.getPlugin()
            .getLog()
            .log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
      }
    }
    return true;
  }