I have a requirement where in i am supposed to compare two csv files. For comparison , we are trying to implement a rules configuration. Now the Rules will have an object like the following :
public class CsvInformation {
private String resultType;
private List<String> primaryKey;
private List<String> standardKey;
private List<String> ignoreKey;
public String getResultType() {
return resultType;
}
public void setResultType(String resultType) {
this.resultType = resultType;
}
public List<String> getPrimaryKey() {
return primaryKey;
}
public void setPrimaryKey(List<String> primaryKey) {
this.primaryKey = primaryKey;
}
public List<String> getStandardKey() {
return standardKey;
}
public void setStandardKey(List<String> standardKey) {
this.standardKey = standardKey;
}
public List<String> getIgnoreKey() {
return ignoreKey;
}
public void setIgnoreKey(List<String> ignoreKey) {
this.ignoreKey = ignoreKey;
}
so i am fetching a list of CSVInformation objects.Now i'd like to map/bind these to a tableView control so that the user will get an option to select values for PrimaryKey,IgnoreKey,StandardKey through a comboBox control in a TableView Cell. The TableView Control should look something similar to the following snapshot.
In the snapshot above, i'd like to fill each row of the TableView with each object of the List of CsvInformation Objects which i am getting from the backEnd. Is this achievable . I googled a bit but everywhere they have mentioned they haven't been able to use a Collection for binding to a comboBox inside a TableView . Any advice/ pointers/ suggestion will be highly appreciated. Thanks
#James_D : Hi James, Thx for the reply. The primary idea is that the user will be given the optoin to select primary Key,Standard Key & Ignore Key so as to tell us which columns to include for comparison and which ones to ignore , which is the primary key etc. Once the user makes that selection for as many rows as are present in the TableView at that time, i need to save these and create a Json out of that.The requirement is such that the tableView needs to comprise of 4 columns : 1 label, 3 Non- Editable Combo-boxes. Now to answer your query on combo box, each combo-box will be unique in nature i.e the entries that'll fill the ComboBox inside the TableView, if i say Row 1 , primaryKey Combo - box will have String values such as Mohit,Neha,Neeraj. Now when i move to fill the fill the next row, i.e Row 2 primaryKey Combo - box will have values such as James,Jason,Bourne.What i am trying to achieve is to create these combo-boxes on the go by binding to a list. I'm attaching a snapshot here for the content of csvHeaderList.Each row in the TableView Content will be from each ondex of the CSVHeaderList. Please let me know if you need any more insights on this.
< TabelView code >
TableView<CsvInformation > table = new TableView<CsvInformation >();
// Create column Result Type (Data type of String).
TableColumn<CsvInformation , String> resultTypeCol = new TableColumn<CsvInformation , String>("Result Type");
// Create column Primary Column (Data type of List<String>).
TableColumn<CsvInformation , List<String>> primaryKeyCol = new TableColumn<CsvInformation , List<String>>("Primary Column");
// Create column Standard Column (Data type of List<String>).
TableColumn<CsvInformation , List<String>> standardCol = new TableColumn<CsvInformation , List<String>>("Standard Column");
// Create column for Ignorable Columns. (Data type of List<String>).
TableColumn<CsvInformation , List<String>> ignoredCol = new TableColumn<CsvInformation , List<String>>("Ignorable Columns");
PropertyValueFactory<CsvInformation , List<CsvInformation >> resultTypeColFactory = new PropertyValueFactory<>(
"resultType");
PropertyValueFactory<CsvInformation , List<CsvInformation >> primaryColFactory = new PropertyValueFactory<>(
"primaryKey");
PropertyValueFactory> standardColFactory = new PropertyValueFactory<>(
"standardKey");
PropertyValueFactory> compareColFactory = new PropertyValueFactory<>(
"ignoreKey");
// Defines how to fill data for each cell.
// Get value from property of CsvInformation.
resultTypeCol.setCellValueFactory(new PropertyValueFactory<>("resultType"));
primaryKeyCol.setCellValueFactory(new PropertyValueFactory<>("primaryKey"));
standardCol.setCellValueFactory(new PropertyValueFactory<>("standardKey"));
ignoredCol.setCellValueFactory(new PropertyValueFactory<>("ignoreKey"));
Where i'm stuck is how to provide my definition for Tablecolumn,Table Cell,Cellfactory for a collection / List like :
TableColumn for mapping my list to a combobox inside a TableView.
Related
I am quite new to entity framework and linq but basically I am using data first and my database has a table called tblNumbers and it has 2 columns, an id column and a numbers column which is populated with int values, I want to populate only the number values into my list but when I try do this I get an error saying that I cannot implicitly convert system.collections.generic.list< int> to system.collections.generic.list<projectname.Models.tblNumber>. I am not sure where to go from this, any help would be much appreciated.
Here is my code:
private DatabaseEntities db = new DatabaseEntities();
public ActionResult MyAction()
{
db.Configuration.ProxyCreationEnabled = false;
List<tblNumber> numbers = db.tblNumbers.Select(column => column.numbers).ToList();
return View();
}
Your List<tblNumber> numbers is expecting a list of tblNumber type and you are selecting column.numbers only
var numbers = db.tblNumbers.Select(column => column.numbers).ToList();
public class Customer {
private static int count = 1;
public Customer(String x, String y) {
super();
this.x = new Simple-String-Property(x);
this.y = new Simple-String-Property(y);
this.id = new Simple-Integer-Property(count);
count++;
}
I have an abstract table which populate data from database after the application start. So i want my id column auto increment after retrieving data. So i use the variable count for static and it work fine. However, when i submit the abstract data to table, the id column back to 1 even though the data on the table show up different number depending from populated database.
First of all, are those dashes in the class name?
Second, if the ID is the primary key it might actually be a feature that you can't change it.
Change primary key (id) of a row in a table and shift the others downwards
I've made an editable cell in my javafx table using http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/table-view.htm#CJAGAAEE, but whatever I try I cannot get the new value. Instead I always get the value in the first column using
firstNameCol.setOnEditCommit(
(CellEditEvent<Person, String> t) -> {
((Person) t.getTableView().getItems().get(
t.getTablePosition().getRow())
).setFirstName(t.getNewValue());
});
(The code example in the link above)
My code is large, its my project but roughly my code so far for this section is.
timeColumn.setCellFactory(TextFieldTableCell.forTableColumn());
timeColumn.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent>() {
#Override
public void handle(TableColumn.CellEditEvent event) {
tableView.getItems().get(event.getTablePosition().getRow());
}
});
I am editing a cell in row 1, column 2 but for some reason it is always returning the object in row 1 column 1 and not the new value in row 1 column 2.
Any advice?
I've event tried
tableView.getItems().get(event.getTablePosition().getRow()) + 1;
But this did not work
Based on #James_D comment above. If you want to get the first column's value then just do
column2.setOnEditCommit( e -> {
//here you can get the value of column1 corresponding to column2
System.out.println(e.getRowValue().getColumn1());
});
This should help you get the correct person.
TableView tempTable = (TableView)event.getTableView();
Person tempPerson = (Person)tempTable.getItems().get(event.getTablePosition().getRow());
tempPerson.setYourMethod(event.getNewValue());//maybe toString?
If your object is not a Person object, then replace Person with your object type.
I am newbie on javafx. I already code in core java to set value to table. But now i am converting my project in javafx to maintain code and to improve design.
I am trying to set value to table view but i am not getting how to set value to tableview.
Here is my code which i am using for swing.
String testbedName = treePath.getPathComponent(1).toString();
TestBed currentTestbed = getTbF().get(testbedName);
propertyTable.getModel().setValueAt(currentTestbed.getTestBedName(), 0, 1);
propertyTable.getModel().setValueAt(currentTestbed.getTestBedFilePath() + "\\" + testbedName + ".xml", 1, 1);
propertyTable.getModel().setValueAt(currentTestbed.getTbElements().size(), 2, 1);
But i need to convert this code in javafx means from JTable to TableView. but tableview not find getModel() method.
I search but didn't get how to set value to table view.
Please give me reference or hint.
Thanks in advance.
In JavaFX you generally don't set the values cell by cell like that. In your case, for example, you would
place your TestBeds in the table:
TableView<TestBed> table = new TableView<>();
table.getItems().addAll(yourTestBeds);
you then create the columns you need, by providing appropriate cell value factories, for example (using Java 8 syntax):
TableColumn<TestBed, String> name = new TableColumn<>();
name.setCellValueFactory(c-> new SimpleStringProperty(c.getValue().getTestBedName()));
If you use Java 7:
name.setCellValueFactory(new Callback<CellDataFeatures<TestBed, String>, ObservableValue<String>>() {
#Override public ObservableValue<String> call(CellDataFeatures<TestBed, String> c) {
return new SimpleStringProperty(c.getValue().getTestBedName()));
}
});
Finally you add the columns to the table:
table.getColumns().addAll(name, someOtherColumn);
Suppose we have a table with two columns, one for a string, the other for a number. To set programmatically the i-th item or row of the table, we can do like this:
//Define the string
String s = "myString" ;
//Define the number
int value = 5;
//Synthesize the item = row
Item item = new Item(s, value);
//Set the i-th item
table.getItems().set(i, item);
Is there a way to make sure the selected item is visible in the Spark DataGrid?
.
Context
I have a data grid bound to an array collection. I receive remotely a service that gives me a ID (string) of an object that is in the collection. Using just the string I loop through the collection to find the item that matches the string. I find the object by it's ID. Now I have the object I want to select in the datagrid. I can set the
dataGrid.selectedItem = object;
Now I need to make sure it's visible. I do not have the row or column index.
.
Update
Using the answer below I've complimented it with this function:
/**
* Ensures the item is visible (for spark data grid)
**/
public function ensureItemIsVisibleInSparkDataGrid(datagrid:spark.components.DataGrid, item:Object):void {
var list:IList = datagrid.dataProvider;
var length:int = list.length;
var itemFound:Boolean;
var object:Object;
var index:int;
for (var i:int;i<length;i++) {
object = list.getItemAt(i);
if (object==item) {
itemFound = true;
index = i;
break;
}
}
if (itemFound) {
datagrid.ensureCellIsVisible(index);
}
}
Yes, it's called ensureCellIsVisible(). You need to know that row and column of the item in question. To get this to work you'd need to listen for the selectionChange event then calculate the row and column of the currently selected item.