package jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.ui;

/*Generated by MPS */

import com.intellij.openapi.actionSystem.AnAction;
import jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.openapi.PaletteElement;
import jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.openapi.PaletteActionGroup;
import jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.openapi.PaletteSimpleAction;
import jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.openapi.PaletteToggleAction;
import jetbrains.mps.lang.editor.diagram.runtime.jetpad.palette.openapi.PaletteSeparator;
import com.intellij.openapi.actionSystem.Separator;

/*package*/ class PaletteElementFactory {
  public static AnAction createPaletteElementAdapter(DiagramPalette palette, PaletteElement element) {
    if (element instanceof PaletteActionGroup) {
      PaletteActionGroup group = ((PaletteActionGroup) element);
      if (group.isPopup()) {
        return new PopupPaletteActionGroupAdapter(palette, group);
      } else {
        return new PaletteActionGroupAdapter(palette, group);
      }
    } else if (element instanceof PaletteSimpleAction) {
      return new PaletteSimpleActionAdapter(((PaletteSimpleAction) element), palette);
    } else if (element instanceof PaletteToggleAction) {
      return new PaletteToggleActionAdapter(((PaletteToggleAction) element), palette);
    } else if (element instanceof PaletteSeparator) {
      return new Separator(element.getText());
    }
    return null;
  }
}
