package jetbrains.mps.ide.actions;

/*Generated by MPS */

import jetbrains.mps.annotations.GeneratedClass;
import jetbrains.mps.nodeEditor.EditorComponent;
import java.util.List;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.project.Project;
import com.intellij.ui.awt.RelativePoint;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.openapi.editor.cells.EditorCell;
import java.awt.Point;

@GeneratedClass(node = "r:00000000-0000-4000-0000-011c895904a4(jetbrains.mps.ide.actions)/3538501397189789300", model = "r:00000000-0000-4000-0000-011c895904a4(jetbrains.mps.ide.actions)")
public final class SimplePopupWithNodeEditor extends PopupWithNodeEditor {
  private final EditorComponent myEditorComponent;
  private final List<SNode> myNodes;

  public SimplePopupWithNodeEditor(final Project project, final EditorComponent editorComponent, final List<SNode> nodes) {
    super(project, editorComponent);
    myEditorComponent = editorComponent;
    myNodes = nodes;
  }

  @Override
  public void show() {
    RelativePoint position = getPositionNextToSelectedCell();
    if (position == null) {
      return;
    }
    myPopup.show(position);
  }

  @Override
  protected void beforePopupShown(@NotNull final LightweightWindowEvent ignored) {
    myUI.update(myNodes);
  }

  @Nullable
  private RelativePoint getPositionNextToSelectedCell() {
    EditorCell cell = myEditorComponent.getSelectedCell();
    if (cell == null) {
      return null;
    }
    return new RelativePoint(myEditorComponent, new Point(cell.getX(), cell.getY()));
  }
}
