PY-19960 PY-14096 Merge right-click menu creation for toggle output and split/merge...
[idea/community.git] / python / ipnb / src / org / jetbrains / plugins / ipnb / editor / panels / IpnbPanel.java
1 package org.jetbrains.plugins.ipnb.editor.panels;
2
3 import com.intellij.ide.DataManager;
4 import com.intellij.openapi.actionSystem.DataContext;
5 import com.intellij.openapi.actionSystem.DefaultActionGroup;
6 import com.intellij.openapi.ui.popup.JBPopupFactory;
7 import com.intellij.openapi.ui.popup.ListPopup;
8 import org.jetbrains.annotations.NotNull;
9 import org.jetbrains.plugins.ipnb.format.cells.IpnbCell;
10
11 import javax.swing.*;
12 import java.awt.*;
13
14 public abstract class IpnbPanel<T extends JComponent, K extends IpnbCell> extends JPanel {
15   protected T myViewPanel;
16   protected K myCell;
17
18   public IpnbPanel(@NotNull final K cell) {
19     super(new CardLayout());
20     myCell = cell;
21   }
22
23   public IpnbPanel(@NotNull final K cell, @NotNull final LayoutManager layoutManager) {
24     super(layoutManager);
25     myCell = cell;
26   }
27
28   public K getCell() {
29     return myCell;
30   }
31
32   public ListPopup createPopupMenu(@NotNull DefaultActionGroup group) {
33     final DataContext context = DataManager.getInstance().getDataContext(this);
34     return JBPopupFactory.getInstance().createActionGroupPopup(null, group, context, JBPopupFactory.ActionSelectionAid.MNEMONICS,
35                                                                false);
36   }
37
38   protected abstract T createViewPanel();
39   
40   protected abstract void addRightClickMenu();
41 }