Package OntoUML.diagram.part

Source Code of OntoUML.diagram.part.OntoUMLCreationWizard

package OntoUML.diagram.part;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
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;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.WorkspaceModifyOperation;

/**
* @generated
*/
public class OntoUMLCreationWizard extends Wizard implements INewWizard {

  /**
   * @generated
   */
  private IWorkbench workbench;

  /**
   * @generated
   */
  protected IStructuredSelection selection;

  /**
   * @generated
   */
  protected OntoUML.diagram.part.OntoUMLCreationWizardPage diagramModelFilePage;

  /**
   * @generated
   */
  protected OntoUML.diagram.part.OntoUMLCreationWizardPage domainModelFilePage;

  /**
   * @generated
   */
  protected Resource diagram;

  /**
   * @generated
   */
  private boolean openNewlyCreatedDiagramEditor = true;

  /**
   * @generated
   */
  public IWorkbench getWorkbench() {
    return workbench;
  }

  /**
   * @generated
   */
  public IStructuredSelection getSelection() {
    return selection;
  }

  /**
   * @generated
   */
  public final Resource getDiagram() {
    return diagram;
  }

  /**
   * @generated
   */
  public final boolean isOpenNewlyCreatedDiagramEditor() {
    return openNewlyCreatedDiagramEditor;
  }

  /**
   * @generated
   */
  public void setOpenNewlyCreatedDiagramEditor(
      boolean openNewlyCreatedDiagramEditor) {
    this.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor;
  }

  /**
   * @generated
   */
  public void init(IWorkbench workbench, IStructuredSelection selection) {
    this.workbench = workbench;
    this.selection = selection;
    setWindowTitle(OntoUML.diagram.part.Messages.OntoUMLCreationWizardTitle);
    setDefaultPageImageDescriptor(OntoUML.diagram.part.OntoUMLDiagramEditorPlugin
        .getBundledImageDescriptor("icons/wizban/NewOntoUMLWizard.gif")); //$NON-NLS-1$
    setNeedsProgressMonitor(true);
  }

  /**
   * @generated
   */
  public void addPages() {
    diagramModelFilePage = new OntoUML.diagram.part.OntoUMLCreationWizardPage(
        "DiagramModelFile", getSelection(), "ontouml_diagram"); //$NON-NLS-1$ //$NON-NLS-2$
    diagramModelFilePage
        .setTitle(OntoUML.diagram.part.Messages.OntoUMLCreationWizard_DiagramModelFilePageTitle);
    diagramModelFilePage
        .setDescription(OntoUML.diagram.part.Messages.OntoUMLCreationWizard_DiagramModelFilePageDescription);
    addPage(diagramModelFilePage);

    domainModelFilePage = new OntoUML.diagram.part.OntoUMLCreationWizardPage(
        "DomainModelFile", getSelection(), "ontouml") { //$NON-NLS-1$ //$NON-NLS-2$

      public void setVisible(boolean visible) {
        if (visible) {
          String fileName = diagramModelFilePage.getFileName();
          fileName = fileName.substring(0, fileName.length()
              - ".ontouml_diagram".length()); //$NON-NLS-1$
          setFileName(OntoUML.diagram.part.OntoUMLDiagramEditorUtil
              .getUniqueFileName(getContainerFullPath(),
                  fileName, "ontouml")); //$NON-NLS-1$
        }
        super.setVisible(visible);
      }
    };
    domainModelFilePage
        .setTitle(OntoUML.diagram.part.Messages.OntoUMLCreationWizard_DomainModelFilePageTitle);
    domainModelFilePage
        .setDescription(OntoUML.diagram.part.Messages.OntoUMLCreationWizard_DomainModelFilePageDescription);
    addPage(domainModelFilePage);
  }

  /**
   * @generated
   */
  public boolean performFinish() {
    IRunnableWithProgress op = new IRunnableWithProgress() {

      public void run(IProgressMonitor monitor)
          throws InvocationTargetException, InterruptedException {
        diagram = OntoUML.diagram.part.OntoUMLDiagramEditorUtil
            .createDiagram(diagramModelFilePage.getURI(),
                domainModelFilePage.getURI(), monitor);
        if (isOpenNewlyCreatedDiagramEditor() && diagram != null) {
          try {
            OntoUML.diagram.part.OntoUMLDiagramEditorUtil
                .openDiagram(diagram);
          } catch (PartInitException e) {
            ErrorDialog
                .openError(
                    getContainer().getShell(),
                    OntoUML.diagram.part.Messages.OntoUMLCreationWizardOpenEditorError,
                    null, e.getStatus());
          }
        }
      }
    };
    try {
      getContainer().run(false, true, op);
    } catch (InterruptedException e) {
      return false;
    } catch (InvocationTargetException e) {
      if (e.getTargetException() instanceof CoreException) {
        ErrorDialog
            .openError(
                getContainer().getShell(),
                OntoUML.diagram.part.Messages.OntoUMLCreationWizardCreationError,
                null, ((CoreException) e.getTargetException())
                    .getStatus());
      } else {
        OntoUML.diagram.part.OntoUMLDiagramEditorPlugin
            .getInstance()
            .logError(
                "Error creating diagram", e.getTargetException()); //$NON-NLS-1$
      }
      return false;
    }
    return diagram != null;
  }
}
TOP

Related Classes of OntoUML.diagram.part.OntoUMLCreationWizard

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.