I'm working on a TableView who should display data from different kind of models. When I use one model everything works fine. But as soon as I add other models it turns out erroneous at OPTable.getColumns().addAll(...); . I can't make sense of the error description.
The method addAll(int, Collection<? extends TableColumn<capture#4-of ?,?>>) in the type List<TableColumn<capture#4-of ?,?>> is not applicable for the arguments (TableColumn<Ofenproben,String>, TableColumn<Ofenproben,String>, TableColumn<Auftrag,String>, TableColumn<Ofenproben,String>, TableColumn<ModelConverter,String>, TableColumn<ModelConverter,String>, TableColumn<ModelConverter,String>)
Here is my TableView:
TableView<?> OPTable= new TableView();
OPTable.setEditable(true);
OPTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
OPTable.setColumnResizePolicy((param) -> true );
TableColumn<Ofenproben, String> TLPCol = new TableColumn<Ofenproben, String>("TLP Typ");
TableColumn<Ofenproben, String> LosCol= new TableColumn<Ofenproben, String>("Losbezeichnung");
TableColumn<Auftrag, String> AKBCol = new TableColumn<Auftrag, String>("Auftragskurzbezeichnung");
AKBCol.setPrefWidth(350);
TableColumn<Ofenproben, String> ProbenNrCol = new TableColumn<Ofenproben, String>("Probennummer");
TableColumn<ModelConverter, String> OfenCol = new TableColumn<ModelConverter, String>("Ofen");
TableColumn<ModelConverter, String> PlatzNrCol = new TableColumn<ModelConverter, String>("Platz");
TableColumn<ModelConverter, String> ProbeFertigCol = new TableColumn<ModelConverter, String>("Proben fertig");
//Sub Columns
TableColumn<ModelConverter, Boolean> EinsCol = new TableColumn<ModelConverter, Boolean>("1");
TableColumn<ModelConverter, Boolean> ZweiCol = new TableColumn<ModelConverter, Boolean>("2");
TableColumn<ModelConverter, Boolean> DreiCol = new TableColumn<ModelConverter, Boolean>("3");
TableColumn<ModelConverter, Boolean> VierCol = new TableColumn<ModelConverter, Boolean>("4");
// Sub columns an Proben Fertig anfügen
ProbeFertigCol.getColumns().addAll(EinsCol, ZweiCol, DreiCol, VierCol);
//Daten einfügen von Klasse Ofenproben
TLPCol.setCellValueFactory(new PropertyValueFactory<>("TLP"));
LosCol.setCellValueFactory(new PropertyValueFactory<>("Los"));
AKBCol.setCellValueFactory(new PropertyValueFactory<>("AKB"));
ProbenNrCol.setCellValueFactory(new PropertyValueFactory<>("ProbenNr"));
OfenCol.setCellValueFactory(new PropertyValueFactory<>("Ofen"));
OfenCol.setCellFactory(TextFieldTableCell.<ModelConverter> forTableColumn());
OfenCol.setOnEditCommit((CellEditEvent<ModelConverter, String> event) -> {
TablePosition<ModelConverter, String> pos = event.getTablePosition();
String newOfen = event.getNewValue();
int row = pos.getRow();
ModelConverter mc = event.getTableView().getItems().get(row);
mc.setOfen(newOfen);
});
PlatzNrCol.setCellValueFactory(new PropertyValueFactory<>("PlatzNr"));
PlatzNrCol.setCellFactory(TextFieldTableCell.<ModelConverter> forTableColumn());
PlatzNrCol.setOnEditCommit((CellEditEvent<ModelConverter, String> event) -> {
TablePosition<ModelConverter, String> pos = event.getTablePosition();
String newStellplatz = event.getNewValue();
int row = pos.getRow();
ModelConverter mc = event.getTableView().getItems().get(row);
mc.setStellplatz(newStellplatz);
});
EinsCol.setCellValueFactory(new PropertyValueFactory<>("checked"));
ZweiCol.setCellValueFactory(new PropertyValueFactory<>("checked"));
DreiCol.setCellValueFactory(new PropertyValueFactory<>("checked"));
VierCol.setCellValueFactory(new PropertyValueFactory<>("checked"));
EinsCol.setCellFactory(CheckBoxTableCell.forTableColumn(EinsCol));
ZweiCol.setCellFactory(CheckBoxTableCell.forTableColumn(ZweiCol));
DreiCol.setCellFactory(CheckBoxTableCell.forTableColumn(DreiCol));
VierCol.setCellFactory(CheckBoxTableCell.forTableColumn(VierCol));
//ObservableList<ModelConverter> list = getProbenList();
//OPTable.setItems(list);
OPTable.getColumns().addAll(TLPCol, LosCol, AKBCol, ProbenNrCol, OfenCol, PlatzNrCol, ProbeFertigCol);
Please help and give me an code example to solve this problem.
Related
I come with a question regarding a LineChart. I have a LineChart with xAxis as a CategoryAxes where I have dates and the yAxis as a NumberAxis where I have some numbers.
My problem is that on the xAxis, the values shown under the chart are overlapped and I cannot find the cause.
Here is my code where I setup the LineChart and display it:
private void createSecondLineChart(String gameName) {
xAxis2 = new CategoryAxis();
xAxis2.setLabel("Dată");
yAxis2.setLabel("Încercări");
yAxis2.setAutoRanging(false);
yAxis2.setLowerBound(0);
yAxis2.setUpperBound(10);
yAxis2.setTickUnit(2);
lineChart2.setTitle("Statistică dată/încercări");
ObservableList<XYChart.Series<String, Number>> chartData = DBUtils.getFirstGameDateStats(Stats.username,
conn);
lineChart2.setData(chartData);
for (XYChart.Series<String, Number> series : chartData) {
for (XYChart.Data<String, Number> entry : series.getData()) {
String date = String.format("Data: %s\n", entry.getXValue());
String tries = String.format("Incercari: %s\n", entry.getYValue().intValue());
double dbAvgScore = DBUtils.getAverageScoreForUserInSpecificDate(Stats.username, entry.getXValue(),
conn);
String avgScore = String.format("Punctaj mediu: %.2f", dbAvgScore);
entry.getNode().setOnMouseEntered(event -> entry.getNode().setStyle("-fx-background-color: #0084b8;"));
entry.getNode().setOnMouseExited(event -> entry.getNode().setStyle(""));
String tooltipText = date + tries + avgScore;
Tooltip t = new Tooltip(tooltipText);
t.setShowDelay(javafx.util.Duration.millis(0));
Tooltip.install(entry.getNode(), t);
}
}
lineChart2.setLegendVisible(false);
lineChart2.setVisible(true);
}
I have a Model that accepts a row number, column, and its value. I want to populate a table view where the value of the column is pointing to the value in the Model on the current column. (Not a native English speaker, so sorry).
Here is what I have so far
public class DynamicTableView extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
ObservableList<TableData> observableList= FXCollections.observableArrayList(
new TableData(1, 1, 123.00),
new TableData(1, 2, 124.00),
new TableData(1, 3, 125.00),
new TableData(2, 1, 126.00),
new TableData(2, 2, 127.00),
new TableData(2, 3, 128.00),
new TableData(3, 1, 129.00),
new TableData(3, 2, 130.00),
new TableData(3, 3, 131.19)
);
TableView<TableData> tableView = new TableView<>(observableList);
//Creating columns
TableColumn<TableData, Short> colRow = new TableColumn<>("Row");
TableColumn<TableData, Double> colCol1 = new TableColumn<>("Column 1");
TableColumn<TableData, Double> colCol2 = new TableColumn<>("Column 2");
TableColumn<TableData, Double> colCol3 = new TableColumn<>("Column 3");
//Set the value
colRow.setCellValueFactory(new PropertyValueFactory<>("rowNumber"));
/* colCol1.setCellValueFactory(new PropertyValueFactory<>("value"));
colCol2.setCellValueFactory(new PropertyValueFactory<>("value"));
colCol3.setCellValueFactory(new PropertyValueFactory<>("value")); */
//add columns to table
tableView.getColumns().addAll(colRow, colCol1, colCol2, colCol3);
JFXButton button = new JFXButton("Add Data");
button.setOnAction (e-> {
observableList.add(new TableData(5, 1, 132.20));
});
VBox root = new VBox(10, button, tableView);
root.setAlignment(Pos.CENTER);
primaryStage.setScene(new Scene(root, 500, 300));
primaryStage.show();
}
public class TableData {
SimpleIntegerProperty rowNumber;
SimpleIntegerProperty columnNumber;
SimpleDoubleProperty value;
public TableData(int row, int col, double val) {
this.rowNumber = new SimpleIntegerProperty(row);
this.columnNumber = new SimpleIntegerProperty(col);
this.value = new SimpleDoubleProperty(val);
}
}
}
Expected Output
+-----+--------+--------+--------+
| Row | Col 1 | Col 2 | Col 3 |
+-----+--------+--------+--------+
| 1 | 123.00 | 124.00 | 125.00 |
+-----+--------+--------+--------+
| 2 | 126.00 | 127.00 | 128.00 |
+-----+--------+--------+--------+
| 3 | 129.00 | 130.00 | 131.19 |
+-----+--------+--------+--------+
I have seen this example https://stackoverflow.com/a/27497094/14660358, but I could hardly follow and implement it to my problem.
The only solution I have so far was to reconstruct my model to something like this :
public class TableData {
SimpleIntegerProperty rowNumber;
SimpleDoubleProperty column1;
SimpleDoubleProperty column2;
SimpleDoubleProperty column3;
public TableData(int row, double col1, double col2, double col3) {
this.rowNumber = new SimpleIntegerProperty(row);
this.column1 = new SimpleDoubleProperty(col1);
this.column2 = new SimpleDoubleProperty(col2);
this.column3 = new SimpleDoubleProperty(col3);
}
}
Then populate the table's column value property to
colCol1.setCellValueFactory(new PropertyValueFactory<>("column1"));
But I knew this is not a good programming practice. So I was hoping for someone to give atleast a much more detailed example if possible :)
PS: I'm still working on the question's title, so sorry if this misleads someone.
Given a dictionary of a directed graph, representing nested groups and their members, return all the users for a given group.
example-
Hashmap-
key|Values
Group1- [ Group3, Group5, User8, User2]
Group2 -[ Group1, User9]
Group3 -[ Group4, User5]
Group4 -[ User1, User3]
Group5 -[ User4, User7]
O/P should be :
group1 : [User1, User3,User5, User4, User7,User8, User2]
group2 : [User1, User3,User5, User6, User7,User8, User9]
group3: [User1, User3,User5]
group4: [User1, User3]
group5: [User4, User7]
I have tried in various way for example a recursive function, but I just ended scratching my head.
public static void main(String[] args) {
HashMap<String, List<String>> hmap = new HashMap<String,List<String>>();
List<String> l1 = new ArrayList<String>();
List<String> l2 = new ArrayList<String>();
List<String> l3 = new ArrayList<String>();
List<String> l4 = new ArrayList<String>();
List<String> l5 = new ArrayList<String>();
l1.add("group3"); l1.add("group5"); l1.add("user8"); l1.add("user2");
l2.add("group1"); l2.add("user9");
l3.add("group4"); l3.add("user5");
l4.add("user1"); l4.add("user3");
l5.add("user4"); l5.add("user9");
hmap.put("group1",l1);
hmap.put("group2",l2);
hmap.put("group3",l3);
hmap.put("group4",l4);
System.out.println(hmap);
flatten(hmap);
}
public static void flatten(HashMap<String, List<String>> hmap){
ArrayList<String> groups = new ArrayList<String>();
for(Entry<String,List<String>> entryset : hmap.entrySet()){
groups.add(entryset.getKey());
}
System.out.println(groups);
for(Entry<String,List<String>> entryset : hmap.entrySet()){
String s1 = entryset.getKey();
//HashSet<String> set1 = new HashSet<String>();
ArrayList<String> values = new ArrayList<String>();
values.addAll(entryset.getValue());
}
Here is one way to do it using Scala:
def run(): Unit =
{
/* Simply initializing the given data into User and Group classes */
val (u1, u2, u3, u4) = (new User("u1"), new User("u2"), new User("u3"), new User("u4"))
val (u5, u6, u7, u8, u9) = (new User("u5"), new User("u6"), new User("u7"), new User("u8"), new User("u9"))
val g5 = new Group(List(u4, u7))
val g4 = new Group(List(u1, u3))
val g3 = new Group(List(g4, u5))
val g1 = new Group(List(g3, g5, u8, u2))
val g2 = new Group(List(g1, u9))
/* Put the groups into a list */
var groups = List(g1, g2, g3, g4, g5)
/* Map/loop over each group, calling `resolveItems` on each */
groups = groups.map{_.resolveItems}
/* Print out each of the resolved groups */
groups.foreach{println}
}
/* A simple class representing the Group entity */
case class Group(var items: List[Any])
{
/*
Returns a new group by recursively resolving the items
in this group into only users
*/
def resolveItems: Group =
{
new Group(this.items.map{
// If the item is a group, resolve it into users
case g: Group => g.resolveItems
// If the item is a user, just move along
case u: User => u
}.distinct)
}
/* Override to string for pretty printing */
override
def toString: String = items.mkString(", ")
}
/* Simply class representing the user entity */
case class User(val name: String)
{
override
def toString : String = name
}
Output:
u1, u3, u5, u4, u7, u8, u2
u1, u3, u5, u4, u7, u8, u2, u9
u1, u3, u5
u1, u3
u4, u7
I am trying to create a TableView with 1 counter + 4 value columns. But for some unknown reason, columns val3, val4 are not getting populated in the tableview. I have updated the getVal2() method with "val3.get()", and I could see the val3 value in column of Value2. So, I suspect that there is some problem with reading to column Value3. I have also checked the naming convention/camel-casing. It looks fine to me. Can any help me fix this ?
ObservableList<Counters> data = FXCollections.observableArrayList();
Iterator<String> counterIterator = counterMap.keySet().iterator();
while(counterIterator.hasNext()) {
String counter = counterIterator.next();
String[] values = counterMap.get(counter);
String val1 = "a", val2 = "b", val3 = "c", val4 = "";
Counters counters = new Counters(counter, val1, val2, val3, val4);
data.add(counters);
}
TableView<Counters> table = new TableView<Counters>();
table.setEditable(true);
TableColumn<Counters, String> counter = new TableColumn<Counters, String>("Counter");
counter.setCellValueFactory(new PropertyValueFactory<Counters, String>("counter"));
TableColumn<Counters, String> val1 = new TableColumn<Counters, String>("Value1");
val1.setCellValueFactory(new PropertyValueFactory<Counters, String>("val1"));
TableColumn<Counters, String> val2 = new TableColumn<Counters, String>("Value2");
val2.setCellValueFactory(new PropertyValueFactory<Counters, String>("val2"));
TableColumn<Counters, String> val3 = new TableColumn<Counters, String>("Value3");
val3.setCellValueFactory(new PropertyValueFactory<Counters, String>("val3"));
TableColumn<Counters, String> val4 = new TableColumn<Counters, String>("Value4");
val3.setCellValueFactory(new PropertyValueFactory<Counters, String>("val4"));
table.getColumns().add(counter);
table.getColumns().add( val1);
table.getColumns().add( val2);
table.getColumns().add( val3);
table.getColumns().add( val4);
table.setItems(data);
public static class Counters {
private SimpleStringProperty counter, val1, val2, val3, val4;
public Counters(String counter, String val1, String val2, String val3, String val4) {
this.counter = new SimpleStringProperty(counter);
this.val1 = new SimpleStringProperty(val1);
this.val2 = new SimpleStringProperty(val2);
this.val3 = new SimpleStringProperty(val3);
this.val4 = new SimpleStringProperty(val4);
}
public String getCounter() {
return counter.get();
}
public void setCounter(String counter) {
this.counter.set(counter);
}
public String getVal1() {
return val1.get();
}
public void setVal1(String val1) {
this.val1.set(val1);
}
public String getVal2() {
return val2.get();
}
public void setVal2(String val2) {
this.val2.set(val2);
}
public String getVal3() {
return val3.get();
}
public void setVal3(String val3) {
this.val3.set(val3);
}
public String getVal4() {
return val4.get();
}
public void setVal4(String val4) {
this.val4.set(val4);
}
}
You have a copy-paste typo in
TableColumn<Counters, String> val4 = new TableColumn<Counters, String>("Value4");
val3.setCellValueFactory(new PropertyValueFactory<Counters, String>("val4"));
Should be
TableColumn<Counters, String> val4 = new TableColumn<Counters, String>("Value4");
val4.setCellValueFactory(new PropertyValueFactory<Counters, String>("val4"));
and val4 is always val4 = "" thats why it looks like they both are empty
In the below code i get all the ids in a arraylist and store it in a session in sample.aspx and retrieve the session value in test.aspx.Now i want to assign the project id to DataSet dsField in page load .How can i get that value separately.
sample.aspx
Button btnView = (Button)e.CommandSource;
Label lblProjectId = (Label)btnView.Parent.FindControl("ProjectID");
Label lblBatchID = (Label)btnView.Parent.FindControl("BatchID");
Label lblImageID = (Label)btnView.Parent.FindControl("ImageID");
Label lblReasons = (Label)btnView.Parent.FindControl("Reasons");
Label lblLayerID = (Label)btnView.Parent.FindControl("LayerID");
Label lblStatusID = (Label)btnView.Parent.FindControl("StatusID");
Label lblProcessID = (Label)btnView.Parent.FindControl("ProcessID");
ArrayList SearchUrlValues = new ArrayList();
SearchUrlValues.Add(lblProjectId);
SearchUrlValues.Add(lblBatchID);
SearchUrlValues.Add(lblProjectId);
SearchUrlValues.Add(lblImageID);
SearchUrlValues.Add(lblReasons);
SearchUrlValues.Add(lblLayerID);
SearchUrlValues.Add(lblStatusID);
SearchUrlValues.Add(lblProcessID);
Session["ProjectDetails"] = SearchUrlValues.ToArray();
Response.Write(SearchUrlValues);
test.aspx:
Array SearchUrlValues = (Array)Session["ProjectDetails"];
if (!IsPostBack)
{
DataSet dsField = GetFieldData(10);//how to assign projectid instead of 10
gmasFieldsContr.dtFieldsInfo = dsField.Tables[0];
gmasFieldsContr.EnumTable = dsField.Tables[1];
gmasFieldsContr.RegularExpressionTable = dsField.Tables[3];
gmasFieldsContr.BindData();
}
public DataSet GetFieldData(int iProjectID)
{
try
{
SqlParameter[] SqlParam = new SqlParameter[1];
SqlParam[0] = new SqlParameter("#i_ProjectID", SqlDbType.Int);
SqlParam[0].Value = iProjectID;
return ExecuteQuery(SqlParam, "spGetFieldData");
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
Edited
In Sample.aspx don't store SearchUrlValues as Array
Button btnView = (Button)e.CommandSource;
Label lblProjectId = (Label)btnView.Parent.FindControl("ProjectID");
Label lblBatchID = (Label)btnView.Parent.FindControl("BatchID");
Label lblImageID = (Label)btnView.Parent.FindControl("ImageID");
Label lblReasons = (Label)btnView.Parent.FindControl("Reasons");
Label lblLayerID = (Label)btnView.Parent.FindControl("LayerID");
Label lblStatusID = (Label)btnView.Parent.FindControl("StatusID");
Label lblProcessID = (Label)btnView.Parent.FindControl("ProcessID");
ArrayList SearchUrlValues = new ArrayList();
SearchUrlValues.Add(lblProjectId);
SearchUrlValues.Add(lblBatchID);
SearchUrlValues.Add(lblProjectId);
SearchUrlValues.Add(lblImageID);
SearchUrlValues.Add(lblReasons);
SearchUrlValues.Add(lblLayerID);
SearchUrlValues.Add(lblStatusID);
SearchUrlValues.Add(lblProcessID);
Session["ProjectDetails"] = SearchUrlValues; // Store it as ArrayList
Response.Write(SearchUrlValues);
Then test.aspx, convert Session object to ArrayList;
var SearchUrlValues = (ArrayList)Session["ProjectDetails"];
if (!IsPostBack)
{
var projectId = int.Parse(SearchUrlValues[0].ToString());
DataSet dsField = GetFieldData(projectId);//how to assign projectid instead of 10
gmasFieldsContr.dtFieldsInfo = dsField.Tables[0];
gmasFieldsContr.EnumTable = dsField.Tables[1];
gmasFieldsContr.RegularExpressionTable = dsField.Tables[3];
gmasFieldsContr.BindData();
}
By the way, please note that you're adding lblProjectId twice;
SearchUrlValues.Add(lblProjectId); // First
SearchUrlValues.Add(lblBatchID);
SearchUrlValues.Add(lblProjectId); // Second
Additionally, I would prefer to use an object to store these values in the session.
public class SearchUrlValues
{
public int lblProjectId { get; set; }
public int lblBatchID { get; set; }
public int lblImageID { get; set; }
public int lblReasons { get; set; }
public int lblLayerID { get; set; }
public int lblStatusID { get; set; }
public int lblProcessID { get; set; }
}
Then, instead of arraylist;
var newSearchUrlValues = new SearchUrlValues()
{
lblProjectId = lblProjectId,
lblBatchID = lblBatchID,
lblImageID = lblImageID,
lblReasons = lblReasons,
lblLayerID = lblLayerID,
lblStatusID = lblStatusID,
lblProcessID = lblProcessID
};
Session["ProjectDetails"] = newSearchUrlValues;
And retrieve it like;
var searchUrlValues = (SearchUrlValues)Session["ProjectDetails"];
var projectId = searchUrlValues.lblProjectId;
Try Like This
ArrayList SearchUrlValues = (ArrayList)Session["ProjectDetails"];
if (!IsPostBack)
{
DataSet dsField = GetFieldData(Convert.ToInt32(SearchUrlValues[0].ToString()));
//fetech 1st element of array List
gmasFieldsContr.dtFieldsInfo = dsField.Tables[0];
gmasFieldsContr.EnumTable = dsField.Tables[1];
gmasFieldsContr.RegularExpressionTable = dsField.Tables[3];
gmasFieldsContr.BindData();
}
public DataSet GetFieldData(int iProjectID)
{
try
{
SqlParameter[] SqlParam = new SqlParameter[1];
SqlParam[0] = new SqlParameter("#i_ProjectID", SqlDbType.Int);
SqlParam[0].Value = iProjectID;
return ExecuteQuery(SqlParam, "spGetFieldData");
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}