PY-19960 Use getters to access cell panel fields
authorValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Wed, 19 Oct 2016 17:17:38 +0000 (20:17 +0300)
committerValentina Kiryushkina <valentina.kiryushkina@jetbrains.com>
Mon, 24 Oct 2016 17:09:48 +0000 (20:09 +0300)
python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbEditablePanel.java
python/ipnb/src/org/jetbrains/plugins/ipnb/editor/panels/IpnbFilePanel.java

index 5abef679b801103453806ef335c864fd981f7900..224a8c3c767564d805db71015b0def604e0654c7 100644 (file)
@@ -287,6 +287,8 @@ public abstract class IpnbEditablePanel<T extends JComponent, K extends IpnbEdit
   public K getCell() {
     return myCell;
   }
-
   
+  public JTextArea getEditablePanel() {
+    return myEditablePanel;
+  }  
 }
index 568952fee3bd607156fbaa040e3e6f814bdbc397..2bb61725de189c1209e643ab2cb3a0e9caa3a5a4 100644 (file)
@@ -43,7 +43,6 @@ import java.awt.event.MouseEvent;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -269,14 +268,12 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
     }
     
     final IpnbEditablePanel cellToMergePanel = getSelectedCell();
-    final IpnbCell cellToMerge = cellToMergePanel.myCell;
-    if (cellToMerge instanceof IpnbEditableCell) {
-      final List<String> currentCellSource = getCellSource(currentCellPanel);
-      final List<String> cellToMergeSource = ((IpnbEditableCell)cellToMerge).getSource();
-      final ArrayList<String> source = mergeCellsSource(currentCellSource, cellToMergeSource, below);
-      ((IpnbEditableCell)cellToMerge).setSource(source);
-      cellToMergePanel.updateCellView();
-    }
+    final IpnbCell cellToMerge = cellToMergePanel.getCell();
+    final List<String> currentCellSource = getCellSource(currentCellPanel);
+    final List<String> cellToMergeSource = ((IpnbEditableCell)cellToMerge).getSource();
+    final ArrayList<String> source = mergeCellsSource(currentCellSource, cellToMergeSource, below);
+    ((IpnbEditableCell)cellToMerge).setSource(source);
+    cellToMergePanel.updateCellView();
     
     actualizeCellData(cellToMerge);
     
@@ -322,7 +319,7 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
     final String newCellText = cellPanel.getText(position);
     
     if (oldCellText != null) {
-      final JTextArea editablePanel = cellPanel.myEditablePanel;
+      final JTextArea editablePanel = cellPanel.getEditablePanel();
       if (editablePanel != null) {
         editablePanel.setText(oldCellText);
       }
@@ -365,15 +362,8 @@ public class IpnbFilePanel extends JPanel implements Scrollable, DataProvider, D
 
   @NotNull
   private static List<String> getCellSource(@NotNull IpnbEditablePanel cellPanel) {
-    final IpnbCell cell = cellPanel.myCell;
-    List<String> source = new ArrayList<>();
-    if (cell instanceof IpnbEditableCell) {
-      source = ((IpnbEditableCell)cell).getSource();
-    }
-    else if (cell instanceof IpnbRawCell) {
-      source = ((IpnbRawCell)cell).getSource();
-    }
-    return source;
+    final IpnbCell cell = cellPanel.getCell();
+    return ((IpnbEditableCell)cell).getSource();
   }
 
   public void deleteSelectedCell() {