Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixed to spreadsheet #104

Merged
merged 5 commits into from
Nov 2, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ private void setupContextMenu(){
extendWithClipboard();
pasteFromClipboard();
});
contextMenu.getItems().addAll(copy,paste);
MenuItem delete = new MenuItem("Delete");
delete.setAccelerator(KeyCombination.keyCombination("Delete"));
delete.setOnAction(actionEvent -> {
deleteSelection();

});
contextMenu.getItems().addAll(copy,paste,delete);
spreadsheet.setContextMenu(contextMenu);
}

Expand Down Expand Up @@ -192,8 +198,10 @@ else if (prevRow != -1) {

Object observableValue = spreadsheet.getGrid().getRows().get(row).get(col).getItem();

// add new item to clipboard
clipboardString.append(String.valueOf(observableValue));
if(observableValue != null){
// add new item to clipboard
clipboardString.append(String.valueOf(observableValue));
}

// remember previous
prevRow = row;
Expand Down Expand Up @@ -223,24 +231,16 @@ private void pasteFromClipboard() {

int rowClipboard = -1;

StringTokenizer rowTokenizer = new StringTokenizer( pasteString, "\n");
while(rowTokenizer.hasMoreTokens()) {

Scanner s = new Scanner(pasteString);
while (s.hasNextLine()) {
rowClipboard++;

String rowString = rowTokenizer.nextToken();

StringTokenizer columnTokenizer = new StringTokenizer(rowString, "\t");

String line = s.nextLine();
String[] items= line.split("\t", -1);
int colClipboard = -1;

while(columnTokenizer.hasMoreTokens()) {

for(int i = 0; i < items.length; i++){
colClipboard++;

// get next cell data from clipboard
String clipboardCellContent = columnTokenizer.nextToken();

String clipboardCellContent = items[i];
// calculate the position in the table cell
int rowTable = pasteCellPosition.getRow() + rowClipboard;
int colTable = pasteCellPosition.getColumn() + colClipboard;
Expand All @@ -264,12 +264,28 @@ private void pasteFromClipboard() {
} catch (Exception ignored) {
}
}
}

}
}

}

/**
* Finds the selected cells and deletes the values within them
*/
private void deleteSelection() {
ObservableList<TablePosition> positionList = spreadsheet.getSelectionModel().getSelectedCells();

for (TablePosition position : positionList) {
int row = position.getRow();
int col = position.getColumn();

spreadsheet.getGrid().getRows().get(row).get(col).setItem(null);

updateProjectDataset(row-2,col,null);
}
}

/**
* Calculates the size of the extended spreadsheet after the clipboard will be pasted
*/
Expand Down