-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
259 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/components/comparison/ComparisonTableDataExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package components.comparison; | ||
|
||
import javafx.scene.Node; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
import javafx.scene.layout.VBox; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ComparisonTableDataExtractor { | ||
public List<List<List<String>>> extractContainerData(VBox container) { | ||
List<List<List<String>>> containerData = new ArrayList<>(); | ||
|
||
// Iterate over the TableView instances in the VBox container | ||
for (Node tableView : container.getChildren()) { | ||
//check if the node is a TableView | ||
if (tableView.getClass() == TableView.class) { | ||
List<List<String>> tableData = extractTableData((TableView<?>) tableView); | ||
containerData.add(tableData); | ||
} | ||
} | ||
|
||
return containerData; | ||
} | ||
|
||
private List<List<String>> extractTableData(TableView<?> tableView) { | ||
List<List<String>> tableData = new ArrayList<>(); | ||
|
||
// Extract column headers | ||
List<String> columnHeaders = new ArrayList<>(); | ||
for (TableColumn<?, ?> column : tableView.getColumns()) { | ||
columnHeaders.add(column.getText()); | ||
} | ||
tableData.add(columnHeaders); | ||
|
||
|
||
// Iterate over the rows in the table | ||
for (int row = 0; row < tableView.getItems().size(); row++) { | ||
List<String> rowData = new ArrayList<>(); | ||
|
||
// Iterate over the columns in each row | ||
for (TableColumn<?, ?> column : tableView.getColumns()) { | ||
Object cellValue = column.getCellData(row); | ||
String cellData = cellValue != null ? cellValue.toString() : ""; | ||
rowData.add(cellData); | ||
} | ||
|
||
tableData.add(rowData); | ||
} | ||
|
||
return tableData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.