Skip to content

Commit 58d9eed

Browse files
committed
devonfw#1454 templateset files read from a temporary folder
ModifyableTemplateSet to add names of the template-set-file increments processed in treeview
1 parent 3c13c13 commit 58d9eed

File tree

11 files changed

+250
-49
lines changed

11 files changed

+250
-49
lines changed

cobigen/gui/src/main/java/com/devonfw/cobigen/gui/App.java

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public void start(Stage primaryStage) throws IOException {
7575
this.window = new Stage();
7676
Parent root = FXMLLoader.load(getClass().getResource("fxml/Primary.fxml"));
7777

78+
System.out.println(1);
7879
App.scene = new Scene(root);
7980
App.scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm());
8081

@@ -83,6 +84,7 @@ public void start(Stage primaryStage) throws IOException {
8384
this.window.getIcons().add(image);
8485
this.window.initStyle(StageStyle.TRANSPARENT);
8586
this.window.setResizable(true);
87+
8688
this.window.setScene(App.scene);
8789
this.window.showAndWait();
8890
}

cobigen/gui/src/main/java/com/devonfw/cobigen/gui/Controller.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import java.io.IOException;
44
import java.net.URL;
5+
import java.util.List;
56
import java.util.ResourceBundle;
67

78
import com.devonfw.cobigen.gui.controllers.DetailsController;
89
import com.devonfw.cobigen.gui.controllers.HomeController;
910
import com.devonfw.cobigen.gui.controllers.MenuController;
11+
import com.devonfw.cobigen.gui.services.TreeViewBuilder;
1012
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
13+
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSetIncrement;
1114

1215
import javafx.event.ActionEvent;
1316
import javafx.fxml.FXML;
@@ -90,21 +93,31 @@ public void loadHome(javafx.event.ActionEvent actionEvent) throws IOException {
9093
}
9194

