package brn.gui.linktable.diagram.part;

import java.io.InputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.wizards.EditorWizardPage;
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.util.DiagramFileCreator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;

import brn.gui.linktable.diagram.edit.parts.GraphEditPart;

import org.eclipse.core.resources.ResourcesPlugin;

/**
 * @generated
 */
public class ModelCreationWizardPage extends EditorWizardPage {

  /**
   * @generated
   */
  public ModelCreationWizardPage(IWorkbench workbench,
      IStructuredSelection selection) {
    super("CreationWizardPage", workbench, selection); //$NON-NLS-1$
    setTitle("Create LinkTableModel Diagram");
    setDescription("Create a new LinkTableModel diagram.");
  }

  /**
   * @generated
   */
  public IFile createAndOpenDiagram(IPath containerPath, String fileName,
      InputStream initialContents, String kind, IWorkbenchWindow dWindow,
      IProgressMonitor progressMonitor, boolean saveDiagram) {
    return ModelDiagramEditorUtil.createAndOpenDiagram(getDiagramFileCreator(),
        containerPath, fileName, initialContents, kind, dWindow,
        progressMonitor, isOpenNewlyCreatedDiagramEditor(), saveDiagram);
  }

  /**
   * @generated
   */
  protected String getDefaultFileName() {
    return "default"; //$NON-NLS-1$
  }

  /**
   * @generated
   */
  public DiagramFileCreator getDiagramFileCreator() {
    return ModelDiagramFileCreator.getInstance();
  }

  /**
   * @generated
   */
  protected String getDiagramKind() {
    return GraphEditPart.MODEL_ID;
  }

  /**
   * @generated
   */
  protected boolean validatePage() {
    if (super.validatePage()) {
      String fileName = getFileName();
      if (fileName == null) {
        return false;
      }
      // appending file extension to correctly process file names including "." symbol
      IPath path = getContainerFullPath().append(
          getDiagramFileCreator().appendExtensionToFileName(fileName));
      path = path.removeFileExtension().addFileExtension("linktable"); //$NON-NLS-1$
      if (ResourcesPlugin.getWorkspace().getRoot().exists(path)) {
        setErrorMessage("Model File already exists: " + path.lastSegment());
        return false;
      }
      return true;
    }
    return false;
  }

}
