Commits

Anonymous committed 74af4aa

SpreadsheetViewSkin access modified in SelectionModel because it was not working in multiple threading.

Comments (0)

Files changed (3)

src/main/java/org/controlsfx/control/spreadsheet/SpreadsheetCells.java

  * <pre>
  * private SpreadsheetCell&lt;?&gt; generateCell(int row, int column, int rowSpan, int colSpan) {
  *		SpreadsheetCell&lt;?&gt; cell;
- *		List&lt;String&gt; stringListTextCell = Arrays.asList("Shanghai","Paris","New York City","Bangkok","Singapore","Johannesburg","Berlin","Wellington","London","Montréal");
+ *		List&lt;String&gt; stringListTextCell = Arrays.asList("Shanghai","Paris","New York City","Bangkok","Singapore","Johannesburg","Berlin","Wellington","London","Montreal");
  *		final double random = Math.random();
  *		if (random &lt; 0.10) {
  *			List&lt;String&gt; stringList = Arrays.asList("China","France","New Zealand","United States","Germany","Canada");

src/main/java/org/controlsfx/control/spreadsheet/SpreadsheetView.java

         tableView.setSelectionModel(new SpreadsheetViewSelectionModel<>(this,tableView));
         getSelectionModel().setCellSelectionEnabled(true);
         getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
-
+        
         /**
          * Set the focus model to track keyboard change and redirect focus on spanned
          * cells
             super(tableView);
             this.tableView = tableView;
             this.spreadsheetView = spreadsheetView;
-            //RunLater because it's not yet instanciated..
-            final Runnable r = new Runnable() {
-                @Override
-                public void run() {
-                	spreadsheetViewSkin = (SpreadsheetViewSkin) tableView.getSkin();
-                }
-            };
-            Platform.runLater(r);
+
             tableView.setOnKeyPressed(new EventHandler<KeyEvent>() {
                 @Override
                 public void handle(KeyEvent t) {
         private void addSelectedRowsAndColumns(TablePosition<?, ?> t){
             final SpreadsheetCell<?> cell = tableView.getItems().get(t.getRow()).get(t.getColumn());
             for(int i=cell.getRow();i<cell.getRowSpan()+cell.getRow();++i){
-            	spreadsheetViewSkin.getSelectedRows().add(i);
+            	getSpreadsheetViewSkin().getSelectedRows().add(i);
                 for(int j=cell.getColumn();j<cell.getColumnSpan()+cell.getColumn();++j){
-                	spreadsheetViewSkin.getSelectedColumns().add(j);
+                	getSpreadsheetViewSkin().getSelectedColumns().add(j);
                 }
             }
         }
         private void removeSelectedRowsAndColumns(TablePosition<?, ?> t){
             final SpreadsheetCell<?> cell = tableView.getItems().get(t.getRow()).get(t.getColumn());
             for(int i=cell.getRow();i<cell.getRowSpan()+cell.getRow();++i){
-            	spreadsheetViewSkin.getSelectedRows().remove(Integer.valueOf(i));
+            	getSpreadsheetViewSkin().getSelectedRows().remove(Integer.valueOf(i));
                 for(int j=cell.getColumn();j<cell.getColumnSpan()+cell.getColumn();++j){
-                	spreadsheetViewSkin.getSelectedColumns().remove(Integer.valueOf(j));
+                	getSpreadsheetViewSkin().getSelectedColumns().remove(Integer.valueOf(j));
                 }
             }
         }
 		
 		private void quietClearSelection() {
             getSelectedCells().clear();
-            spreadsheetViewSkin.getSelectedRows().clear();
-            spreadsheetViewSkin.getSelectedColumns().clear();
+            getSpreadsheetViewSkin().getSelectedRows().clear();
+            getSpreadsheetViewSkin().getSelectedColumns().clear();
         }
 
 		private TablePosition<ObservableList<SpreadsheetCell<?>>, ?> getFocusedCell() {
             final int newColumnIndex = columnIndex + offset;
             return getTableView().getVisibleLeafColumn(newColumnIndex);
         }
+		private SpreadsheetViewSkin getSpreadsheetViewSkin(){
+			if(spreadsheetViewSkin == null){
+				spreadsheetViewSkin = SpreadsheetViewSkin.getSkin();
+			}
+			return spreadsheetViewSkin;
+		}
     }
     
     /**

src/samples/java/org/controlsfx/samples/SpreadsheetView/HelloSpreadsheetView.java

 	 */
 	private SpreadsheetCell<?> generateCell(int row, int column, int rowSpan, int colSpan) {
 		SpreadsheetCell<?> cell;
-		List<String> stringListTextCell = Arrays.asList("Shanghai","Paris","New York City","Bangkok","Singapore","Johannesburg","Berlin","Wellington","London","Montréal");
+		List<String> stringListTextCell = Arrays.asList("Shanghai","Paris","New York City","Bangkok","Singapore","Johannesburg","Berlin","Wellington","London","Montreal");
 		final double random = Math.random();
 		if (random < 0.10) {
 			List<String> stringList = Arrays.asList("China","France","New Zealand","United States","Germany","Canada");