/** @generated */
 static {
   DatamodelerDiagramEditorPlugin.getInstance()
       .getImageRegistry()
       .put(
           "Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); // $NON-NLS-1$
   DatamodelerDiagramEditorPlugin.getInstance()
       .getImageRegistry()
       .put("Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); // $NON-NLS-1$
 }
 /** @generated */
 private String getSchema_1000Text(View view) {
   ESchema domainModelElement = (ESchema) view.getElement();
   if (domainModelElement != null) {
     return domainModelElement.getName();
   } else {
     DatamodelerDiagramEditorPlugin.getInstance()
         .logError("No domain element for view with visualID = " + 1000); // $NON-NLS-1$
     return ""; //$NON-NLS-1$
   }
 }
  /**
   * (Modified template: NavigatorLabelProvider.xpt)
   *
   * @generated
   */
  public Image getImage(View view) {

    EObject element = view.getElement();

    ImageDescriptor imageDescriptor =
        DatamodelerDiagramEditorPlugin.getInstance().getItemImageDescriptor(element);

    if (imageDescriptor != null) return imageDescriptor.createImage();

    return getImage("Navigator?UnknownElement", null); // $NON-NLS-1$
  }
 /** @generated */
 private String getForeignKey_4001Text(View view) {
   IParser parser =
       DatamodelerParserProvider.getParser(
           DatamodelerElementTypes.ForeignKey_4001,
           view.getElement() != null ? view.getElement() : view,
           DatamodelerVisualIDRegistry.getType(RelationshipForeignKeyEditPart.VISUAL_ID));
   if (parser != null) {
     return parser.getPrintString(
         new EObjectAdapter(view.getElement() != null ? view.getElement() : view),
         ParserOptions.NONE.intValue());
   } else {
     DatamodelerDiagramEditorPlugin.getInstance()
         .logError("Parser was not found for label " + 6001); // $NON-NLS-1$
     return ""; //$NON-NLS-1$
   }
 }
 /** @generated */
 private String getPersistentTable_2009Text(View view) {
   IParser parser =
       DatamodelerParserProvider.getParser(
           DatamodelerElementTypes.PersistentTable_2009,
           view.getElement() != null ? view.getElement() : view,
           DatamodelerVisualIDRegistry.getType(PersistentTableNameEditPart.VISUAL_ID));
   if (parser != null) {
     return parser.getPrintString(
         new EObjectAdapter(view.getElement() != null ? view.getElement() : view),
         ParserOptions.NONE.intValue());
   } else {
     DatamodelerDiagramEditorPlugin.getInstance()
         .logError("Parser was not found for label " + 5004); // $NON-NLS-1$
     return ""; //$NON-NLS-1$
   }
 }
  /** @generated */
  private Image getImage(String key, IElementType elementType) {
    ImageRegistry imageRegistry = DatamodelerDiagramEditorPlugin.getInstance().getImageRegistry();
    Image image = imageRegistry.get(key);
    if (image == null
        && elementType != null
        && DatamodelerElementTypes.isKnownElementType(elementType)) {
      image = DatamodelerElementTypes.getImage(elementType);
      imageRegistry.put(key, image);
    }

    if (image == null) {
      image = imageRegistry.get("Navigator?ImageNotFound"); // $NON-NLS-1$
      imageRegistry.put(key, image);
    }
    return image;
  }
  /** @generated */
  public Image getImage(Object element) {
    if (element instanceof DatamodelerNavigatorGroup) {
      DatamodelerNavigatorGroup group = (DatamodelerNavigatorGroup) element;
      return DatamodelerDiagramEditorPlugin.getInstance().getBundledImage(group.getIcon());
    }

    if (element instanceof DatamodelerNavigatorItem) {
      DatamodelerNavigatorItem navigatorItem = (DatamodelerNavigatorItem) element;
      if (!isOwnView(navigatorItem.getView())) {
        return super.getImage(element);
      }
      return getImage(navigatorItem.getView());
    }

    // Due to plugin.xml content will be called only for "own" views
    if (element instanceof IAdaptable) {
      View view = (View) ((IAdaptable) element).getAdapter(View.class);
      if (view != null && isOwnView(view)) {
        return getImage(view);
      }
    }

    return super.getImage(element);
  }
  @Override
  public boolean performFinish() {
    _wizardPage.setPageComplete(false);
    TransactionalEditingDomain myEditingDomain = DataModelerUtils.getDataModelerEditingDomain();

    _schema = _wizardPage.getSchema();

    if (_schema.eIsProxy())
      _schema = (ESchema) EcoreUtil.resolve(_schema, myEditingDomain.getResourceSet());

    if (!_schema.eIsProxy()) _resource = _schema.eResource();

    if (_resource == null) return true;

    String path = _resource.getURI().toPlatformString(true);

    LinkedList<IFile> affectedFiles = new LinkedList<IFile>();

    IResource workspaceResource =
        ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));

    if (workspaceResource instanceof IFile) affectedFiles.add((IFile) workspaceResource);

    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(
            myEditingDomain,
            "Comando de creación de diagramas", //$NON-NLS-1$
            affectedFiles) {

          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {

            _diagram =
                ViewService.createDiagram(
                    _schema,
                    SchemaEditPart.MODEL_ID,
                    DatamodelerDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
            _diagram.setName(_wizardPage.getDiagramName());
            _resource.getContents().add(_diagram);

            return CommandResult.newOKCommandResult();
          }
        };
    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new NullProgressMonitor(), null);

      _resource.save(DatamodelerDiagramEditorUtil.getSaveOptions());

      final URI diagramURI = EcoreUtil.getURI(_diagram);

      Display.getCurrent()
          .asyncExec(
              new Runnable() {

                @Override
                public void run() {
                  if (diagramURI.toPlatformString(true) != null)
                    try {
                      UtilsDataModelerUI.openDiagram(diagramURI, _diagram.getName());
                    } catch (PartInitException ex) {
                      DatamodelerDiagramEditorPlugin.getInstance()
                          .logError("Unable to open editor", ex); // $NON-NLS-1$
                    }
                }
              });

    } catch (ExecutionException e) {
      DatamodelerDiagramEditorPlugin.getInstance()
          .logError("Unable to create model and diagram", e); // $NON-NLS-1$
    } catch (IOException ex) {
      DatamodelerDiagramEditorPlugin.getInstance()
          .logError("Save operation failed for: " + _resource.getURI(), ex); // $NON-NLS-1$
    }

    return true;
  }