Skip to content

Commit a92682f

Browse files
committed
Add Table View demo to the Primary Scene
Fix dependencies issue (the project Liberica JDK already includes JavaFx modules)
1 parent 20668a5 commit a92682f

File tree

13 files changed

+157
-16
lines changed

13 files changed

+157
-16
lines changed

javafx-oop-demo.iml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,5 @@
1010
</content>
1111
<orderEntry type="inheritedJdk" />
1212
<orderEntry type="sourceFolder" forTests="false" />
13-
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:11.0.2" level="project" />
14-
<orderEntry type="library" name="Maven: org.openjfx:javafx-controls:win:11.0.2" level="project" />
15-
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:11.0.2" level="project" />
16-
<orderEntry type="library" name="Maven: org.openjfx:javafx-graphics:win:11.0.2" level="project" />
17-
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:11.0.2" level="project" />
18-
<orderEntry type="library" name="Maven: org.openjfx:javafx-base:win:11.0.2" level="project" />
19-
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:11.0.2" level="project" />
20-
<orderEntry type="library" name="Maven: org.openjfx:javafx-fxml:win:11.0.2" level="project" />
2113
</component>
2214
</module>

src/main/java/com/sankdev/PrimaryController.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
package com.sankdev;
22

3+
import com.sankdev.portfolio.Item;
4+
import com.sankdev.portfolio.Portfolio;
35
import java.io.IOException;
6+
import java.net.URL;
7+
import java.util.List;
48
import java.util.ResourceBundle;
59
import javafx.fxml.FXML;
10+
import javafx.scene.control.TableColumn;
11+
import javafx.scene.control.TableView;
12+
import javafx.scene.control.cell.PropertyValueFactory;
613

714
public class PrimaryController {
815

16+
@FXML
17+
private TableView<Item> tableView;
18+
@FXML
19+
private TableColumn<Item, String> idCol;
20+
@FXML
21+
private TableColumn<Item, String> nameCol;
22+
23+
public PrimaryController() {
24+
System.out.println("===>>> Inside Primary Controller constructor");
25+
}
26+
27+
public void initialize() {
28+
System.out.println("===>>> Inside Primary Controller initialize() method");
29+
idCol.setCellValueFactory(new PropertyValueFactory<>("id"));
30+
nameCol.setCellValueFactory(new PropertyValueFactory<>("name"));
31+
32+
tableView.getItems().setAll(parseUserList());
33+
}
34+
35+
private List<Item> parseUserList() {
36+
// parse and construct User datamodel list by looping your ResultSet rs
37+
// and return the list
38+
Portfolio portfolio = new Portfolio();
39+
return portfolio.getItems();
40+
}
41+
942
@FXML
1043
private void switchToSecondary() throws IOException {
1144
App.setRoot("secondary");
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package com.sankdev.portfolio;
22

3-
public class Achievement extends Item {
3+
public abstract class Achievement extends Item {
44

5+
private String issuer;
6+
7+
public Achievement(String id, String name) {
8+
super(id, name);
9+
}
10+
11+
public String getIssuer() {
12+
return issuer;
13+
}
14+
15+
public void setIssuer(String issuer) {
16+
this.issuer = issuer;
17+
}
518
}

src/main/java/com/sankdev/portfolio/Certificate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
public class Certificate extends Achievement {
44

5+
public Certificate(String id, String name) {
6+
super(id, name);
7+
}
58
}

src/main/java/com/sankdev/portfolio/Diploma.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
public class Diploma extends Achievement {
44

5+
public Diploma(String id, String name) {
6+
super(id, name);
7+
}
58
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
package com.sankdev.portfolio;
22

3+
import java.util.Objects;
4+
35
public abstract class Item {
46

7+
private String id;
8+
9+
private String name;
10+
11+
public Item(String id, String name) {
12+
this.id = id;
13+
this.name = name;
14+
}
15+
16+
public String getId() {
17+
return id;
18+
}
19+
20+
public void setId(String id) {
21+
this.id = id;
22+
}
23+
24+
public String getName() {
25+
return name;
26+
}
27+
28+
public void setName(String name) {
29+
this.name = name;
30+
}
31+
32+
@Override
33+
public boolean equals(Object o) {
34+
if (this == o) {
35+
return true;
36+
}
37+
if (!(o instanceof Item)) {
38+
return false;
39+
}
40+
Item item = (Item) o;
41+
return id.equals(item.id) && name.equals(item.name);
42+
}
43+
44+
@Override
45+
public int hashCode() {
46+
return Objects.hash(id, name);
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return "Item{" +
52+
"id='" + id + '\'' +
53+
", name='" + name + '\'' +
54+
'}';
55+
}
556
}

src/main/java/com/sankdev/portfolio/Participation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
public class Participation extends Achievement {
44

5+
public Participation(String id, String name) {
6+
super(id, name);
7+
}
58
}

src/main/java/com/sankdev/portfolio/Patent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
public class Patent extends Achievement {
44

5+
public Patent(String id, String name) {
6+
super(id, name);
7+
}
58
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.sankdev.portfolio;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Portfolio {
7+
8+
private List<Item> items;
9+
10+
public Portfolio() {
11+
System.out.println("===>>> Inside Portfolio constructor");
12+
items = new ArrayList<>();
13+
items.add(new Certificate("Uni1", "My certificate"));
14+
items.add(new Diploma("Uni2", "Higher degree"));
15+
items.add(new Publication("1234", "Nature magazine article"));
16+
for (Item tempItem :
17+
items) {
18+
System.out.println(tempItem);
19+
}
20+
}
21+
22+
public List<Item> getItems() {
23+
return items;
24+
}
25+
}

src/main/java/com/sankdev/portfolio/Publication.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22

33
public class Publication extends Item {
44

5+
public Publication(String id, String name) {
6+
super(id, name);
7+
}
58
}

0 commit comments

Comments
 (0)