package jetbrains.mps.testHybridEditor.diagram.generated.editor;

/*Generated by MPS */

import jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.openapi.PaletteActionGroup;
import java.util.Map;
import java.util.List;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.internal.collections.runtime.MapSequence;
import java.util.HashMap;
import jetbrains.mps.nodeEditor.cells.jetpad.DiagramCell;
import jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.openapi.PaletteElement;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import jetbrains.mps.scope.ModelPlusImportedScope;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import javax.swing.Icon;
import org.jetbrains.mps.openapi.language.SConcept;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import org.jetbrains.mps.openapi.language.SProperty;

public class MyMainActionGroup implements PaletteActionGroup {
  private Map<String, List<SNode>> tagToGroupMap = MapSequence.fromMap(new HashMap<String, List<SNode>>());
  private DiagramCell myDiagramCell;

  public MyMainActionGroup(DiagramCell diagramCell) {
    myDiagramCell = diagramCell;
  }

  public PaletteElement[] getElements() {
    List<PaletteElement> groups = ListSequence.fromList(new ArrayList<PaletteElement>());
    ModelPlusImportedScope scope = new ModelPlusImportedScope(myDiagramCell.getSNode().getModel(), false, CONCEPTS.MetaBlock$17);
    for (SNode node : Sequence.fromIterable(scope.getAvailableElements(null)).where((it) -> SNodeOperations.isInstanceOf(it, CONCEPTS.MetaBlock$17))) {
      String key = SPropertyOperations.getString(SNodeOperations.cast(node, CONCEPTS.MetaBlock$17), PROPS.path$4KJO);
      if (!(MapSequence.fromMap(tagToGroupMap).containsKey(key))) {
        MapSequence.fromMap(tagToGroupMap).put(key, ListSequence.fromList(new ArrayList<SNode>()));
      }
      ListSequence.fromList(MapSequence.fromMap(tagToGroupMap).get(key)).addElement(node);
    }
    for (String tag : MapSequence.fromMap(tagToGroupMap).keySet()) {
      ListSequence.fromList(groups).addElement(new MyActionGroup(MapSequence.fromMap(tagToGroupMap).get(tag), myDiagramCell, myDiagramCell.getSNode(), tag));
    }
    ListSequence.fromList(groups).addElement(new MyConnectorCreationAction(myDiagramCell));
    return ListSequence.fromList(groups).toGenericArray(PaletteElement.class);
  }
  public boolean isPopup() {
    return false;
  }
  public Icon getIcon() {
    return null;
  }
  public String getText() {
    return "";
  }

  private static final class CONCEPTS {
    /*package*/ static final SConcept MetaBlock$17 = MetaAdapterFactory.getConcept(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec40c2c8L, "jetbrains.mps.testHybridEditor.structure.MetaBlock");
  }

  private static final class PROPS {
    /*package*/ static final SProperty path$4KJO = MetaAdapterFactory.getProperty(0x913a1d639e1948faL, 0xad03e33ecccd3814L, 0x20a804e2ec40c2c8L, 0x206c20835c7e9707L, "path");
  }
}