9295
/**
96+
* Load increment from selected template-set from observable list
97+
*
9398
* @throws IOException
9499
*/
95100
public void loadDetails() throws IOException {
96101

97-
// TODO: getIncrements() for Tree View when #1517 is merged
98-
// Add parameter Increments
99-
102+
// selected from observable list
100103
TemplateSet selectedItem = this.menuController.searchResultsView.getSelectionModel().getSelectedItem();
101-
102104
if (selectedItem == null) {
103105
this.home.setVisible(true);
104106
this.details.setVisible(false);
105107
} else {
106108
this.home.setVisible(false);
107109
this.details.setVisible(true);
110+
111+
// Extract all increments from selected templateSet in list
112+
List<TemplateSetIncrement> templatesetIncrements = selectedItem.getTemplateSetConfiguration()
113+
.getTemplatesConfiguration().getIncrements().getIncrementList();
114+
115+
// icnrements converted to strings to make it ready for tree view builder
116+
String[] increments = TreeViewBuilder.transformIncrementsToArray(templatesetIncrements);
117+
118+
// shows the tree view of increments of selected template set
119+
this.detailsController.showTreeView(TreeViewBuilder.buildTreeView(increments));
120+
108121
// TODO
109122
this.detailsController.showName(selectedItem.getTemplateSetVersion());
110123
}

cobigen/gui/src/main/java/com/devonfw/cobigen/gui/controllers/DetailsController.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import java.util.List;
66
import java.util.ResourceBundle;
77

8-
import com.devonfw.cobigen.gui.services.TreeViewBuilder;
9-
108
import javafx.fxml.FXML;
119
import javafx.fxml.Initializable;
1210
import javafx.scene.control.Button;
@@ -42,8 +40,9 @@ public class DetailsController implements Initializable {
4240
@Override
4341
public void initialize(URL location, ResourceBundle resources) {
4442

43+
// increment section of the gui
4544
showVersion();
46-
showTreeView(TreeViewBuilder.buildTreeView(TreeViewBuilder.transformIncrementsToArray(this.INCREMENTS)));
45+
// showTreeView(TreeViewBuilder.buildTreeView(TreeViewBuilder.transformIncrementsToArray(this.INCREMENTS)));
4746

4847
}
4948

@@ -61,6 +60,7 @@ public void showName(String name) {
6160
*/
6261
private void showVersion() {
6362

63+
// is it the version used in templateSet or the snapshot version?
6464
// TODO: getVersion()
6565

6666
}
@@ -84,6 +84,7 @@ public void showTreeView(TreeView<String> treeView) {
8484
@FXML
8585
public void installTemplateSet(javafx.event.ActionEvent actionEvent) {
8686

87+
// What does it exactly mean by installing and where
8788
// TODO
8889
}
8990

@@ -93,6 +94,8 @@ public void installTemplateSet(javafx.event.ActionEvent actionEvent) {
9394
@FXML
9495
public void updateTemplateSet(javafx.event.ActionEvent actionEvent) {
9596

97+
// what model is previous and whats the new one
98+
9699
// TODO
97100
}
98101

@@ -102,6 +105,8 @@ public void updateTemplateSet(javafx.event.ActionEvent actionEvent) {
102105
@FXML
103106
public void uninstallTemplateSet(javafx.event.ActionEvent actionEvent) {
104107

108+
// what is referred to by the word uninstall.
109+
105110
// TODO
106111
}
107112

cobigen/gui/src/main/java/com/devonfw/cobigen/gui/controllers/MenuController.java

+16-21
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import java.util.ResourceBundle;
66

77
import com.devonfw.cobigen.gui.Controller;
8+
import com.devonfw.cobigen.gui.model.ModifyableTemplateSet;
9+
import com.devonfw.cobigen.gui.model.TemplateSetModel;
810
import com.devonfw.cobigen.gui.services.TemplateSetCell;
9-
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
1011

11-
import javafx.collections.FXCollections;
1212
import javafx.collections.ObservableList;
1313
import javafx.collections.transformation.FilteredList;
1414
import javafx.event.EventHandler;
@@ -25,8 +25,6 @@
2525
*/
2626
public class MenuController implements Initializable {
2727

28-
public ObservableList<TemplateSet> templateSetObservableList;
29-
3028
@FXML
3129
private Controller controller;
3230

@@ -43,25 +41,16 @@ public class MenuController implements Initializable {
4341
public Button goSearch;
4442

4543
@FXML
46-
public ListView<TemplateSet> searchResultsView;
44+
public ListView<ModifyableTemplateSet> searchResultsView;
45+
46+
private TemplateSetModel tsModel = new TemplateSetModel();
4747

4848
/**
4949
* The constructor.
5050
*/
5151
public MenuController() {
5252

53-
this.templateSetObservableList = FXCollections.observableArrayList();
54-
55-
// Add the template sets, populate observable list (before initialize)
56-
// this.templateSetObservableList.addAll(new TemplateSet("Template Set 1"), new TemplateSet("Template Set 2"),
57-
// new TemplateSet("Template Set 3"), new TemplateSet("Template Set 4"));
58-
59-
// Path templateSetFile = Paths.get(testdataRoot).resolve("template-set.xml");
60-
//
61-
// TemplateSetArtifactReader artifactReader = new TemplateSetArtifactReader();
62-
//
63-
// TemplateSet templateSet = artifactReader.retrieveTemplateSet(templateSetFile);
64-
//
53+
this.tsModel.loadallAvaliableTemplateSets();
6554
// List<TemplateSetTag> tagsList = new ArrayList<>();
6655
// tagsList.addAll(templateSet.getTemplateSetConfiguration().getContextConfiguration().getTags().getTagsList());
6756
}
@@ -80,8 +69,10 @@ public void injectController(Controller controller) {
8069
@Override
8170
public void initialize(URL location, ResourceBundle resources) {
8271

72+
// the line sets up the template cells in observable list
8373
this.searchResultsView.setCellFactory(resultsView -> new TemplateSetCell());
8474

75+
// home button brings back the previous state
8576
this.homeButton.setOnAction(event -> {
8677
try {
8778
this.controller.loadHome(event);
@@ -90,9 +81,10 @@ public void initialize(URL location, ResourceBundle resources) {
9081
}
9182
});
9283

93-
this.searchResultsView.setItems(this.templateSetObservableList);
84+
// binds the List with model
85+
this.searchResultsView.setItems(this.tsModel.getTemplateSetObservableList());
9486

95-
// Handle item selection
87+
// Load increments of selected template set
9688
this.searchResultsView.setOnMouseClicked(new EventHandler<MouseEvent>() {
9789

9890
@Override
@@ -107,9 +99,12 @@ public void handle(MouseEvent event) {
10799
});
108100

109101
// Initialize filtered List
110-
ObservableList<TemplateSet> listCopy = this.templateSetObservableList;
111-
FilteredList<TemplateSet> filteredData = new FilteredList<>(this.templateSetObservableList, b -> true);
112102

103+
ObservableList<ModifyableTemplateSet> listCopy = this.tsModel.getTemplateSetObservableList();
104+
FilteredList<ModifyableTemplateSet> filteredData = new FilteredList<>(this.tsModel.getTemplateSetObservableList(),
105+
b -> true);
106+
107+
// no idea what it does
113108
this.searchBar.textProperty().addListener((observable, oldValue, newValue) -> {
114109
filteredData.setPredicate(templateSets -> {
115110
// if no search value, then display all records or whatever records it currently has, no changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.devonfw.cobigen.gui.model;
2+
3+
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
4+
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSetConfiguration;
5+
6+
/**
7+
* TODO alsaad This type ...
8+
*
9+
*/
10+
public class ModifyableTemplateSet extends TemplateSet {
11+
12+
/**
13+
* The constructor.
14+
*
15+
* @param templateSetVersion
16+
* @param templateSetConfiguration
17+
* @param templateSet name
18+
*/
19+
public ModifyableTemplateSet(String templateSetVersion, TemplateSetConfiguration templateSetConfiguration,
20+
String name) {
21+
22+
super(templateSetVersion, templateSetConfiguration);
23+
this.name = name;
24+
}
25+
26+
private String name;
27+
28+
/**
29+
* @return name
30+
*/
31+
public String getName() {
32+
33+
return this.name;
34+
}
35+
36+
/**
37+
* @param name new value of {@link #getname}.
38+
*/
39+
public void setName(String name) {
40+
41+
this.name = name;
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.devonfw.cobigen.gui.model;
2+
3+
import java.nio.file.Path;
4+
import java.nio.file.Paths;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import com.devonfw.cobigen.retriever.ArtifactRetriever;
9+
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
10+
11+
import javafx.collections.FXCollections;
12+
import javafx.collections.ObservableList;
13+
14+
/**
15+
* TODO alsaad This type ...
16+
*
17+
*/
18+
public class TemplateSetModel {
19+
private final ObservableList<ModifyableTemplateSet> templateSetObservableList;
20+
21+
private List<String> templatesetNames = new ArrayList<>();
22+
23+
public TemplateSetModel() {
24+
25+
this.templateSetObservableList = FXCollections.observableArrayList();
26+
}
27+
28+
/**
29+
* @return templateSetObservableList
30+
*/
31+
public ObservableList<ModifyableTemplateSet> getTemplateSetObservableList() {
32+
33+
return this.templateSetObservableList;
34+
}
35+
36+
public void loadallAvaliableTemplateSets() {
37+
38+
// Load all the paths of template set from cobigen home folder or where?
39+
// How to access paths of all template sets and load it here
40+
/** Test data root path */
41+
final String testdataRoot = "src/main/resources/com/devonfw/cobigen/gui/TemplateSetArtifactReaderTest";
42+
List<ModifyableTemplateSet> mTS = new ArrayList<>();
43+
44+
List<Path> templateSetFiles = new ArrayList<>();
45+
templateSetFiles.add(Paths.get(testdataRoot).resolve("crud-java-server-app-2021.08.001-template-set.xml"));
46+
this.templatesetNames.add(templateSetFiles.get(0).getFileName().toString());
47+
templateSetFiles.add(Paths.get(testdataRoot).resolve("template-set.xml"));
48+
this.templatesetNames.add(templateSetFiles.get(1).getFileName().toString());
49+
50+
List<TemplateSet> templateSets = ArtifactRetriever.retrieveTemplateSetData(templateSetFiles);
51+
int i = 0;
52+
for (TemplateSet set : templateSets) {
53+
ModifyableTemplateSet mts = new ModifyableTemplateSet(set.getTemplateSetVersion(),
54+
set.getTemplateSetConfiguration(), this.templatesetNames.get(i++));
55+
mTS.add(mts);
56+
57+
}
58+
59+
this.templateSetObservableList.addAll(mTS);
60+
}
61+
62+
}

cobigen/gui/src/main/java/com/devonfw/cobigen/gui/services/TemplateSetCell.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.io.IOException;
44

5-
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
5+
import com.devonfw.cobigen.gui.model.ModifyableTemplateSet;
66

77
import javafx.fxml.FXML;
88
import javafx.fxml.FXMLLoader;
@@ -15,7 +15,7 @@
1515
* TODO nneuhaus This type ...
1616
*
1717
*/
18-
public class TemplateSetCell extends ListCell<TemplateSet> {
18+
public class TemplateSetCell extends ListCell<ModifyableTemplateSet> {
1919

2020
FXMLLoader loader;
2121

@@ -28,8 +28,9 @@ public class TemplateSetCell extends ListCell<TemplateSet> {
2828
@FXML
2929
private Button installButton;
3030

31+
// when this method suppose to be called
3132
@Override
32-
protected void updateItem(TemplateSet templateSet, boolean empty) {
33+
protected void updateItem(ModifyableTemplateSet templateSet, boolean empty) {
3334

3435
super.updateItem(templateSet, empty);
3536
if (empty || templateSet == null) {
@@ -38,7 +39,6 @@ protected void updateItem(TemplateSet templateSet, boolean empty) {
3839
setPrefHeight(45.0);
3940
} else {
4041
if (this.loader == null) {
41-
// FXMLLoader(getClass().getResource("com/devonfw/cobigen/gui))
4242
this.loader = new FXMLLoader(
4343
getClass().getClassLoader().getResource("com/devonfw/cobigen/gui/fxml/TemplateSetCell.fxml"));
4444
this.loader.setController(this);
@@ -49,10 +49,7 @@ protected void updateItem(TemplateSet templateSet, boolean empty) {
4949
e.printStackTrace();
5050
}
5151
}
52-
53-
// TODO:
54-
// this.titleLabel.setText(templateSet.getName());
55-
// setText(templateSet.getName());
52+
this.titleLabel.setText(templateSet.getName());
5653
this.installButton.setOnAction(event -> {
5754
System.out.println("INSTALLIEREN!!!");
5855
});

cobigen/gui/src/main/java/com/devonfw/cobigen/gui/services/TemplateSetCellFactory.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.devonfw.cobigen.gui.services;
22

3-
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;
3+
import com.devonfw.cobigen.gui.model.ModifyableTemplateSet;
44

55
import javafx.scene.control.ListCell;
66
import javafx.scene.control.ListView;
@@ -10,10 +10,11 @@
1010
* TODO nneuhaus This type ...
1111
*
1212
*/
13-
public class TemplateSetCellFactory implements Callback<ListView<TemplateSet>, ListCell<TemplateSet>> {
13+
public class TemplateSetCellFactory
14+
implements Callback<ListView<ModifyableTemplateSet>, ListCell<ModifyableTemplateSet>> {
1415

1516
@Override
16-
public ListCell<TemplateSet> call(ListView<TemplateSet> param) {
17+
public ListCell<ModifyableTemplateSet> call(ListView<ModifyableTemplateSet> param) {
1718

1819
return new TemplateSetCell();
1920
}

0 commit comments

Comments
 (0)