/* (non-Javadoc)
   * @See org.teiid.designer.ui.actions.INewSiblingAction#canCreateChild(org.eclipse.emf.ecore.EObject)
   */
  @Override
  public boolean canCreateSibling(EObject parent) {
    // Convert eObject selection to IFile
    ModelResource mr = ModelUtilities.getModelResourceForModelObject(parent);
    if (mr != null) {
      IFile modelFile = null;

      try {
        modelFile = (IFile) mr.getCorrespondingResource();
      } catch (ModelWorkspaceException ex) {
        UiConstants.Util.log(ex);
      }
      if (modelFile != null) {
        return isApplicable(new StructuredSelection(modelFile));
      }
    }

    return false;
  }
  private EObject createViewProcedureInTxn(
      ModelResource modelResource, RelationalViewProcedure viewProcedure) {
    EObject newTable = null;

    boolean requiredStart =
        ModelerCore.startTxn(true, true, Messages.createRelationalViewProcedureTitle, this);
    boolean succeeded = false;
    try {
      ModelEditor editor =
          ModelEditorManager.getModelEditorForFile(
              (IFile) modelResource.getCorrespondingResource(), true);
      if (editor != null) {
        boolean isDirty = editor.isDirty();

        RelationalViewModelFactory factory = new RelationalViewModelFactory();

        RelationalModel relModel = new RelationalModel("dummy"); // $NON-NLS-1$
        relModel.addChild(viewProcedure);

        factory.build(modelResource, relModel, new NullProgressMonitor());

        if (!isDirty && editor.isDirty()) {
          editor.doSave(new NullProgressMonitor());
        }
        succeeded = true;

        for (Object child : modelResource.getEObjects()) {
          EObject eObj = (EObject) child;
          if (ModelerCore.getModelEditor()
              .getName(eObj)
              .equalsIgnoreCase(this.relationalViewProcedure.getName())) {
            newTable = eObj;
            break;
          }
        }
      }
    } catch (Exception e) {
      MessageDialog.openError(
          Display.getCurrent().getActiveShell(),
          Messages.createRelationalViewProcedureExceptionMessage,
          e.getMessage());
      IStatus status =
          new Status(
              IStatus.ERROR,
              UiConstants.PLUGIN_ID,
              Messages.createRelationalViewProcedureExceptionMessage,
              e);
      UiConstants.Util.log(status);

      return null;
    } finally {
      // if we started the txn, commit it.
      if (requiredStart) {
        if (succeeded) {
          ModelerCore.commitTxn();
        } else {
          ModelerCore.rollbackTxn();
        }
      }
    }

    return newTable;
  }